Received: from maia.hub.org (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id D4708635783 for ; Mon, 12 Apr 2010 10:21:56 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 12996-08-2 for ; Mon, 12 Apr 2010 13:21:37 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-iw0-f187.google.com (mail-iw0-f187.google.com [209.85.223.187]) by mail.postgresql.org (Postfix) with ESMTP id 006DE6357F2 for ; Mon, 12 Apr 2010 10:21:39 -0300 (ADT) Received: by iwn17 with SMTP id 17so2200240iwn.19 for ; Mon, 12 Apr 2010 06:21:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:received:message-id:subject:from:to:cc:content-type; bh=bhIfvFI5InUkikJwc14DPiyuP/MTBa3Tnc0q2x7qqxU=; b=uxu+ZevkJK9TV2U4w0cw92RcHEyrdpnsbZXwrlo6iKaYHVvZIIUAXXL4TgeE36tS7i seMs7Mxrc61AMQ6C1sg5bvCrk1muQzVut1Pcd6MMZsmW4/GBPfKqkb77bVs39lQ/Hfh4 L+U80CMpSRioskhuMV3paNYthD1BvxtMZM2jw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=O+YtU6tRAZEGdEQwb//AizEHQCZqtozL2+pyfKOQKw5oKyJk+07yQhqeBQlCSwuXhQ +TfKhimJyAu3ga3p+tTk9wE7/TkHDjrZX18XQsbnQfwcMtoPss6oG6pfBxc12n57iaS6 qsuDUqVsVK/8dn1RY0L7mpuzYKCnxKgmpAgDk= MIME-Version: 1.0 Received: by 10.231.38.194 with HTTP; Mon, 12 Apr 2010 06:21:38 -0700 (PDT) In-Reply-To: <3BA4A0CF-11CE-4165-A97C-88FB1607EF87@silentmedia.com> References: <3BA4A0CF-11CE-4165-A97C-88FB1607EF87@silentmedia.com> Date: Mon, 12 Apr 2010 09:21:38 -0400 Received: by 10.231.148.18 with SMTP id n18mr1913476ibv.7.1271078498419; Mon, 12 Apr 2010 06:21:38 -0700 (PDT) Message-ID: Subject: Re: function performs differently with different values From: Robert Haas To: Ben Chobot Cc: PostgreSQL - Performance Content-Type: text/plain; charset=ISO-8859-1 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.157 tagged_above=-10 required=5 tests=AWL=-1.157 X-Spam-Level: X-Archive-Number: 201004/150 X-Sequence-Number: 38400 On Sat, Apr 10, 2010 at 4:47 PM, Ben Chobot wrote: > My understanding is that this generally happens because the plan should be different for the different values, but the first time the function is run it caches the plan for one of the values and will never use the appropriate plan for the second value. No, it plans based on a sort of "generic value", not the first one you supply. The way to get at that plan is: PREPARE foo AS ; EXPLAIN EXECUTE foo (parameters); ...Robert