Re: Stable function being evaluated more than once in a single query

From: "Jim C(dot) Nasby" <jnasby(at)pervasive(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Mark Liberman <mliberman(at)mixedsignals(dot)com>, pgsql-performance(at)postgresql(dot)org
Subject: Re: Stable function being evaluated more than once in a single query
Date: 2006-01-14 00:06:40
Message-ID: 20060114000640.GN9017@pervasive.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs pgsql-performance

On Wed, Jan 11, 2006 at 11:33:23PM -0500, Tom Lane wrote:
> Mark Liberman <mliberman(at)mixedsignals(dot)com> writes:
> > I've got a set-returning function, defined as STABLE, that I reference twice
> > within a single query, yet appears to be evaluated via two seperate function
> > scans.
>
> There is no guarantee, express or implied, that this won't be the case.
>
> (Seems like we just discussed this a couple days ago...)

Well, from 32.6:

"This category allows the optimizer to optimize away multiple calls of
the function within a single query."

That could certainly be read as indicating that if the function is used
twice in one query it could be optimized to one call.

Is the issue that the optimizer won't combine two function calls (ie:
SELECT foo(..) ... WHERE foo(..)), or is it that sometimes it won't make
the optimization (maybe depending on the query plan, for example)?
--
Jim C. Nasby, Sr. Engineering Consultant jnasby(at)pervasive(dot)com
Pervasive Software http://pervasive.com work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461

In response to

Responses

Browse pgsql-docs by date

  From Date Subject
Next Message Tom Lane 2006-01-14 00:27:28 Re: Stable function being evaluated more than once in a single query
Previous Message Anjan Kumar. A. 2006-01-12 23:05:45 Re: Please Help: PostgreSQL Query Optimizer

Browse pgsql-performance by date

  From Date Subject
Next Message Jim C. Nasby 2006-01-14 00:17:58 Re: Throwing unnecessary joins away
Previous Message Jim C. Nasby 2006-01-13 23:34:54 Re: Slow query with joins