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
659659OpernameGetCandidates (List * names ,char oprkind )
660660{
661661FuncCandidateList resultList = NULL ;
662+ char * resultSpace = NULL ;
663+ int nextResult = 0 ;
662664char * schemaname ;
663665char * opername ;
664666Oid namespaceId ;
@@ -685,6 +687,20 @@ OpernameGetCandidates(List *names, char oprkind)
685687CStringGetDatum (opername ),
6866880 ,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+
688704for (i = 0 ;i < catlist -> n_members ;i ++ )
689705{
690706HeapTuple 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+
773790newResult -> pathpos = pathpos ;
774791newResult -> oid = HeapTupleGetOid (opertup );
775792newResult -> nargs = 2 ;