Tighten nullingrels checks for outer joins When fixing up the targetlist and qpqual of an outer join, we must account for the effects of the outer join. Vars and PHVs appearing there are logically above the join, so they should have nullingrels equal to the input Vars/PHVs' nullingrels plus the bit added by the outer join.
Determining the effects of the outer join can be tricky when the join has been commuted with another one per outer join identity 3. In this case, the Vars/PHVs in the join's targetlist and qpqual should have the same nullingrels that they would if the two joins had been done in syntactic order. Unfortunately, in setrefs.c, we don't have enough information to identify what that should be, so we have to use superset nullingrels matches instead of exact ones. However, we can tighten the check somewhat. Currently, we check whether the jointype is JOIN_INNER and use NRM_SUPERSET if it is not. We can improve this by checking whether the Join node has non-empty ojrelids and using NRM_SUPERSET only in that case. This allows us to perform exact matches in more situations. To support this, we record the outer-join relids in Join plan nodes. This information can also improve EXPLAIN (RANGE_TABLE) output by showing which outer-join relids are completed by each Join plan node. We may discover additional uses for this information in the future. Author: Richard Guo <[email protected]> Discussion: https://postgr.es/m/cambws482_dfhzq079zpp6c8uvmfdz3jj+4k8tvru9g2bw34...@mail.gmail.com Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/4721430f199ffaf0936dc19bd473f34e8b1ee791 Modified Files -------------- contrib/pg_overexplain/expected/pg_overexplain.out | 40 ++++++++++++++++++++-- contrib/pg_overexplain/pg_overexplain.c | 14 ++++++++ contrib/pg_overexplain/sql/pg_overexplain.sql | 14 ++++++-- src/backend/optimizer/plan/createplan.c | 39 +++++++++++++++++++-- src/backend/optimizer/plan/setrefs.c | 18 +++++----- src/include/nodes/plannodes.h | 2 ++ 6 files changed, 111 insertions(+), 16 deletions(-)
