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

Commitefdcca5

Browse files
committed
Make better use of the new List implementation in a couple of places
In nodeAppend.c and nodeMergeAppend.c there were some foreach loops whichlooped over the list of subplans and only performed any work if thesubplan index was found in a Bitmapset. With the old linked listimplementation of List, this form made sense as accessing the Nth listelement was O(N). However, thanks to1cff1b9 we now have array-basedlists, so accessing the Nth element has become O(1).Here we make the most of the O(1) lookups and just loop over the setmembers of the Bitmapset with bms_next_member(). This performs slightlybetter when a small number of the list items are in the Bitmapset. Microbenchmarks show that when the Bitmapset contains all or most of the listitems then the new code is ever so slightly slower. In practice, the costis so small that it's drowned out by various other things such as lockingthe relations belonging to each subplan, etc.The primary goal here is to leave better code examples around which benefitbetter from the new list implementation.Reviewed-by: Tom LaneDiscussion:https://postgr.es/m/CAKJS1f8ZcsLVgkF4wOfRyMYTcPgLFiUAOedFC+U2vK_aFZk-BA@mail.gmail.com
1 parent23bccc8 commitefdcca5

File tree

2 files changed

+15
-24
lines changed

2 files changed

+15
-24
lines changed

‎src/backend/executor/nodeAppend.c

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ ExecInitAppend(Append *node, EState *estate, int eflags)
107107
intfirstvalid;
108108
inti,
109109
j;
110-
ListCell*lc;
111110

112111
/* check for unsupported flags */
113112
Assert(!(eflags&EXEC_FLAG_MARK));
@@ -211,24 +210,20 @@ ExecInitAppend(Append *node, EState *estate, int eflags)
211210
*
212211
* While at it, find out the first valid partial plan.
213212
*/
214-
j=i=0;
213+
j=0;
215214
firstvalid=nplans;
216-
foreach(lc,node->appendplans)
215+
i=-1;
216+
while ((i=bms_next_member(validsubplans,i)) >=0)
217217
{
218-
if (bms_is_member(i,validsubplans))
219-
{
220-
Plan*initNode= (Plan*)lfirst(lc);
218+
Plan*initNode= (Plan*)list_nth(node->appendplans,i);
221219

222-
/*
223-
* Record the lowest appendplans index which is a valid partial
224-
* plan.
225-
*/
226-
if (i >=node->first_partial_plan&&j<firstvalid)
227-
firstvalid=j;
220+
/*
221+
* Record the lowest appendplans index which is a valid partial plan.
222+
*/
223+
if (i >=node->first_partial_plan&&j<firstvalid)
224+
firstvalid=j;
228225

229-
appendplanstates[j++]=ExecInitNode(initNode,estate,eflags);
230-
}
231-
i++;
226+
appendplanstates[j++]=ExecInitNode(initNode,estate,eflags);
232227
}
233228

234229
appendstate->as_first_partial_plan=firstvalid;

‎src/backend/executor/nodeMergeAppend.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ ExecInitMergeAppend(MergeAppend *node, EState *estate, int eflags)
7070
intnplans;
7171
inti,
7272
j;
73-
ListCell*lc;
7473

7574
/* check for unsupported flags */
7675
Assert(!(eflags& (EXEC_FLAG_BACKWARD |EXEC_FLAG_MARK)));
@@ -177,16 +176,13 @@ ExecInitMergeAppend(MergeAppend *node, EState *estate, int eflags)
177176
* call ExecInitNode on each of the valid plans to be executed and save
178177
* the results into the mergeplanstates array.
179178
*/
180-
j=i=0;
181-
foreach(lc,node->mergeplans)
179+
j=0;
180+
i=-1;
181+
while ((i=bms_next_member(validsubplans,i)) >=0)
182182
{
183-
if (bms_is_member(i,validsubplans))
184-
{
185-
Plan*initNode= (Plan*)lfirst(lc);
183+
Plan*initNode= (Plan*)list_nth(node->mergeplans,i);
186184

187-
mergeplanstates[j++]=ExecInitNode(initNode,estate,eflags);
188-
}
189-
i++;
185+
mergeplanstates[j++]=ExecInitNode(initNode,estate,eflags);
190186
}
191187

192188
mergestate->ps.ps_ProjInfo=NULL;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp