Hans-Jürgen Schönig <postgres@cybertec.at> writes:
> Josh Berkus wrote:
>> Frankly, I don't think there *is* any safe way to use volatile functions in
>> subqueries -- I certainly avoid it, except now() and random() which as
>> discussed are special cases. Perhaps a WARNING is in order?
> Personally I like Josh's idea. A warning would be a nice thing.
From the planner's perspective, it would have to warn about any volatile
function, which would probably be overly chatty --- remember that the
default marking for user-defined functions is "volatile".
This default may also be a good reason not to put in the anti-flattening
defenses I suggested before, because it would mean that even slight
sloppiness in the definition of a user function could cripple subquery
optimization. I'm not sure that that's a strong argument, but it's
something to think about.
It'd be easy enough to put in the anti-flattening defenses (checks (1)
and (2) in my prior message) but I've got mixed emotions about whether
this is really a good thing to do. Any opinions out there?
regards, tom lane