Re: Trivial function query optimized badly - Mailing list pgsql-performance

From Craig A. James
Subject Re: Trivial function query optimized badly
Date
Msg-id 459C93BC.30502@modgraph-usa.com
Whole thread Raw
In response to Re: Trivial function query optimized badly  ("Adam Rich" <adam.r@sbcglobal.net>)
List pgsql-performance
Adam Rich wrote:
> Craig,
> What version of postgres are you using?  I just tested this on PG 8.1.2
> and was unable to reproduce these results.  I wrote a simple function
> that returns the same text passed to it, after sleeping for 1 second.
> I use it in a where clause, like your example below, and regardless of
> the number of rows in the table, it still takes roughly 1 second,
> indicating to me the function is only called once.

Sorry, I forgot that critical piece of info: I'm using 8.1.4.

Your results would indicate that 8.1.2 creates a different plan than 8.1.4, or else there's some configuration
parameterthat's different between your installation and mine that causes a radically different plan to be used.  I
assumeyou vacuum/analyzed the table before you ran the query. 

> Is it possible that your function really isn't immutable? Would PG
> realize this and fall back to treating it as VOLATILE ?

Now that you say this, this seems more like a bug with the definition of IMMUTABLE.  The function should only be called
onceif it's given a constant string, right?  So the fact that Postgres called it once per row is just wrong. 

Craig


pgsql-performance by date:

Previous
From: "Adam Rich"
Date:
Subject: Re: Trivial function query optimized badly
Next
From: Tom Lane
Date:
Subject: Re: Trivial function query optimized badly