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