select (case when px is not null then pf = px
else pf is not distinct from py
end);
Every single time this function is called “px is not null” will be evaluated and then one of the two branches will be evaluated. Nothing the optimizer does will change that. The planner for the function internals does not know whether px will or will not be null on any given invocation.
David J.