aboutsummaryrefslogtreecommitdiff
path: root/src/backend/optimizer/path/allpaths.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2018-08-01 19:42:46 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2018-08-01 19:42:52 -0400
commit1c2cb2744bf3d8ad751cd5cf3b347f10f48492b3 (patch)
tree78cbab7db4dacbac9f47b4c78974ba3c8f6c9184 /src/backend/optimizer/path/allpaths.c
parentc40489e449ea08e154cd62fa055785873f7bdac8 (diff)
downloadpostgresql-1c2cb2744bf3d8ad751cd5cf3b347f10f48492b3.tar.gz
postgresql-1c2cb2744bf3d8ad751cd5cf3b347f10f48492b3.zip
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
Diffstat (limited to 'src/backend/optimizer/path/allpaths.c')
-rw-r--r--src/backend/optimizer/path/allpaths.c27
1 files changed, 11 insertions, 16 deletions
diff --git a/src/backend/optimizer/path/allpaths.c b/src/backend/optimizer/path/allpaths.c
index f04c30af456..0e80aeb65cd 100644
--- a/src/backend/optimizer/path/allpaths.c
+++ b/src/backend/optimizer/path/allpaths.c
@@ -1388,7 +1388,6 @@ add_paths_to_append_rel(PlannerInfo *root, RelOptInfo *rel,
List *all_child_outers = NIL;
ListCell *l;
List *partitioned_rels = NIL;
- bool build_partitioned_rels = false;
double partial_rows = -1;
/* If appropriate, consider parallel append */
@@ -1413,10 +1412,11 @@ add_paths_to_append_rel(PlannerInfo *root, RelOptInfo *rel,
if (rel->part_scheme != NULL)
{
if (IS_SIMPLE_REL(rel))
- partitioned_rels = rel->partitioned_child_rels;
+ partitioned_rels = list_make1(rel->partitioned_child_rels);
else if (IS_JOIN_REL(rel))
{
int relid = -1;
+ List *partrels = NIL;
/*
* For a partitioned joinrel, concatenate the component rels'
@@ -1430,16 +1430,16 @@ add_paths_to_append_rel(PlannerInfo *root, RelOptInfo *rel,
component = root->simple_rel_array[relid];
Assert(component->part_scheme != NULL);
Assert(list_length(component->partitioned_child_rels) >= 1);
- partitioned_rels =
- list_concat(partitioned_rels,
+ partrels =
+ list_concat(partrels,
list_copy(component->partitioned_child_rels));
}
+
+ partitioned_rels = list_make1(partrels);
}
Assert(list_length(partitioned_rels) >= 1);
}
- else if (rel->rtekind == RTE_SUBQUERY)
- build_partitioned_rels = true;
/*
* For every non-dummy child, remember the cheapest path. Also, identify
@@ -1453,17 +1453,12 @@ add_paths_to_append_rel(PlannerInfo *root, RelOptInfo *rel,
Path *cheapest_partial_path = NULL;
/*
- * If we need to build partitioned_rels, accumulate the partitioned
- * rels for this child. We must ensure that parents are always listed
- * before their child partitioned tables.
+ * For UNION ALLs with non-empty partitioned_child_rels, accumulate
+ * the Lists of child relations.
*/
- if (build_partitioned_rels)
- {
- List *cprels = childrel->partitioned_child_rels;
-
- partitioned_rels = list_concat(partitioned_rels,
- list_copy(cprels));
- }
+ if (rel->rtekind == RTE_SUBQUERY && childrel->partitioned_child_rels != NIL)
+ partitioned_rels = lappend(partitioned_rels,
+ childrel->partitioned_child_rels);
/*
* If child has an unparameterized cheapest-total path, add that to