pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Erik Jones <ejones@engineyard.com>
To: Robert Haas <robertmhaas@gmail.com>
Cc: Keresztury Balázs <balazs@gaslightmusic.hu>
Cc: pgsql-performance@postgresql.org
Subject: Re: forced sequential scan when condition has current_user
Date: Mon, 4 Jan 2010 15:13:43 -0800
Message-ID: <E56D1346-6E42-40D5-9CF1-239F5104F3A5@engineyard.com> (raw)
In-Reply-To: <603c8f071001041359u58159c49k10587c7c46424672@mail.gmail.com>
References: <000f01ca8d87$88e71f30$9ab55d90$@hu>
	<603c8f071001041359u58159c49k10587c7c46424672@mail.gmail.com>


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:

"A STABLE function cannot modify the database and is guaranteed to return the same results given the same arguments for all rows within a single statement. This category allows the optimizer to optimize multiple calls of the function to a single call. In particular, it is safe to use an expression containing such a function in an index scan condition. (Since an index scan will evaluate the comparison value only once, not once at each row, it is not valid to use a VOLATILE function in an index scan condition.)"

postgres=# select provolatile from pg_proc where proname = 'current_user';
 provolatile 
-------------
 s

So, I think the OP's question is still valid.

Erik Jones, Database Administrator
Engine Yard
Support, Scalability, Reliability
866.518.9273 x 260
Location: US/Pacific
IRC: mage2k








view thread (9+ messages)  latest in thread

Message-ID: <E56D1346-6E42-40D5-9CF1-239F5104F3A5@engineyard.com>
Permalink:  ../E56D1346-6E42-40D5-9CF1-239F5104F3A5@engineyard.com/
Also on:    postgresql.org/message-id/E56D1346-6E42-40D5-9CF1-239F5104F3A5@engineyard.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: ejones@engineyard.com, robertmhaas@gmail.com, balazs@gaslightmusic.hu
  Subject: Re: forced sequential scan when condition has current_user
  In-Reply-To: <E56D1346-6E42-40D5-9CF1-239F5104F3A5@engineyard.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox