Re: Should planner fold "stable" functions for estimation purposes? - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Should planner fold "stable" functions for estimation purposes?
Date
Msg-id 13889.1079139840@sss.pgh.pa.us
Whole thread Raw
In response to Should planner fold "stable" functions for estimation purposes?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Rod Taylor <rbt@rbt.ca> writes:
>> It would not be correct to reduce the righthand side to a constant in
>> advance of execution, of course, but is it reasonable to compute its
>> current value solely for purposes of comparison to column statistics?

> So this means it would be double evaluated? A flag will be required to
> prevent this for functions that do more than just return a value or have
> a high cost in execution.

Functions with side-effects had better be marked volatile anyway, so I'm
not worried about that case.  As for the expense argument, keep in mind
that the one extra evaluation in the planner is likely to save you an
awful lot of evaluations at runtime, if it convinces the planner to use
an indexscan and not a seqscan.  We are after all talking about
functions appearing in WHERE, and I wouldn't think that people can
reasonably expect those to get evaluated just once.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Should planner fold "stable" functions for estimation purposes?
Next
From: Tom Lane
Date:
Subject: Re: Log rotation