mirror of
https://github.com/postgres/postgres.git
synced 2025-11-13 16:22:44 +03:00
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.
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
#
|
||||
#
|
||||
# IDENTIFICATION
|
||||
# $Header: /cvsroot/pgsql/src/backend/utils/Attic/Gen_fmgrtab.sh.in,v 1.13 1999/01/25 00:44:53 tgl Exp $
|
||||
# $Header: /cvsroot/pgsql/src/backend/utils/Attic/Gen_fmgrtab.sh.in,v 1.14 1999/03/29 01:30:35 tgl Exp $
|
||||
#
|
||||
# NOTES
|
||||
# Passes any -D options on to cpp prior to generating the list
|
||||
@@ -83,7 +83,7 @@ cat > $HFILE <<FuNkYfMgRsTuFf
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: Gen_fmgrtab.sh.in,v 1.13 1999/01/25 00:44:53 tgl Exp $
|
||||
* $Id: Gen_fmgrtab.sh.in,v 1.14 1999/03/29 01:30:35 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
* ******************************
|
||||
@@ -172,10 +172,19 @@ FmgrInfo *fmgr_pl_finfo;
|
||||
#define SEL_CONSTANT 1 /* constant does not vary (not a parameter) */
|
||||
#define SEL_RIGHT 2 /* constant appears to right of operator */
|
||||
|
||||
/*
|
||||
* Constant macros for the OIDs of entries in pg_proc.
|
||||
* NOTE: if the same "proname" is used for more than one
|
||||
* internal-function entry in pg_proc, the equivalent macro
|
||||
* will be defined with the lowest OID among those entries.
|
||||
*/
|
||||
FuNkYfMgRsTuFf
|
||||
awk '{ print $2, $1; }' $RAWFILE | \
|
||||
@TR@ @TRARGS@ | \
|
||||
sed -e 's/^/#define F_/' >> $HFILE
|
||||
|
||||
@TR@ @TRARGS@ < $RAWFILE | \
|
||||
awk '
|
||||
BEGIN { OFS = ""; }
|
||||
{ if (seenit[$2]++ == 0) print "#define F_", $2, " ", $1; }' >> $HFILE
|
||||
|
||||
cat >> $HFILE <<FuNkYfMgRsTuFf
|
||||
|
||||
#endif /* FMGR_H */
|
||||
@@ -197,7 +206,7 @@ cat > $TABCFILE <<FuNkYfMgRtAbStUfF
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/Attic/Gen_fmgrtab.sh.in,v 1.13 1999/01/25 00:44:53 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/Attic/Gen_fmgrtab.sh.in,v 1.14 1999/03/29 01:30:35 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
*
|
||||
@@ -235,12 +244,16 @@ cat > $TABCFILE <<FuNkYfMgRtAbStUfF
|
||||
#include "utils/fmgrtab.h"
|
||||
|
||||
FuNkYfMgRtAbStUfF
|
||||
awk '{ print "extern char *" $2 "();"; }' $RAWFILE >> $TABCFILE
|
||||
|
||||
awk '{ print "extern char *", $(NF-1), "();"; }' $RAWFILE >> $TABCFILE
|
||||
|
||||
cat >> $TABCFILE <<FuNkYfMgRtAbStUfF
|
||||
|
||||
static FmgrCall fmgr_builtins[] = {
|
||||
FuNkYfMgRtAbStUfF
|
||||
awk '{ printf (" {%d , %d , %s, \"%s\" },\n"), $1, $8, $2, $2 }' $RAWFILE >> $TABCFILE
|
||||
|
||||
awk '{ printf (" {%d, %d, %s },\n"), $1, $8, $(NF-1) }' $RAWFILE >> $TABCFILE
|
||||
|
||||
cat >> $TABCFILE <<FuNkYfMgRtAbStUfF
|
||||
/* guardian value */
|
||||
#ifndef WIN32
|
||||
@@ -276,16 +289,6 @@ FmgrCall *fmgr_isbuiltin(Oid id)
|
||||
return (FmgrCall *) NULL;
|
||||
}
|
||||
|
||||
func_ptr fmgr_lookupByName(char *name)
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<FMGR_NBUILTINS; i++) {
|
||||
if (strcmp(name,fmgr_builtins[i].funcName) == 0)
|
||||
return(fmgr_builtins[i].func);
|
||||
}
|
||||
return((func_ptr) NULL);
|
||||
}
|
||||
|
||||
FuNkYfMgRtAbStUfF
|
||||
|
||||
rm -f $RAWFILE
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/fmgr/fmgr.c,v 1.22 1999/02/13 23:19:52 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/fmgr/fmgr.c,v 1.23 1999/03/29 01:30:36 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -169,14 +169,20 @@ fmgr_info(Oid procedureId, FmgrInfo *finfo)
|
||||
finfo->fn_plhandler = NULL;
|
||||
finfo->fn_oid = procedureId;
|
||||
|
||||
if (!(fcp = fmgr_isbuiltin(procedureId)))
|
||||
if ((fcp = fmgr_isbuiltin(procedureId)) != NULL)
|
||||
{
|
||||
/* Fast path for builtin functions: don't bother consulting pg_proc */
|
||||
finfo->fn_addr = fcp->func;
|
||||
finfo->fn_nargs = fcp->nargs;
|
||||
}
|
||||
else
|
||||
{
|
||||
procedureTuple = SearchSysCacheTuple(PROOID,
|
||||
ObjectIdGetDatum(procedureId),
|
||||
ObjectIdGetDatum(procedureId),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(procedureTuple))
|
||||
{
|
||||
elog(ERROR, "fmgr_info: function %d: cache lookup failed\n",
|
||||
elog(ERROR, "fmgr_info: function %d: cache lookup failed",
|
||||
procedureId);
|
||||
}
|
||||
procedureStruct = (FormData_pg_proc *) GETSTRUCT(procedureTuple);
|
||||
@@ -190,11 +196,12 @@ fmgr_info(Oid procedureId, FmgrInfo *finfo)
|
||||
switch (language)
|
||||
{
|
||||
case INTERNALlanguageId:
|
||||
finfo->fn_addr = fmgr_lookupByName(procedureStruct->proname.data);
|
||||
if (!finfo->fn_addr)
|
||||
elog(ERROR, "fmgr_info: function %s: not in internal table",
|
||||
procedureStruct->proname.data);
|
||||
finfo->fn_nargs = procedureStruct->pronargs;
|
||||
/*
|
||||
* Since we already tried to look up the OID as a builtin
|
||||
* function, we should never get here...
|
||||
*/
|
||||
elog(ERROR, "fmgr_info: function %d: not in internal table",
|
||||
procedureId);
|
||||
break;
|
||||
case ClanguageId:
|
||||
finfo->fn_addr = fmgr_dynamic(procedureId, &(finfo->fn_nargs));
|
||||
@@ -239,11 +246,6 @@ fmgr_info(Oid procedureId, FmgrInfo *finfo)
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
finfo->fn_addr = fcp->func;
|
||||
finfo->fn_nargs = fcp->nargs;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user