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

Commite7c2b95

Browse files
committed
Optimize a few list_delete_ptr calls
There is a handful of places where we called list_delete_ptr() to removesome element from a List. In many of these places we know, or with verylittle additional effort know the index of the ListCell that we need toremove.Here we change all of those places to instead either use one of;list_delete_nth_cell(), foreach_delete_current() or list_delete_last().Each of these saves from having to iterate over the list to search for theelement to remove by its pointer value.There are some small performance gains to be had by doing this, but in thegeneral case, none of these lists are likely to be very large, so thelookup was probably never that expensive anyway. However, some of thecalls are in fairly hot code paths, e.g process_equivalence(). So anysmall gains there are useful.Author: Zhijie Hou and David RowleyDiscussion:https://postgr.es/m/b3517353ec7c4f87aa560678fbb1034b@G08CNEXMBPEKD05.g08.fujitsu.local
1 parent85c5428 commite7c2b95

File tree

5 files changed

+16
-12
lines changed

5 files changed

+16
-12
lines changed

‎src/backend/optimizer/path/equivclass.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ process_equivalence(PlannerInfo *root,
137137
EquivalenceMember*em1,
138138
*em2;
139139
ListCell*lc1;
140+
intec2_idx;
140141

141142
/* Should not already be marked as having generated an eclass */
142143
Assert(restrictinfo->left_ec==NULL);
@@ -258,6 +259,7 @@ process_equivalence(PlannerInfo *root,
258259
*/
259260
ec1=ec2=NULL;
260261
em1=em2=NULL;
262+
ec2_idx=-1;
261263
foreach(lc1,root->eq_classes)
262264
{
263265
EquivalenceClass*cur_ec= (EquivalenceClass*)lfirst(lc1);
@@ -311,6 +313,7 @@ process_equivalence(PlannerInfo *root,
311313
equal(item2,cur_em->em_expr))
312314
{
313315
ec2=cur_ec;
316+
ec2_idx=foreach_current_index(lc1);
314317
em2=cur_em;
315318
if (ec1)
316319
break;
@@ -371,7 +374,7 @@ process_equivalence(PlannerInfo *root,
371374
ec1->ec_max_security=Max(ec1->ec_max_security,
372375
ec2->ec_max_security);
373376
ec2->ec_merged=ec1;
374-
root->eq_classes=list_delete_ptr(root->eq_classes,ec2);
377+
root->eq_classes=list_delete_nth_cell(root->eq_classes,ec2_idx);
375378
/* just to avoid debugging confusion w/ dangling pointers: */
376379
ec2->ec_members=NIL;
377380
ec2->ec_sources=NIL;
@@ -1964,6 +1967,7 @@ reconsider_full_join_clause(PlannerInfo *root, RestrictInfo *rinfo)
19641967
boolmatchleft;
19651968
boolmatchright;
19661969
ListCell*lc2;
1970+
intcoal_idx=-1;
19671971

19681972
/* Ignore EC unless it contains pseudoconstants */
19691973
if (!cur_ec->ec_has_const)
@@ -2008,6 +2012,7 @@ reconsider_full_join_clause(PlannerInfo *root, RestrictInfo *rinfo)
20082012

20092013
if (equal(leftvar,cfirst)&&equal(rightvar,csecond))
20102014
{
2015+
coal_idx=foreach_current_index(lc2);
20112016
match= true;
20122017
break;
20132018
}
@@ -2072,7 +2077,7 @@ reconsider_full_join_clause(PlannerInfo *root, RestrictInfo *rinfo)
20722077
*/
20732078
if (matchleft&&matchright)
20742079
{
2075-
cur_ec->ec_members=list_delete_ptr(cur_ec->ec_members,coal_em);
2080+
cur_ec->ec_members=list_delete_nth_cell(cur_ec->ec_members,coal_idx);
20762081
return true;
20772082
}
20782083

‎src/backend/optimizer/path/joinpath.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,8 +1005,8 @@ sort_inner_and_outer(PlannerInfo *root,
10051005
/* Make a pathkey list with this guy first */
10061006
if (l!=list_head(all_pathkeys))
10071007
outerkeys=lcons(front_pathkey,
1008-
list_delete_ptr(list_copy(all_pathkeys),
1009-
front_pathkey));
1008+
list_delete_nth_cell(list_copy(all_pathkeys),
1009+
foreach_current_index(l)));
10101010
else
10111011
outerkeys=all_pathkeys;/* no work at first one... */
10121012

‎src/backend/parser/parse_expr.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,11 +1698,12 @@ transformMultiAssignRef(ParseState *pstate, MultiAssignRef *maref)
16981698
/*
16991699
* If we're at the last column, delete the RowExpr from
17001700
* p_multiassign_exprs; we don't need it anymore, and don't want it in
1701-
* the finished UPDATE tlist.
1701+
* the finished UPDATE tlist. We assume this is still the last entry
1702+
* in p_multiassign_exprs.
17021703
*/
17031704
if (maref->colno==maref->ncolumns)
17041705
pstate->p_multiassign_exprs=
1705-
list_delete_ptr(pstate->p_multiassign_exprs,tle);
1706+
list_delete_last(pstate->p_multiassign_exprs);
17061707

17071708
returnresult;
17081709
}

‎src/backend/parser/parse_utilcmd.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ generateSerialExtraStmts(CreateStmtContext *cxt, ColumnDef *column,
360360
CreateSeqStmt*seqstmt;
361361
AlterSeqStmt*altseqstmt;
362362
List*attnamelist;
363+
intnameEl_idx=-1;
363364

364365
/*
365366
* Determine namespace and name to use for the sequence.
@@ -386,6 +387,7 @@ generateSerialExtraStmts(CreateStmtContext *cxt, ColumnDef *column,
386387
(errcode(ERRCODE_SYNTAX_ERROR),
387388
errmsg("conflicting or redundant options")));
388389
nameEl=defel;
390+
nameEl_idx=foreach_current_index(option);
389391
}
390392
}
391393

@@ -405,7 +407,7 @@ generateSerialExtraStmts(CreateStmtContext *cxt, ColumnDef *column,
405407
}
406408
sname=rv->relname;
407409
/* Remove the SEQUENCE NAME item from seqoptions */
408-
seqoptions=list_delete_ptr(seqoptions,nameEl);
410+
seqoptions=list_delete_nth_cell(seqoptions,nameEl_idx);
409411
}
410412
else
411413
{

‎src/backend/rewrite/rewriteHandler.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -650,11 +650,7 @@ adjustJoinTreeList(Query *parsetree, bool removert, int rt_index)
650650
if (IsA(rtr,RangeTblRef)&&
651651
rtr->rtindex==rt_index)
652652
{
653-
newjointree=list_delete_ptr(newjointree,rtr);
654-
655-
/*
656-
* foreach is safe because we exit loop after list_delete...
657-
*/
653+
newjointree=foreach_delete_current(newjointree,l);
658654
break;
659655
}
660656
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp