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 qual clauses in parameterized paths
Date: Mon, 07 Sep 2026 02:52:50 +0000
Message-ID: <E1x3PTV-00000003n5W-0Bqt@gemulon.postgresql.org> (raw)

Fix duplicate qual clauses in parameterized paths

When outer-join identity 3 permits a join to commute with lower outer
joins, we generate multiple clone versions of its join clause, of
which only one should be applied in any given plan.  When building a
join relation's restriction list, subbuild_joinrel_restrictlist
selects the appropriate clone by checking required_relids and
incompatible_relids, but no such selection was made for movable join
clauses pushed down into a parameterized path.  As a result, a
parameterized scan or join could enforce more than one clone of the
same condition, shown by EXPLAIN as a duplicate qual.  This wastes
effort evaluating the same condition repeatedly.  What is worse, it
applies the clause's selectivity multiple times, underestimating the
result's row count.

To fix, in get_baserel_parampathinfo and get_joinrel_parampathinfo,
skip a clone clause if any outer join listed in its
incompatible_relids has already been computed below the point of
evaluation.

Back-patch to v19, but no further.  While this bug goes back to v16,
applying the fix in released branches risks destabilizing plans that
users are currently happy with, and there have been no field
complaints.

Author: Richard Guo <guofenglinux@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Tender Wang <tndrwang@gmail.com>
Discussion: https://postgr.es/m/CAMbWs4-g5TFF5k=jfe3JVWqtv_cCTOMmQRUp0_E8fApgqcqBng@mail.gmail.com
Backpatch-through: 19

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/f836b688f8dc627ce97760dec5569aa7c064ffe9

Modified Files
--------------
src/backend/optimizer/util/relnode.c | 14 ++++++++++
src/include/nodes/pathnodes.h        |  2 +-
src/test/regress/expected/join.out   | 51 +++++++++++++++++++++++++++++++++---
src/test/regress/sql/join.sql        | 22 ++++++++++++++++
4 files changed, 85 insertions(+), 4 deletions(-)



view thread (2+ messages)  latest in thread

Message-ID: <E1x3PTV-00000003n5W-0Bqt@gemulon.postgresql.org>
Permalink:  ../E1x3PTV-00000003n5W-0Bqt@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1x3PTV-00000003n5W-0Bqt@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 qual clauses in parameterized paths
  In-Reply-To: <E1x3PTV-00000003n5W-0Bqt@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