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

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Jim C(dot) Nasby" <jnasby(at)pervasive(dot)com>
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:27:28
Message-ID: 16007.1137198448@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs pgsql-performance

"Jim C. Nasby" <jnasby(at)pervasive(dot)com> writes:
> 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)?

What the STABLE category actually does is give the planner permission to
use the function within an indexscan qualification, eg,
WHERE indexed_column = f(42)
Since an indexscan involves evaluating the comparison expression just
once and using its value to search the index, this would be incorrect
if the expression's value might change from row to row. (For VOLATILE
functions, we assume that the correct behavior is the naive SQL
semantics of actually computing the WHERE clause at each candidate row.)

There is no function cache and no checking for duplicate expressions.
I think we do check for duplicate aggregate expressions, but not
anything else.

regards, tom lane

In response to

Responses

Browse pgsql-docs by date

  From Date Subject
Next Message Jim C. Nasby 2006-01-14 00:43:48 Re: [PERFORM] Stable function being evaluated more than once in a single query
Previous Message Jim C. Nasby 2006-01-14 00:06:40 Re: Stable function being evaluated more than once in a single query

Browse pgsql-performance by date

  From Date Subject
Next Message Jim C. Nasby 2006-01-14 00:43:48 Re: [PERFORM] Stable function being evaluated more than once in a single query
Previous Message Jim C. Nasby 2006-01-14 00:22:05 Re: Throwing unnecessary joins away