Re: function(contants) evaluated for every row - Mailing list pgsql-hackers

From Marti Raudsepp
Subject Re: function(contants) evaluated for every row
Date
Msg-id AANLkTikACkchLRvOZxJSP7_xxKZ29o4isy95NvNm7-0i@mail.gmail.com
Whole thread Raw
In response to Re: function(contants) evaluated for every row  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: function(contants) evaluated for every row
List pgsql-hackers
On Wed, Nov 24, 2010 at 21:52, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Bruce Momjian <bruce@momjian.us> writes:
>> Notice the to_date()'s were not converted to constants in EXPLAIN so
>> they are evaluated for every row.  to_date() is marked STABLE.

> No.  This is per expectation.  Only IMMUTABLE functions can be folded to
> constants in advance of the query.

This is something that has bit me in the past.

I realize that STABLE functions cannot be constant-folded at
planning-time. But are there good reasons why it cannot called only
once at execution-time?

As long as *only* STABLE or IMMUTABLE functions are used in a query,
we can assume that settings like timezone won't change in the middle
of the execution of a function, thus STABLE function calls can be
collapsed -- right?

Regards,
Marti


pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: profiling pgbench
Next
From: Peter Eisentraut
Date:
Subject: Re: Per-column collation, work in progress