Skip to content

Commit 07f9f4d

Browse files
committed
Tweak OpernameGetCandidates() to reduce palloc overhead --- profiling
showed that for common operator names such as '=', the pallocs done by this routine occupied a surprisingly large fraction of the total time for the parser to process an operator.
1 parent 21b3c0e commit 07f9f4d

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, char oprkind)
660660
{
661661
FuncCandidateList resultList = NULL;
662+
char *resultSpace = NULL;
663+
int nextResult = 0;
662664
char *schemaname;
663665
char *opername;
664666
Oid namespaceId;
@@ -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+
#define SPACE_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
HeapTuple opertup = &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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy