Skip to content

Commit 5472743

Browse files
committed
Revert "Move PartitionPruneInfo out of plan nodes into PlannedStmt"
This reverts commit ec38694 and its fixup 589bb81. This change was intended to support query planning avoiding acquisition of locks on partitions that were going to be pruned; however, the overall project took a different direction at [1] and this bit is no longer needed. Put things back the way they were as agreed in [2], to avoid unnecessary complexity. Discussion: [1] https://postgr.es/m/4191508.1674157166@sss.pgh.pa.us Discussion: [2] https://postgr.es/m/20230502175409.kcoirxczpdha26wt@alvherre.pgsql
1 parent 919c486 commit 5472743

File tree

16 files changed

+63
-135
lines changed

16 files changed

+63
-135
lines changed

src/backend/executor/execMain.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,6 @@ InitPlan(QueryDesc *queryDesc, int eflags)
824824
ExecInitRangeTable(estate, rangeTable, plannedstmt->permInfos);
825825

826826
estate->es_plannedstmt = plannedstmt;
827-
estate->es_part_prune_infos = plannedstmt->partPruneInfos;
828827

829828
/*
830829
* Next, build the ExecRowMark array from the PlanRowMark(s), if any.

src/backend/executor/execParallel.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ ExecSerializePlan(Plan *plan, EState *estate)
183183
pstmt->dependsOnRole = false;
184184
pstmt->parallelModeNeeded = false;
185185
pstmt->planTree = plan;
186-
pstmt->partPruneInfos = estate->es_part_prune_infos;
187186
pstmt->rtable = estate->es_range_table;
188187
pstmt->permInfos = estate->es_rteperminfos;
189188
pstmt->resultRelations = NIL;

src/backend/executor/execPartition.c

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1778,9 +1778,6 @@ adjust_partition_colnos_using_map(List *colnos, AttrMap *attrMap)
17781778
* Initialize data structure needed for run-time partition pruning and
17791779
* do initial pruning if needed
17801780
*
1781-
* 'root_parent_relids' identifies the relation to which both the parent plan
1782-
* and the PartitionPruneInfo given by 'part_prune_index' belong.
1783-
*
17841781
* On return, *initially_valid_subplans is assigned the set of indexes of
17851782
* child subplans that must be initialized along with the parent plan node.
17861783
* Initial pruning is performed here if needed and in that case only the
@@ -1793,24 +1790,11 @@ adjust_partition_colnos_using_map(List *colnos, AttrMap *attrMap)
17931790
PartitionPruneState *
17941791
ExecInitPartitionPruning(PlanState *planstate,
17951792
int n_total_subplans,
1796-
int part_prune_index,
1797-
Bitmapset *root_parent_relids,
1793+
PartitionPruneInfo *pruneinfo,
17981794
Bitmapset **initially_valid_subplans)
17991795
{
18001796
PartitionPruneState *prunestate;
18011797
EState *estate = planstate->state;
1802-
PartitionPruneInfo *pruneinfo;
1803-
1804-
/* Obtain the pruneinfo we need, and make sure it's the right one */
1805-
pruneinfo = list_nth(estate->es_part_prune_infos, part_prune_index);
1806-
if (!bms_equal(root_parent_relids, pruneinfo->root_parent_relids))
1807-
ereport(ERROR,
1808-
errcode(ERRCODE_INTERNAL_ERROR),
1809-
errmsg_internal("mismatching PartitionPruneInfo found at part_prune_index %d",
1810-
part_prune_index),
1811-
errdetail_internal("plan node relids %s, pruneinfo relids %s",
1812-
bmsToString(root_parent_relids),
1813-
bmsToString(pruneinfo->root_parent_relids)));
18141798

18151799
/* We may need an expression context to evaluate partition exprs */
18161800
ExecAssignExprContext(estate, planstate);

src/backend/executor/execUtils.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ CreateExecutorState(void)
123123
estate->es_rowmarks = NULL;
124124
estate->es_rteperminfos = NIL;
125125
estate->es_plannedstmt = NULL;
126-
estate->es_part_prune_infos = NIL;
127126

128127
estate->es_junkFilter = NULL;
129128

src/backend/executor/nodeAppend.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ ExecInitAppend(Append *node, EState *estate, int eflags)
134134
appendstate->as_begun = false;
135135

136136
/* If run-time partition pruning is enabled, then set that up now */
137-
if (node->part_prune_index >= 0)
137+
if (node->part_prune_info != NULL)
138138
{
139139
PartitionPruneState *prunestate;
140140

@@ -145,8 +145,7 @@ ExecInitAppend(Append *node, EState *estate, int eflags)
145145
*/
146146
prunestate = ExecInitPartitionPruning(&appendstate->ps,
147147
list_length(node->appendplans),
148-
node->part_prune_index,
149-
node->apprelids,
148+
node->part_prune_info,
150149
&validsubplans);
151150
appendstate->as_prune_state = prunestate;
152151
nplans = bms_num_members(validsubplans);

src/backend/executor/nodeMergeAppend.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ ExecInitMergeAppend(MergeAppend *node, EState *estate, int eflags)
8282
mergestate->ps.ExecProcNode = ExecMergeAppend;
8383

8484
/* If run-time partition pruning is enabled, then set that up now */
85-
if (node->part_prune_index >= 0)
85+
if (node->part_prune_info != NULL)
8686
{
8787
PartitionPruneState *prunestate;
8888

@@ -93,8 +93,7 @@ ExecInitMergeAppend(MergeAppend *node, EState *estate, int eflags)
9393
*/
9494
prunestate = ExecInitPartitionPruning(&mergestate->ps,
9595
list_length(node->mergeplans),
96-
node->part_prune_index,
97-
node->apprelids,
96+
node->part_prune_info,
9897
&validsubplans);
9998
mergestate->ms_prune_state = prunestate;
10099
nplans = bms_num_members(validsubplans);

src/backend/optimizer/plan/createplan.c

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,6 +1203,7 @@ create_append_plan(PlannerInfo *root, AppendPath *best_path, int flags)
12031203
ListCell *subpaths;
12041204
int nasyncplans = 0;
12051205
RelOptInfo *rel = best_path->path.parent;
1206+
PartitionPruneInfo *partpruneinfo = NULL;
12061207
int nodenumsortkeys = 0;
12071208
AttrNumber *nodeSortColIdx = NULL;
12081209
Oid *nodeSortOperators = NULL;
@@ -1353,9 +1354,6 @@ create_append_plan(PlannerInfo *root, AppendPath *best_path, int flags)
13531354
subplans = lappend(subplans, subplan);
13541355
}
13551356

1356-
/* Set below if we find quals that we can use to run-time prune */
1357-
plan->part_prune_index = -1;
1358-
13591357
/*
13601358
* If any quals exist, they may be useful to perform further partition
13611359
* pruning during execution. Gather information needed by the executor to
@@ -1379,14 +1377,16 @@ create_append_plan(PlannerInfo *root, AppendPath *best_path, int flags)
13791377
}
13801378

13811379
if (prunequal != NIL)
1382-
plan->part_prune_index = make_partition_pruneinfo(root, rel,
1383-
best_path->subpaths,
1384-
prunequal);
1380+
partpruneinfo =
1381+
make_partition_pruneinfo(root, rel,
1382+
best_path->subpaths,
1383+
prunequal);
13851384
}
13861385

13871386
plan->appendplans = subplans;
13881387
plan->nasyncplans = nasyncplans;
13891388
plan->first_partial_plan = best_path->first_partial_path;
1389+
plan->part_prune_info = partpruneinfo;
13901390

13911391
copy_generic_path_info(&plan->plan, (Path *) best_path);
13921392

@@ -1425,6 +1425,7 @@ create_merge_append_plan(PlannerInfo *root, MergeAppendPath *best_path,
14251425
List *subplans = NIL;
14261426
ListCell *subpaths;
14271427
RelOptInfo *rel = best_path->path.parent;
1428+
PartitionPruneInfo *partpruneinfo = NULL;
14281429

14291430
/*
14301431
* We don't have the actual creation of the MergeAppend node split out
@@ -1517,9 +1518,6 @@ create_merge_append_plan(PlannerInfo *root, MergeAppendPath *best_path,
15171518
subplans = lappend(subplans, subplan);
15181519
}
15191520

1520-
/* Set below if we find quals that we can use to run-time prune */
1521-
node->part_prune_index = -1;
1522-
15231521
/*
15241522
* If any quals exist, they may be useful to perform further partition
15251523
* pruning during execution. Gather information needed by the executor to
@@ -1535,13 +1533,13 @@ create_merge_append_plan(PlannerInfo *root, MergeAppendPath *best_path,
15351533
Assert(best_path->path.param_info == NULL);
15361534

15371535
if (prunequal != NIL)
1538-
node->part_prune_index = make_partition_pruneinfo(root, rel,
1539-
best_path->subpaths,
1540-
prunequal);
1536+
partpruneinfo = make_partition_pruneinfo(root, rel,
1537+
best_path->subpaths,
1538+
prunequal);
15411539
}
15421540

15431541
node->mergeplans = subplans;
1544-
1542+
node->part_prune_info = partpruneinfo;
15451543

15461544
/*
15471545
* If prepare_sort_from_pathkeys added sort columns, but we were told to

src/backend/optimizer/plan/planner.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,6 @@ standard_planner(Query *parse, const char *query_string, int cursorOptions,
522522
result->dependsOnRole = glob->dependsOnRole;
523523
result->parallelModeNeeded = glob->parallelModeNeeded;
524524
result->planTree = top_plan;
525-
result->partPruneInfos = glob->partPruneInfos;
526525
result->rtable = glob->finalrtable;
527526
result->permInfos = glob->finalrteperminfos;
528527
result->resultRelations = glob->resultRelations;

src/backend/optimizer/plan/setrefs.c

Lines changed: 30 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -350,29 +350,6 @@ set_plan_references(PlannerInfo *root, Plan *plan)
350350
palloc0(list_length(glob->subplans) * sizeof(bool));
351351
}
352352

353-
/* Also fix up the information in PartitionPruneInfos. */
354-
foreach(lc, root->partPruneInfos)
355-
{
356-
PartitionPruneInfo *pruneinfo = lfirst(lc);
357-
ListCell *l;
358-
359-
pruneinfo->root_parent_relids =
360-
offset_relid_set(pruneinfo->root_parent_relids, rtoffset);
361-
foreach(l, pruneinfo->prune_infos)
362-
{
363-
List *prune_infos = lfirst(l);
364-
ListCell *l2;
365-
366-
foreach(l2, prune_infos)
367-
{
368-
PartitionedRelPruneInfo *pinfo = lfirst(l2);
369-
370-
/* RT index of the table to which the pinfo belongs. */
371-
pinfo->rtindex += rtoffset;
372-
}
373-
}
374-
}
375-
376353
/* Now fix the Plan tree */
377354
result = set_plan_refs(root, plan, rtoffset);
378355

@@ -1728,29 +1705,6 @@ set_customscan_references(PlannerInfo *root,
17281705
cscan->custom_relids = offset_relid_set(cscan->custom_relids, rtoffset);
17291706
}
17301707

1731-
/*
1732-
* register_partpruneinfo
1733-
* Subroutine for set_append_references and set_mergeappend_references
1734-
*
1735-
* Add the PartitionPruneInfo from root->partPruneInfos at the given index
1736-
* into PlannerGlobal->partPruneInfos and return its index there.
1737-
*/
1738-
static int
1739-
register_partpruneinfo(PlannerInfo *root, int part_prune_index)
1740-
{
1741-
PlannerGlobal *glob = root->glob;
1742-
PartitionPruneInfo *pruneinfo;
1743-
1744-
Assert(part_prune_index >= 0 &&
1745-
part_prune_index < list_length(root->partPruneInfos));
1746-
pruneinfo = list_nth_node(PartitionPruneInfo, root->partPruneInfos,
1747-
part_prune_index);
1748-
1749-
glob->partPruneInfos = lappend(glob->partPruneInfos, pruneinfo);
1750-
1751-
return list_length(glob->partPruneInfos) - 1;
1752-
}
1753-
17541708
/*
17551709
* set_append_references
17561710
* Do set_plan_references processing on an Append
@@ -1803,12 +1757,21 @@ set_append_references(PlannerInfo *root,
18031757

18041758
aplan->apprelids = offset_relid_set(aplan->apprelids, rtoffset);
18051759

1806-
/*
1807-
* Add PartitionPruneInfo, if any, to PlannerGlobal and update the index.
1808-
*/
1809-
if (aplan->part_prune_index >= 0)
1810-
aplan->part_prune_index =
1811-
register_partpruneinfo(root, aplan->part_prune_index);
1760+
if (aplan->part_prune_info)
1761+
{
1762+
foreach(l, aplan->part_prune_info->prune_infos)
1763+
{
1764+
List *prune_infos = lfirst(l);
1765+
ListCell *l2;
1766+
1767+
foreach(l2, prune_infos)
1768+
{
1769+
PartitionedRelPruneInfo *pinfo = lfirst(l2);
1770+
1771+
pinfo->rtindex += rtoffset;
1772+
}
1773+
}
1774+
}
18121775

18131776
/* We don't need to recurse to lefttree or righttree ... */
18141777
Assert(aplan->plan.lefttree == NULL);
@@ -1870,12 +1833,21 @@ set_mergeappend_references(PlannerInfo *root,
18701833

18711834
mplan->apprelids = offset_relid_set(mplan->apprelids, rtoffset);
18721835

1873-
/*
1874-
* Add PartitionPruneInfo, if any, to PlannerGlobal and update the index.
1875-
*/
1876-
if (mplan->part_prune_index >= 0)
1877-
mplan->part_prune_index =
1878-
register_partpruneinfo(root, mplan->part_prune_index);
1836+
if (mplan->part_prune_info)
1837+
{
1838+
foreach(l, mplan->part_prune_info->prune_infos)
1839+
{
1840+
List *prune_infos = lfirst(l);
1841+
ListCell *l2;
1842+
1843+
foreach(l2, prune_infos)
1844+
{
1845+
PartitionedRelPruneInfo *pinfo = lfirst(l2);
1846+
1847+
pinfo->rtindex += rtoffset;
1848+
}
1849+
}
1850+
}
18791851

18801852
/* We don't need to recurse to lefttree or righttree ... */
18811853
Assert(mplan->plan.lefttree == NULL);

src/backend/partitioning/partprune.c

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -210,20 +210,16 @@ static void partkey_datum_from_expr(PartitionPruneContext *context,
210210

211211
/*
212212
* make_partition_pruneinfo
213-
* Checks if the given set of quals can be used to build pruning steps
214-
* that the executor can use to prune away unneeded partitions. If
215-
* suitable quals are found then a PartitionPruneInfo is built and tagged
216-
* onto the PlannerInfo's partPruneInfos list.
217-
*
218-
* The return value is the 0-based index of the item added to the
219-
* partPruneInfos list or -1 if nothing was added.
213+
* Builds a PartitionPruneInfo which can be used in the executor to allow
214+
* additional partition pruning to take place. Returns NULL when
215+
* partition pruning would be useless.
220216
*
221217
* 'parentrel' is the RelOptInfo for an appendrel, and 'subpaths' is the list
222218
* of scan paths for its child rels.
223219
* 'prunequal' is a list of potential pruning quals (i.e., restriction
224220
* clauses that are applicable to the appendrel).
225221
*/
226-
int
222+
PartitionPruneInfo *
227223
make_partition_pruneinfo(PlannerInfo *root, RelOptInfo *parentrel,
228224
List *subpaths,
229225
List *prunequal)
@@ -337,11 +333,10 @@ make_partition_pruneinfo(PlannerInfo *root, RelOptInfo *parentrel,
337333
* quals, then we can just not bother with run-time pruning.
338334
*/
339335
if (prunerelinfos == NIL)
340-
return -1;
336+
return NULL;
341337

342338
/* Else build the result data structure */
343339
pruneinfo = makeNode(PartitionPruneInfo);
344-
pruneinfo->root_parent_relids = parentrel->relids;
345340
pruneinfo->prune_infos = prunerelinfos;
346341

347342
/*
@@ -364,9 +359,7 @@ make_partition_pruneinfo(PlannerInfo *root, RelOptInfo *parentrel,
364359
else
365360
pruneinfo->other_subplans = NULL;
366361

367-
root->partPruneInfos = lappend(root->partPruneInfos, pruneinfo);
368-
369-
return list_length(root->partPruneInfos) - 1;
362+
return pruneinfo;
370363
}
371364

372365
/*

src/include/catalog/catversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@
5757
*/
5858

5959
/* yyyymmddN */
60-
#define CATALOG_VERSION_NO 202304211
60+
#define CATALOG_VERSION_NO 202305041
6161

6262
#endif

src/include/executor/execPartition.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ typedef struct PartitionPruneState
123123

124124
extern PartitionPruneState *ExecInitPartitionPruning(PlanState *planstate,
125125
int n_total_subplans,
126-
int part_prune_index,
127-
Bitmapset *root_parent_relids,
126+
PartitionPruneInfo *pruneinfo,
128127
Bitmapset **initially_valid_subplans);
129128
extern Bitmapset *ExecFindMatchingSubPlans(PartitionPruneState *prunestate,
130129
bool initial_prune);
130+
131131
#endif /* EXECPARTITION_H */

src/include/nodes/execnodes.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,6 @@ typedef struct EState
623623
* ExecRowMarks, or NULL if none */
624624
List *es_rteperminfos; /* List of RTEPermissionInfo */
625625
PlannedStmt *es_plannedstmt; /* link to top of plan tree */
626-
List *es_part_prune_infos; /* PlannedStmt.partPruneInfos */
627626
const char *es_sourceText; /* Source text from QueryDesc */
628627

629628
JunkFilter *es_junkFilter; /* top-level junk filter, if any */

src/include/nodes/pathnodes.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,6 @@ typedef struct PlannerGlobal
125125
/* "flat" list of AppendRelInfos */
126126
List *appendRelations;
127127

128-
/* List of PartitionPruneInfo contained in the plan */
129-
List *partPruneInfos;
130-
131128
/* OIDs of relations the plan depends on */
132129
List *relationOids;
133130

@@ -547,9 +544,6 @@ struct PlannerInfo
547544

548545
/* Does this query modify any partition key columns? */
549546
bool partColsUpdated;
550-
551-
/* PartitionPruneInfos added in this query's plan. */
552-
List *partPruneInfos;
553547
};
554548

555549

0 commit comments

Comments
 (0)