Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit321f648

Browse files
committed
Assorted cosmetic cleanup of run-time-partition-pruning code.
Use "subplan" rather than "subnode" to refer to the child plans ofa partitioning Append; this seems a bit more specific and henceclearer. Improve assorted comments. No non-cosmetic changes.David Rowley and Tom LaneDiscussion:https://postgr.es/m/CAFj8pRBjrufA3ocDm8o4LPGNye9Y+pm1b9kCwode4X04CULG3g@mail.gmail.com
1 parent939449d commit321f648

File tree

7 files changed

+147
-156
lines changed

7 files changed

+147
-156
lines changed

‎src/backend/executor/execPartition.c

Lines changed: 77 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,9 +1334,9 @@ adjust_partition_tlist(List *tlist, TupleConversionMap *map)
13341334
* Run-Time Partition Pruning Support.
13351335
*
13361336
* The following series of functions exist to support the removal of unneeded
1337-
*subnodes for queries against partitioned tables. The supporting functions
1338-
* here are designed to work with anynode type which supports an arbitrary
1339-
* number ofsubnodes, e.g. Append, MergeAppend.
1337+
*subplans for queries against partitioned tables. The supporting functions
1338+
* here are designed to work with anyplan type which supports an arbitrary
1339+
* number ofsubplans, e.g. Append, MergeAppend.
13401340
*
13411341
* When pruning involves comparison of a partition key to a constant, it's
13421342
* done by the planner. However, if we have a comparison to a non-constant
@@ -1346,85 +1346,83 @@ adjust_partition_tlist(List *tlist, TupleConversionMap *map)
13461346
*
13471347
* We must distinguish expressions containing PARAM_EXEC Params from
13481348
* expressions that don't contain those. Even though a PARAM_EXEC Param is
1349-
* considered to be a stable expression, it can change value from onenode
1350-
* scan to the next during query execution. Stable comparison expressions
1351-
* that don't involve such Params allow partition pruning to be done once
1352-
* during executor startup. Expressions that do involve such Params require
1353-
* us to prune separately for each scan of the parent plan node.
1349+
* considered to be a stable expression, it can change value from oneplan
1350+
*nodescan to the next during query execution. Stable comparison
1351+
*expressionsthat don't involve such Params allow partition pruning to be
1352+
*done onceduring executor startup. Expressions that do involve such Params
1353+
*requireus to prune separately for each scan of the parent plan node.
13541354
*
1355-
* Note that pruning away unneededsubnodes during executor startup has the
1356-
* added benefit of not having to initialize the unneededsubnodes at all.
1355+
* Note that pruning away unneededsubplans during executor startup has the
1356+
* added benefit of not having to initialize the unneededsubplans at all.
13571357
*
13581358
*
13591359
* Functions:
13601360
*
13611361
* ExecSetupPartitionPruneState:
1362-
*This must be called by nodes before any partition pruning is
1363-
*attempted. Normally executor startup is a good time. This function
1364-
*creates the PartitionPruneState details which are required by each
1365-
*of the two pruning functions, details include information about
1366-
*how to map the partition index details which are returned by the
1367-
*planner's partition prune function into subnode indexes.
1362+
*Creates the PartitionPruneState required by each of the two pruning
1363+
*functions. Details stored include how to map the partition index
1364+
*returned by the partition pruning code into subplan indexes.
13681365
*
13691366
* ExecFindInitialMatchingSubPlans:
1370-
*Returns indexes of matchingsubnodes. Partition pruning is attempted
1367+
*Returns indexes of matchingsubplans. Partition pruning is attempted
13711368
*without any evaluation of expressions containing PARAM_EXEC Params.
1372-
*This function must be called during executor startup for thegiven
1373-
*node before thesubnodes themselves are initialized.Subnodes which
1374-
*are found not to match by this function mustnotbeincluded in the
1375-
*node's list ofsubnodesas this function performs a remap of the
1376-
*partition index to subplan index map and the newly created map
1377-
*provides indexes only forsubnodes which remain after calling this
1378-
*function.
1369+
*This function must be called during executor startup for theparent
1370+
*plan before thesubplans themselves are initialized.Subplans which
1371+
*are found not to match by this function must beremoved from the
1372+
*plan's list ofsubplans during execution,as this function performs a
1373+
*remap of thepartition index to subplan index map and the newly
1374+
*created mapprovides indexes only forsubplans which remain after
1375+
*calling thisfunction.
13791376
*
13801377
* ExecFindMatchingSubPlans:
1381-
*Returns indexes of matching subnodes after evaluating all available
1382-
*expressions. This function can only be called while the executor is
1383-
*running.
1378+
*Returns indexes of matching subplans after evaluating all available
1379+
*expressions. This function can only be called during execution and
1380+
*must be called again each time the value of a Param listed in
1381+
*PartitionPruneState's 'execparamids' changes.
13841382
*-------------------------------------------------------------------------
13851383
*/
13861384

13871385
/*
13881386
* ExecSetupPartitionPruneState
1389-
*Setuptherequireddata structure which is required for calling
1387+
*Set upthe data structure required for calling
13901388
*ExecFindInitialMatchingSubPlans and ExecFindMatchingSubPlans.
13911389
*
1390+
* 'planstate' is the parent plan node's execution state.
1391+
*
13921392
* 'partitionpruneinfo' is a List of PartitionPruneInfos as generated by
1393-
* make_partition_pruneinfo. Here we build aPartitionPruneContext for each
1394-
* item inthe List.These contexts can be re-used each time we re-evaulate
1395-
* which partitions match the pruning steps provided in each
1396-
* PartitionPruneInfo.
1393+
* make_partition_pruneinfo. Here we build aPartitionPruneState containing a
1394+
*PartitionPruningData for eachitem inthat List.This data can be re-used
1395+
*each time we re-evaluatewhich partitions match the pruning steps provided
1396+
*in eachPartitionPruneInfo.
13971397
*/
13981398
PartitionPruneState*
13991399
ExecSetupPartitionPruneState(PlanState*planstate,List*partitionpruneinfo)
14001400
{
1401-
PartitionPruningData*prunedata;
14021401
PartitionPruneState*prunestate;
1402+
PartitionPruningData*prunedata;
14031403
ListCell*lc;
14041404
inti;
14051405

14061406
Assert(partitionpruneinfo!=NIL);
14071407

1408+
/*
1409+
* Allocate the data structure
1410+
*/
14081411
prunestate= (PartitionPruneState*)palloc(sizeof(PartitionPruneState));
14091412
prunedata= (PartitionPruningData*)
14101413
palloc(sizeof(PartitionPruningData)*list_length(partitionpruneinfo));
14111414

1412-
/*
1413-
* The first item in the array contains the details for the query's target
1414-
* partition, so record that as the root of the partition hierarchy.
1415-
*/
14161415
prunestate->partprunedata=prunedata;
14171416
prunestate->num_partprunedata=list_length(partitionpruneinfo);
14181417
prunestate->do_initial_prune= false;/* may be set below */
14191418
prunestate->do_exec_prune= false;/* may be set below */
14201419
prunestate->execparamids=NULL;
14211420

14221421
/*
1423-
* Create a sub memory context which we'll use when making calls to the
1424-
* query planner's function to determine which partitions will match. The
1425-
* planner is not too careful about freeing memory, so we'll ensure we
1426-
* call the function in this context to avoid any memory leaking in the
1427-
* executor's memory context.
1422+
* Create a short-term memory context which we'll use when making calls to
1423+
* the partition pruning functions. This avoids possible memory leaks,
1424+
* since the pruning functions call comparison functions that aren't under
1425+
* our control.
14281426
*/
14291427
prunestate->prune_context=
14301428
AllocSetContextCreate(CurrentMemoryContext,
@@ -1448,8 +1446,8 @@ ExecSetupPartitionPruneState(PlanState *planstate, List *partitionpruneinfo)
14481446
* We must make a copy of this rather than pointing directly to the
14491447
* plan's version as we may end up making modifications to it later.
14501448
*/
1451-
pprune->subnode_map=palloc(sizeof(int)*pinfo->nparts);
1452-
memcpy(pprune->subnode_map,pinfo->subnode_map,
1449+
pprune->subplan_map=palloc(sizeof(int)*pinfo->nparts);
1450+
memcpy(pprune->subplan_map,pinfo->subplan_map,
14531451
sizeof(int)*pinfo->nparts);
14541452

14551453
/* We can use the subpart_map verbatim, since we never modify it */
@@ -1525,7 +1523,7 @@ ExecSetupPartitionPruneState(PlanState *planstate, List *partitionpruneinfo)
15251523

15261524
/*
15271525
* Accumulate the IDs of all PARAM_EXEC Params affecting the
1528-
* partitioning decisions at this node.
1526+
* partitioning decisions at thisplannode.
15291527
*/
15301528
prunestate->execparamids=bms_add_members(prunestate->execparamids,
15311529
pinfo->execparamids);
@@ -1540,22 +1538,19 @@ ExecSetupPartitionPruneState(PlanState *planstate, List *partitionpruneinfo)
15401538

15411539
/*
15421540
* ExecFindInitialMatchingSubPlans
1543-
*Determine which subset of subplan nodes we need to initialize based
1544-
*on the details stored in 'prunestate'. Here we only determine the
1545-
*matching partitions using values known during plan startup, which
1546-
*excludes any expressions containing PARAM_EXEC Params.
1541+
*Identify the set of subplans that cannot be eliminated by initial
1542+
*pruning (disregarding any pruning constraints involving PARAM_EXEC
1543+
*Params). Also re-map the translation matrix which allows conversion
1544+
*of partition indexes into subplan indexes to account for the unneeded
1545+
*subplans having been removed.
15471546
*
1548-
* It is expected that callers of this function do so only once during their
1549-
* init plan. The caller must only initialize the subnodes which are returned
1550-
* by this function. The remaining subnodes should be discarded. Once this
1551-
* function has been called, future calls to ExecFindMatchingSubPlans will
1552-
* return its matching subnode indexes assuming that the caller discarded
1553-
* the original non-matching subnodes.
1547+
* Must only be called once per 'prunestate', and only if initial pruning
1548+
* is required.
15541549
*
1555-
* 'nsubnodes' must be passed as the total number of unprunedsubnodes.
1550+
* 'nsubplans' must be passed as the total number of unprunedsubplans.
15561551
*/
15571552
Bitmapset*
1558-
ExecFindInitialMatchingSubPlans(PartitionPruneState*prunestate,intnsubnodes)
1553+
ExecFindInitialMatchingSubPlans(PartitionPruneState*prunestate,intnsubplans)
15591554
{
15601555
PartitionPruningData*pprune;
15611556
MemoryContextoldcontext;
@@ -1584,33 +1579,33 @@ ExecFindInitialMatchingSubPlans(PartitionPruneState *prunestate, int nsubnodes)
15841579
ResetExprContext(pprune->context.planstate->ps_ExprContext);
15851580

15861581
/*
1587-
* If anysubnodes were pruned, we must re-sequence thesubnode indexes so
1582+
* If anysubplans were pruned, we must re-sequence thesubplan indexes so
15881583
* that ExecFindMatchingSubPlans properly returns the indexes from the
1589-
*subnodes which will remain after execution of this function.
1584+
*subplans which will remain after execution of this function.
15901585
*/
1591-
if (bms_num_members(result)<nsubnodes)
1586+
if (bms_num_members(result)<nsubplans)
15921587
{
1593-
int*new_subnode_indexes;
1588+
int*new_subplan_indexes;
15941589
inti;
15951590
intnewidx;
15961591

15971592
/*
15981593
* First we must build an array which we can use to adjust the
1599-
* existingsubnode_map so that it contains the newsubnode indexes.
1594+
* existingsubplan_map so that it contains the newsubplan indexes.
16001595
*/
1601-
new_subnode_indexes= (int*)palloc(sizeof(int)*nsubnodes);
1596+
new_subplan_indexes= (int*)palloc(sizeof(int)*nsubplans);
16021597
newidx=0;
1603-
for (i=0;i<nsubnodes;i++)
1598+
for (i=0;i<nsubplans;i++)
16041599
{
16051600
if (bms_is_member(i,result))
1606-
new_subnode_indexes[i]=newidx++;
1601+
new_subplan_indexes[i]=newidx++;
16071602
else
1608-
new_subnode_indexes[i]=-1;/* Newly pruned */
1603+
new_subplan_indexes[i]=-1;/* Newly pruned */
16091604
}
16101605

16111606
/*
1612-
* Now we can re-sequence each PartitionPruneInfo'ssubnode_map so
1613-
* that they point to the new index of thesubnode.
1607+
* Now we can re-sequence each PartitionPruneInfo'ssubplan_map so
1608+
* that they point to the new index of thesubplan.
16141609
*/
16151610
for (i=0;i<prunestate->num_partprunedata;i++)
16161611
{
@@ -1622,7 +1617,7 @@ ExecFindInitialMatchingSubPlans(PartitionPruneState *prunestate, int nsubnodes)
16221617

16231618
/*
16241619
* We also need to reset the present_parts field so that it only
1625-
* contains partition indexes that we actually still havesubnodes
1620+
* contains partition indexes that we actually still havesubplans
16261621
* for. It seems easier to build a fresh one, rather than trying
16271622
* to update the existing one.
16281623
*/
@@ -1631,20 +1626,20 @@ ExecFindInitialMatchingSubPlans(PartitionPruneState *prunestate, int nsubnodes)
16311626

16321627
for (j=0;j<nparts;j++)
16331628
{
1634-
intoldidx=pprune->subnode_map[j];
1629+
intoldidx=pprune->subplan_map[j];
16351630

16361631
/*
1637-
* If this partition existed as asubnode then change the old
1638-
*subnode index to the newsubnode index. The new index may
1632+
* If this partition existed as asubplan then change the old
1633+
*subplan index to the newsubplan index. The new index may
16391634
* become -1 if the partition was pruned above, or it may just
1640-
* come earlier in thesubnode list due to somesubnodes being
1635+
* come earlier in thesubplan list due to somesubplans being
16411636
* removed earlier in the list.
16421637
*/
16431638
if (oldidx >=0)
16441639
{
1645-
pprune->subnode_map[j]=new_subnode_indexes[oldidx];
1640+
pprune->subplan_map[j]=new_subplan_indexes[oldidx];
16461641

1647-
if (new_subnode_indexes[oldidx] >=0)
1642+
if (new_subplan_indexes[oldidx] >=0)
16481643
pprune->present_parts=
16491644
bms_add_member(pprune->present_parts,j);
16501645
}
@@ -1686,7 +1681,7 @@ ExecFindInitialMatchingSubPlans(PartitionPruneState *prunestate, int nsubnodes)
16861681
}
16871682
}
16881683

1689-
pfree(new_subnode_indexes);
1684+
pfree(new_subplan_indexes);
16901685
}
16911686

16921687
returnresult;
@@ -1695,7 +1690,7 @@ ExecFindInitialMatchingSubPlans(PartitionPruneState *prunestate, int nsubnodes)
16951690
/*
16961691
* ExecFindMatchingSubPlans
16971692
*Determine which subplans match the pruning steps detailed in
1698-
*'pprune' for the current comparison expression values.
1693+
*'prunestate' for the current comparison expression values.
16991694
*
17001695
* Here we assume we may evaluate PARAM_EXEC Params.
17011696
*/
@@ -1767,28 +1762,24 @@ find_matching_subplans_recurse(PartitionPruneState *prunestate,
17671762
partset=pprune->present_parts;
17681763
}
17691764

1770-
/* Translate partset intosubnode indexes */
1765+
/* Translate partset intosubplan indexes */
17711766
i=-1;
17721767
while ((i=bms_next_member(partset,i)) >=0)
17731768
{
1774-
if (pprune->subnode_map[i] >=0)
1769+
if (pprune->subplan_map[i] >=0)
17751770
*validsubplans=bms_add_member(*validsubplans,
1776-
pprune->subnode_map[i]);
1771+
pprune->subplan_map[i]);
17771772
else
17781773
{
17791774
intpartidx=pprune->subpart_map[i];
17801775

1781-
if (partidx!=-1)
1776+
if (partidx>=0)
17821777
find_matching_subplans_recurse(prunestate,
17831778
&prunestate->partprunedata[partidx],
17841779
initial_prune,validsubplans);
17851780
else
17861781
{
1787-
/*
1788-
* This could only happen if clauses used in planning where
1789-
* more restrictive than those used here, or if the maps are
1790-
* somehow corrupt.
1791-
*/
1782+
/* Shouldn't happen */
17921783
elog(ERROR,"partition missing from subplans");
17931784
}
17941785
}

‎src/backend/nodes/copyfuncs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1186,7 +1186,7 @@ _copyPartitionPruneInfo(const PartitionPruneInfo *from)
11861186
COPY_BITMAPSET_FIELD(present_parts);
11871187
COPY_SCALAR_FIELD(nparts);
11881188
COPY_SCALAR_FIELD(nexprs);
1189-
COPY_POINTER_FIELD(subnode_map,from->nparts*sizeof(int));
1189+
COPY_POINTER_FIELD(subplan_map,from->nparts*sizeof(int));
11901190
COPY_POINTER_FIELD(subpart_map,from->nparts*sizeof(int));
11911191
COPY_POINTER_FIELD(hasexecparam,from->nexprs*sizeof(bool));
11921192
COPY_SCALAR_FIELD(do_initial_prune);

‎src/backend/nodes/outfuncs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,9 +1023,9 @@ _outPartitionPruneInfo(StringInfo str, const PartitionPruneInfo *node)
10231023
WRITE_INT_FIELD(nparts);
10241024
WRITE_INT_FIELD(nexprs);
10251025

1026-
appendStringInfoString(str," :subnode_map");
1026+
appendStringInfoString(str," :subplan_map");
10271027
for (i=0;i<node->nparts;i++)
1028-
appendStringInfo(str," %d",node->subnode_map[i]);
1028+
appendStringInfo(str," %d",node->subplan_map[i]);
10291029

10301030
appendStringInfoString(str," :subpart_map");
10311031
for (i=0;i<node->nparts;i++)

‎src/backend/nodes/readfuncs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2333,7 +2333,7 @@ _readPartitionPruneInfo(void)
23332333
READ_BITMAPSET_FIELD(present_parts);
23342334
READ_INT_FIELD(nparts);
23352335
READ_INT_FIELD(nexprs);
2336-
READ_INT_ARRAY(subnode_map,local_node->nparts);
2336+
READ_INT_ARRAY(subplan_map,local_node->nparts);
23372337
READ_INT_ARRAY(subpart_map,local_node->nparts);
23382338
READ_BOOL_ARRAY(hasexecparam,local_node->nexprs);
23392339
READ_BOOL_FIELD(do_initial_prune);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp