Robert Haas <robertmhaas@gmail.com> writes:
> It still seems like awfully weird behavior.
Why? The WHERE condition relates only to the output of the _stats
subquery, so why shouldn't it be evaluated there, rather than after
the join?
In a green field I might agree that we should de-optimize such cases,
but the problem with doing so is that it would totally destroy
performance for cases in which a user has defined a function that's
actually stable or immutable but they forgot to mark it so. If
VOLATILE weren't the default marking, such a change wouldn't be so
problematic ... but it is. Given that the behavior has been like
this since the late stone age, I'm not inclined to change it.
regards, tom lane