mirror of
https://github.com/postgres/postgres.git
synced 2025-04-21 12:05:57 +03:00
Make better use of the new List implementation in a couple of places
In nodeAppend.c and nodeMergeAppend.c there were some foreach loops which looped over the list of subplans and only performed any work if the subplan index was found in a Bitmapset. With the old linked list implementation of List, this form made sense as accessing the Nth list element was O(N). However, thanks to 1cff1b95a we now have array-based lists, so accessing the Nth element has become O(1). Here we make the most of the O(1) lookups and just loop over the set members of the Bitmapset with bms_next_member(). This performs slightly better when a small number of the list items are in the Bitmapset. Micro benchmarks show that when the Bitmapset contains all or most of the list items then the new code is ever so slightly slower. In practice, the cost is so small that it's drowned out by various other things such as locking the relations belonging to each subplan, etc. The primary goal here is to leave better code examples around which benefit better from the new list implementation. Reviewed-by: Tom Lane Discussion: https://postgr.es/m/CAKJS1f8ZcsLVgkF4wOfRyMYTcPgLFiUAOedFC+U2vK_aFZk-BA@mail.gmail.com
This commit is contained in:
parent
23bccc823d
commit
efdcca55a3
@ -107,7 +107,6 @@ ExecInitAppend(Append *node, EState *estate, int eflags)
|
||||
int firstvalid;
|
||||
int i,
|
||||
j;
|
||||
ListCell *lc;
|
||||
|
||||
/* check for unsupported flags */
|
||||
Assert(!(eflags & EXEC_FLAG_MARK));
|
||||
@ -211,24 +210,20 @@ ExecInitAppend(Append *node, EState *estate, int eflags)
|
||||
*
|
||||
* While at it, find out the first valid partial plan.
|
||||
*/
|
||||
j = i = 0;
|
||||
j = 0;
|
||||
firstvalid = nplans;
|
||||
foreach(lc, node->appendplans)
|
||||
i = -1;
|
||||
while ((i = bms_next_member(validsubplans, i)) >= 0)
|
||||
{
|
||||
if (bms_is_member(i, validsubplans))
|
||||
{
|
||||
Plan *initNode = (Plan *) lfirst(lc);
|
||||
Plan *initNode = (Plan *) list_nth(node->appendplans, i);
|
||||
|
||||
/*
|
||||
* Record the lowest appendplans index which is a valid partial
|
||||
* plan.
|
||||
*/
|
||||
if (i >= node->first_partial_plan && j < firstvalid)
|
||||
firstvalid = j;
|
||||
/*
|
||||
* Record the lowest appendplans index which is a valid partial plan.
|
||||
*/
|
||||
if (i >= node->first_partial_plan && j < firstvalid)
|
||||
firstvalid = j;
|
||||
|
||||
appendplanstates[j++] = ExecInitNode(initNode, estate, eflags);
|
||||
}
|
||||
i++;
|
||||
appendplanstates[j++] = ExecInitNode(initNode, estate, eflags);
|
||||
}
|
||||
|
||||
appendstate->as_first_partial_plan = firstvalid;
|
||||
|
@ -70,7 +70,6 @@ ExecInitMergeAppend(MergeAppend *node, EState *estate, int eflags)
|
||||
int nplans;
|
||||
int i,
|
||||
j;
|
||||
ListCell *lc;
|
||||
|
||||
/* check for unsupported flags */
|
||||
Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK)));
|
||||
@ -177,16 +176,13 @@ ExecInitMergeAppend(MergeAppend *node, EState *estate, int eflags)
|
||||
* call ExecInitNode on each of the valid plans to be executed and save
|
||||
* the results into the mergeplanstates array.
|
||||
*/
|
||||
j = i = 0;
|
||||
foreach(lc, node->mergeplans)
|
||||
j = 0;
|
||||
i = -1;
|
||||
while ((i = bms_next_member(validsubplans, i)) >= 0)
|
||||
{
|
||||
if (bms_is_member(i, validsubplans))
|
||||
{
|
||||
Plan *initNode = (Plan *) lfirst(lc);
|
||||
Plan *initNode = (Plan *) list_nth(node->mergeplans, i);
|
||||
|
||||
mergeplanstates[j++] = ExecInitNode(initNode, estate, eflags);
|
||||
}
|
||||
i++;
|
||||
mergeplanstates[j++] = ExecInitNode(initNode, estate, eflags);
|
||||
}
|
||||
|
||||
mergestate->ps.ps_ProjInfo = NULL;
|
||||
|
Loading…
x
Reference in New Issue
Block a user