Re: Trivial function query optimized badly

From: "Craig A(dot) James" <cjames(at)modgraph-usa(dot)com>
To: Adam Rich <adam(dot)r(at)sbcglobal(dot)net>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Trivial function query optimized badly
Date: 2007-01-04 05:42:20
Message-ID: 459C93BC.30502@modgraph-usa.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 parameter that's different between your installation and mine that causes a radically different plan to be used. I assume you 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 once if it's given a constant string, right? So the fact that Postgres called it once per row is just wrong.

Craig

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Tom Lane 2007-01-04 05:46:50 Re: Trivial function query optimized badly
Previous Message Adam Rich 2007-01-04 04:17:48 Re: Trivial function query optimized badly