agora inbox for pgsql-committers@postgresql.org  
help / color / mirror / Atom feed
From: Richard Guo <rguo@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix duplicate enforcement of EC-derived conditions
Date: Thu, 10 Sep 2026 01:04:21 +0000
Message-ID: <E1x4TDA-00000004Csr-2s0R@gemulon.postgresql.org> (raw)

Fix duplicate enforcement of EC-derived conditions

A clause connecting the same two EC members can be requested from the
EC machinery in different contexts.  When building parameterized index
paths for a relation, generate_implied_equalities_for_column derives
an indexable clause with parent_ec set, to mark it as redundant with
other join clauses derived from the same EC.  Meanwhile, at a join
where the relations of a multi-relation EC member first come together,
generate_join_implied_equalities emits a clause equating the same two
members with parent_ec unset, since that clause is the sole enforcer
of its member there and must not be dropped as redundant.  Because
create_join_clause treats parent_ec as part of its cache-lookup key,
such requests can yield two different RestrictInfos for the same
condition, carrying different rinfo_serials.

This breaks the assumption that one condition has exactly one serial
number, which create_nestloop_path relies on to drop join clauses that
are already enforced within a parameterized inner path.  As a result,
the same condition could be enforced twice at different plan levels,
wasting execution effort and applying the clause's selectivity twice,
underestimating the join's row count.

To fix, make create_join_clause copy the rinfo_serial from an existing
clause that connects the same two members with the opposite parent_ec
marking, so that the two clauses keep their distinct markings but are
recognized as the same condition.

As a result, a duplicate join filter disappears from one of the
existing regression plans (the "cardinal_number" query in join.sql);
the other plan changes are join-order differences between plans of
essentially equal cost.

Author: Richard Guo <guofenglinux@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/CAMbWs4-3yZeBMGQDpmYRPdV-sL_=6H2AN=MoeneOT+VUk28PPg@mail.gmail.com
Backpatch-through: 19

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/895c1b5fe1ecaf3d0c5cb1ce5a85ab95e4c27dfb

Modified Files
--------------
src/backend/optimizer/path/equivclass.c | 15 ++++++++
src/test/regress/expected/join.out      | 63 ++++++++++++++++++++++++++-------
src/test/regress/sql/join.sql           | 24 +++++++++++++
3 files changed, 89 insertions(+), 13 deletions(-)



view thread (2+ messages)  latest in thread

Message-ID: <E1x4TDA-00000004Csr-2s0R@gemulon.postgresql.org>
Permalink:  ../E1x4TDA-00000004Csr-2s0R@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1x4TDA-00000004Csr-2s0R@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 using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: rguo@postgresql.org, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Fix duplicate enforcement of EC-derived conditions
  In-Reply-To: <E1x4TDA-00000004Csr-2s0R@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 agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox