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

Commit07f9f4d

Browse files
committed
Tweak OpernameGetCandidates() to reduce palloc overhead --- profiling
showed that for common operator names such as '=', the pallocs done bythis routine occupied a surprisingly large fraction of the total timefor the parser to process an operator.
1 parent21b3c0e commit07f9f4d

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

‎src/backend/catalog/namespace.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Portions Copyright (c) 1994, Regents of the University of California
1414
*
1515
* IDENTIFICATION
16-
* $PostgreSQL: pgsql/src/backend/catalog/namespace.c,v 1.60 2003/12/12 18:45:08 petere Exp $
16+
* $PostgreSQL: pgsql/src/backend/catalog/namespace.c,v 1.61 2003/12/29 21:33:09 tgl Exp $
1717
*
1818
*-------------------------------------------------------------------------
1919
*/
@@ -659,6 +659,8 @@ FuncCandidateList
659659
OpernameGetCandidates(List*names,charoprkind)
660660
{
661661
FuncCandidateListresultList=NULL;
662+
char*resultSpace=NULL;
663+
intnextResult=0;
662664
char*schemaname;
663665
char*opername;
664666
OidnamespaceId;
@@ -685,6 +687,20 @@ OpernameGetCandidates(List *names, char oprkind)
685687
CStringGetDatum(opername),
686688
0,0,0);
687689

690+
/*
691+
* In typical scenarios, most if not all of the operators found by the
692+
* catcache search will end up getting returned; and there can be quite
693+
* a few, for common operator names such as '=' or '+'. To reduce the
694+
* time spent in palloc, we allocate the result space as an array large
695+
* enough to hold all the operators. The original coding of this routine
696+
* did a separate palloc for each operator, but profiling revealed that
697+
* the pallocs used an unreasonably large fraction of parsing time.
698+
*/
699+
#defineSPACE_PER_OP MAXALIGN(sizeof(struct _FuncCandidateList) + sizeof(Oid))
700+
701+
if (catlist->n_members>0)
702+
resultSpace=palloc(catlist->n_members*SPACE_PER_OP);
703+
688704
for (i=0;i<catlist->n_members;i++)
689705
{
690706
HeapTupleopertup=&catlist->members[i]->tuple;
@@ -768,8 +784,9 @@ OpernameGetCandidates(List *names, char oprkind)
768784
/*
769785
* Okay to add it to result list
770786
*/
771-
newResult= (FuncCandidateList)
772-
palloc(sizeof(struct_FuncCandidateList)+sizeof(Oid));
787+
newResult= (FuncCandidateList) (resultSpace+nextResult);
788+
nextResult+=SPACE_PER_OP;
789+
773790
newResult->pathpos=pathpos;
774791
newResult->oid=HeapTupleGetOid(opertup);
775792
newResult->nargs=2;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp