Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit c537d42

Browse files
committed
Modify fmgr so that internal name (compiler name) of a built-in
function is found in prosrc field of pg_proc, not proname. This allows multiple aliases of a built-in to all be implemented as direct builtins, without needing a level of indirection through an SQL function. Replace existing SQL alias functions with builtin entries accordingly. Save a few K by not storing string names of builtin functions in fmgr's internal table (if you really want 'em, get 'em from pg_proc...). Update opr_sanity with a few more cross-checks.
1 parent fdf6be8 commit c537d42

File tree

6 files changed

+1223
-1026
lines changed

6 files changed

+1223
-1026
lines changed

src/backend/utils/Gen_fmgrtab.sh.in

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#
99
#
1010
# IDENTIFICATION
11-
# $Header: /cvsroot/pgsql/src/backend/utils/Attic/Gen_fmgrtab.sh.in,v 1.13 1999/01/25 00:44:53 tgl Exp $
11+
# $Header: /cvsroot/pgsql/src/backend/utils/Attic/Gen_fmgrtab.sh.in,v 1.14 1999/03/29 01:30:35 tgl Exp $
1212
#
1313
# NOTES
1414
# Passes any -D options on to cpp prior to generating the list
@@ -83,7 +83,7 @@ cat > $HFILE <<FuNkYfMgRsTuFf
8383
*
8484
* Copyright (c) 1994, Regents of the University of California
8585
*
86-
* $Id: Gen_fmgrtab.sh.in,v 1.13 1999/01/25 00:44:53 tgl Exp $
86+
* $Id: Gen_fmgrtab.sh.in,v 1.14 1999/03/29 01:30:35 tgl Exp $
8787
*
8888
* NOTES
8989
* ******************************
@@ -172,10 +172,19 @@ FmgrInfo *fmgr_pl_finfo;
172172
#define SEL_CONSTANT 1 /* constant does not vary (not a parameter) */
173173
#define SEL_RIGHT 2 /* constant appears to right of operator */
174174
175+
/*
176+
* Constant macros for the OIDs of entries in pg_proc.
177+
* NOTE: if the same "proname" is used for more than one
178+
* internal-function entry in pg_proc, the equivalent macro
179+
* will be defined with the lowest OID among those entries.
180+
*/
175181
FuNkYfMgRsTuFf
176-
awk '{ print $2, $1; }' $RAWFILE | \
177-
@TR@ @TRARGS@ | \
178-
sed -e 's/^/#define F_/' >> $HFILE
182+
183+
@TR@ @TRARGS@ < $RAWFILE | \
184+
awk '
185+
BEGIN { OFS = ""; }
186+
{ if (seenit[$2]++ == 0) print "#define F_", $2, " ", $1; }' >> $HFILE
187+
179188
cat >> $HFILE <<FuNkYfMgRsTuFf
180189
181190
#endif /* FMGR_H */
@@ -197,7 +206,7 @@ cat > $TABCFILE <<FuNkYfMgRtAbStUfF
197206
*
198207
*
199208
* IDENTIFICATION
200-
* $Header: /cvsroot/pgsql/src/backend/utils/Attic/Gen_fmgrtab.sh.in,v 1.13 1999/01/25 00:44:53 tgl Exp $
209+
* $Header: /cvsroot/pgsql/src/backend/utils/Attic/Gen_fmgrtab.sh.in,v 1.14 1999/03/29 01:30:35 tgl Exp $
201210
*
202211
* NOTES
203212
*
@@ -235,12 +244,16 @@ cat > $TABCFILE <<FuNkYfMgRtAbStUfF
235244
#include "utils/fmgrtab.h"
236245
237246
FuNkYfMgRtAbStUfF
238-
awk '{ print "extern char *" $2 "();"; }' $RAWFILE >> $TABCFILE
247+
248+
awk '{ print "extern char *", $(NF-1), "();"; }' $RAWFILE >> $TABCFILE
249+
239250
cat >> $TABCFILE <<FuNkYfMgRtAbStUfF
240251
241252
static FmgrCall fmgr_builtins[] = {
242253
FuNkYfMgRtAbStUfF
243-
awk '{ printf (" {%d , %d , %s, \"%s\" },\n"), $1, $8, $2, $2 }' $RAWFILE >> $TABCFILE
254+
255+
awk '{ printf (" {%d, %d, %s },\n"), $1, $8, $(NF-1) }' $RAWFILE >> $TABCFILE
256+
244257
cat >> $TABCFILE <<FuNkYfMgRtAbStUfF
245258
/* guardian value */
246259
#ifndef WIN32
@@ -276,16 +289,6 @@ FmgrCall *fmgr_isbuiltin(Oid id)
276289
return (FmgrCall *) NULL;
277290
}
278291
279-
func_ptr fmgr_lookupByName(char *name)
280-
{
281-
int i;
282-
for (i=0; i<FMGR_NBUILTINS; i++) {
283-
if (strcmp(name,fmgr_builtins[i].funcName) == 0)
284-
return(fmgr_builtins[i].func);
285-
}
286-
return((func_ptr) NULL);
287-
}
288-
289292
FuNkYfMgRtAbStUfF
290293

291294
rm -f $RAWFILE

src/backend/utils/fmgr/fmgr.c

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/fmgr/fmgr.c,v 1.22 1999/02/13 23:19:52 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/fmgr/fmgr.c,v 1.23 1999/03/29 01:30:36 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -169,14 +169,20 @@ fmgr_info(Oid procedureId, FmgrInfo *finfo)
169169
finfo->fn_plhandler = NULL;
170170
finfo->fn_oid = procedureId;
171171

172-
if (!(fcp = fmgr_isbuiltin(procedureId)))
172+
if ((fcp = fmgr_isbuiltin(procedureId)) != NULL)
173+
{
174+
/* Fast path for builtin functions: don't bother consulting pg_proc */
175+
finfo->fn_addr = fcp->func;
176+
finfo->fn_nargs = fcp->nargs;
177+
}
178+
else
173179
{
174180
procedureTuple = SearchSysCacheTuple(PROOID,
175-
ObjectIdGetDatum(procedureId),
181+
ObjectIdGetDatum(procedureId),
176182
0, 0, 0);
177183
if (!HeapTupleIsValid(procedureTuple))
178184
{
179-
elog(ERROR, "fmgr_info: function %d: cache lookup failed\n",
185+
elog(ERROR, "fmgr_info: function %d: cache lookup failed",
180186
procedureId);
181187
}
182188
procedureStruct = (FormData_pg_proc *) GETSTRUCT(procedureTuple);
@@ -190,11 +196,12 @@ fmgr_info(Oid procedureId, FmgrInfo *finfo)
190196
switch (language)
191197
{
192198
case INTERNALlanguageId:
193-
finfo->fn_addr = fmgr_lookupByName(procedureStruct->proname.data);
194-
if (!finfo->fn_addr)
195-
elog(ERROR, "fmgr_info: function %s: not in internal table",
196-
procedureStruct->proname.data);
197-
finfo->fn_nargs = procedureStruct->pronargs;
199+
/*
200+
* Since we already tried to look up the OID as a builtin
201+
* function, we should never get here...
202+
*/
203+
elog(ERROR, "fmgr_info: function %d: not in internal table",
204+
procedureId);
198205
break;
199206
case ClanguageId:
200207
finfo->fn_addr = fmgr_dynamic(procedureId, &(finfo->fn_nargs));
@@ -239,11 +246,6 @@ fmgr_info(Oid procedureId, FmgrInfo *finfo)
239246
break;
240247
}
241248
}
242-
else
243-
{
244-
finfo->fn_addr = fcp->func;
245-
finfo->fn_nargs = fcp->nargs;
246-
}
247249
}
248250

249251
/*

0 commit comments

Comments
 (0)