agora inbox for pgsql-committers@postgresql.orghelp / color / mirror / Atom feed
pgsql: Strip PlaceHolderVars from partition pruning operands 2+ messages / 1 participants [nested] [flat]
* pgsql: Strip PlaceHolderVars from partition pruning operands @ 2026-04-09 07:45 Richard Guo <rguo@postgresql.org> 0 siblings, 0 replies; 2+ messages in thread From: Richard Guo @ 2026-04-09 07:45 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Strip PlaceHolderVars from partition pruning operands When pulling up a subquery, its targetlist items may be wrapped in PlaceHolderVars to enforce separate identity or as a result of outer joins. This causes any upper-level WHERE clauses referencing these outputs to contain PlaceHolderVars, which prevents partprune.c from recognizing that they match partition key columns, defeating partition pruning. To fix, strip PlaceHolderVars from operands before comparing them to partition keys. A PlaceHolderVar with empty phnullingrels appearing in a relation-scan-level expression is effectively a no-op, so stripping it is safe. This parallels the existing treatment in indxpath.c for index matching. In passing, rename strip_phvs_in_index_operand() to strip_noop_phvs() and move it from indxpath.c to placeholder.c, since it is now a general-purpose utility used by both index matching and partition pruning code. Back-patch to v18. Although this issue exists before that, changes in that version made it common enough to notice. Given the lack of field reports for older versions, I am not back-patching further. In the v18 back-patch, strip_phvs_in_index_operand() is retained as a thin wrapper around the new strip_noop_phvs() to avoid breaking third-party extensions that may reference it. Reported-by: Cándido Antonio Martínez Descalzo <candido@ninehq.com> Diagnosed-by: David Rowley <dgrowleyml@gmail.com> Author: Richard Guo <guofenglinux@gmail.com> Discussion: https://postgr.es/m/CAH5YaUwVUWETTyVECTnhs7C=CVwi+uMSQH=cOkwAUqMdvXdwWA@mail.gmail.com Backpatch-through: 18 Branch ------ REL_18_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/8e8b2bef780e65102ac89260427181fb655c9c3b Modified Files -------------- src/backend/optimizer/path/indxpath.c | 86 ++--------------- src/backend/optimizer/plan/createplan.c | 2 +- src/backend/optimizer/util/placeholder.c | 91 ++++++++++++++++++ src/backend/partitioning/partprune.c | 28 ++++-- src/include/optimizer/placeholder.h | 1 + src/test/regress/expected/partition_prune.out | 132 ++++++++++++++++++++++++++ src/test/regress/sql/partition_prune.sql | 71 ++++++++++++++ 7 files changed, 324 insertions(+), 87 deletions(-) ^ permalink raw reply [nested|flat] 2+ messages in thread
* pgsql: Strip PlaceHolderVars from partition pruning operands @ 2026-04-09 07:45 Richard Guo <rguo@postgresql.org> 0 siblings, 0 replies; 2+ messages in thread From: Richard Guo @ 2026-04-09 07:45 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Strip PlaceHolderVars from partition pruning operands When pulling up a subquery, its targetlist items may be wrapped in PlaceHolderVars to enforce separate identity or as a result of outer joins. This causes any upper-level WHERE clauses referencing these outputs to contain PlaceHolderVars, which prevents partprune.c from recognizing that they match partition key columns, defeating partition pruning. To fix, strip PlaceHolderVars from operands before comparing them to partition keys. A PlaceHolderVar with empty phnullingrels appearing in a relation-scan-level expression is effectively a no-op, so stripping it is safe. This parallels the existing treatment in indxpath.c for index matching. In passing, rename strip_phvs_in_index_operand() to strip_noop_phvs() and move it from indxpath.c to placeholder.c, since it is now a general-purpose utility used by both index matching and partition pruning code. Back-patch to v18. Although this issue exists before that, changes in that version made it common enough to notice. Given the lack of field reports for older versions, I am not back-patching further. In the v18 back-patch, strip_phvs_in_index_operand() is retained as a thin wrapper around the new strip_noop_phvs() to avoid breaking third-party extensions that may reference it. Reported-by: Cándido Antonio Martínez Descalzo <candido@ninehq.com> Diagnosed-by: David Rowley <dgrowleyml@gmail.com> Author: Richard Guo <guofenglinux@gmail.com> Discussion: https://postgr.es/m/CAH5YaUwVUWETTyVECTnhs7C=CVwi+uMSQH=cOkwAUqMdvXdwWA@mail.gmail.com Backpatch-through: 18 Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/c1408956e393958cc93ef0dd622de406c7f3b8da Modified Files -------------- src/backend/optimizer/path/indxpath.c | 91 +----------------- src/backend/optimizer/plan/createplan.c | 2 +- src/backend/optimizer/util/placeholder.c | 91 ++++++++++++++++++ src/backend/partitioning/partprune.c | 28 ++++-- src/include/optimizer/paths.h | 1 - src/include/optimizer/placeholder.h | 1 + src/test/regress/expected/partition_prune.out | 132 ++++++++++++++++++++++++++ src/test/regress/sql/partition_prune.sql | 71 ++++++++++++++ 8 files changed, 320 insertions(+), 97 deletions(-) ^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2026-04-09 07:45 UTC | newest] Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2026-04-09 07:45 pgsql: Strip PlaceHolderVars from partition pruning operands Richard Guo <rguo@postgresql.org> 2026-04-09 07:45 pgsql: Strip PlaceHolderVars from partition pruning operands 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