13
13
* Portions Copyright (c) 1994, Regents of the University of California
14
14
*
15
15
* 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 $
17
17
*
18
18
*-------------------------------------------------------------------------
19
19
*/
@@ -659,6 +659,8 @@ FuncCandidateList
659
659
OpernameGetCandidates (List * names , char oprkind )
660
660
{
661
661
FuncCandidateList resultList = NULL ;
662
+ char * resultSpace = NULL ;
663
+ int nextResult = 0 ;
662
664
char * schemaname ;
663
665
char * opername ;
664
666
Oid namespaceId ;
@@ -685,6 +687,20 @@ OpernameGetCandidates(List *names, char oprkind)
685
687
CStringGetDatum (opername ),
686
688
0 , 0 , 0 );
687
689
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
+
688
704
for (i = 0 ; i < catlist -> n_members ; i ++ )
689
705
{
690
706
HeapTuple opertup = & catlist -> members [i ]-> tuple ;
@@ -768,8 +784,9 @@ OpernameGetCandidates(List *names, char oprkind)
768
784
/*
769
785
* Okay to add it to result list
770
786
*/
771
- newResult = (FuncCandidateList )
772
- palloc (sizeof (struct _FuncCandidateList ) + sizeof (Oid ));
787
+ newResult = (FuncCandidateList ) (resultSpace + nextResult );
788
+ nextResult += SPACE_PER_OP ;
789
+
773
790
newResult -> pathpos = pathpos ;
774
791
newResult -> oid = HeapTupleGetOid (opertup );
775
792
newResult -> nargs = 2 ;
0 commit comments