]> granicus.if.org Git - postgresql/commit
Fix run-time partition pruning for appends with multiple source rels.
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 1 Aug 2018 23:42:46 +0000 (19:42 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 1 Aug 2018 23:42:52 +0000 (19:42 -0400)
commit1c2cb2744bf3d8ad751cd5cf3b347f10f48492b3
tree78cbab7db4dacbac9f47b4c78974ba3c8f6c9184
parentc40489e449ea08e154cd62fa055785873f7bdac8
Fix run-time partition pruning for appends with multiple source rels.

The previous coding here supposed that if run-time partitioning applied to
a particular Append/MergeAppend plan, then all child plans of that node
must be members of a single partitioning hierarchy.  This is totally wrong,
since an Append could be formed from a UNION ALL: we could have multiple
hierarchies sharing the same Append, or child plans that aren't part of any
hierarchy.

To fix, restructure the related plan-time and execution-time data
structures so that we can have a separate list or array for each
partitioning hierarchy.  Also track subplans that are not part of any
hierarchy, and make sure they don't get pruned.

Per reports from Phil Florent and others.  Back-patch to v11, since
the bug originated there.

David Rowley, with a lot of cosmetic adjustments by me; thanks also
to Amit Langote for review.

Discussion: https://postgr.es/m/HE1PR03MB17068BB27404C90B5B788BCABA7B0@HE1PR03MB1706.eurprd03.prod.outlook.com
16 files changed:
src/backend/executor/execPartition.c
src/backend/executor/nodeAppend.c
src/backend/executor/nodeMergeAppend.c
src/backend/nodes/copyfuncs.c
src/backend/nodes/outfuncs.c
src/backend/nodes/readfuncs.c
src/backend/optimizer/path/allpaths.c
src/backend/optimizer/plan/createplan.c
src/backend/optimizer/plan/planner.c
src/backend/partitioning/partprune.c
src/include/executor/execPartition.h
src/include/nodes/nodes.h
src/include/nodes/plannodes.h
src/include/partitioning/partprune.h
src/test/regress/expected/partition_prune.out
src/test/regress/sql/partition_prune.sql