agora inbox for pgsql-committers@postgresql.orghelp / color / mirror / Atom feed
pgsql: Fix duplicate qual clauses in parameterized paths 2+ messages / 1 participants [nested] [flat]
* pgsql: Fix duplicate qual clauses in parameterized paths @ 2026-09-07 02:52 Richard Guo <rguo@postgresql.org> 0 siblings, 0 replies; 2+ messages in thread From: Richard Guo @ 2026-09-07 02:52 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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(-) ^ permalink raw reply [nested|flat] 2+ messages in thread
* pgsql: Fix duplicate qual clauses in parameterized paths @ 2026-09-07 02:52 Richard Guo <rguo@postgresql.org> 0 siblings, 0 replies; 2+ messages in thread From: Richard Guo @ 2026-09-07 02:52 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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 ------ REL_19_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/2ad899642020ef7125818fddd494f5c76b928293 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(-) ^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2026-09-07 02:52 UTC | newest] Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2026-09-07 02:52 pgsql: Fix duplicate qual clauses in parameterized paths Richard Guo <rguo@postgresql.org> 2026-09-07 02:52 pgsql: Fix duplicate qual clauses in parameterized paths Richard Guo <rguo@postgresql.org>
This inbox is served by agora; see mirroring instructions for how to clone and mirror all data and code used for this inbox