I can't help pondering how 0001 collects the quals used to prove a forced-null Var non-nullable. Pass 1 gathers them into every subtree's state so that pass 2 doesn't have to re-walk the jointree at decision time.
Two things bother me about that. First, we already have this traversal: find_subquery_safe_quals() does the same job for query_outputs_are_not_nullable(). Two copies with the same rule seems like something we should avoid. Second, pass 1 builds a list at every FromExpr and every inner or semi join, for every query containing an outer join, and each level copies what its children collected, so in a deep chain of inner joins the same quals get copied over and over on the way up. What is worse, if there are no forced-null Vars in upper quals (which is quite common), all of the lists we build in pass 1 are just wasted. So I think a better approach is to keep just the jointree node in the pass 1 state, and have pass 2 call find_subquery_safe_quals() where it needs the proof. The walk is cheap enough to do on demand. Attached is a patch showing what I mean. - Richard
v1-0001-Collect-quals-for-outer-join-reduction-on-demand.patch
Description: Binary data
