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

Commit69025c5

Browse files
committed
Improve ExecFindInitialMatchingSubPlans's subplan renumbering logic.
We don't need two passes if we scan child partitions before parents,as that way the children's present_parts are up to date before they'reneeded. I (tgl) think there's actually a bug being fixed here, for thecase of an intermediate partitioned table with no direct leaf children,but haven't attempted to construct a test case to prove it.David RowleyDiscussion:https://postgr.es/m/CAKJS1f-6GODRNgEtdPxCnAPme2h2hTztB6LmtfdmcYAAOE0kQg@mail.gmail.com
1 parent4e23236 commit69025c5

File tree

1 file changed

+22
-46
lines changed

1 file changed

+22
-46
lines changed

‎src/backend/executor/execPartition.c

Lines changed: 22 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,8 +1442,8 @@ ExecSetupPartitionPruneState(PlanState *planstate, List *partitionpruneinfo)
14421442
intn_steps;
14431443

14441444
/*
1445-
* We mustmake acopyof this rather than pointing directly to the
1446-
* plan's version as we may end up making modifications to it later.
1445+
* We must copythe subplan_map rather than pointing directly to the
1446+
* plan's version, as we may end up making modifications to it later.
14471447
*/
14481448
pprune->subplan_map=palloc(sizeof(int)*pinfo->nparts);
14491449
memcpy(pprune->subplan_map,pinfo->subplan_map,
@@ -1589,8 +1589,8 @@ ExecFindInitialMatchingSubPlans(PartitionPruneState *prunestate, int nsubplans)
15891589
intnewidx;
15901590

15911591
/*
1592-
* First we must buildanarray whichwe can use to adjust the
1593-
*existing subplan_map so that it contains thenewsubplan indexes.
1592+
* First we must builda temporaryarray whichmaps old subplan
1593+
*indexes tonewones.
15941594
*/
15951595
new_subplan_indexes= (int*)palloc(sizeof(int)*nsubplans);
15961596
newidx=0;
@@ -1603,79 +1603,55 @@ ExecFindInitialMatchingSubPlans(PartitionPruneState *prunestate, int nsubplans)
16031603
}
16041604

16051605
/*
1606-
* Now we can re-sequence each PartitionPruneInfo's subplan_map so
1607-
* that they point to the new index of the subplan.
1606+
* Now we can update each PartitionPruneInfo's subplan_map with new
1607+
* subplan indexes. We must also recompute its present_parts bitmap.
1608+
* We perform this loop in back-to-front order so that we determine
1609+
* present_parts for the lowest-level partitioned tables first. This
1610+
* way we can tell whether a sub-partitioned table's partitions were
1611+
* entirely pruned so we can exclude that from 'present_parts'.
16081612
*/
1609-
for (i=0;i<prunestate->num_partprunedata;i++)
1613+
for (i=prunestate->num_partprunedata-1;i>=0;i--)
16101614
{
16111615
intnparts;
16121616
intj;
16131617

16141618
pprune=&prunestate->partprunedata[i];
16151619
nparts=pprune->context.nparts;
1616-
1617-
/*
1618-
* We also need to reset the present_parts field so that it only
1619-
* contains partition indexes that we actually still have subplans
1620-
* for. It seems easier to build a fresh one, rather than trying
1621-
* to update the existing one.
1622-
*/
1620+
/* We just rebuild present_parts from scratch */
16231621
bms_free(pprune->present_parts);
16241622
pprune->present_parts=NULL;
16251623

16261624
for (j=0;j<nparts;j++)
16271625
{
16281626
intoldidx=pprune->subplan_map[j];
1627+
intsubidx;
16291628

16301629
/*
16311630
* If this partition existed as a subplan then change the old
16321631
* subplan index to the new subplan index. The new index may
16331632
* become -1 if the partition was pruned above, or it may just
16341633
* come earlier in the subplan list due to some subplans being
1635-
* removed earlier in the list.
1634+
* removed earlier in the list. If it's a subpartition, add
1635+
* it to present_parts unless it's entirely pruned.
16361636
*/
16371637
if (oldidx >=0)
16381638
{
1639+
Assert(oldidx<nsubplans);
16391640
pprune->subplan_map[j]=new_subplan_indexes[oldidx];
16401641

16411642
if (new_subplan_indexes[oldidx] >=0)
16421643
pprune->present_parts=
16431644
bms_add_member(pprune->present_parts,j);
16441645
}
1645-
}
1646-
}
1647-
1648-
/*
1649-
* Now we must determine which sub-partitioned tables still have
1650-
* unpruned partitions. The easiest way to do this is to simply loop
1651-
* over each PartitionPruningData again checking if there are any
1652-
* 'present_parts' in the sub-partitioned table. We needn't bother
1653-
* doing this if there are no sub-partitioned tables.
1654-
*/
1655-
if (prunestate->num_partprunedata>1)
1656-
{
1657-
for (i=0;i<prunestate->num_partprunedata;i++)
1658-
{
1659-
intnparts;
1660-
intj;
1661-
1662-
pprune=&prunestate->partprunedata[i];
1663-
nparts=pprune->context.nparts;
1664-
1665-
for (j=0;j<nparts;j++)
1646+
elseif ((subidx=pprune->subpart_map[j]) >=0)
16661647
{
1667-
intsubidx=pprune->subpart_map[j];
1668-
1669-
if (subidx >=0)
1670-
{
1671-
PartitionPruningData*subprune;
1648+
PartitionPruningData*subprune;
16721649

1673-
subprune=&prunestate->partprunedata[subidx];
1650+
subprune=&prunestate->partprunedata[subidx];
16741651

1675-
if (!bms_is_empty(subprune->present_parts))
1676-
pprune->present_parts=
1677-
bms_add_member(pprune->present_parts,j);
1678-
}
1652+
if (!bms_is_empty(subprune->present_parts))
1653+
pprune->present_parts=
1654+
bms_add_member(pprune->present_parts,j);
16791655
}
16801656
}
16811657
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp