pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Guo <rguo@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Don't build child-join EC members that reference outside rels
Date: Mon, 26 Oct 2026 02:33:29 +0000
Message-ID: <E1xLAWf-00000000mLi-04vP@gemulon.postgresql.org> (raw)

Don't build child-join EC members that reference outside rels

add_child_join_rel_equivalences() built a child version of every
multi-relation EquivalenceClass member that overlapped the child
join's topmost parent relids.  For a member that also references a
relation outside the join, the child version is of no use for what
these members exist for, which is matching sort pathkeys of the child
join, since such a member cannot be computed there.

The only effect of these members was on the clauses generated for
parameterized child-join paths, and it was a harmful one.  Each child
join nested within a larger child join supplies its own version of
such a member, as does each rebuild of the same child join by GEQO.
These versions are all the same expression, yet
generate_join_implied_equalities() would equate them to each other,
producing redundant clauses that share one rinfo_serial and so trip
the assertion added by commit 8510bcc98.  Even a lone such member
could yield a join clause that duplicates a condition already enforced
by the inner path, as seen in an existing regression test whose plan
now loses a redundant join filter.

To fix, consider only members that can be computed at the child join's
topmost parent joinrel.  This matches what add_child_rel_equivalences()
has done for base relations since commit 2489d76c4.

In passing, simplify how both functions compute the child member's
relids.  Now that the parent member's relids are known to lie within
the parent rel, the child member's relids are simply the child rel's.

Back-patch to v19, as with commit 8510bcc98.

Reported-by: Alexander Lakhin <exclusion@gmail.com>
Author: Richard Guo <guofenglinux@gmail.com>
Discussion: https://postgr.es/m/4a0d7906-14f4-4992-8815-16e17e1f6655@gmail.com
Backpatch-through: 19

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/022a80fe6c1d82f7777bd52f9d3e5f9952533109

Modified Files
--------------
src/backend/optimizer/path/equivclass.c      |  35 +++-----
src/test/regress/expected/partition_join.out | 122 ++++++++++++++++++++++++++-
src/test/regress/sql/partition_join.sql      |  25 ++++++
3 files changed, 158 insertions(+), 24 deletions(-)



view thread (2+ messages)  latest in thread

Message-ID: <E1xLAWf-00000000mLi-04vP@gemulon.postgresql.org>
Permalink:  ../E1xLAWf-00000000mLi-04vP@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1xLAWf-00000000mLi-04vP@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: rguo@postgresql.org
  Subject: Re: pgsql: Don't build child-join EC members that reference outside rels
  In-Reply-To: <E1xLAWf-00000000mLi-04vP@gemulon.postgresql.org>
  References: <E1xLAWf-00000000mLi-04vP@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox