pgsql: Strip PlaceHolderVars from partition pruning operands

Поиск
Список
Период
Сортировка
От Richard Guo
Тема pgsql: Strip PlaceHolderVars from partition pruning operands
Дата
Msg-id E1wAk4S-0006wS-0k@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
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(-)


В списке pgsql-committers по дате отправления: