@@ -124,6 +124,7 @@ static BitmapHeapScan *create_bitmap_scan_plan(PlannerInfo *root,
124
124
static Plan * create_bitmap_subplan (PlannerInfo * root , Path * bitmapqual ,
125
125
List * * qual , List * * indexqual , List * * indexECs );
126
126
static void bitmap_subplan_mark_shared (Plan * plan );
127
+ static List * flatten_partitioned_rels (List * partitioned_rels );
127
128
static TidScan * create_tidscan_plan (PlannerInfo * root , TidPath * best_path ,
128
129
List * tlist , List * scan_clauses );
129
130
static SubqueryScan * create_subqueryscan_plan (PlannerInfo * root ,
@@ -202,7 +203,8 @@ static NamedTuplestoreScan *make_namedtuplestorescan(List *qptlist, List *qpqual
202
203
static WorkTableScan * make_worktablescan (List * qptlist , List * qpqual ,
203
204
Index scanrelid , int wtParam );
204
205
static Append * make_append (List * appendplans , int first_partial_plan ,
205
- List * tlist , List * partitioned_rels , List * partpruneinfos );
206
+ List * tlist , List * partitioned_rels ,
207
+ PartitionPruneInfo * partpruneinfo );
206
208
static RecursiveUnion * make_recursive_union (List * tlist ,
207
209
Plan * lefttree ,
208
210
Plan * righttree ,
@@ -1030,7 +1032,7 @@ create_append_plan(PlannerInfo *root, AppendPath *best_path)
1030
1032
List * subplans = NIL ;
1031
1033
ListCell * subpaths ;
1032
1034
RelOptInfo * rel = best_path -> path .parent ;
1033
- List * partpruneinfos = NIL ;
1035
+ PartitionPruneInfo * partpruneinfo = NULL ;
1034
1036
1035
1037
/*
1036
1038
* The subpaths list could be empty, if every child was proven empty by
@@ -1068,6 +1070,11 @@ create_append_plan(PlannerInfo *root, AppendPath *best_path)
1068
1070
subplans = lappend (subplans , subplan );
1069
1071
}
1070
1072
1073
+ /*
1074
+ * If any quals exist, they may be useful to perform further partition
1075
+ * pruning during execution. Gather information needed by the executor to
1076
+ * do partition pruning.
1077
+ */
1071
1078
if (enable_partition_pruning &&
1072
1079
rel -> reloptkind == RELOPT_BASEREL &&
1073
1080
best_path -> partitioned_rels != NIL )
@@ -1095,10 +1102,11 @@ create_append_plan(PlannerInfo *root, AppendPath *best_path)
1095
1102
* partition indexes into subpath indexes.
1096
1103
*/
1097
1104
if (prunequal != NIL )
1098
- partpruneinfos =
1099
- make_partition_pruneinfo (root ,
1105
+ partpruneinfo =
1106
+ make_partition_pruneinfo (root , rel ,
1107
+ best_path -> subpaths ,
1100
1108
best_path -> partitioned_rels ,
1101
- best_path -> subpaths , prunequal );
1109
+ prunequal );
1102
1110
}
1103
1111
1104
1112
/*
@@ -1110,7 +1118,7 @@ create_append_plan(PlannerInfo *root, AppendPath *best_path)
1110
1118
1111
1119
plan = make_append (subplans , best_path -> first_partial_path ,
1112
1120
tlist , best_path -> partitioned_rels ,
1113
- partpruneinfos );
1121
+ partpruneinfo );
1114
1122
1115
1123
copy_generic_path_info (& plan -> plan , (Path * ) best_path );
1116
1124
@@ -1218,7 +1226,8 @@ create_merge_append_plan(PlannerInfo *root, MergeAppendPath *best_path)
1218
1226
subplans = lappend (subplans , subplan );
1219
1227
}
1220
1228
1221
- node -> partitioned_rels = best_path -> partitioned_rels ;
1229
+ node -> partitioned_rels =
1230
+ flatten_partitioned_rels (best_path -> partitioned_rels );
1222
1231
node -> mergeplans = subplans ;
1223
1232
1224
1233
return (Plan * ) node ;
@@ -4968,6 +4977,27 @@ bitmap_subplan_mark_shared(Plan *plan)
4968
4977
elog (ERROR , "unrecognized node type: %d" , nodeTag (plan ));
4969
4978
}
4970
4979
4980
+ /*
4981
+ * flatten_partitioned_rels
4982
+ * Convert List of Lists into a single List with all elements from the
4983
+ * sub-lists.
4984
+ */
4985
+ static List *
4986
+ flatten_partitioned_rels (List * partitioned_rels )
4987
+ {
4988
+ List * newlist = NIL ;
4989
+ ListCell * lc ;
4990
+
4991
+ foreach (lc , partitioned_rels )
4992
+ {
4993
+ List * sublist = lfirst (lc );
4994
+
4995
+ newlist = list_concat (newlist , list_copy (sublist ));
4996
+ }
4997
+
4998
+ return newlist ;
4999
+ }
5000
+
4971
5001
/*****************************************************************************
4972
5002
*
4973
5003
* PLAN NODE BUILDING ROUTINES
@@ -5311,7 +5341,7 @@ make_foreignscan(List *qptlist,
5311
5341
static Append *
5312
5342
make_append (List * appendplans , int first_partial_plan ,
5313
5343
List * tlist , List * partitioned_rels ,
5314
- List * partpruneinfos )
5344
+ PartitionPruneInfo * partpruneinfo )
5315
5345
{
5316
5346
Append * node = makeNode (Append );
5317
5347
Plan * plan = & node -> plan ;
@@ -5322,8 +5352,8 @@ make_append(List *appendplans, int first_partial_plan,
5322
5352
plan -> righttree = NULL ;
5323
5353
node -> appendplans = appendplans ;
5324
5354
node -> first_partial_plan = first_partial_plan ;
5325
- node -> partitioned_rels = partitioned_rels ;
5326
- node -> part_prune_infos = partpruneinfos ;
5355
+ node -> partitioned_rels = flatten_partitioned_rels ( partitioned_rels ) ;
5356
+ node -> part_prune_info = partpruneinfo ;
5327
5357
return node ;
5328
5358
}
5329
5359
@@ -6480,7 +6510,7 @@ make_modifytable(PlannerInfo *root,
6480
6510
node -> operation = operation ;
6481
6511
node -> canSetTag = canSetTag ;
6482
6512
node -> nominalRelation = nominalRelation ;
6483
- node -> partitioned_rels = partitioned_rels ;
6513
+ node -> partitioned_rels = flatten_partitioned_rels ( partitioned_rels ) ;
6484
6514
node -> partColsUpdated = partColsUpdated ;
6485
6515
node -> resultRelations = resultRelations ;
6486
6516
node -> resultRelIndex = -1 ; /* will be set correctly in setrefs.c */
0 commit comments