]> 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:53 +0000 (19:42 -0400)
commit1b54e91faabf3764b6786915881e514e42dccf89
treede03f8f7eff455000b7c2b14b8c2dac88e9ab60a
parent7326a7d63801673d3569def65cb7955d6486f254
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
15 files changed:
src/backend/executor/execPartition.c
src/backend/executor/nodeAppend.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