Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id CB6026338E0 for ; Mon, 4 Jan 2010 22:14:24 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 24560-09 for ; Tue, 5 Jan 2010 02:14:14 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail.postnewspapers.com.au (202-89-185-120.static.dsl.amnet.net.au [202.89.185.120]) by mail.postgresql.org (Postfix) with ESMTP id 05D086331E2 for ; Mon, 4 Jan 2010 22:14:08 -0400 (AST) Received: from localhost (access [127.0.0.1]) by mail.postnewspapers.com.au (Postfix) with ESMTP id B99C01E0437; Tue, 5 Jan 2010 10:14:03 +0800 (WST) X-Virus-Scanned: Debian amavisd-new at postnewspapers.com.au Received: from mail.postnewspapers.com.au ([127.0.0.1]) by localhost (access.postnewspapers.com.au [127.0.0.1]) (amavisd-new, port 10024) with LMTP id DmnBAyGhIk7f; Tue, 5 Jan 2010 10:14:02 +0800 (WST) Received: from [10.1.1.5] (124-169-133-89.dyn.iinet.net.au [124.169.133.89]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "Craig Ringer", Issuer "POST Certificate Authority" (verified OK)) by mail.postnewspapers.com.au (Postfix) with ESMTPSA id 0F0EE1E0436; Tue, 5 Jan 2010 10:14:02 +0800 (WST) Message-ID: <4B42A068.103@postnewspapers.com.au> Date: Tue, 05 Jan 2010 10:14:00 +0800 From: Craig Ringer User-Agent: Thunderbird 2.0.0.23 (X11/20090817) MIME-Version: 1.0 To: Erik Jones CC: Robert Haas , =?ISO-8859-1?Q?Keresztury_Bal=E1?= =?ISO-8859-1?Q?zs?= , pgsql-performance@postgresql.org Subject: Re: forced sequential scan when condition has current_user References: <000f01ca8d87$88e71f30$9ab55d90$@hu> <603c8f071001041359u58159c49k10587c7c46424672@mail.gmail.com> In-Reply-To: X-Enigmail-Version: 0.95.7 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.589 tagged_above=-10 required=5 tests=BAYES_00=-2.599, FH_DATE_PAST_20XX=3.188 X-Spam-Level: X-Archive-Number: 201001/36 X-Sequence-Number: 36916 Erik Jones wrote: > On Jan 4, 2010, at 1:59 PM, Robert Haas wrote: > >> The thing is, PostgreSQL doesn't know at planning time what the value of >> current_user() will be, so the plan can't depend on that; the planner >> just takes its best shot. > > current_user() is a stable function and the manual is explicit that the result of stable function can be used in an index scan: Yes ... but the planner doesn't know the value current_user will return, so it can't use its statistics on the frequency with which a _particular_ value occurs to make decisions. It has to come up with the best generic plan for any value that current_user might return. It's as if current_user were a query parameter that won't be resolved until EXECUTE time. Arguably, in this particular case the planner *could* know what value current_user will return, but adding such special cases to the planner without a really good reason seems undesirable. -- Craig Ringer