pgsql: Tighten nullingrels checks for outer joins

From: Richard Guo <rguo(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Tighten nullingrels checks for outer joins
Date: 2026-07-08 03:02:40
Message-ID: E1whIYa-0005ZR-1K@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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 <guofenglinux(at)gmail(dot)com>
Discussion: https://postgr.es/m/CAMbWs482_DFHzQ079ZPp6c8UvmFdz3Jj+4K8tVRu9g2Bw34NPA@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(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Fujii Masao 2026-07-08 03:20:07 pgsql: pg_recvlogical: send final feedback on SIGINT/SIGTERM shutdown
Previous Message Erik Rijkers 2026-07-08 02:26:10 Re: pgsql: Cleanup comments/docs around the new shmem request callbacks