To prove that a forced-null Var is non-nullable in every matching row, reduce_outer_joins() uses the strict quals that hold for every row a subtree emits. The first pass currently gathers those quals into each subtree's state, so that the second pass need not re-walk the jointree at decision time. That duplicates find_subquery_safe_quals(), which already performs this traversal for query_outputs_are_not_nullable(), and it charges every query containing an outer join for a list build at every FromExpr and every inner or semi join, whether or not any upper qual turns out to force a Var null. Since each level copies what its children collected, the space required grows quadratically with the depth of nested inner joins. What it buys is small even then: the walk it avoids is cheap enough to be called on demand. So rename find_subquery_safe_quals() to find_safe_quals(), export it, and drop safe_quals from the first pass's state in favor of the subtree's jointree node. The second pass calls find_safe_quals() at the point where it needs the proof. Also stop treating a semijoin there like a left join: semijoins are reachable from the new caller, and a semijoin emits only matched left-hand rows, so its ON quals do hold for every output row. Author: Richard Guo <guofenglinux@gmail.com> Discussion: https://postgr.es/m/CAMbWs4-6FazY7+vCOvR0-vqNuaXOZic8O4D4ZrwMm2woi+Q3uA@mail.gmail.com
PostgreSQL Database Management System
This directory contains the source code distribution of the PostgreSQL database management system.
PostgreSQL is an advanced object-relational database management system that supports an extended subset of the SQL standard, including transactions, foreign keys, subqueries, triggers, user-defined types and functions. This distribution also contains C language bindings.
Copyright and license information can be found in the file COPYRIGHT.
General documentation about this version of PostgreSQL can be found at https://www.postgresql.org/docs/devel/. In particular, information about building PostgreSQL from the source code can be found at https://www.postgresql.org/docs/devel/installation.html.
The latest version of this software, and related software, may be obtained at https://www.postgresql.org/download/. For more information look at our web site located at https://www.postgresql.org/.