mirror of
https://github.com/postgres/postgres.git
synced 2025-11-13 16:22:44 +03:00
First round of changes for new fmgr interface. fmgr itself and the
key call sites are changed, but most called functions are still oldstyle. An exception is that the PL managers are updated (so, for example, NULL handling now behaves as expected in plperl and plpgsql functions). NOTE initdb is forced due to added column in pg_proc.
This commit is contained in:
@@ -34,7 +34,7 @@
|
||||
#
|
||||
#
|
||||
# IDENTIFICATION
|
||||
# $Header: /cvsroot/pgsql/src/backend/Makefile,v 1.47 2000/05/11 17:46:28 momjian Exp $
|
||||
# $Header: /cvsroot/pgsql/src/backend/Makefile,v 1.48 2000/05/28 17:55:51 tgl Exp $
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
@@ -79,7 +79,7 @@ all: postgres $(POSTGRES_IMP) global1.bki.source local1_template1.bki.source \
|
||||
global1.description local1_template1.description
|
||||
|
||||
ifneq ($(PORTNAME), win)
|
||||
postgres: fmgr.h $(OBJS) $(VERSIONOBJ)
|
||||
postgres: utils/fmgroids.h $(OBJS) $(VERSIONOBJ)
|
||||
$(CC) $(CFLAGS) -o postgres $(OBJS) $(OBJS1) $(VERSIONOBJ) $(LDFLAGS)
|
||||
else
|
||||
postgres: $(DLLOBJS) $(SRCDIR)/utils/dllinit.o postgres.def libpostgres.a
|
||||
@@ -126,15 +126,12 @@ parse.h: parser/parse.h
|
||||
parser/parse.h:
|
||||
$(MAKE) -C parser parse.h
|
||||
|
||||
fmgr.h: utils/fmgr.h
|
||||
cp utils/fmgr.h .
|
||||
|
||||
utils/fmgr.h:
|
||||
$(MAKE) -C utils fmgr.h
|
||||
utils/fmgroids.h:
|
||||
$(MAKE) -C utils fmgroids.h
|
||||
|
||||
#############################################################################
|
||||
clean:
|
||||
rm -f postgres$(X) $(POSTGRES_IMP) fmgr.h parse.h \
|
||||
rm -f postgres$(X) $(POSTGRES_IMP) parse.h \
|
||||
global1.bki.source local1_template1.bki.source \
|
||||
global1.description local1_template1.description
|
||||
ifeq ($(PORTNAME), win)
|
||||
@@ -205,7 +202,7 @@ install-templates: $(TEMPLATEDIR) \
|
||||
$(INSTALL) $(INSTLOPTS) pg_options.sample \
|
||||
$(TEMPLATEDIR)/pg_options.sample
|
||||
|
||||
install-headers: fmgr.h $(SRCDIR)/include/config.h
|
||||
install-headers: utils/fmgroids.h $(SRCDIR)/include/config.h
|
||||
-@if [ ! -d $(HEADERDIR) ]; then mkdir $(HEADERDIR); fi
|
||||
-@if [ ! -d $(HEADERDIR)/port ]; then mkdir $(HEADERDIR)/port; fi
|
||||
-@if [ ! -d $(HEADERDIR)/port/$(PORTNAME) ]; \
|
||||
@@ -222,8 +219,6 @@ install-headers: fmgr.h $(SRCDIR)/include/config.h
|
||||
then mkdir $(HEADERDIR)/executor; fi
|
||||
-@if [ ! -d $(HEADERDIR)/commands ]; \
|
||||
then mkdir $(HEADERDIR)/commands; fi
|
||||
$(INSTALL) $(INSTLOPTS) fmgr.h \
|
||||
$(HEADERDIR)/fmgr.h
|
||||
$(INSTALL) $(INSTLOPTS) $(SRCDIR)/include/os.h \
|
||||
$(HEADERDIR)/os.h
|
||||
$(INSTALL) $(INSTLOPTS) $(SRCDIR)/include/config.h \
|
||||
@@ -244,6 +239,8 @@ install-headers: fmgr.h $(SRCDIR)/include/config.h
|
||||
$(HEADERDIR)/utils/geo_decls.h
|
||||
$(INSTALL) $(INSTLOPTS) $(SRCDIR)/include/utils/elog.h \
|
||||
$(HEADERDIR)/utils/elog.h
|
||||
$(INSTALL) $(INSTLOPTS) utils/fmgroids.h \
|
||||
$(HEADERDIR)/utils/fmgroids.h
|
||||
$(INSTALL) $(INSTLOPTS) $(SRCDIR)/include/utils/palloc.h \
|
||||
$(HEADERDIR)/utils/palloc.h
|
||||
$(INSTALL) $(INSTLOPTS) $(SRCDIR)/include/utils/mcxt.h \
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
# Makefile for access/common
|
||||
#
|
||||
# IDENTIFICATION
|
||||
# $Header: /cvsroot/pgsql/src/backend/access/common/Makefile,v 1.16 2000/01/19 02:58:50 petere Exp $
|
||||
# $Header: /cvsroot/pgsql/src/backend/access/common/Makefile,v 1.17 2000/05/28 17:55:52 tgl Exp $
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
@@ -21,12 +21,7 @@ all: SUBSYS.o
|
||||
SUBSYS.o: $(OBJS)
|
||||
$(LD) $(LDREL) $(LDOUT) SUBSYS.o $(OBJS)
|
||||
|
||||
heaptuple.o heapvalid.o tupdesc.o: ../../fmgr.h
|
||||
|
||||
../../fmgr.h:
|
||||
$(MAKE) -C ../.. fmgr.h
|
||||
|
||||
dep depend: ../../fmgr.h
|
||||
dep depend:
|
||||
$(CC) -MM $(CFLAGS) *.c >depend
|
||||
|
||||
clean:
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/index/indexam.c,v 1.42 2000/04/12 17:14:47 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/index/indexam.c,v 1.43 2000/05/28 17:55:52 tgl Exp $
|
||||
*
|
||||
* INTERFACE ROUTINES
|
||||
* index_open - open an index relation by relationId
|
||||
@@ -418,28 +418,43 @@ GetIndexValue(HeapTuple tuple,
|
||||
bool *attNull)
|
||||
{
|
||||
Datum returnVal;
|
||||
bool isNull = FALSE;
|
||||
|
||||
if (PointerIsValid(fInfo) && FIgetProcOid(fInfo) != InvalidOid)
|
||||
{
|
||||
int i;
|
||||
Datum *attData = (Datum *) palloc(FIgetnArgs(fInfo) * sizeof(Datum));
|
||||
FmgrInfo flinfo;
|
||||
FunctionCallInfoData fcinfo;
|
||||
int i;
|
||||
bool anynull = false;
|
||||
|
||||
/*
|
||||
* XXX ought to store lookup info in FuncIndexInfo so it need not
|
||||
* be repeated on each call?
|
||||
*/
|
||||
fmgr_info(FIgetProcOid(fInfo), &flinfo);
|
||||
|
||||
MemSet(&fcinfo, 0, sizeof(fcinfo));
|
||||
fcinfo.flinfo = &flinfo;
|
||||
fcinfo.nargs = FIgetnArgs(fInfo);
|
||||
|
||||
for (i = 0; i < FIgetnArgs(fInfo); i++)
|
||||
{
|
||||
attData[i] = heap_getattr(tuple,
|
||||
attrNums[i],
|
||||
hTupDesc,
|
||||
attNull);
|
||||
if (*attNull)
|
||||
isNull = TRUE;
|
||||
fcinfo.arg[i] = heap_getattr(tuple,
|
||||
attrNums[i],
|
||||
hTupDesc,
|
||||
&fcinfo.argnull[i]);
|
||||
anynull |= fcinfo.argnull[i];
|
||||
}
|
||||
if (flinfo.fn_strict && anynull)
|
||||
{
|
||||
/* force a null result for strict function */
|
||||
returnVal = (Datum) 0;
|
||||
*attNull = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
returnVal = FunctionCallInvoke(&fcinfo);
|
||||
*attNull = fcinfo.isnull;
|
||||
}
|
||||
returnVal = (Datum) fmgr_array_args(FIgetProcOid(fInfo),
|
||||
FIgetnArgs(fInfo),
|
||||
(char **) attData,
|
||||
&isNull);
|
||||
pfree(attData);
|
||||
*attNull = isNull;
|
||||
}
|
||||
else
|
||||
returnVal = heap_getattr(tuple, attrNums[attOff], hTupDesc, attNull);
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/index/Attic/istrat.c,v 1.42 2000/04/12 17:14:47 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/index/Attic/istrat.c,v 1.43 2000/05/28 17:55:52 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "catalog/pg_index.h"
|
||||
#include "catalog/pg_operator.h"
|
||||
#include "miscadmin.h"
|
||||
#include "utils/fmgroids.h"
|
||||
#include "utils/syscache.h"
|
||||
|
||||
#ifdef USE_ASSERT_CHECKING
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.81 2000/04/12 17:14:54 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.82 2000/05/28 17:55:53 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -34,6 +34,7 @@
|
||||
#include "miscadmin.h"
|
||||
#include "tcop/tcopprot.h"
|
||||
#include "utils/builtins.h"
|
||||
#include "utils/fmgroids.h"
|
||||
#include "utils/lsyscache.h"
|
||||
#include "utils/portal.h"
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.128 2000/05/25 21:25:32 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.129 2000/05/28 17:55:54 tgl Exp $
|
||||
*
|
||||
*
|
||||
* INTERFACE ROUTINES
|
||||
@@ -63,6 +63,7 @@
|
||||
#include "tcop/tcopprot.h"
|
||||
#include "utils/builtins.h"
|
||||
#include "utils/catcache.h"
|
||||
#include "utils/fmgroids.h"
|
||||
#include "utils/portal.h"
|
||||
#include "utils/relcache.h"
|
||||
#include "utils/syscache.h"
|
||||
@@ -1148,7 +1149,7 @@ RelationTruncateIndexes(Relation heapRelation)
|
||||
/* If a valid where predicate, compute predicate Node */
|
||||
if (VARSIZE(&index->indpred) != 0)
|
||||
{
|
||||
predString = fmgr(F_TEXTOUT, &index->indpred);
|
||||
predString = textout(&index->indpred);
|
||||
oldPred = stringToNode(predString);
|
||||
pfree(predString);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.110 2000/05/20 23:11:28 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.111 2000/05/28 17:55:54 tgl Exp $
|
||||
*
|
||||
*
|
||||
* INTERFACE ROUTINES
|
||||
@@ -42,6 +42,7 @@
|
||||
#include "storage/smgr.h"
|
||||
#include "utils/builtins.h"
|
||||
#include "utils/catcache.h"
|
||||
#include "utils/fmgroids.h"
|
||||
#include "utils/relcache.h"
|
||||
#include "utils/syscache.h"
|
||||
#include "utils/temprel.h"
|
||||
@@ -688,11 +689,11 @@ UpdateIndexRelation(Oid indexoid,
|
||||
if (predicate != NULL)
|
||||
{
|
||||
predString = nodeToString(predicate);
|
||||
predText = (text *) fmgr(F_TEXTIN, predString);
|
||||
predText = textin(predString);
|
||||
pfree(predString);
|
||||
}
|
||||
else
|
||||
predText = (text *) fmgr(F_TEXTIN, "");
|
||||
predText = textin("");
|
||||
|
||||
predLen = VARSIZE(predText);
|
||||
itupLen = predLen + sizeof(FormData_pg_index);
|
||||
@@ -832,11 +833,11 @@ UpdateIndexPredicate(Oid indexoid, Node *oldPred, Node *predicate)
|
||||
if (newPred != NULL)
|
||||
{
|
||||
predString = nodeToString(newPred);
|
||||
predText = (text *) fmgr(F_TEXTIN, predString);
|
||||
predText = textin(predString);
|
||||
pfree(predString);
|
||||
}
|
||||
else
|
||||
predText = (text *) fmgr(F_TEXTIN, "");
|
||||
predText = textin("");
|
||||
|
||||
/* open the index system catalog relation */
|
||||
pg_index = heap_openr(IndexRelationName, RowExclusiveLock);
|
||||
@@ -2109,7 +2110,7 @@ reindex_index(Oid indexId, bool force)
|
||||
/* If a valid where predicate, compute predicate Node */
|
||||
if (VARSIZE(&index->indpred) != 0)
|
||||
{
|
||||
predString = fmgr(F_TEXTOUT, &index->indpred);
|
||||
predString = textout(&index->indpred);
|
||||
oldPred = stringToNode(predString);
|
||||
pfree(predString);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/catalog/indexing.c,v 1.60 2000/04/12 17:14:56 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/catalog/indexing.c,v 1.61 2000/05/28 17:55:54 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "catalog/indexing.h"
|
||||
#include "catalog/pg_index.h"
|
||||
#include "miscadmin.h"
|
||||
#include "utils/fmgroids.h"
|
||||
#include "utils/syscache.h"
|
||||
|
||||
/*
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_operator.c,v 1.49 2000/01/26 05:56:10 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_operator.c,v 1.50 2000/05/28 17:55:54 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
* these routines moved here from commands/define.c and somewhat cleaned up.
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "miscadmin.h"
|
||||
#include "parser/parse_func.h"
|
||||
#include "utils/builtins.h"
|
||||
#include "utils/fmgroids.h"
|
||||
#include "utils/syscache.h"
|
||||
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_proc.c,v 1.42 2000/04/12 17:14:56 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_proc.c,v 1.43 2000/05/28 17:55:54 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "access/heapam.h"
|
||||
#include "catalog/catname.h"
|
||||
#include "catalog/indexing.h"
|
||||
#include "catalog/pg_language.h"
|
||||
#include "catalog/pg_proc.h"
|
||||
#include "catalog/pg_type.h"
|
||||
#include "miscadmin.h"
|
||||
@@ -24,7 +25,6 @@
|
||||
#include "parser/parse_type.h"
|
||||
#include "tcop/tcopprot.h"
|
||||
#include "utils/builtins.h"
|
||||
#include "utils/fmgrtab.h"
|
||||
#include "utils/lsyscache.h"
|
||||
#include "utils/sets.h"
|
||||
#include "utils/syscache.h"
|
||||
@@ -41,8 +41,9 @@ ProcedureCreate(char *procedureName,
|
||||
char *languageName,
|
||||
char *prosrc,
|
||||
char *probin,
|
||||
bool canCache,
|
||||
bool trusted,
|
||||
bool canCache,
|
||||
bool isStrict,
|
||||
int32 byte_pct,
|
||||
int32 perbyte_cpu,
|
||||
int32 percall_cpu,
|
||||
@@ -74,6 +75,15 @@ ProcedureCreate(char *procedureName,
|
||||
Assert(PointerIsValid(prosrc));
|
||||
Assert(PointerIsValid(probin));
|
||||
|
||||
tup = SearchSysCacheTuple(LANGNAME,
|
||||
PointerGetDatum(languageName),
|
||||
0, 0, 0);
|
||||
|
||||
if (!HeapTupleIsValid(tup))
|
||||
elog(ERROR, "ProcedureCreate: no such language '%s'", languageName);
|
||||
|
||||
languageObjectId = tup->t_data->t_oid;
|
||||
|
||||
parameterCount = 0;
|
||||
MemSet(typev, 0, FUNC_MAX_ARGS * sizeof(Oid));
|
||||
foreach(x, argList)
|
||||
@@ -86,7 +96,7 @@ ProcedureCreate(char *procedureName,
|
||||
|
||||
if (strcmp(strVal(t), "opaque") == 0)
|
||||
{
|
||||
if (strcmp(languageName, "sql") == 0)
|
||||
if (languageObjectId == SQLlanguageId)
|
||||
elog(ERROR, "ProcedureCreate: sql functions cannot take type \"opaque\"");
|
||||
toid = 0;
|
||||
}
|
||||
@@ -120,7 +130,7 @@ ProcedureCreate(char *procedureName,
|
||||
elog(ERROR, "ProcedureCreate: procedure %s already exists with same arguments",
|
||||
procedureName);
|
||||
|
||||
if (!strcmp(languageName, "sql"))
|
||||
if (languageObjectId == SQLlanguageId)
|
||||
{
|
||||
|
||||
/*
|
||||
@@ -129,7 +139,7 @@ ProcedureCreate(char *procedureName,
|
||||
* matches a function already in pg_proc. If so just return the
|
||||
* OID of the existing set.
|
||||
*/
|
||||
if (!strcmp(procedureName, GENERICSETNAME))
|
||||
if (strcmp(procedureName, GENERICSETNAME) == 0)
|
||||
{
|
||||
#ifdef SETS_FIXED
|
||||
/* ----------
|
||||
@@ -138,7 +148,7 @@ ProcedureCreate(char *procedureName,
|
||||
* have been removed. Instead a sequential heap scan
|
||||
* or something better must get implemented. The reason
|
||||
* for removing is that nbtree index crashes if sources
|
||||
* exceed 2K what's likely for procedural languages.
|
||||
* exceed 2K --- what's likely for procedural languages.
|
||||
*
|
||||
* 1999/09/30 Jan
|
||||
* ----------
|
||||
@@ -158,18 +168,9 @@ ProcedureCreate(char *procedureName,
|
||||
}
|
||||
}
|
||||
|
||||
tup = SearchSysCacheTuple(LANGNAME,
|
||||
PointerGetDatum(languageName),
|
||||
0, 0, 0);
|
||||
|
||||
if (!HeapTupleIsValid(tup))
|
||||
elog(ERROR, "ProcedureCreate: no such language %s", languageName);
|
||||
|
||||
languageObjectId = tup->t_data->t_oid;
|
||||
|
||||
if (strcmp(returnTypeName, "opaque") == 0)
|
||||
{
|
||||
if (strcmp(languageName, "sql") == 0)
|
||||
if (languageObjectId == SQLlanguageId)
|
||||
elog(ERROR, "ProcedureCreate: sql functions cannot return type \"opaque\"");
|
||||
typeObjectId = 0;
|
||||
}
|
||||
@@ -181,16 +182,10 @@ ProcedureCreate(char *procedureName,
|
||||
{
|
||||
elog(NOTICE, "ProcedureCreate: type '%s' is not yet defined",
|
||||
returnTypeName);
|
||||
#ifdef NOT_USED
|
||||
elog(NOTICE, "ProcedureCreate: creating a shell for type '%s'",
|
||||
returnTypeName);
|
||||
#endif
|
||||
typeObjectId = TypeShellMake(returnTypeName);
|
||||
if (!OidIsValid(typeObjectId))
|
||||
{
|
||||
elog(ERROR, "ProcedureCreate: could not create type '%s'",
|
||||
returnTypeName);
|
||||
}
|
||||
}
|
||||
else if (!defined)
|
||||
{
|
||||
@@ -219,7 +214,7 @@ ProcedureCreate(char *procedureName,
|
||||
* procedure's text in the prosrc attribute.
|
||||
*/
|
||||
|
||||
if (strcmp(languageName, "sql") == 0)
|
||||
if (languageObjectId == SQLlanguageId)
|
||||
{
|
||||
querytree_list = pg_parse_and_rewrite(prosrc, typev, parameterCount,
|
||||
FALSE);
|
||||
@@ -237,16 +232,50 @@ ProcedureCreate(char *procedureName,
|
||||
* FUNCTION xyz AS '' LANGUAGE 'internal'. To preserve some modicum
|
||||
* of backwards compatibility, accept an empty 'prosrc' value as
|
||||
* meaning the supplied SQL function name.
|
||||
*
|
||||
* XXX: we could treat "internal" and "newinternal" language specs
|
||||
* as equivalent, and take the actual language ID from the table of
|
||||
* known builtin functions. Is that a better idea than making the
|
||||
* user specify the right thing? Not sure.
|
||||
*/
|
||||
|
||||
if (strcmp(languageName, "internal") == 0)
|
||||
if (languageObjectId == INTERNALlanguageId ||
|
||||
languageObjectId == NEWINTERNALlanguageId)
|
||||
{
|
||||
Oid actualLangID;
|
||||
|
||||
if (strlen(prosrc) == 0)
|
||||
prosrc = procedureName;
|
||||
if (fmgr_lookupByName(prosrc) == (func_ptr) NULL)
|
||||
actualLangID = fmgr_internal_language(prosrc);
|
||||
if (actualLangID == InvalidOid)
|
||||
elog(ERROR,
|
||||
"ProcedureCreate: there is no builtin function named \"%s\"",
|
||||
"ProcedureCreate: there is no builtin function named \"%s\"",
|
||||
prosrc);
|
||||
if (actualLangID != languageObjectId)
|
||||
elog(ERROR,
|
||||
"ProcedureCreate: \"%s\" is not %s internal function",
|
||||
prosrc,
|
||||
((languageObjectId == INTERNALlanguageId) ?
|
||||
"an old-style" : "a new-style"));
|
||||
}
|
||||
|
||||
/*
|
||||
* If this is a dynamically loadable procedure, make sure that the
|
||||
* library file exists, is loadable, and contains the specified link
|
||||
* symbol.
|
||||
*
|
||||
* We used to perform these checks only when the function was first
|
||||
* called, but it seems friendlier to verify the library's validity
|
||||
* at CREATE FUNCTION time.
|
||||
*/
|
||||
|
||||
if (languageObjectId == ClanguageId ||
|
||||
languageObjectId == NEWClanguageId)
|
||||
{
|
||||
/* If link symbol is specified as "-", substitute procedure name */
|
||||
if (strcmp(prosrc, "-") == 0)
|
||||
prosrc = procedureName;
|
||||
(void) load_external_function(probin, prosrc);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -265,9 +294,10 @@ ProcedureCreate(char *procedureName,
|
||||
values[i++] = Int32GetDatum(GetUserId());
|
||||
values[i++] = ObjectIdGetDatum(languageObjectId);
|
||||
/* XXX isinherited is always false for now */
|
||||
values[i++] = Int8GetDatum((bool) 0);
|
||||
values[i++] = Int8GetDatum((bool) false);
|
||||
values[i++] = Int8GetDatum(trusted);
|
||||
values[i++] = Int8GetDatum(canCache);
|
||||
values[i++] = Int8GetDatum(isStrict);
|
||||
values[i++] = UInt16GetDatum(parameterCount);
|
||||
values[i++] = Int8GetDatum(returnsSet);
|
||||
values[i++] = ObjectIdGetDatum(typeObjectId);
|
||||
@@ -276,8 +306,8 @@ ProcedureCreate(char *procedureName,
|
||||
values[i++] = Int32GetDatum(perbyte_cpu); /* properbyte_cpu */
|
||||
values[i++] = Int32GetDatum(percall_cpu); /* propercall_cpu */
|
||||
values[i++] = Int32GetDatum(outin_ratio); /* prooutin_ratio */
|
||||
values[i++] = (Datum) fmgr(F_TEXTIN, prosrc); /* prosrc */
|
||||
values[i++] = (Datum) fmgr(F_TEXTIN, probin); /* probin */
|
||||
values[i++] = (Datum) textin(prosrc); /* prosrc */
|
||||
values[i++] = (Datum) textin(probin); /* probin */
|
||||
|
||||
rel = heap_openr(ProcedureRelationName, RowExclusiveLock);
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_type.c,v 1.50 2000/04/12 17:14:56 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_type.c,v 1.51 2000/05/28 17:55:54 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "miscadmin.h"
|
||||
#include "parser/parse_func.h"
|
||||
#include "utils/builtins.h"
|
||||
#include "utils/fmgroids.h"
|
||||
#include "utils/syscache.h"
|
||||
|
||||
|
||||
@@ -190,7 +191,7 @@ TypeShellMakeWithOpenRelation(Relation pg_type_desc, char *typeName)
|
||||
/*
|
||||
* ... and fill typdefault with a bogus value
|
||||
*/
|
||||
values[i++] = (Datum) fmgr(F_TEXTIN, typeName); /* 15 */
|
||||
values[i++] = (Datum) textin(typeName); /* 15 */
|
||||
|
||||
/* ----------------
|
||||
* create a new type tuple with FormHeapTuple
|
||||
@@ -449,10 +450,9 @@ TypeCreate(char *typeName,
|
||||
* initialize the default value for this type.
|
||||
* ----------------
|
||||
*/
|
||||
values[i] = (Datum) fmgr(F_TEXTIN, /* 16 */
|
||||
PointerIsValid(defaultTypeValue)
|
||||
? defaultTypeValue : "-"); /* XXX default
|
||||
* typdefault */
|
||||
values[i] = (Datum) textin(PointerIsValid(defaultTypeValue) /* 16 */
|
||||
? defaultTypeValue : "-"); /* XXX default
|
||||
* typdefault */
|
||||
|
||||
/* ----------------
|
||||
* open pg_type and begin a scan for the type name.
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/async.c,v 1.60 2000/05/14 03:18:35 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/async.c,v 1.61 2000/05/28 17:55:54 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -87,6 +87,7 @@
|
||||
#include "libpq/libpq.h"
|
||||
#include "libpq/pqformat.h"
|
||||
#include "miscadmin.h"
|
||||
#include "utils/fmgroids.h"
|
||||
#include "utils/ps_status.h"
|
||||
#include "utils/syscache.h"
|
||||
#include "utils/trace.h"
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.71 2000/04/12 17:14:57 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.72 2000/05/28 17:55:54 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
* The PortalExecutorHeapMemory crap needs to be eliminated
|
||||
@@ -40,6 +40,7 @@
|
||||
#include "optimizer/prep.h"
|
||||
#include "utils/acl.h"
|
||||
#include "utils/builtins.h"
|
||||
#include "utils/fmgroids.h"
|
||||
#include "utils/syscache.h"
|
||||
#include "utils/temprel.h"
|
||||
#include "commands/trigger.h"
|
||||
@@ -614,12 +615,15 @@ AlterTableAlterColumn(const char *relationName,
|
||||
HeapTuple tuple;
|
||||
|
||||
attr_rel = heap_openr(AttributeRelationName, AccessExclusiveLock);
|
||||
ScanKeyEntryInitialize(&scankeys[0], 0x0, Anum_pg_attribute_attrelid, F_OIDEQ,
|
||||
ScanKeyEntryInitialize(&scankeys[0], 0x0,
|
||||
Anum_pg_attribute_attrelid, F_OIDEQ,
|
||||
ObjectIdGetDatum(myrelid));
|
||||
ScanKeyEntryInitialize(&scankeys[1], 0x0, Anum_pg_attribute_attnum, F_INT2EQ,
|
||||
ScanKeyEntryInitialize(&scankeys[1], 0x0,
|
||||
Anum_pg_attribute_attnum, F_INT2EQ,
|
||||
Int16GetDatum(attnum));
|
||||
ScanKeyEntryInitialize(&scankeys[2], 0x0, Anum_pg_attribute_atthasdef, F_BOOLEQ,
|
||||
TRUE);
|
||||
ScanKeyEntryInitialize(&scankeys[2], 0x0,
|
||||
Anum_pg_attribute_atthasdef, F_BOOLEQ,
|
||||
Int32GetDatum(TRUE));
|
||||
|
||||
scan = heap_beginscan(attr_rel, false, SnapshotNow, 3, scankeys);
|
||||
AssertState(scan != NULL);
|
||||
@@ -661,9 +665,11 @@ drop_default(Oid relid, int16 attnum)
|
||||
HeapTuple tuple;
|
||||
|
||||
attrdef_rel = heap_openr(AttrDefaultRelationName, AccessExclusiveLock);
|
||||
ScanKeyEntryInitialize(&scankeys[0], 0x0, Anum_pg_attrdef_adrelid, F_OIDEQ,
|
||||
ScanKeyEntryInitialize(&scankeys[0], 0x0,
|
||||
Anum_pg_attrdef_adrelid, F_OIDEQ,
|
||||
ObjectIdGetDatum(relid));
|
||||
ScanKeyEntryInitialize(&scankeys[1], 0x0, Anum_pg_attrdef_adnum, F_INT2EQ,
|
||||
ScanKeyEntryInitialize(&scankeys[1], 0x0,
|
||||
Anum_pg_attrdef_adnum, F_INT2EQ,
|
||||
Int16GetDatum(attnum));
|
||||
|
||||
scan = heap_beginscan(attrdef_rel, false, SnapshotNow, 2, scankeys);
|
||||
|
||||
@@ -27,11 +27,12 @@
|
||||
#include "catalog/pg_type.h"
|
||||
#include "commands/comment.h"
|
||||
#include "miscadmin.h"
|
||||
#include "parser/parse.h"
|
||||
#include "rewrite/rewriteRemove.h"
|
||||
#include "utils/acl.h"
|
||||
#include "utils/fmgroids.h"
|
||||
#include "utils/syscache.h"
|
||||
|
||||
#include "../backend/parser/parse.h"
|
||||
|
||||
/*------------------------------------------------------------------
|
||||
* Static Function Prototypes --
|
||||
@@ -153,7 +154,7 @@ CreateComments(Oid oid, char *comment)
|
||||
}
|
||||
i = 0;
|
||||
values[i++] = ObjectIdGetDatum(oid);
|
||||
values[i++] = (Datum) fmgr(F_TEXTIN, comment);
|
||||
values[i++] = (Datum) textin(comment);
|
||||
}
|
||||
|
||||
/*** Now, open pg_description and attempt to find the old tuple ***/
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.106 2000/05/18 01:52:45 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.107 2000/05/28 17:55:54 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -680,7 +680,7 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim, char *null
|
||||
indexNatts[i] = natts;
|
||||
if (VARSIZE(&pgIndexP[i]->indpred) != 0)
|
||||
{
|
||||
predString = fmgr(F_TEXTOUT, &pgIndexP[i]->indpred);
|
||||
predString = textout(&pgIndexP[i]->indpred);
|
||||
indexPred[i] = stringToNode(predString);
|
||||
pfree(predString);
|
||||
/* make dummy ExprContext for use by ExecQual */
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.54 2000/05/25 06:53:43 ishii Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.55 2000/05/28 17:55:55 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -37,6 +37,7 @@
|
||||
#include "storage/fd.h" /* for closeAllVfds */
|
||||
#include "storage/sinval.h" /* for DatabaseHasActiveBackends */
|
||||
#include "utils/builtins.h"
|
||||
#include "utils/fmgroids.h"
|
||||
#include "utils/elog.h"
|
||||
#include "utils/palloc.h"
|
||||
#include "utils/rel.h"
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/define.c,v 1.42 2000/05/12 18:51:59 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/define.c,v 1.43 2000/05/28 17:55:55 tgl Exp $
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The "DefineFoo" routines take the parse tree and pick out the
|
||||
@@ -35,8 +35,6 @@
|
||||
*/
|
||||
#include <ctype.h>
|
||||
#include <math.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
|
||||
#include "postgres.h"
|
||||
|
||||
@@ -66,18 +64,20 @@ static void
|
||||
case_translate_language_name(const char *input, char *output)
|
||||
{
|
||||
/*-------------------------------------------------------------------------
|
||||
Translate the input language name to lower case, except if it's C,
|
||||
translate to upper case.
|
||||
Translate the input language name to lower case, except if it's "C",
|
||||
translate to upper case, or "newC", translate to that spelling.
|
||||
--------------------------------------------------------------------------*/
|
||||
int i;
|
||||
|
||||
for (i = 0; i < NAMEDATALEN && input[i]; ++i)
|
||||
for (i = 0; i < NAMEDATALEN-1 && input[i]; ++i)
|
||||
output[i] = tolower(input[i]);
|
||||
|
||||
output[i] = '\0';
|
||||
|
||||
if (strcmp(output, "c") == 0)
|
||||
output[0] = 'C';
|
||||
else if (strcmp(output, "newc") == 0)
|
||||
output[3] = 'C';
|
||||
}
|
||||
|
||||
|
||||
@@ -108,9 +108,10 @@ compute_return_type(const Node *returnType,
|
||||
|
||||
|
||||
static void
|
||||
compute_full_attributes(List *parameters, int32 *byte_pct_p,
|
||||
int32 *perbyte_cpu_p, int32 *percall_cpu_p,
|
||||
int32 *outin_ratio_p, bool *canCache_p)
|
||||
compute_full_attributes(List *parameters,
|
||||
int32 *byte_pct_p, int32 *perbyte_cpu_p,
|
||||
int32 *percall_cpu_p, int32 *outin_ratio_p,
|
||||
bool *canCache_p, bool *isStrict_p)
|
||||
{
|
||||
/*--------------------------------------------------------------------------
|
||||
Interpret the parameters *parameters and return their contents as
|
||||
@@ -119,14 +120,20 @@ compute_full_attributes(List *parameters, int32 *byte_pct_p,
|
||||
These parameters supply optional information about a function.
|
||||
All have defaults if not specified.
|
||||
|
||||
Note: as of version 6.6, canCache is used (if set, the optimizer's
|
||||
constant-folder is allowed to pre-evaluate the function if all its
|
||||
inputs are constant). The other four are not used. They used to be
|
||||
Note: currently, only two of these parameters actually do anything:
|
||||
|
||||
* canCache means the optimizer's constant-folder is allowed to
|
||||
pre-evaluate the function when all its inputs are constants.
|
||||
|
||||
* isStrict means the function should not be called when any NULL
|
||||
inputs are present; instead a NULL result value should be assumed.
|
||||
|
||||
The other four parameters are not used anywhere. They used to be
|
||||
used in the "expensive functions" optimizer, but that's been dead code
|
||||
for a long time.
|
||||
|
||||
Since canCache is useful for any function, we now allow attributes to be
|
||||
supplied for all functions regardless of language.
|
||||
Since canCache and isStrict are useful for any function, we now allow
|
||||
attributes to be supplied for all functions regardless of language.
|
||||
---------------------------------------------------------------------------*/
|
||||
List *pl;
|
||||
|
||||
@@ -136,6 +143,7 @@ compute_full_attributes(List *parameters, int32 *byte_pct_p,
|
||||
*percall_cpu_p = PERCALL_CPU;
|
||||
*outin_ratio_p = OUTIN_RATIO;
|
||||
*canCache_p = false;
|
||||
*isStrict_p = false;
|
||||
|
||||
foreach(pl, parameters)
|
||||
{
|
||||
@@ -143,6 +151,8 @@ compute_full_attributes(List *parameters, int32 *byte_pct_p,
|
||||
|
||||
if (strcasecmp(param->defname, "iscachable") == 0)
|
||||
*canCache_p = true;
|
||||
else if (strcasecmp(param->defname, "isstrict") == 0)
|
||||
*isStrict_p = true;
|
||||
else if (strcasecmp(param->defname, "trusted") == 0)
|
||||
{
|
||||
|
||||
@@ -182,24 +192,17 @@ static void
|
||||
interpret_AS_clause(const char *languageName, const List *as,
|
||||
char **prosrc_str_p, char **probin_str_p)
|
||||
{
|
||||
struct stat stat_buf;
|
||||
|
||||
Assert(as != NIL);
|
||||
|
||||
if (strcmp(languageName, "C") == 0)
|
||||
if (strcmp(languageName, "C") == 0 ||
|
||||
strcmp(languageName, "newC") == 0)
|
||||
{
|
||||
|
||||
/*
|
||||
* For "C" language, store the file name in probin and, when
|
||||
* given, the link symbol name in prosrc. But first, stat the
|
||||
* file to make sure it's there!
|
||||
* given, the link symbol name in prosrc.
|
||||
*/
|
||||
|
||||
if (stat(strVal(lfirst(as)), &stat_buf) == -1)
|
||||
elog(ERROR, "stat failed on file '%s': %m", strVal(lfirst(as)));
|
||||
|
||||
*probin_str_p = strVal(lfirst(as));
|
||||
|
||||
if (lnext(as) == NULL)
|
||||
*prosrc_str_p = "-";
|
||||
else
|
||||
@@ -239,8 +242,8 @@ CreateFunction(ProcedureStmt *stmt, CommandDest dest)
|
||||
char languageName[NAMEDATALEN];
|
||||
|
||||
/*
|
||||
* name of language of function, with case adjusted: "C", "internal",
|
||||
* or "SQL"
|
||||
* name of language of function, with case adjusted: "C", "newC",
|
||||
* "internal", "newinternal", "sql", etc.
|
||||
*/
|
||||
|
||||
bool returnsSet;
|
||||
@@ -257,19 +260,21 @@ CreateFunction(ProcedureStmt *stmt, CommandDest dest)
|
||||
perbyte_cpu,
|
||||
percall_cpu,
|
||||
outin_ratio;
|
||||
bool canCache;
|
||||
|
||||
bool canCache,
|
||||
isStrict;
|
||||
|
||||
case_translate_language_name(stmt->language, languageName);
|
||||
|
||||
if (strcmp(languageName, "C") == 0 ||
|
||||
strcmp(languageName, "internal") == 0)
|
||||
strcmp(languageName, "newC") == 0 ||
|
||||
strcmp(languageName, "internal") == 0 ||
|
||||
strcmp(languageName, "newinternal") == 0)
|
||||
{
|
||||
if (!superuser())
|
||||
elog(ERROR,
|
||||
"Only users with Postgres superuser privilege are "
|
||||
"permitted to create a function "
|
||||
"in the '%s' language. Others may use the 'sql' language "
|
||||
"permitted to create a function in the '%s' language.\n\t"
|
||||
"Others may use the 'sql' language "
|
||||
"or the created procedural languages.",
|
||||
languageName);
|
||||
}
|
||||
@@ -288,28 +293,23 @@ CreateFunction(ProcedureStmt *stmt, CommandDest dest)
|
||||
0, 0, 0);
|
||||
|
||||
if (!HeapTupleIsValid(languageTuple))
|
||||
{
|
||||
|
||||
elog(ERROR,
|
||||
"Unrecognized language specified in a CREATE FUNCTION: "
|
||||
"'%s'. Recognized languages are sql, C, internal "
|
||||
"and the created procedural languages.",
|
||||
"'%s'.\n\tRecognized languages are sql, C, newC, "
|
||||
"internal, newinternal, and created procedural languages.",
|
||||
languageName);
|
||||
}
|
||||
|
||||
/* Check that this language is a PL */
|
||||
languageStruct = (Form_pg_language) GETSTRUCT(languageTuple);
|
||||
if (!(languageStruct->lanispl))
|
||||
{
|
||||
elog(ERROR,
|
||||
"Language '%s' isn't defined as PL", languageName);
|
||||
}
|
||||
|
||||
/*
|
||||
* Functions in untrusted procedural languages are restricted to
|
||||
* be defined by postgres superusers only
|
||||
*/
|
||||
if (languageStruct->lanpltrusted == false && !superuser())
|
||||
if (!languageStruct->lanpltrusted && !superuser())
|
||||
{
|
||||
elog(ERROR, "Only users with Postgres superuser privilege "
|
||||
"are permitted to create a function in the '%s' "
|
||||
@@ -324,7 +324,7 @@ CreateFunction(ProcedureStmt *stmt, CommandDest dest)
|
||||
|
||||
compute_full_attributes(stmt->withClause,
|
||||
&byte_pct, &perbyte_cpu, &percall_cpu,
|
||||
&outin_ratio, &canCache);
|
||||
&outin_ratio, &canCache, &isStrict);
|
||||
|
||||
interpret_AS_clause(languageName, stmt->as, &prosrc_str, &probin_str);
|
||||
|
||||
@@ -338,8 +338,9 @@ CreateFunction(ProcedureStmt *stmt, CommandDest dest)
|
||||
languageName,
|
||||
prosrc_str, /* converted to text later */
|
||||
probin_str, /* converted to text later */
|
||||
canCache,
|
||||
true, /* (obsolete "trusted") */
|
||||
canCache,
|
||||
isStrict,
|
||||
byte_pct,
|
||||
perbyte_cpu,
|
||||
percall_cpu,
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.26 2000/04/25 10:38:38 inoue Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.27 2000/05/28 17:55:55 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -37,6 +37,7 @@
|
||||
#include "parser/parse_func.h"
|
||||
#include "parser/parse_type.h"
|
||||
#include "utils/builtins.h"
|
||||
#include "utils/fmgroids.h"
|
||||
#include "utils/syscache.h"
|
||||
#include "miscadmin.h" /* ReindexDatabase() */
|
||||
#include "utils/portal.h" /* ReindexDatabase() */
|
||||
@@ -298,7 +299,7 @@ ExtendIndex(char *indexRelationName, Expr *predicate, List *rangetable)
|
||||
{
|
||||
char *predString;
|
||||
|
||||
predString = fmgr(F_TEXTOUT, &index->indpred);
|
||||
predString = textout(&index->indpred);
|
||||
oldPred = stringToNode(predString);
|
||||
pfree(predString);
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "catalog/pg_shadow.h"
|
||||
#include "commands/proclang.h"
|
||||
#include "fmgr.h"
|
||||
#include "utils/builtins.h"
|
||||
#include "utils/syscache.h"
|
||||
|
||||
|
||||
@@ -119,7 +120,7 @@ CreateProceduralLanguage(CreatePLangStmt *stmt)
|
||||
values[i++] = Int8GetDatum((bool) 1);
|
||||
values[i++] = Int8GetDatum(stmt->pltrusted);
|
||||
values[i++] = ObjectIdGetDatum(procTup->t_data->t_oid);
|
||||
values[i++] = (Datum) fmgr(F_TEXTIN, stmt->plcompiler);
|
||||
values[i++] = (Datum) textin(stmt->plcompiler);
|
||||
|
||||
rel = heap_openr(LanguageRelationName, RowExclusiveLock);
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.64 2000/04/16 04:25:42 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.65 2000/05/28 17:55:55 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "miscadmin.h"
|
||||
#include "utils/acl.h"
|
||||
#include "utils/builtins.h"
|
||||
#include "utils/fmgroids.h"
|
||||
#include "utils/inval.h"
|
||||
#include "utils/syscache.h"
|
||||
#include "utils/tqual.h"
|
||||
@@ -757,16 +758,9 @@ equalTriggerDescs(TriggerDesc *trigdesc1, TriggerDesc *trigdesc2)
|
||||
static HeapTuple
|
||||
ExecCallTriggerFunc(Trigger *trigger)
|
||||
{
|
||||
|
||||
if (trigger->tgfunc.fn_addr == NULL)
|
||||
fmgr_info(trigger->tgfoid, &trigger->tgfunc);
|
||||
|
||||
if (trigger->tgfunc.fn_plhandler != NULL)
|
||||
{
|
||||
return (HeapTuple) (*(trigger->tgfunc.fn_plhandler))
|
||||
(&trigger->tgfunc);
|
||||
}
|
||||
|
||||
return (HeapTuple) ((*fmgr_faddr(&trigger->tgfunc)) ());
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: user.c,v 1.53 2000/05/04 20:06:07 tgl Exp $
|
||||
* $Id: user.c,v 1.54 2000/05/28 17:55:55 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -33,6 +33,7 @@
|
||||
#include "utils/acl.h"
|
||||
#include "utils/array.h"
|
||||
#include "utils/builtins.h"
|
||||
#include "utils/fmgroids.h"
|
||||
#include "utils/syscache.h"
|
||||
|
||||
static void CheckPgUserAclNotNull(void);
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.148 2000/05/19 03:22:29 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.149 2000/05/28 17:55:55 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -38,6 +38,7 @@
|
||||
#include "tcop/tcopprot.h"
|
||||
#include "utils/acl.h"
|
||||
#include "utils/builtins.h"
|
||||
#include "utils/fmgroids.h"
|
||||
#include "utils/inval.h"
|
||||
#include "utils/portal.h"
|
||||
#include "utils/relcache.h"
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/executor/execQual.c,v 1.69 2000/04/12 17:15:08 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/executor/execQual.c,v 1.70 2000/05/28 17:55:55 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -41,6 +41,7 @@
|
||||
#include "executor/functions.h"
|
||||
#include "executor/nodeSubplan.h"
|
||||
#include "utils/builtins.h"
|
||||
#include "utils/fmgroids.h"
|
||||
#include "utils/fcache2.h"
|
||||
|
||||
|
||||
@@ -64,7 +65,8 @@ static Datum ExecEvalAnd(Expr *andExpr, ExprContext *econtext, bool *isNull);
|
||||
static Datum ExecEvalFunc(Expr *funcClause, ExprContext *econtext,
|
||||
bool *isNull, bool *isDone);
|
||||
static void ExecEvalFuncArgs(FunctionCachePtr fcache, ExprContext *econtext,
|
||||
List *argList, Datum argV[], bool *argIsDone);
|
||||
List *argList, FunctionCallInfo fcinfo,
|
||||
bool *argIsDone);
|
||||
static Datum ExecEvalNot(Expr *notclause, ExprContext *econtext, bool *isNull);
|
||||
static Datum ExecEvalOper(Expr *opClause, ExprContext *econtext,
|
||||
bool *isNull);
|
||||
@@ -614,15 +616,12 @@ static void
|
||||
ExecEvalFuncArgs(FunctionCachePtr fcache,
|
||||
ExprContext *econtext,
|
||||
List *argList,
|
||||
Datum argV[],
|
||||
FunctionCallInfo fcinfo,
|
||||
bool *argIsDone)
|
||||
{
|
||||
int i;
|
||||
bool *nullVect;
|
||||
List *arg;
|
||||
|
||||
nullVect = fcache->nullVect;
|
||||
|
||||
i = 0;
|
||||
foreach(arg, argList)
|
||||
{
|
||||
@@ -632,16 +631,16 @@ ExecEvalFuncArgs(FunctionCachePtr fcache,
|
||||
* as arguments but we make an exception in the case of nested dot
|
||||
* expressions. We have to watch out for this case here.
|
||||
*/
|
||||
argV[i] = ExecEvalExpr((Node *) lfirst(arg),
|
||||
econtext,
|
||||
&nullVect[i],
|
||||
argIsDone);
|
||||
fcinfo->arg[i] = ExecEvalExpr((Node *) lfirst(arg),
|
||||
econtext,
|
||||
&fcinfo->argnull[i],
|
||||
argIsDone);
|
||||
|
||||
if (!(*argIsDone))
|
||||
{
|
||||
if (i != 0)
|
||||
elog(ERROR, "functions can only take sets in their first argument");
|
||||
fcache->setArg = (char *) argV[0];
|
||||
fcache->setArg = fcinfo->arg[0];
|
||||
fcache->hasSetArg = true;
|
||||
}
|
||||
i++;
|
||||
@@ -658,40 +657,45 @@ ExecMakeFunctionResult(Node *node,
|
||||
bool *isNull,
|
||||
bool *isDone)
|
||||
{
|
||||
Datum argV[FUNC_MAX_ARGS];
|
||||
FunctionCachePtr fcache;
|
||||
Func *funcNode = NULL;
|
||||
Oper *operNode = NULL;
|
||||
bool funcisset = false;
|
||||
FunctionCallInfoData fcinfo;
|
||||
FunctionCachePtr fcache;
|
||||
List *ftlist;
|
||||
bool funcisset;
|
||||
Datum result;
|
||||
bool argDone;
|
||||
|
||||
MemSet(&fcinfo, 0, sizeof(fcinfo));
|
||||
|
||||
/*
|
||||
* This is kind of ugly, Func nodes now have targetlists so that we
|
||||
* know when and what to project out from postquel function results.
|
||||
* This means we have to pass the func node all the way down instead
|
||||
* of using only the fcache struct as before. ExecMakeFunctionResult
|
||||
* becomes a little bit more of a dual personality as a result.
|
||||
* ExecMakeFunctionResult becomes a little bit more of a dual personality
|
||||
* as a result.
|
||||
*/
|
||||
if (IsA(node, Func))
|
||||
{
|
||||
funcNode = (Func *) node;
|
||||
fcache = funcNode->func_fcache;
|
||||
fcache = ((Func *) node)->func_fcache;
|
||||
ftlist = ((Func *) node)->func_tlist;
|
||||
funcisset = (((Func *) node)->funcid == F_SETEVAL);
|
||||
}
|
||||
else
|
||||
{
|
||||
operNode = (Oper *) node;
|
||||
fcache = operNode->op_fcache;
|
||||
fcache = ((Oper *) node)->op_fcache;
|
||||
ftlist = NIL;
|
||||
funcisset = false;
|
||||
}
|
||||
|
||||
fcinfo.flinfo = &fcache->func;
|
||||
fcinfo.nargs = fcache->nargs;
|
||||
|
||||
/*
|
||||
* arguments is a list of expressions to evaluate before passing to
|
||||
* the function manager. We collect the results of evaluating the
|
||||
* expressions into a datum array (argV) and pass this array to
|
||||
* arrayFmgr()
|
||||
* the function manager. We collect the results of evaluating the
|
||||
* expressions into the FunctionCallInfo struct. Note we assume that
|
||||
* fcache->nargs is the correct length of the arguments list!
|
||||
*/
|
||||
if (fcache->nargs != 0)
|
||||
if (fcache->nargs > 0)
|
||||
{
|
||||
bool argDone;
|
||||
|
||||
if (fcache->nargs > FUNC_MAX_ARGS)
|
||||
elog(ERROR, "ExecMakeFunctionResult: too many arguments");
|
||||
|
||||
@@ -700,21 +704,23 @@ ExecMakeFunctionResult(Node *node,
|
||||
* returning a set of tuples (i.e. a nested dot expression). We
|
||||
* don't want to evaluate the arguments again until the function
|
||||
* is done. hasSetArg will always be false until we eval the args
|
||||
* for the first time. We should set this in the parser.
|
||||
* for the first time.
|
||||
*/
|
||||
if ((fcache->hasSetArg) && fcache->setArg != NULL)
|
||||
if (fcache->hasSetArg && fcache->setArg != (Datum) 0)
|
||||
{
|
||||
argV[0] = (Datum) fcache->setArg;
|
||||
fcinfo.arg[0] = fcache->setArg;
|
||||
argDone = false;
|
||||
}
|
||||
else
|
||||
ExecEvalFuncArgs(fcache, econtext, arguments, argV, &argDone);
|
||||
ExecEvalFuncArgs(fcache, econtext, arguments, &fcinfo, &argDone);
|
||||
|
||||
if ((fcache->hasSetArg) && (argDone))
|
||||
if (fcache->hasSetArg && argDone)
|
||||
{
|
||||
/* can only get here if input is an empty set. */
|
||||
if (isDone)
|
||||
*isDone = true;
|
||||
return (Datum) NULL;
|
||||
*isNull = true;
|
||||
return (Datum) 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -731,27 +737,23 @@ ExecMakeFunctionResult(Node *node,
|
||||
* which defines this set. So replace the existing funcid in the
|
||||
* funcnode with the set's OID. Also, we want a new fcache which
|
||||
* points to the right function, so get that, now that we have the
|
||||
* right OID. Also zero out the argV, since the real set doesn't take
|
||||
* right OID. Also zero out fcinfo.arg, since the real set doesn't take
|
||||
* any arguments.
|
||||
*/
|
||||
if (((Func *) node)->funcid == F_SETEVAL)
|
||||
if (funcisset)
|
||||
{
|
||||
funcisset = true;
|
||||
if (fcache->setArg)
|
||||
{
|
||||
argV[0] = 0;
|
||||
|
||||
((Func *) node)->funcid = (Oid) PointerGetDatum(fcache->setArg);
|
||||
|
||||
((Func *) node)->funcid = DatumGetObjectId(fcache->setArg);
|
||||
}
|
||||
else
|
||||
{
|
||||
((Func *) node)->funcid = (Oid) argV[0];
|
||||
setFcache(node, argV[0], NIL, econtext);
|
||||
((Func *) node)->funcid = DatumGetObjectId(fcinfo.arg[0]);
|
||||
setFcache(node, DatumGetObjectId(fcinfo.arg[0]), NIL, econtext);
|
||||
fcache = ((Func *) node)->func_fcache;
|
||||
fcache->setArg = (char *) argV[0];
|
||||
argV[0] = (Datum) 0;
|
||||
fcache->setArg = fcinfo.arg[0];
|
||||
}
|
||||
fcinfo.arg[0] = (Datum) 0;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -760,11 +762,6 @@ ExecMakeFunctionResult(Node *node,
|
||||
*/
|
||||
if (fcache->language == SQLlanguageId)
|
||||
{
|
||||
Datum result;
|
||||
bool argDone;
|
||||
|
||||
Assert(funcNode);
|
||||
|
||||
/*--------------------
|
||||
* This loop handles the situation where we are iterating through
|
||||
* all results in a nested dot function (whose argument function
|
||||
@@ -777,8 +774,37 @@ ExecMakeFunctionResult(Node *node,
|
||||
*/
|
||||
for (;;)
|
||||
{
|
||||
result = postquel_function(funcNode, (char **) argV,
|
||||
isNull, isDone);
|
||||
/*
|
||||
* If function is strict, and there are any NULL arguments,
|
||||
* skip calling the function (at least for this set of args).
|
||||
*/
|
||||
bool callit = true;
|
||||
|
||||
if (fcinfo.flinfo->fn_strict)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < fcinfo.nargs; i++)
|
||||
{
|
||||
if (fcinfo.argnull[i])
|
||||
{
|
||||
callit = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (callit)
|
||||
{
|
||||
result = postquel_function(&fcinfo, fcache, ftlist, isDone);
|
||||
*isNull = fcinfo.isnull;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = (Datum) 0;
|
||||
*isDone = true;
|
||||
*isNull = true;
|
||||
}
|
||||
|
||||
if (!*isDone)
|
||||
break; /* got a result from current argument */
|
||||
@@ -786,7 +812,7 @@ ExecMakeFunctionResult(Node *node,
|
||||
break; /* input not a set, so done */
|
||||
|
||||
/* OK, get the next argument... */
|
||||
ExecEvalFuncArgs(fcache, econtext, arguments, argV, &argDone);
|
||||
ExecEvalFuncArgs(fcache, econtext, arguments, &fcinfo, &argDone);
|
||||
|
||||
if (argDone)
|
||||
{
|
||||
@@ -795,10 +821,11 @@ ExecMakeFunctionResult(Node *node,
|
||||
* End of arguments, so reset the setArg flag and say
|
||||
* "Done"
|
||||
*/
|
||||
fcache->setArg = (char *) NULL;
|
||||
fcache->setArg = (Datum) 0;
|
||||
fcache->hasSetArg = false;
|
||||
*isDone = true;
|
||||
result = (Datum) NULL;
|
||||
*isNull = true;
|
||||
result = (Datum) 0;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -826,21 +853,34 @@ ExecMakeFunctionResult(Node *node,
|
||||
if (*isDone)
|
||||
((Func *) node)->func_fcache = NULL;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
int i;
|
||||
|
||||
/* A non-SQL function cannot return a set, at present. */
|
||||
if (isDone)
|
||||
*isDone = true;
|
||||
for (i = 0; i < fcache->nargs; i++)
|
||||
if (fcache->nullVect[i] == true)
|
||||
*isNull = true;
|
||||
/*
|
||||
* If function is strict, and there are any NULL arguments,
|
||||
* skip calling the function and return NULL.
|
||||
*/
|
||||
if (fcinfo.flinfo->fn_strict)
|
||||
{
|
||||
int i;
|
||||
|
||||
return (Datum) fmgr_c(&fcache->func, (FmgrValues *) argV, isNull);
|
||||
for (i = 0; i < fcinfo.nargs; i++)
|
||||
{
|
||||
if (fcinfo.argnull[i])
|
||||
{
|
||||
*isNull = true;
|
||||
return (Datum) 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
result = FunctionCallInvoke(&fcinfo);
|
||||
*isNull = fcinfo.isnull;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/executor/execUtils.c,v 1.55 2000/04/12 17:15:08 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/executor/execUtils.c,v 1.56 2000/05/28 17:55:55 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -52,6 +52,8 @@
|
||||
#include "executor/execdebug.h"
|
||||
#include "executor/executor.h"
|
||||
#include "miscadmin.h"
|
||||
#include "utils/builtins.h"
|
||||
#include "utils/fmgroids.h"
|
||||
|
||||
static void ExecGetIndexKeyInfo(Form_pg_index indexTuple, int *numAttsOutP,
|
||||
AttrNumber **attsOutP, FuncIndexInfoPtr fInfoP);
|
||||
@@ -843,7 +845,7 @@ ExecOpenIndices(Oid resultRelationOid,
|
||||
*/
|
||||
if (VARSIZE(&indexStruct->indpred) != 0)
|
||||
{
|
||||
predString = fmgr(F_TEXTOUT, &indexStruct->indpred);
|
||||
predString = textout(&indexStruct->indpred);
|
||||
predicate = (PredInfo *) stringToNode(predString);
|
||||
pfree(predString);
|
||||
}
|
||||
|
||||
@@ -2,14 +2,13 @@
|
||||
*
|
||||
* functions.c
|
||||
* Routines to handle functions called from the executor
|
||||
* Putting this stuff in fmgr makes the postmaster a mess....
|
||||
*
|
||||
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/executor/functions.c,v 1.33 2000/04/12 17:15:09 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/executor/functions.c,v 1.34 2000/05/28 17:55:55 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -24,7 +23,6 @@
|
||||
#include "tcop/utility.h"
|
||||
#include "utils/datum.h"
|
||||
|
||||
#undef new
|
||||
|
||||
typedef enum
|
||||
{
|
||||
@@ -39,18 +37,18 @@ typedef struct local_es
|
||||
ExecStatus status;
|
||||
} execution_state;
|
||||
|
||||
#define LAST_POSTQUEL_COMMAND(es) ((es)->next == (execution_state *)NULL)
|
||||
#define LAST_POSTQUEL_COMMAND(es) ((es)->next == (execution_state *) NULL)
|
||||
|
||||
/* non-export function prototypes */
|
||||
static TupleDesc postquel_start(execution_state *es);
|
||||
static execution_state *init_execution_state(FunctionCachePtr fcache,
|
||||
char *args[]);
|
||||
static execution_state *init_execution_state(FunctionCachePtr fcache);
|
||||
static TupleTableSlot *postquel_getnext(execution_state *es);
|
||||
static void postquel_end(execution_state *es);
|
||||
static void postquel_sub_params(execution_state *es, int nargs,
|
||||
char *args[], bool *nullV);
|
||||
static Datum postquel_execute(execution_state *es, FunctionCachePtr fcache,
|
||||
List *fTlist, char **args, bool *isNull);
|
||||
static void postquel_sub_params(execution_state *es, FunctionCallInfo fcinfo);
|
||||
static Datum postquel_execute(execution_state *es,
|
||||
FunctionCallInfo fcinfo,
|
||||
FunctionCachePtr fcache,
|
||||
List *func_tlist);
|
||||
|
||||
|
||||
Datum
|
||||
@@ -64,7 +62,6 @@ ProjectAttribute(TupleDesc TD,
|
||||
Var *attrVar = (Var *) tlist->expr;
|
||||
AttrNumber attrno = attrVar->varattno;
|
||||
|
||||
|
||||
val = heap_getattr(tup, attrno, TD, isnullP);
|
||||
if (*isnullP)
|
||||
return (Datum) NULL;
|
||||
@@ -77,8 +74,7 @@ ProjectAttribute(TupleDesc TD,
|
||||
}
|
||||
|
||||
static execution_state *
|
||||
init_execution_state(FunctionCachePtr fcache,
|
||||
char *args[])
|
||||
init_execution_state(FunctionCachePtr fcache)
|
||||
{
|
||||
execution_state *newes;
|
||||
execution_state *nextes;
|
||||
@@ -196,13 +192,10 @@ postquel_end(execution_state *es)
|
||||
}
|
||||
|
||||
static void
|
||||
postquel_sub_params(execution_state *es,
|
||||
int nargs,
|
||||
char *args[],
|
||||
bool *nullV)
|
||||
postquel_sub_params(execution_state *es, FunctionCallInfo fcinfo)
|
||||
{
|
||||
ParamListInfo paramLI;
|
||||
EState *estate;
|
||||
ParamListInfo paramLI;
|
||||
|
||||
estate = es->estate;
|
||||
paramLI = estate->es_param_list_info;
|
||||
@@ -211,9 +204,9 @@ postquel_sub_params(execution_state *es,
|
||||
{
|
||||
if (paramLI->kind == PARAM_NUM)
|
||||
{
|
||||
Assert(paramLI->id <= nargs);
|
||||
paramLI->value = (Datum) args[(paramLI->id - 1)];
|
||||
paramLI->isnull = nullV[(paramLI->id - 1)];
|
||||
Assert(paramLI->id <= fcinfo->nargs);
|
||||
paramLI->value = fcinfo->arg[paramLI->id - 1];
|
||||
paramLI->isnull = fcinfo->argnull[paramLI->id - 1];
|
||||
}
|
||||
paramLI++;
|
||||
}
|
||||
@@ -264,10 +257,9 @@ copy_function_result(FunctionCachePtr fcache,
|
||||
|
||||
static Datum
|
||||
postquel_execute(execution_state *es,
|
||||
FunctionCallInfo fcinfo,
|
||||
FunctionCachePtr fcache,
|
||||
List *fTlist,
|
||||
char **args,
|
||||
bool *isNull)
|
||||
List *func_tlist)
|
||||
{
|
||||
TupleTableSlot *slot;
|
||||
Datum value;
|
||||
@@ -278,8 +270,8 @@ postquel_execute(execution_state *es,
|
||||
* ExecutorStart->ExecInitIndexScan->ExecEvalParam works ok. (But
|
||||
* note: I HOPE we can do it here). - vadim 01/22/97
|
||||
*/
|
||||
if (fcache->nargs > 0)
|
||||
postquel_sub_params(es, fcache->nargs, args, fcache->nullVect);
|
||||
if (fcinfo->nargs > 0)
|
||||
postquel_sub_params(es, fcinfo);
|
||||
|
||||
if (es->status == F_EXEC_START)
|
||||
{
|
||||
@@ -293,7 +285,7 @@ postquel_execute(execution_state *es,
|
||||
{
|
||||
postquel_end(es);
|
||||
es->status = F_EXEC_DONE;
|
||||
*isNull = true;
|
||||
fcinfo->isnull = true;
|
||||
|
||||
/*
|
||||
* If this isn't the last command for the function we have to
|
||||
@@ -315,19 +307,20 @@ postquel_execute(execution_state *es,
|
||||
* logic and code redundancy here.
|
||||
*/
|
||||
resSlot = copy_function_result(fcache, slot);
|
||||
if (fTlist != NIL)
|
||||
if (func_tlist != NIL)
|
||||
{
|
||||
TargetEntry *tle = lfirst(fTlist);
|
||||
TargetEntry *tle = lfirst(func_tlist);
|
||||
|
||||
value = ProjectAttribute(resSlot->ttc_tupleDescriptor,
|
||||
tle,
|
||||
resSlot->val,
|
||||
isNull);
|
||||
&fcinfo->isnull);
|
||||
}
|
||||
else
|
||||
{
|
||||
value = (Datum) resSlot;
|
||||
*isNull = false;
|
||||
/* XXX is this right? Return whole tuple slot?? */
|
||||
value = PointerGetDatum(resSlot);
|
||||
fcinfo->isnull = false;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -353,11 +346,13 @@ postquel_execute(execution_state *es,
|
||||
}
|
||||
|
||||
Datum
|
||||
postquel_function(Func *funcNode, char **args, bool *isNull, bool *isDone)
|
||||
postquel_function(FunctionCallInfo fcinfo,
|
||||
FunctionCachePtr fcache,
|
||||
List *func_tlist,
|
||||
bool *isDone)
|
||||
{
|
||||
execution_state *es;
|
||||
Datum result = 0;
|
||||
FunctionCachePtr fcache = funcNode->func_fcache;
|
||||
CommandId savedId;
|
||||
|
||||
/*
|
||||
@@ -371,7 +366,7 @@ postquel_function(Func *funcNode, char **args, bool *isNull, bool *isDone)
|
||||
es = (execution_state *) fcache->func_state;
|
||||
if (es == NULL)
|
||||
{
|
||||
es = init_execution_state(fcache, args);
|
||||
es = init_execution_state(fcache);
|
||||
fcache->func_state = (char *) es;
|
||||
}
|
||||
|
||||
@@ -388,15 +383,19 @@ postquel_function(Func *funcNode, char **args, bool *isNull, bool *isDone)
|
||||
while (es != (execution_state *) NULL)
|
||||
{
|
||||
result = postquel_execute(es,
|
||||
fcinfo,
|
||||
fcache,
|
||||
funcNode->func_tlist,
|
||||
args,
|
||||
isNull);
|
||||
func_tlist);
|
||||
if (es->status != F_EXEC_DONE)
|
||||
break;
|
||||
es = es->next;
|
||||
}
|
||||
|
||||
/*
|
||||
* Restore outer command ID.
|
||||
*/
|
||||
SetScanCommandId(savedId);
|
||||
|
||||
/*
|
||||
* If we've gone through every command in this function, we are done.
|
||||
*/
|
||||
@@ -417,17 +416,15 @@ postquel_function(Func *funcNode, char **args, bool *isNull, bool *isDone)
|
||||
* Let caller know we're finished.
|
||||
*/
|
||||
*isDone = true;
|
||||
SetScanCommandId(savedId);
|
||||
return (fcache->oneResult) ? result : (Datum) NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* If we got a result from a command within the function it has to be
|
||||
* the final command. All others shouldn't be returing anything.
|
||||
* the final command. All others shouldn't be returning anything.
|
||||
*/
|
||||
Assert(LAST_POSTQUEL_COMMAND(es));
|
||||
*isDone = false;
|
||||
|
||||
SetScanCommandId(savedId);
|
||||
*isDone = false;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/executor/nodeAgg.c,v 1.63 2000/04/12 17:15:09 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/executor/nodeAgg.c,v 1.64 2000/05/28 17:55:55 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -218,8 +218,13 @@ static void
|
||||
advance_transition_functions(AggStatePerAgg peraggstate,
|
||||
Datum newVal, bool isNull)
|
||||
{
|
||||
Datum args[2];
|
||||
FunctionCallInfoData fcinfo;
|
||||
|
||||
MemSet(&fcinfo, 0, sizeof(fcinfo));
|
||||
|
||||
/*
|
||||
* XXX reconsider isNULL handling here
|
||||
*/
|
||||
if (OidIsValid(peraggstate->xfn1_oid) && !isNull)
|
||||
{
|
||||
if (peraggstate->noInitValue)
|
||||
@@ -244,28 +249,48 @@ advance_transition_functions(AggStatePerAgg peraggstate,
|
||||
else
|
||||
{
|
||||
/* apply transition function 1 */
|
||||
args[0] = peraggstate->value1;
|
||||
args[1] = newVal;
|
||||
newVal = (Datum) fmgr_c(&peraggstate->xfn1,
|
||||
(FmgrValues *) args,
|
||||
&isNull);
|
||||
if (!peraggstate->transtype1ByVal)
|
||||
fcinfo.flinfo = &peraggstate->xfn1;
|
||||
fcinfo.nargs = 2;
|
||||
fcinfo.arg[0] = peraggstate->value1;
|
||||
fcinfo.argnull[0] = peraggstate->value1IsNull;
|
||||
fcinfo.arg[1] = newVal;
|
||||
fcinfo.argnull[1] = isNull;
|
||||
if (fcinfo.flinfo->fn_strict &&
|
||||
(peraggstate->value1IsNull || isNull))
|
||||
{
|
||||
/* don't call a strict function with NULL inputs */
|
||||
newVal = (Datum) 0;
|
||||
fcinfo.isnull = true;
|
||||
}
|
||||
else
|
||||
newVal = FunctionCallInvoke(&fcinfo);
|
||||
if (!peraggstate->transtype1ByVal && !peraggstate->value1IsNull)
|
||||
pfree(peraggstate->value1);
|
||||
peraggstate->value1 = newVal;
|
||||
peraggstate->value1IsNull = fcinfo.isnull;
|
||||
}
|
||||
}
|
||||
|
||||
if (OidIsValid(peraggstate->xfn2_oid))
|
||||
{
|
||||
/* apply transition function 2 */
|
||||
args[0] = peraggstate->value2;
|
||||
isNull = false; /* value2 cannot be null, currently */
|
||||
newVal = (Datum) fmgr_c(&peraggstate->xfn2,
|
||||
(FmgrValues *) args,
|
||||
&isNull);
|
||||
if (!peraggstate->transtype2ByVal)
|
||||
fcinfo.flinfo = &peraggstate->xfn2;
|
||||
fcinfo.nargs = 1;
|
||||
fcinfo.arg[0] = peraggstate->value2;
|
||||
fcinfo.argnull[0] = peraggstate->value2IsNull;
|
||||
fcinfo.isnull = false; /* must reset after use by xfn1 */
|
||||
if (fcinfo.flinfo->fn_strict && peraggstate->value2IsNull)
|
||||
{
|
||||
/* don't call a strict function with NULL inputs */
|
||||
newVal = (Datum) 0;
|
||||
fcinfo.isnull = true;
|
||||
}
|
||||
else
|
||||
newVal = FunctionCallInvoke(&fcinfo);
|
||||
if (!peraggstate->transtype2ByVal && !peraggstate->value2IsNull)
|
||||
pfree(peraggstate->value2);
|
||||
peraggstate->value2 = newVal;
|
||||
peraggstate->value2IsNull = fcinfo.isnull;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -276,8 +301,10 @@ static void
|
||||
finalize_aggregate(AggStatePerAgg peraggstate,
|
||||
Datum *resultVal, bool *resultIsNull)
|
||||
{
|
||||
Aggref *aggref = peraggstate->aggref;
|
||||
char *args[2];
|
||||
Aggref *aggref = peraggstate->aggref;
|
||||
FunctionCallInfoData fcinfo;
|
||||
|
||||
MemSet(&fcinfo, 0, sizeof(fcinfo));
|
||||
|
||||
/*
|
||||
* If it's a DISTINCT aggregate, all we've done so far is to stuff the
|
||||
@@ -337,21 +364,41 @@ finalize_aggregate(AggStatePerAgg peraggstate,
|
||||
if (OidIsValid(peraggstate->finalfn_oid) &&
|
||||
!peraggstate->noInitValue)
|
||||
{
|
||||
fcinfo.flinfo = &peraggstate->finalfn;
|
||||
if (peraggstate->finalfn.fn_nargs > 1)
|
||||
{
|
||||
args[0] = (char *) peraggstate->value1;
|
||||
args[1] = (char *) peraggstate->value2;
|
||||
fcinfo.nargs = 2;
|
||||
fcinfo.arg[0] = peraggstate->value1;
|
||||
fcinfo.argnull[0] = peraggstate->value1IsNull;
|
||||
fcinfo.arg[1] = peraggstate->value2;
|
||||
fcinfo.argnull[1] = peraggstate->value2IsNull;
|
||||
}
|
||||
else if (OidIsValid(peraggstate->xfn1_oid))
|
||||
args[0] = (char *) peraggstate->value1;
|
||||
{
|
||||
fcinfo.nargs = 1;
|
||||
fcinfo.arg[0] = peraggstate->value1;
|
||||
fcinfo.argnull[0] = peraggstate->value1IsNull;
|
||||
}
|
||||
else if (OidIsValid(peraggstate->xfn2_oid))
|
||||
args[0] = (char *) peraggstate->value2;
|
||||
{
|
||||
fcinfo.nargs = 1;
|
||||
fcinfo.arg[0] = peraggstate->value2;
|
||||
fcinfo.argnull[0] = peraggstate->value2IsNull;
|
||||
}
|
||||
else
|
||||
elog(ERROR, "ExecAgg: no valid transition functions??");
|
||||
*resultIsNull = false;
|
||||
*resultVal = (Datum) fmgr_c(&peraggstate->finalfn,
|
||||
(FmgrValues *) args,
|
||||
resultIsNull);
|
||||
if (fcinfo.flinfo->fn_strict &&
|
||||
(fcinfo.argnull[0] || fcinfo.argnull[1]))
|
||||
{
|
||||
/* don't call a strict function with NULL inputs */
|
||||
*resultVal = (Datum) 0;
|
||||
*resultIsNull = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
*resultVal = FunctionCallInvoke(&fcinfo);
|
||||
*resultIsNull = fcinfo.isnull;
|
||||
}
|
||||
}
|
||||
else if (OidIsValid(peraggstate->xfn1_oid))
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
# Makefile for libpq subsystem (backend half of libpq interface)
|
||||
#
|
||||
# IDENTIFICATION
|
||||
# $Header: /cvsroot/pgsql/src/backend/libpq/Makefile,v 1.17 2000/01/19 02:58:52 petere Exp $
|
||||
# $Header: /cvsroot/pgsql/src/backend/libpq/Makefile,v 1.18 2000/05/28 17:55:56 tgl Exp $
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
@@ -29,11 +29,6 @@ all: SUBSYS.o
|
||||
SUBSYS.o: $(OBJS)
|
||||
$(LD) $(LDREL) $(LDOUT) SUBSYS.o $(OBJS)
|
||||
|
||||
be-dumpdata.o be-pqexec.o: ../fmgr.h
|
||||
|
||||
../fmgr.h:
|
||||
$(MAKE) -C .. fmgr.h
|
||||
|
||||
depend dep:
|
||||
$(CC) -MM $(CFLAGS) *.c >depend
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/libpq/Attic/be-pqexec.c,v 1.31 2000/03/17 02:36:08 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/libpq/Attic/be-pqexec.c,v 1.32 2000/05/28 17:55:56 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -42,11 +42,11 @@ static char *strmake(char *str, int len);
|
||||
* result_buf : pointer to result buffer (&int if integer)
|
||||
* result_len : length of return value.
|
||||
* result_is_int : If the result is an integer, this must be non-zero
|
||||
* args : pointer to a NULL terminated arg array.
|
||||
* args : pointer to an array of PQArgBlock items.
|
||||
* (length, if integer, and result-pointer)
|
||||
* nargs : # of arguments in args array.
|
||||
*
|
||||
* This code scavanged from HandleFunctionRequest() in tcop/fastpath.h
|
||||
* This code scavenged from HandleFunctionRequest() in tcop/fastpath.h
|
||||
* ----------------
|
||||
*/
|
||||
char *
|
||||
@@ -57,46 +57,53 @@ PQfn(int fnid,
|
||||
PQArgBlock *args,
|
||||
int nargs)
|
||||
{
|
||||
char *retval; /* XXX - should be datum, maybe ? */
|
||||
char *arg[FUNC_MAX_ARGS];
|
||||
bool isNull;
|
||||
int i;
|
||||
FmgrInfo flinfo;
|
||||
FunctionCallInfoData fcinfo;
|
||||
Datum retval;
|
||||
int i;
|
||||
|
||||
/* ----------------
|
||||
* fill args[] array
|
||||
* ----------------
|
||||
*/
|
||||
if (nargs > FUNC_MAX_ARGS)
|
||||
elog(ERROR, "functions cannot have more than %d arguments",
|
||||
FUNC_MAX_ARGS);
|
||||
|
||||
/* ----------------
|
||||
* set up the argument block for the function manager
|
||||
* ----------------
|
||||
*/
|
||||
fmgr_info((Oid) fnid, &flinfo);
|
||||
|
||||
MemSet(&fcinfo, 0, sizeof(fcinfo));
|
||||
fcinfo.flinfo = &flinfo;
|
||||
fcinfo.nargs = nargs;
|
||||
|
||||
for (i = 0; i < nargs; i++)
|
||||
{
|
||||
if (args[i].len == VAR_LENGTH_ARG)
|
||||
arg[i] = (char *) args[i].u.ptr;
|
||||
fcinfo.arg[i] = (Datum) args[i].u.ptr;
|
||||
else if ((Size) args[i].len > sizeof(int4))
|
||||
elog(ERROR, "arg_length of argument %d too long", i);
|
||||
else
|
||||
arg[i] = (char *) args[i].u.integer;
|
||||
fcinfo.arg[i] = (Datum) args[i].u.integer;
|
||||
}
|
||||
|
||||
/* ----------------
|
||||
* call the postgres function manager
|
||||
* ----------------
|
||||
*/
|
||||
retval = fmgr_array_args(fnid, nargs, arg, &isNull);
|
||||
retval = FunctionCallInvoke(&fcinfo);
|
||||
|
||||
/* ----------------
|
||||
* put the result in the buffer the user specified and
|
||||
* return the proper code.
|
||||
* ----------------
|
||||
*/
|
||||
if (isNull) /* void retval */
|
||||
if (fcinfo.isnull) /* void retval */
|
||||
return "0";
|
||||
|
||||
if (result_is_int)
|
||||
*result_buf = (int) retval;
|
||||
*result_buf = DatumGetInt32(retval);
|
||||
else
|
||||
memmove(result_buf, retval, result_len);
|
||||
memmove(result_buf, DatumGetPointer(retval), result_len);
|
||||
return "G";
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/nodes/Attic/freefuncs.c,v 1.40 2000/04/12 17:15:16 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/nodes/Attic/freefuncs.c,v 1.41 2000/05/28 17:55:57 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -530,16 +530,12 @@ _freeFcache(FunctionCachePtr ptr)
|
||||
{
|
||||
if (ptr->argOidVect)
|
||||
pfree(ptr->argOidVect);
|
||||
if (ptr->nullVect)
|
||||
pfree(ptr->nullVect);
|
||||
if (ptr->src)
|
||||
pfree(ptr->src);
|
||||
if (ptr->bin)
|
||||
pfree(ptr->bin);
|
||||
if (ptr->func_state)
|
||||
pfree(ptr->func_state);
|
||||
if (ptr->setArg)
|
||||
pfree(ptr->setArg);
|
||||
|
||||
pfree(ptr);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/clausesel.c,v 1.34 2000/04/12 17:15:19 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/clausesel.c,v 1.35 2000/05/28 17:55:58 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "optimizer/plancat.h"
|
||||
#include "optimizer/restrictinfo.h"
|
||||
#include "parser/parsetree.h"
|
||||
#include "utils/fmgroids.h"
|
||||
#include "utils/lsyscache.h"
|
||||
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/indxpath.c,v 1.83 2000/04/16 04:41:01 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/indxpath.c,v 1.84 2000/05/28 17:55:58 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -37,6 +37,7 @@
|
||||
#include "parser/parse_oper.h"
|
||||
#include "parser/parsetree.h"
|
||||
#include "utils/builtins.h"
|
||||
#include "utils/fmgroids.h"
|
||||
#include "utils/lsyscache.h"
|
||||
#include "utils/syscache.h"
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/plancat.c,v 1.50 2000/04/12 17:15:24 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/plancat.c,v 1.51 2000/05/28 17:55:59 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -28,6 +28,8 @@
|
||||
#include "optimizer/paths.h"
|
||||
#include "optimizer/plancat.h"
|
||||
#include "parser/parsetree.h"
|
||||
#include "utils/builtins.h"
|
||||
#include "utils/fmgroids.h"
|
||||
#include "utils/syscache.h"
|
||||
#include "catalog/catalog.h"
|
||||
#include "miscadmin.h"
|
||||
@@ -117,7 +119,7 @@ find_secondary_indexes(Query *root, Index relid)
|
||||
info->indproc = index->indproc; /* functional index ?? */
|
||||
if (VARSIZE(&index->indpred) != 0) /* partial index ?? */
|
||||
{
|
||||
char *predString = fmgr(F_TEXTOUT, &index->indpred);
|
||||
char *predString = textout(&index->indpred);
|
||||
|
||||
info->indpred = (List *) stringToNode(predString);
|
||||
pfree(predString);
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: analyze.c,v 1.142 2000/04/12 17:15:26 momjian Exp $
|
||||
* $Id: analyze.c,v 1.143 2000/05/28 17:56:00 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "parser/parse_target.h"
|
||||
#include "parser/parse_type.h"
|
||||
#include "utils/builtins.h"
|
||||
#include "utils/fmgroids.h"
|
||||
#include "utils/numeric.h"
|
||||
|
||||
void CheckSelectForUpdate(Query *qry); /* no points for style... */
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/parse_func.c,v 1.79 2000/05/26 03:56:40 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/parse_func.c,v 1.80 2000/05/28 17:56:00 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -34,6 +34,7 @@
|
||||
#include "parser/parse_target.h"
|
||||
#include "utils/acl.h"
|
||||
#include "utils/builtins.h"
|
||||
#include "utils/fmgroids.h"
|
||||
#include "utils/lsyscache.h"
|
||||
#include "utils/syscache.h"
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/parse_node.c,v 1.39 2000/04/12 17:15:27 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/parse_node.c,v 1.40 2000/05/28 17:56:00 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -442,14 +442,11 @@ make_const(Value *value)
|
||||
case T_Float:
|
||||
if (fitsInFloat(value))
|
||||
{
|
||||
float64 fltval = (float64) palloc(sizeof(float64data));
|
||||
|
||||
*fltval = floatVal(value);
|
||||
val = Float64GetDatum(fltval);
|
||||
val = Float8GetDatum(floatVal(value));
|
||||
|
||||
typeid = FLOAT8OID;
|
||||
typelen = sizeof(float64data);
|
||||
typebyval = false;
|
||||
typelen = sizeof(float8);
|
||||
typebyval = false; /* XXX might change someday */
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/parse_oper.c,v 1.40 2000/04/12 17:15:27 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/parse_oper.c,v 1.41 2000/05/28 17:56:00 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "parser/parse_func.h"
|
||||
#include "parser/parse_oper.h"
|
||||
#include "parser/parse_type.h"
|
||||
#include "utils/fmgroids.h"
|
||||
#include "utils/syscache.h"
|
||||
|
||||
static Oid *oper_select_candidate(int nargs, Oid *input_typeids,
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: alpha.h,v 1.4 2000/01/26 05:56:44 momjian Exp $
|
||||
* $Id: alpha.h,v 1.5 2000/05/28 17:56:02 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -29,7 +29,7 @@
|
||||
*
|
||||
*/
|
||||
#define pg_dlopen(f) dlopen(f, RTLD_LAZY)
|
||||
#define pg_dlsym(h, f) ((func_ptr)dlsym(h, f))
|
||||
#define pg_dlsym(h, f) ((PGFunction) dlsym(h, f))
|
||||
#define pg_dlclose(h) dlclose(h)
|
||||
#define pg_dlerror() dlerror()
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#define pg_dlclose dlclose
|
||||
#define pg_dlerror dlerror
|
||||
#else
|
||||
#define pg_dlsym(handle, funcname) ((func_ptr) dld_get_func((funcname)))
|
||||
#define pg_dlsym(handle, funcname) ((PGFunction) dld_get_func((funcname)))
|
||||
#define pg_dlclose(handle) ({ dld_unlink_by_file(handle, 1); free(handle); })
|
||||
#endif
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/port/dynloader/hpux.c,v 1.13 2000/04/26 23:35:34 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/port/dynloader/hpux.c,v 1.14 2000/05/28 17:56:02 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
* all functions are defined here -- it's impossible to trace the
|
||||
@@ -39,13 +39,13 @@ pg_dlopen(char *filename)
|
||||
return (void *) handle;
|
||||
}
|
||||
|
||||
func_ptr
|
||||
PGFunction
|
||||
pg_dlsym(void *handle, char *funcname)
|
||||
{
|
||||
func_ptr f;
|
||||
PGFunction f;
|
||||
|
||||
if (shl_findsym((shl_t *) & handle, funcname, TYPE_PROCEDURE, &f) == -1)
|
||||
f = (func_ptr) NULL;
|
||||
f = (PGFunction) NULL;
|
||||
return f;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/port/dynloader/hpux.h,v 1.3 2000/01/26 05:56:44 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/port/dynloader/hpux.h,v 1.4 2000/05/28 17:56:02 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
* all functions are defined here -- it's impossible to trace the
|
||||
@@ -17,7 +17,9 @@
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
/* System includes */
|
||||
#include "fmgr.h"
|
||||
|
||||
void *pg_dlopen(char *filename);
|
||||
func_ptr pg_dlsym(void *handle, char *funcname);
|
||||
PGFunction pg_dlsym(void *handle, char *funcname);
|
||||
void pg_dlclose(void *handle);
|
||||
char *pg_dlerror();
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: linux.h,v 1.8 2000/01/26 05:56:44 momjian Exp $
|
||||
* $Id: linux.h,v 1.9 2000/05/28 17:56:02 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -27,7 +27,7 @@
|
||||
#define pg_dlsym(handle, funcname) (NULL)
|
||||
#define pg_dlclose(handle) ({})
|
||||
#else
|
||||
#define pg_dlsym(handle, funcname) ((func_ptr) dld_get_func((funcname)))
|
||||
#define pg_dlsym(handle, funcname) ((PGFunction) dld_get_func((funcname)))
|
||||
#define pg_dlclose(handle) ({ dld_unlink_by_file(handle, 1); free(handle); })
|
||||
#endif
|
||||
#else
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/port/dynloader/Attic/qnx4.c,v 1.1 1999/12/16 01:25:04 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/port/dynloader/Attic/qnx4.c,v 1.2 2000/05/28 17:56:02 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
*
|
||||
@@ -30,7 +30,7 @@ pg_dlopen(char *filename)
|
||||
return (void *) NULL;
|
||||
}
|
||||
|
||||
func_ptr
|
||||
PGFunction
|
||||
pg_dlsym(void *handle, char *funcname)
|
||||
{
|
||||
return NULL;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/port/dynloader/Attic/qnx4.h,v 1.1 1999/12/16 01:25:04 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/port/dynloader/Attic/qnx4.h,v 1.2 2000/05/28 17:56:02 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
*
|
||||
@@ -15,6 +15,6 @@
|
||||
*/
|
||||
/* System includes */
|
||||
void *pg_dlopen(char *filename);
|
||||
func_ptr pg_dlsym(void *handle, char *funcname);
|
||||
PGFunction pg_dlsym(void *handle, char *funcname);
|
||||
void pg_dlclose(void *handle);
|
||||
char *pg_dlerror();
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteRemove.c,v 1.36 2000/04/12 17:15:32 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteRemove.c,v 1.37 2000/05/28 17:56:02 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "commands/comment.h"
|
||||
#include "rewrite/rewriteRemove.h"
|
||||
#include "rewrite/rewriteSupport.h"
|
||||
#include "utils/fmgroids.h"
|
||||
#include "utils/syscache.h"
|
||||
|
||||
/*-----------------------------------------------------------------------
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/storage/large_object/inv_api.c,v 1.67 2000/04/12 17:15:37 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/storage/large_object/inv_api.c,v 1.68 2000/05/28 17:56:03 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -31,6 +31,7 @@
|
||||
#include "miscadmin.h"
|
||||
#include "storage/large_object.h"
|
||||
#include "storage/smgr.h"
|
||||
#include "utils/fmgroids.h"
|
||||
#include "utils/relcache.h"
|
||||
|
||||
/*
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
# Makefile for tcop
|
||||
#
|
||||
# IDENTIFICATION
|
||||
# $Header: /cvsroot/pgsql/src/backend/tcop/Makefile,v 1.21 2000/01/19 02:58:56 petere Exp $
|
||||
# $Header: /cvsroot/pgsql/src/backend/tcop/Makefile,v 1.22 2000/05/28 17:56:04 tgl Exp $
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
@@ -29,18 +29,12 @@ SUBSYS.o: $(OBJS)
|
||||
# dependencies (because they don't even exist until you make them),
|
||||
# they are hardcoded here.
|
||||
|
||||
utility.o: ../parse.h ../fmgr.h
|
||||
aclchk.o: ../fmgr.h
|
||||
fastpath.o: ../fmgr.h
|
||||
postgres.o: ../fmgr.h
|
||||
utility.o: ../parse.h
|
||||
|
||||
../parse.h:
|
||||
$(MAKE) -C .. parse.h
|
||||
|
||||
../fmgr.h:
|
||||
$(MAKE) -C .. fmgr.h
|
||||
|
||||
dep depend: ../parse.h ../fmgr.h
|
||||
dep depend: ../parse.h
|
||||
$(CC) -MM $(CFLAGS) *.c >depend
|
||||
|
||||
clean:
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/tcop/fastpath.c,v 1.38 2000/04/12 17:15:43 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/tcop/fastpath.c,v 1.39 2000/05/28 17:56:04 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
* This cruft is the server side of PQfn.
|
||||
@@ -76,11 +76,9 @@
|
||||
* ----------------
|
||||
*/
|
||||
static void
|
||||
SendFunctionResult(Oid fid, /* function id */
|
||||
char *retval,/* actual return value */
|
||||
SendFunctionResult(Datum retval, /* actual return value */
|
||||
bool retbyval,
|
||||
int retlen /* the length according to the catalogs */
|
||||
)
|
||||
int retlen) /* the length according to the catalogs */
|
||||
{
|
||||
StringInfoData buf;
|
||||
|
||||
@@ -93,19 +91,21 @@ SendFunctionResult(Oid fid, /* function id */
|
||||
if (retbyval)
|
||||
{ /* by-value */
|
||||
pq_sendint(&buf, retlen, 4);
|
||||
pq_sendint(&buf, (int) (Datum) retval, retlen);
|
||||
pq_sendint(&buf, DatumGetInt32(retval), retlen);
|
||||
}
|
||||
else
|
||||
{ /* by-reference ... */
|
||||
if (retlen < 0)
|
||||
{ /* ... varlena */
|
||||
pq_sendint(&buf, VARSIZE(retval) - VARHDRSZ, VARHDRSZ);
|
||||
pq_sendbytes(&buf, VARDATA(retval), VARSIZE(retval) - VARHDRSZ);
|
||||
struct varlena *v = (struct varlena *) DatumGetPointer(retval);
|
||||
|
||||
pq_sendint(&buf, VARSIZE(v) - VARHDRSZ, VARHDRSZ);
|
||||
pq_sendbytes(&buf, VARDATA(v), VARSIZE(v) - VARHDRSZ);
|
||||
}
|
||||
else
|
||||
{ /* ... fixed */
|
||||
pq_sendint(&buf, retlen, 4);
|
||||
pq_sendbytes(&buf, retval, retlen);
|
||||
pq_sendbytes(&buf, DatumGetPointer(retval), retlen);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -127,12 +127,12 @@ SendFunctionResult(Oid fid, /* function id */
|
||||
struct fp_info
|
||||
{
|
||||
Oid funcid;
|
||||
int nargs;
|
||||
FmgrInfo flinfo; /* function lookup info for funcid */
|
||||
bool argbyval[FUNC_MAX_ARGS];
|
||||
int32 arglen[FUNC_MAX_ARGS]; /* signed (for varlena) */
|
||||
bool retbyval;
|
||||
int32 retlen; /* signed (for varlena) */
|
||||
TransactionId xid;
|
||||
TransactionId xid; /* when the lookup was done */
|
||||
CommandId cid;
|
||||
};
|
||||
|
||||
@@ -147,17 +147,17 @@ static struct fp_info last_fp = {InvalidOid};
|
||||
* valid_fp_info
|
||||
*
|
||||
* RETURNS:
|
||||
* 1 if the state in 'fip' is valid
|
||||
* 0 otherwise
|
||||
* T if the state in 'fip' is valid for the given func OID
|
||||
* F otherwise
|
||||
*
|
||||
* "valid" means:
|
||||
* "invalid" means:
|
||||
* The saved state was either uninitialized, for another function,
|
||||
* or from a previous command. (Commands can do updates, which
|
||||
* may invalidate catalog entries for subsequent commands. This
|
||||
* is overly pessimistic but since there is no smarter invalidation
|
||||
* scheme...).
|
||||
*/
|
||||
static int
|
||||
static bool
|
||||
valid_fp_info(Oid func_id, struct fp_info * fip)
|
||||
{
|
||||
Assert(OidIsValid(func_id));
|
||||
@@ -212,11 +212,10 @@ update_fp_info(Oid func_id, struct fp_info * fip)
|
||||
func_id);
|
||||
}
|
||||
pp = (Form_pg_proc) GETSTRUCT(func_htp);
|
||||
fip->nargs = pp->pronargs;
|
||||
rettype = pp->prorettype;
|
||||
argtypes = pp->proargtypes;
|
||||
|
||||
for (i = 0; i < fip->nargs; ++i)
|
||||
for (i = 0; i < fip->flinfo.fn_nargs; ++i)
|
||||
{
|
||||
if (OidIsValid(argtypes[i]))
|
||||
{
|
||||
@@ -252,6 +251,8 @@ update_fp_info(Oid func_id, struct fp_info * fip)
|
||||
fip->xid = GetCurrentTransactionId();
|
||||
fip->cid = GetCurrentCommandId();
|
||||
|
||||
fmgr_info(func_id, &fip->flinfo);
|
||||
|
||||
/*
|
||||
* This must be last!
|
||||
*/
|
||||
@@ -279,11 +280,9 @@ HandleFunctionRequest()
|
||||
int argsize;
|
||||
int nargs;
|
||||
int tmp;
|
||||
char *arg[FUNC_MAX_ARGS];
|
||||
char *retval;
|
||||
bool isNull;
|
||||
FunctionCallInfoData fcinfo;
|
||||
Datum retval;
|
||||
int i;
|
||||
uint32 palloced;
|
||||
char *p;
|
||||
struct fp_info *fip;
|
||||
|
||||
@@ -305,89 +304,81 @@ HandleFunctionRequest()
|
||||
* XXX FIXME: elog() here means we lose sync with the frontend, since
|
||||
* we have not swallowed all of its input message. What should happen
|
||||
* is we absorb all of the input message per protocol syntax, and
|
||||
* *then* do error checking and elog if appropriate.
|
||||
* *then* do error checking (including lookup of the given function ID)
|
||||
* and elog if appropriate. Unfortunately, because we cannot even read
|
||||
* the message properly without knowing whether the data types are
|
||||
* pass-by-ref or pass-by-value, it's not all that easy to fix :-(.
|
||||
* This protocol is misdesigned.
|
||||
*/
|
||||
|
||||
if (fip->nargs != nargs)
|
||||
if (fip->flinfo.fn_nargs != nargs || nargs > FUNC_MAX_ARGS)
|
||||
{
|
||||
elog(ERROR, "HandleFunctionRequest: actual arguments (%d) != registered arguments (%d)",
|
||||
nargs, fip->nargs);
|
||||
nargs, fip->flinfo.fn_nargs);
|
||||
}
|
||||
|
||||
/*
|
||||
* Copy arguments into arg vector. If we palloc() an argument, we
|
||||
* need to remember, so that we pfree() it after the call.
|
||||
*/
|
||||
palloced = 0x0;
|
||||
for (i = 0; i < FUNC_MAX_ARGS; ++i)
|
||||
{
|
||||
if (i >= nargs)
|
||||
arg[i] = (char *) NULL;
|
||||
else
|
||||
{
|
||||
if (pq_getint(&argsize, 4))
|
||||
return EOF;
|
||||
MemSet(&fcinfo, 0, sizeof(fcinfo));
|
||||
fcinfo.flinfo = &fip->flinfo;
|
||||
fcinfo.nargs = nargs;
|
||||
|
||||
Assert(argsize > 0);
|
||||
if (fip->argbyval[i])
|
||||
{ /* by-value */
|
||||
Assert(argsize <= 4);
|
||||
if (pq_getint(&tmp, argsize))
|
||||
/*
|
||||
* Copy supplied arguments into arg vector. Note there is no way for
|
||||
* frontend to specify a NULL argument --- more misdesign.
|
||||
*/
|
||||
for (i = 0; i < nargs; ++i)
|
||||
{
|
||||
if (pq_getint(&argsize, 4))
|
||||
return EOF;
|
||||
if (fip->argbyval[i])
|
||||
{ /* by-value */
|
||||
if (argsize < 1 || argsize > 4)
|
||||
elog(ERROR, "HandleFunctionRequest: bogus argsize %d",
|
||||
argsize);
|
||||
/* XXX should we demand argsize == fip->arglen[i] ? */
|
||||
if (pq_getint(&tmp, argsize))
|
||||
return EOF;
|
||||
fcinfo.arg[i] = (Datum) tmp;
|
||||
}
|
||||
else
|
||||
{ /* by-reference ... */
|
||||
if (fip->arglen[i] < 0)
|
||||
{ /* ... varlena */
|
||||
if (argsize < 0)
|
||||
elog(ERROR, "HandleFunctionRequest: bogus argsize %d",
|
||||
argsize);
|
||||
/* I suspect this +1 isn't really needed - tgl 5/2000 */
|
||||
p = palloc(argsize + VARHDRSZ + 1); /* Added +1 to solve
|
||||
* memory leak - Peter
|
||||
* 98 Jan 6 */
|
||||
VARSIZE(p) = argsize + VARHDRSZ;
|
||||
if (pq_getbytes(VARDATA(p), argsize))
|
||||
return EOF;
|
||||
arg[i] = (char *) tmp;
|
||||
}
|
||||
else
|
||||
{ /* by-reference ... */
|
||||
if (fip->arglen[i] < 0)
|
||||
{ /* ... varlena */
|
||||
if (!(p = palloc(argsize + VARHDRSZ + 1))) /* Added +1 to solve
|
||||
* memory leak - Peter
|
||||
* 98 Jan 6 */
|
||||
elog(ERROR, "HandleFunctionRequest: palloc failed");
|
||||
VARSIZE(p) = argsize + VARHDRSZ;
|
||||
if (pq_getbytes(VARDATA(p), argsize))
|
||||
return EOF;
|
||||
}
|
||||
else
|
||||
{ /* ... fixed */
|
||||
/* XXX cross our fingers and trust "argsize" */
|
||||
if (!(p = palloc(argsize + 1)))
|
||||
elog(ERROR, "HandleFunctionRequest: palloc failed");
|
||||
if (pq_getbytes(p, argsize))
|
||||
return EOF;
|
||||
}
|
||||
palloced |= (1 << i);
|
||||
arg[i] = p;
|
||||
{ /* ... fixed */
|
||||
if (argsize != fip->arglen[i])
|
||||
elog(ERROR, "HandleFunctionRequest: bogus argsize %d, should be %d",
|
||||
argsize, fip->arglen[i]);
|
||||
p = palloc(argsize + 1); /* +1 in case argsize is 0 */
|
||||
if (pq_getbytes(p, argsize))
|
||||
return EOF;
|
||||
}
|
||||
fcinfo.arg[i] = PointerGetDatum(p);
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef NO_FASTPATH
|
||||
retval = fmgr_array_args(fid, nargs, arg, &isNull);
|
||||
#ifdef NO_FASTPATH
|
||||
/* force a NULL return */
|
||||
retval = (Datum) 0;
|
||||
fcinfo.isnull = true;
|
||||
#else
|
||||
retval = NULL;
|
||||
retval = FunctionCallInvoke(&fcinfo);
|
||||
#endif /* NO_FASTPATH */
|
||||
|
||||
/* free palloc'ed arguments */
|
||||
for (i = 0; i < nargs; ++i)
|
||||
{
|
||||
if (palloced & (1 << i))
|
||||
pfree(arg[i]);
|
||||
}
|
||||
|
||||
/*
|
||||
* If this is an ordinary query (not a retrieve portal p ...), then we
|
||||
* return the data to the user. If the return value was palloc'ed,
|
||||
* then it must also be freed.
|
||||
*/
|
||||
#ifndef NO_FASTPATH
|
||||
SendFunctionResult(fid, retval, fip->retbyval, fip->retlen);
|
||||
#else
|
||||
SendFunctionResult(fid, retval, fip->retbyval, 0);
|
||||
#endif /* NO_FASTPATH */
|
||||
|
||||
if (!fip->retbyval)
|
||||
pfree(retval);
|
||||
if (fcinfo.isnull)
|
||||
SendFunctionResult(retval, fip->retbyval, 0);
|
||||
else
|
||||
SendFunctionResult(retval, fip->retbyval, fip->retlen);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
#!/bin/sh
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Gen_fmgrtab.sh--
|
||||
# shell script to generate fmgr.h and fmgrtab.c from pg_proc.h
|
||||
# Gen_fmgrtab.sh
|
||||
# shell script to generate fmgroids.h and fmgrtab.c from pg_proc.h
|
||||
#
|
||||
# Copyright (c) 1994, Regents of the University of California
|
||||
# Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
||||
# Portions Copyright (c) 1994, Regents of the University of California
|
||||
#
|
||||
#
|
||||
# IDENTIFICATION
|
||||
# $Header: /cvsroot/pgsql/src/backend/utils/Attic/Gen_fmgrtab.sh.in,v 1.21 2000/05/22 02:34:21 momjian Exp $
|
||||
# $Header: /cvsroot/pgsql/src/backend/utils/Attic/Gen_fmgrtab.sh.in,v 1.22 2000/05/28 17:56:05 tgl Exp $
|
||||
#
|
||||
# NOTES
|
||||
# Passes any -D options on to cpp prior to generating the list
|
||||
@@ -16,12 +17,6 @@
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
if [ $? != 0 ]
|
||||
then
|
||||
echo `basename $0`: Bad option
|
||||
exit 1
|
||||
fi
|
||||
|
||||
BKIOPTS=''
|
||||
|
||||
#
|
||||
@@ -32,7 +27,7 @@ for opt in $*
|
||||
do
|
||||
case $opt in
|
||||
-D) BKIOPTS="$BKIOPTS -D$2"; shift; shift;;
|
||||
-D*) BKIOPTS="$BKIOPTS $1";shift;;
|
||||
-D*) BKIOPTS="$BKIOPTS $1"; shift;;
|
||||
--) shift; break;;
|
||||
-*) shift;;
|
||||
esac
|
||||
@@ -41,8 +36,8 @@ done
|
||||
INFILE=$1
|
||||
RAWFILE=fmgr.raw
|
||||
CPPTMPFILE=fmgrtmp.c
|
||||
HFILE=fmgr.h
|
||||
TABCFILE=fmgrtab.c
|
||||
OIDSFILE=fmgroids.h
|
||||
TABLEFILE=fmgrtab.c
|
||||
|
||||
#
|
||||
# Generate the file containing raw pg_proc tuple data
|
||||
@@ -63,7 +58,8 @@ sed -e 's/^.*OID[^=]*=[^0-9]*//' \
|
||||
-e 's/[ ]*).*$//' | \
|
||||
awk '
|
||||
/^#/ { print; next; }
|
||||
$4 == "11" { print; next; }' > $CPPTMPFILE
|
||||
$4 == "11" { print; next; }
|
||||
$4 == "12" { print; next; }' > $CPPTMPFILE
|
||||
|
||||
@CPP@ $BKIOPTS $CPPTMPFILE | \
|
||||
egrep '^[0-9]' | \
|
||||
@@ -72,18 +68,21 @@ sort -n > $RAWFILE
|
||||
rm -f $CPPTMPFILE
|
||||
|
||||
#
|
||||
# Generate fmgr.h
|
||||
# Generate fmgroids.h
|
||||
#
|
||||
cat > $HFILE <<FuNkYfMgRsTuFf
|
||||
cat > $OIDSFILE <<FuNkYfMgRsTuFf
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* $HFILE--
|
||||
* Definitions for using internal procedures.
|
||||
* $OIDSFILE
|
||||
* Macros that define the OIDs of built-in functions.
|
||||
*
|
||||
* These macros can be used to avoid a catalog lookup when a specific
|
||||
* fmgr-callable function needs to be referenced.
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: Gen_fmgrtab.sh.in,v 1.21 2000/05/22 02:34:21 momjian Exp $
|
||||
* $Id: Gen_fmgrtab.sh.in,v 1.22 2000/05/28 17:56:05 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
* ******************************
|
||||
@@ -91,77 +90,12 @@ cat > $HFILE <<FuNkYfMgRsTuFf
|
||||
* ******************************
|
||||
*
|
||||
* It has been GENERATED by $0
|
||||
* from $1
|
||||
* from $INFILE
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef FMGR_H
|
||||
#define FMGR_H
|
||||
|
||||
#include "postgres.h"
|
||||
|
||||
typedef struct {
|
||||
char *data[FUNC_MAX_ARGS];
|
||||
} FmgrValues;
|
||||
|
||||
typedef struct {
|
||||
func_ptr fn_addr;
|
||||
func_ptr fn_plhandler;
|
||||
Oid fn_oid;
|
||||
int fn_nargs;
|
||||
} FmgrInfo;
|
||||
|
||||
/*
|
||||
* defined in fmgr.c
|
||||
*/
|
||||
extern char *fmgr_c(FmgrInfo *finfo, FmgrValues *values, bool *isNull);
|
||||
extern void fmgr_info(Oid procedureId, FmgrInfo *finfo);
|
||||
extern char *fmgr(Oid procedureId, ... );
|
||||
extern char *fmgr_ptr(FmgrInfo *finfo, ... );
|
||||
extern char *fmgr_array_args(Oid procedureId, int nargs,
|
||||
char *args[], bool *isNull);
|
||||
|
||||
/*
|
||||
* defined in dfmgr.c
|
||||
*/
|
||||
extern func_ptr fmgr_dynamic(Oid procedureId, int *pronargs);
|
||||
extern void load_file(char *filename);
|
||||
|
||||
/*
|
||||
* For performance reasons, we often want to simply jump through a
|
||||
* a function pointer (if it's valid, that is). These calls have
|
||||
* been macroized so we can run them through a routine that does
|
||||
* sanity-checking (and so we can track them down more easily when
|
||||
* we must).
|
||||
*/
|
||||
|
||||
/* We don't make this static so fmgr_faddr() macros can access it */
|
||||
extern FmgrInfo *fmgr_pl_finfo;
|
||||
|
||||
#define fmgr_faddr(finfo) \
|
||||
( \
|
||||
fmgr_pl_finfo = (finfo), \
|
||||
(func_ptr)(finfo)->fn_addr \
|
||||
)
|
||||
|
||||
#ifdef TRACE_FMGR_PTR
|
||||
#define FMGR_PTR2(FINFO, ARG1, ARG2) \
|
||||
fmgr_ptr(FINFO, 2, ARG1, ARG2)
|
||||
#else
|
||||
#define FMGR_PTR2(FINFO, ARG1, ARG2) \
|
||||
( \
|
||||
((FINFO)->fn_addr) ? \
|
||||
(*(fmgr_faddr(FINFO)))(ARG1, ARG2) \
|
||||
: \
|
||||
fmgr((FINFO)->fn_oid, ARG1, ARG2) \
|
||||
)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Flags for the builtin oprrest selectivity routines.
|
||||
*/
|
||||
#define SEL_CONSTANT 1 /* constant does not vary (not a parameter) */
|
||||
#define SEL_RIGHT 2 /* constant appears to right of operator */
|
||||
#ifndef FMGROIDS_H
|
||||
#define FMGROIDS_H
|
||||
|
||||
/*
|
||||
* Constant macros for the OIDs of entries in pg_proc.
|
||||
@@ -174,30 +108,33 @@ FuNkYfMgRsTuFf
|
||||
tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' < $RAWFILE | \
|
||||
awk '
|
||||
BEGIN { OFS = ""; }
|
||||
{ if (seenit[$2]++ == 0) print "#define F_", $2, " ", $1; }' >> $HFILE
|
||||
{ if (seenit[$2]++ == 0) print "#define F_", $2, " ", $1; }' >> $OIDSFILE
|
||||
|
||||
cat >> $HFILE <<FuNkYfMgRsTuFf
|
||||
cat >> $OIDSFILE <<FuNkYfMgRsTuFf
|
||||
|
||||
#endif /* FMGR_H */
|
||||
#endif /* FMGROIDS_H */
|
||||
FuNkYfMgRsTuFf
|
||||
|
||||
#
|
||||
# Generate fmgr function table file.
|
||||
# Generate fmgr's built-in-function table.
|
||||
#
|
||||
# Print out the bogus function declarations, then the table that
|
||||
# refers to them.
|
||||
# Print out the function declarations, then the table that refers to them.
|
||||
# NB: the function declarations are bogus in the case of old-style functions,
|
||||
# although they should be correct for new-style. Therefore we need to compile
|
||||
# this table definition as a separate C file that won't need to include any
|
||||
# "real" declarations for those functions!
|
||||
#
|
||||
cat > $TABCFILE <<FuNkYfMgRtAbStUfF
|
||||
cat > $TABLEFILE <<FuNkYfMgRtAbStUfF
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* $TABCFILE--
|
||||
* $TABLEFILE
|
||||
* The function manager's table of internal functions.
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/Attic/Gen_fmgrtab.sh.in,v 1.21 2000/05/22 02:34:21 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/Attic/Gen_fmgrtab.sh.in,v 1.22 2000/05/28 17:56:05 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
*
|
||||
@@ -206,72 +143,41 @@ cat > $TABCFILE <<FuNkYfMgRtAbStUfF
|
||||
* ******************************
|
||||
*
|
||||
* It has been GENERATED by $0
|
||||
* from $1
|
||||
* from $INFILE
|
||||
*
|
||||
* We lie here to cc about the return type and arguments of the
|
||||
* We lie here to cc about the return type and arguments of old-style
|
||||
* builtin functions; all ld cares about is the fact that it
|
||||
* will need to resolve an external function reference.
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "postgres.h"
|
||||
|
||||
#include "utils/fmgrtab.h"
|
||||
|
||||
FuNkYfMgRtAbStUfF
|
||||
|
||||
awk '{ print "extern char *", $(NF-1), "();"; }' $RAWFILE >> $TABCFILE
|
||||
awk '{ print "extern Datum", $(NF-1), "(PG_FUNCTION_ARGS);"; }' $RAWFILE >> $TABLEFILE
|
||||
|
||||
cat >> $TABCFILE <<FuNkYfMgRtAbStUfF
|
||||
cat >> $TABLEFILE <<FuNkYfMgRtAbStUfF
|
||||
|
||||
static FmgrCall fmgr_builtins[] = {
|
||||
const FmgrBuiltin fmgr_builtins[] = {
|
||||
FuNkYfMgRtAbStUfF
|
||||
|
||||
awk '{ printf (" {%d, %d, %s, \"%s\" },\n"), $1, $8, $(NF-1), $(NF-1) }' $RAWFILE >> $TABCFILE
|
||||
awk '{ printf (" { %d, \"%s\", %d, %s, %s, %s },\n"), \
|
||||
$1, $(NF-1), $9, \
|
||||
($8 == "t") ? "true" : "false", \
|
||||
($4 == "11") ? "true" : "false", \
|
||||
$(NF-1) }' $RAWFILE >> $TABLEFILE
|
||||
|
||||
cat >> $TABCFILE <<FuNkYfMgRtAbStUfF
|
||||
cat >> $TABLEFILE <<FuNkYfMgRtAbStUfF
|
||||
/* dummy entry is easier than getting rid of comma after last real one */
|
||||
{ 0, 0, (func_ptr) NULL, NULL }
|
||||
{ 0, NULL, 0, false, false, (PGFunction) NULL }
|
||||
};
|
||||
|
||||
/* Note FMGR_NBUILTINS excludes the dummy entry */
|
||||
#define FMGR_NBUILTINS ((sizeof(fmgr_builtins) / sizeof(FmgrCall)) - 1)
|
||||
|
||||
FmgrCall *fmgr_isbuiltin(Oid id)
|
||||
{
|
||||
int low = 0;
|
||||
int high = FMGR_NBUILTINS - 1;
|
||||
|
||||
/* Loop invariant: low is the first index that could contain target
|
||||
* entry, and high is the last index that could contain it.
|
||||
*/
|
||||
while (low <= high) {
|
||||
int i = (high + low) / 2;
|
||||
FmgrCall * ptr = &fmgr_builtins[i];
|
||||
if (id == ptr->proid)
|
||||
return ptr;
|
||||
else if (id > ptr->proid)
|
||||
low = i + 1;
|
||||
else
|
||||
high = i - 1;
|
||||
}
|
||||
return (FmgrCall *) NULL;
|
||||
}
|
||||
|
||||
func_ptr fmgr_lookupByName(char *name)
|
||||
{
|
||||
/* Lookup a builtin by name. Note there can be more than one entry in
|
||||
* the array matching this name, but they should all point to the same
|
||||
* routine.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
/* Note fmgr_nbuiltins excludes the dummy entry */
|
||||
const int fmgr_nbuiltins = (sizeof(fmgr_builtins) / sizeof(FmgrBuiltin)) - 1;
|
||||
|
||||
FuNkYfMgRtAbStUfF
|
||||
|
||||
|
||||
@@ -4,12 +4,12 @@
|
||||
# Makefile for utils
|
||||
#
|
||||
# IDENTIFICATION
|
||||
# $Header: /cvsroot/pgsql/src/backend/utils/Makefile,v 1.10 1999/12/13 22:34:28 momjian Exp $
|
||||
# $Header: /cvsroot/pgsql/src/backend/utils/Makefile,v 1.11 2000/05/28 17:56:05 tgl Exp $
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
SRCDIR = ../..
|
||||
include ../../Makefile.global
|
||||
include $(SRCDIR)/Makefile.global
|
||||
|
||||
INCLUDE_OPT = -I..
|
||||
|
||||
@@ -35,19 +35,14 @@ SUBSYS.o: $(OBJS)
|
||||
submake:
|
||||
for i in $(DIRS); do $(MAKE) -C $$i SUBSYS.o; done
|
||||
|
||||
fmgrtab.o: ../fmgr.h
|
||||
|
||||
../fmgr.h:
|
||||
$(MAKE) -C .. fmgr.h
|
||||
|
||||
fmgr.h fmgrtab.c: ./Gen_fmgrtab.sh ../../include/catalog/pg_proc.h
|
||||
sh $(SHOPTS) Gen_fmgrtab.sh ../../include/catalog/pg_proc.h
|
||||
fmgroids.h fmgrtab.c: Gen_fmgrtab.sh $(SRCDIR)/include/catalog/pg_proc.h
|
||||
$(SHELL) $(SHOPTS) Gen_fmgrtab.sh $(SRCDIR)/include/catalog/pg_proc.h
|
||||
|
||||
clean:
|
||||
rm -f SUBSYS.o fmgr.h fmgrtab.o fmgrtab.c
|
||||
rm -f SUBSYS.o fmgroids.h fmgrtab.o fmgrtab.c
|
||||
for i in $(DIRS); do $(MAKE) -C $$i clean; done
|
||||
|
||||
dep depend: fmgr.h fmgrtab.c
|
||||
dep depend: fmgroids.h fmgrtab.c
|
||||
for i in $(DIRS); do $(MAKE) -C $$i depend; done
|
||||
|
||||
ifeq (depend,$(wildcard depend))
|
||||
|
||||
@@ -3,6 +3,12 @@
|
||||
* int8.c
|
||||
* Internal 64-bit integer operations
|
||||
*
|
||||
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/int8.c,v 1.19 2000/05/28 17:56:05 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#include <ctype.h>
|
||||
@@ -18,6 +24,11 @@
|
||||
|
||||
#include "utils/int8.h"
|
||||
|
||||
/* this should be set in config.h, but just in case it wasn't: */
|
||||
#ifndef INT64_FORMAT
|
||||
#define INT64_FORMAT "%ld"
|
||||
#endif
|
||||
|
||||
#define MAXINT8LEN 25
|
||||
|
||||
#ifndef INT_MAX
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/regproc.c,v 1.54 2000/04/12 17:15:51 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/regproc.c,v 1.55 2000/05/28 17:56:05 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "catalog/pg_type.h"
|
||||
#include "miscadmin.h"
|
||||
#include "utils/builtins.h"
|
||||
#include "utils/fmgroids.h"
|
||||
#include "utils/syscache.h"
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.66 2000/05/26 17:19:15 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.67 2000/05/28 17:56:06 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -889,17 +889,17 @@ convert_numeric_to_scalar(Datum value, Oid typid)
|
||||
switch (typid)
|
||||
{
|
||||
case BOOLOID:
|
||||
return (double) DatumGetUInt8(value);
|
||||
return (double) DatumGetBool(value);
|
||||
case INT2OID:
|
||||
return (double) DatumGetInt16(value);
|
||||
case INT4OID:
|
||||
return (double) DatumGetInt32(value);
|
||||
case INT8OID:
|
||||
return (double) (*i8tod((int64 *) DatumGetPointer(value)));
|
||||
return (double) DatumGetInt64(value);
|
||||
case FLOAT4OID:
|
||||
return (double) (*DatumGetFloat32(value));
|
||||
return (double) DatumGetFloat4(value);
|
||||
case FLOAT8OID:
|
||||
return (double) (*DatumGetFloat64(value));
|
||||
return (double) DatumGetFloat8(value);
|
||||
case NUMERICOID:
|
||||
return (double) (*numeric_float8((Numeric) DatumGetPointer(value)));
|
||||
case OIDOID:
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/sets.c,v 1.30 2000/01/26 05:57:14 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/sets.c,v 1.31 2000/05/28 17:56:06 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -56,8 +56,9 @@ SetDefine(char *querystr, char *typename)
|
||||
"sql", /* languageName */
|
||||
querystr, /* sourceCode */
|
||||
fileName, /* fileName */
|
||||
false, /* canCache */
|
||||
true, /* trusted */
|
||||
false, /* canCache XXX appropriate? */
|
||||
false, /* isStrict XXX appropriate? */
|
||||
100, /* byte_pct */
|
||||
0, /* perbyte_cpu */
|
||||
0, /* percall_cpu */
|
||||
|
||||
3
src/backend/utils/cache/catcache.c
vendored
3
src/backend/utils/cache/catcache.c
vendored
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/cache/catcache.c,v 1.63 2000/04/12 17:15:52 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/cache/catcache.c,v 1.64 2000/05/28 17:56:06 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "catalog/indexing.h"
|
||||
#include "miscadmin.h"
|
||||
#include "utils/builtins.h"
|
||||
#include "utils/fmgroids.h"
|
||||
#include "utils/catcache.h"
|
||||
#include "utils/syscache.h"
|
||||
|
||||
|
||||
56
src/backend/utils/cache/fcache.c
vendored
56
src/backend/utils/cache/fcache.c
vendored
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/cache/Attic/fcache.c,v 1.30 2000/04/12 17:15:53 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/cache/Attic/fcache.c,v 1.31 2000/05/28 17:56:06 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -24,20 +24,9 @@
|
||||
|
||||
static Oid GetDynamicFuncArgType(Var *arg, ExprContext *econtext);
|
||||
static FunctionCachePtr init_fcache(Oid foid,
|
||||
bool use_syscache,
|
||||
List *argList,
|
||||
ExprContext *econtext);
|
||||
List *argList,
|
||||
ExprContext *econtext);
|
||||
|
||||
/*-----------------------------------------------------------------
|
||||
*
|
||||
* Initialize the 'FunctionCache' given the PG_PROC oid.
|
||||
*
|
||||
*
|
||||
* NOTE: This function can be called when the system cache is being
|
||||
* initialized. Therefore, use_syscache should ONLY be true
|
||||
* when the function return type is interesting (ie: set_fcache).
|
||||
*-----------------------------------------------------------------
|
||||
*/
|
||||
#define FuncArgTypeIsDynamic(arg) \
|
||||
(IsA(arg,Var) && ((Var*)arg)->varattno == InvalidAttrNumber)
|
||||
|
||||
@@ -53,7 +42,6 @@ GetDynamicFuncArgType(Var *arg, ExprContext *econtext)
|
||||
rtid = ((Var *) arg)->varno;
|
||||
relname = (char *) getrelname(rtid, econtext->ecxt_range_table);
|
||||
|
||||
|
||||
tup = SearchSysCacheTuple(TYPENAME,
|
||||
PointerGetDatum(relname),
|
||||
0, 0, 0);
|
||||
@@ -64,9 +52,14 @@ GetDynamicFuncArgType(Var *arg, ExprContext *econtext)
|
||||
return tup->t_data->t_oid;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------
|
||||
*
|
||||
* Initialize a 'FunctionCache' struct given the PG_PROC oid.
|
||||
*
|
||||
*-----------------------------------------------------------------
|
||||
*/
|
||||
static FunctionCachePtr
|
||||
init_fcache(Oid foid,
|
||||
bool use_syscache,
|
||||
List *argList,
|
||||
ExprContext *econtext)
|
||||
{
|
||||
@@ -79,16 +72,13 @@ init_fcache(Oid foid,
|
||||
text *tmp;
|
||||
bool isNull;
|
||||
|
||||
retval = (FunctionCachePtr) palloc(sizeof(FunctionCache));
|
||||
MemSet(retval, 0, sizeof(FunctionCache));
|
||||
|
||||
/* ----------------
|
||||
* get the procedure tuple corresponding to the given functionOid
|
||||
* ----------------
|
||||
*/
|
||||
retval = (FunctionCachePtr) palloc(sizeof(FunctionCache));
|
||||
memset(retval, 0, sizeof(FunctionCache));
|
||||
|
||||
if (!use_syscache)
|
||||
elog(ERROR, "what the ????, init the fcache without the catalogs?");
|
||||
|
||||
procedureTuple = SearchSysCacheTuple(PROCOID,
|
||||
ObjectIdGetDatum(foid),
|
||||
0, 0, 0);
|
||||
@@ -114,8 +104,7 @@ init_fcache(Oid foid,
|
||||
typeStruct = (Form_pg_type) GETSTRUCT(typeTuple);
|
||||
|
||||
/* ----------------
|
||||
* get the type length and by-value from the type tuple and
|
||||
* save the information in our one element cache.
|
||||
* get the type length and by-value flag from the type tuple
|
||||
* ----------------
|
||||
*/
|
||||
retval->typlen = typeStruct->typlen;
|
||||
@@ -136,10 +125,9 @@ init_fcache(Oid foid,
|
||||
retval->foid = foid;
|
||||
retval->language = procedureStruct->prolang;
|
||||
retval->func_state = (char *) NULL;
|
||||
retval->setArg = NULL;
|
||||
retval->setArg = (Datum) 0;
|
||||
retval->hasSetArg = false;
|
||||
retval->oneResult = !procedureStruct->proretset;
|
||||
retval->istrusted = procedureStruct->proistrusted;
|
||||
|
||||
/*
|
||||
* If we are returning exactly one result then we have to copy tuples
|
||||
@@ -162,9 +150,8 @@ init_fcache(Oid foid,
|
||||
slot->ttc_tupleDescriptor = (TupleDesc) NULL;
|
||||
slot->ttc_buffer = InvalidBuffer;
|
||||
slot->ttc_whichplan = -1;
|
||||
retval->funcSlot = (Pointer) slot;
|
||||
|
||||
relationTuple = (HeapTuple)
|
||||
relationTuple =
|
||||
SearchSysCacheTuple(RELNAME,
|
||||
PointerGetDatum(&typeStruct->typname),
|
||||
0, 0, 0);
|
||||
@@ -177,10 +164,12 @@ init_fcache(Oid foid,
|
||||
else
|
||||
td = CreateTemplateTupleDesc(1);
|
||||
|
||||
((TupleTableSlot *) retval->funcSlot)->ttc_tupleDescriptor = td;
|
||||
slot->ttc_tupleDescriptor = td;
|
||||
|
||||
retval->funcSlot = (Pointer) slot;
|
||||
}
|
||||
else
|
||||
retval->funcSlot = (char *) NULL;
|
||||
retval->funcSlot = (Pointer) NULL;
|
||||
|
||||
nargs = procedureStruct->pronargs;
|
||||
retval->nargs = nargs;
|
||||
@@ -189,8 +178,6 @@ init_fcache(Oid foid,
|
||||
{
|
||||
Oid *argTypes;
|
||||
|
||||
retval->nullVect = (bool *) palloc(retval->nargs * sizeof(bool));
|
||||
|
||||
if (retval->language == SQLlanguageId)
|
||||
{
|
||||
int i;
|
||||
@@ -218,7 +205,6 @@ init_fcache(Oid foid,
|
||||
else
|
||||
{
|
||||
retval->argOidVect = (Oid *) NULL;
|
||||
retval->nullVect = (BoolPtr) NULL;
|
||||
}
|
||||
|
||||
if (procedureStruct->prolang == SQLlanguageId)
|
||||
@@ -257,7 +243,7 @@ init_fcache(Oid foid,
|
||||
retval->nargs = retval->func.fn_nargs;
|
||||
}
|
||||
else
|
||||
retval->func.fn_addr = (func_ptr) NULL;
|
||||
retval->func.fn_addr = (PGFunction) NULL;
|
||||
|
||||
return retval;
|
||||
}
|
||||
@@ -269,7 +255,7 @@ setFcache(Node *node, Oid foid, List *argList, ExprContext *econtext)
|
||||
Oper *onode;
|
||||
FunctionCachePtr fcache;
|
||||
|
||||
fcache = init_fcache(foid, true, argList, econtext);
|
||||
fcache = init_fcache(foid, argList, econtext);
|
||||
|
||||
if (IsA(node, Oper))
|
||||
{
|
||||
|
||||
3
src/backend/utils/cache/relcache.c
vendored
3
src/backend/utils/cache/relcache.c
vendored
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.96 2000/05/21 02:28:55 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.97 2000/05/28 17:56:06 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -58,6 +58,7 @@
|
||||
#include "storage/bufmgr.h"
|
||||
#include "storage/smgr.h"
|
||||
#include "utils/catcache.h"
|
||||
#include "utils/fmgroids.h"
|
||||
#include "utils/relcache.h"
|
||||
#include "utils/temprel.h"
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/fmgr/dfmgr.c,v 1.39 2000/04/12 17:15:57 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/fmgr/dfmgr.c,v 1.40 2000/05/28 17:56:07 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -17,190 +17,127 @@
|
||||
|
||||
#include "postgres.h"
|
||||
|
||||
#include "utils/dynamic_loader.h"
|
||||
|
||||
#include "access/heapam.h"
|
||||
#include "catalog/catname.h"
|
||||
#include "catalog/pg_proc.h"
|
||||
#include "dynloader.h"
|
||||
#include "utils/builtins.h"
|
||||
#include "utils/dynamic_loader.h"
|
||||
#include "utils/syscache.h"
|
||||
|
||||
|
||||
/*
|
||||
* List of dynamically loaded files.
|
||||
*/
|
||||
|
||||
typedef struct df_files
|
||||
{
|
||||
struct df_files *next; /* List link */
|
||||
dev_t device; /* Device file is on */
|
||||
ino_t inode; /* Inode number of file */
|
||||
void *handle; /* a handle for pg_dl* functions */
|
||||
char filename[1]; /* Full pathname of file */
|
||||
/* we allocate the block big enough for actual length of pathname.
|
||||
* filename[] must be last item in struct!
|
||||
*/
|
||||
} DynamicFileList;
|
||||
|
||||
static DynamicFileList *file_list = (DynamicFileList *) NULL;
|
||||
static DynamicFileList *file_tail = (DynamicFileList *) NULL;
|
||||
|
||||
#define NOT_EQUAL(A, B) (((A).st_ino != (B).inode) \
|
||||
|| ((A).st_dev != (B).device))
|
||||
#define SAME_INODE(A,B) ((A).st_ino == (B).inode && (A).st_dev == (B).device)
|
||||
|
||||
static Oid procedureId_save = -1;
|
||||
static int pronargs_save;
|
||||
static func_ptr user_fn_save = (func_ptr) NULL;
|
||||
static func_ptr handle_load(char *filename, char *funcname);
|
||||
|
||||
func_ptr
|
||||
fmgr_dynamic(Oid procedureId, int *pronargs)
|
||||
PGFunction
|
||||
fmgr_dynamic(Oid functionId)
|
||||
{
|
||||
HeapTuple procedureTuple;
|
||||
Form_pg_proc procedureStruct;
|
||||
char *proname,
|
||||
*linksymbol,
|
||||
*prosrcstring,
|
||||
*probinstring;
|
||||
char *prosrcstring = NULL;
|
||||
Datum probinattr;
|
||||
Datum prosrcattr;
|
||||
func_ptr user_fn;
|
||||
Relation rel;
|
||||
Datum prosrcattr,
|
||||
probinattr;
|
||||
PGFunction user_fn;
|
||||
bool isnull;
|
||||
|
||||
/* Implement simple one-element cache for function lookups */
|
||||
if (procedureId == procedureId_save)
|
||||
{
|
||||
*pronargs = pronargs_save;
|
||||
return user_fn_save;
|
||||
}
|
||||
|
||||
/*
|
||||
* The procedure isn't a builtin, so we'll have to do a catalog lookup
|
||||
* to find its pg_proc entry. Moreover, since probin is varlena,
|
||||
* we're going to have to use heap_getattr, which means we need the
|
||||
* reldesc, which means we need to open the relation. So we might as
|
||||
* well do that first and get the benefit of SI inval if needed.
|
||||
*/
|
||||
rel = heap_openr(ProcedureRelationName, AccessShareLock);
|
||||
|
||||
procedureTuple = SearchSysCacheTuple(PROCOID,
|
||||
ObjectIdGetDatum(procedureId),
|
||||
ObjectIdGetDatum(functionId),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(procedureTuple))
|
||||
{
|
||||
elog(ERROR, "fmgr: Cache lookup failed for procedure %u\n",
|
||||
procedureId);
|
||||
return (func_ptr) NULL;
|
||||
}
|
||||
|
||||
elog(ERROR, "fmgr_dynamic: function %u: cache lookup failed",
|
||||
functionId);
|
||||
procedureStruct = (Form_pg_proc) GETSTRUCT(procedureTuple);
|
||||
|
||||
proname = NameStr(procedureStruct->proname);
|
||||
pronargs_save = *pronargs = procedureStruct->pronargs;
|
||||
probinattr = heap_getattr(procedureTuple,
|
||||
Anum_pg_proc_probin,
|
||||
RelationGetDescr(rel), &isnull);
|
||||
if (!PointerIsValid(probinattr) /* || isnull */ )
|
||||
|
||||
prosrcattr = SysCacheGetAttr(PROCOID, procedureTuple,
|
||||
Anum_pg_proc_prosrc, &isnull);
|
||||
if (isnull || !PointerIsValid(prosrcattr))
|
||||
{
|
||||
heap_close(rel, AccessShareLock);
|
||||
elog(ERROR, "fmgr: Could not extract probin for %u from %s",
|
||||
procedureId, ProcedureRelationName);
|
||||
return (func_ptr) NULL;
|
||||
elog(ERROR, "fmgr: Could not extract prosrc for %u from pg_proc",
|
||||
functionId);
|
||||
}
|
||||
probinstring = textout((struct varlena *) probinattr);
|
||||
prosrcstring = textout((text *) DatumGetPointer(prosrcattr));
|
||||
|
||||
prosrcattr = heap_getattr(procedureTuple,
|
||||
Anum_pg_proc_prosrc,
|
||||
RelationGetDescr(rel), &isnull);
|
||||
|
||||
if (isnull)
|
||||
{ /* Use the proname for the link symbol */
|
||||
linksymbol = proname;
|
||||
}
|
||||
else if (!PointerIsValid(prosrcattr))
|
||||
{ /* pg_proc must be messed up! */
|
||||
heap_close(rel, AccessShareLock);
|
||||
elog(ERROR, "fmgr: Could not extract prosrc for %u from %s",
|
||||
procedureId, ProcedureRelationName);
|
||||
return (func_ptr) NULL;
|
||||
}
|
||||
else
|
||||
{ /* The text in prosrcattr is either "-" or
|
||||
* a link symbol */
|
||||
prosrcstring = textout((struct varlena *) prosrcattr);
|
||||
if (strcmp(prosrcstring, "-") == 0)
|
||||
linksymbol = proname;
|
||||
else
|
||||
linksymbol = prosrcstring;
|
||||
probinattr = SysCacheGetAttr(PROCOID, procedureTuple,
|
||||
Anum_pg_proc_probin, &isnull);
|
||||
if (isnull || !PointerIsValid(probinattr))
|
||||
{
|
||||
elog(ERROR, "fmgr: Could not extract probin for %u from pg_proc",
|
||||
functionId);
|
||||
}
|
||||
probinstring = textout((text *) DatumGetPointer(probinattr));
|
||||
|
||||
heap_close(rel, AccessShareLock);
|
||||
|
||||
user_fn = handle_load(probinstring, linksymbol);
|
||||
user_fn = load_external_function(probinstring, prosrcstring);
|
||||
|
||||
pfree(prosrcstring);
|
||||
pfree(probinstring);
|
||||
if (prosrcstring)
|
||||
pfree(prosrcstring);
|
||||
|
||||
procedureId_save = procedureId;
|
||||
user_fn_save = user_fn;
|
||||
|
||||
return user_fn;
|
||||
}
|
||||
|
||||
static func_ptr
|
||||
handle_load(char *filename, char *funcname)
|
||||
PGFunction
|
||||
load_external_function(char *filename, char *funcname)
|
||||
{
|
||||
DynamicFileList *file_scanner = (DynamicFileList *) NULL;
|
||||
func_ptr retval = (func_ptr) NULL;
|
||||
DynamicFileList *file_scanner;
|
||||
PGFunction retval;
|
||||
char *load_error;
|
||||
struct stat stat_buf;
|
||||
|
||||
/*
|
||||
* Do this because loading files may screw up the dynamic function
|
||||
* manager otherwise.
|
||||
* Scan the list of loaded FILES to see if the file has been loaded.
|
||||
*/
|
||||
procedureId_save = -1;
|
||||
|
||||
/*
|
||||
* Scan the list of loaded FILES to see if the function has been
|
||||
* loaded.
|
||||
*/
|
||||
|
||||
if (filename != (char *) NULL)
|
||||
for (file_scanner = file_list;
|
||||
file_scanner != (DynamicFileList *) NULL &&
|
||||
strcmp(filename, file_scanner->filename) != 0;
|
||||
file_scanner = file_scanner->next)
|
||||
;
|
||||
if (file_scanner == (DynamicFileList *) NULL)
|
||||
{
|
||||
/*
|
||||
* Check for same files - different paths (ie, symlink or link)
|
||||
*/
|
||||
if (stat(filename, &stat_buf) == -1)
|
||||
elog(ERROR, "stat failed on file '%s': %m", filename);
|
||||
|
||||
for (file_scanner = file_list;
|
||||
file_scanner != (DynamicFileList *) NULL
|
||||
&& file_scanner->filename != (char *) NULL
|
||||
&& strcmp(filename, file_scanner->filename) != 0;
|
||||
file_scanner != (DynamicFileList *) NULL &&
|
||||
!SAME_INODE(stat_buf, *file_scanner);
|
||||
file_scanner = file_scanner->next)
|
||||
;
|
||||
if (file_scanner == (DynamicFileList *) NULL)
|
||||
{
|
||||
if (stat(filename, &stat_buf) == -1)
|
||||
elog(ERROR, "stat failed on file '%s': %m", filename);
|
||||
|
||||
for (file_scanner = file_list;
|
||||
file_scanner != (DynamicFileList *) NULL
|
||||
&& (NOT_EQUAL(stat_buf, *file_scanner));
|
||||
file_scanner = file_scanner->next)
|
||||
;
|
||||
|
||||
/*
|
||||
* Same files - different paths (ie, symlink or link)
|
||||
*/
|
||||
if (file_scanner != (DynamicFileList *) NULL)
|
||||
strcpy(file_scanner->filename, filename);
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
file_scanner = (DynamicFileList *) NULL;
|
||||
|
||||
/*
|
||||
* File not loaded yet.
|
||||
*/
|
||||
|
||||
if (file_scanner == (DynamicFileList *) NULL)
|
||||
{
|
||||
if (file_list == (DynamicFileList *) NULL)
|
||||
{
|
||||
file_list = (DynamicFileList *)
|
||||
malloc(sizeof(DynamicFileList));
|
||||
file_scanner = file_list;
|
||||
}
|
||||
else
|
||||
{
|
||||
file_tail->next = (DynamicFileList *)
|
||||
malloc(sizeof(DynamicFileList));
|
||||
file_scanner = file_tail->next;
|
||||
}
|
||||
MemSet((char *) file_scanner, 0, sizeof(DynamicFileList));
|
||||
/*
|
||||
* File not loaded yet.
|
||||
*/
|
||||
file_scanner = (DynamicFileList *)
|
||||
malloc(sizeof(DynamicFileList) + strlen(filename));
|
||||
if (file_scanner == NULL)
|
||||
elog(FATAL, "Out of memory in load_external_function");
|
||||
|
||||
MemSet((char *) file_scanner, 0, sizeof(DynamicFileList));
|
||||
strcpy(file_scanner->filename, filename);
|
||||
file_scanner->device = stat_buf.st_dev;
|
||||
file_scanner->inode = stat_buf.st_ino;
|
||||
@@ -210,42 +147,36 @@ handle_load(char *filename, char *funcname)
|
||||
if (file_scanner->handle == (void *) NULL)
|
||||
{
|
||||
load_error = (char *) pg_dlerror();
|
||||
if (file_scanner == file_list)
|
||||
file_list = (DynamicFileList *) NULL;
|
||||
else
|
||||
file_tail->next = (DynamicFileList *) NULL;
|
||||
|
||||
free((char *) file_scanner);
|
||||
elog(ERROR, "Load of file %s failed: %s", filename, load_error);
|
||||
}
|
||||
|
||||
/*
|
||||
* Just load the file - we are done with that so return.
|
||||
*/
|
||||
/* OK to link it into list */
|
||||
if (file_list == (DynamicFileList *) NULL)
|
||||
file_list = file_scanner;
|
||||
else
|
||||
file_tail->next = file_scanner;
|
||||
file_tail = file_scanner;
|
||||
|
||||
if (funcname == (char *) NULL)
|
||||
return (func_ptr) NULL;
|
||||
}
|
||||
|
||||
retval = (func_ptr) pg_dlsym(file_scanner->handle, funcname);
|
||||
/*
|
||||
* If funcname is NULL, we only wanted to load the file.
|
||||
*/
|
||||
if (funcname == (char *) NULL)
|
||||
return (PGFunction) NULL;
|
||||
|
||||
if (retval == (func_ptr) NULL)
|
||||
retval = pg_dlsym(file_scanner->handle, funcname);
|
||||
|
||||
if (retval == (PGFunction) NULL)
|
||||
elog(ERROR, "Can't find function %s in file %s", funcname, filename);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function loads files by the following:
|
||||
*
|
||||
* If the file is already loaded:
|
||||
* o Zero out that file's loaded space (so it doesn't screw up linking)
|
||||
* o Free all space associated with that file
|
||||
* o Free that file's descriptor.
|
||||
*
|
||||
* Now load the file by calling handle_load with a NULL argument as the
|
||||
* function.
|
||||
* This function loads a shlib file without looking up any particular
|
||||
* function in it. If the same shlib has previously been loaded,
|
||||
* unload and reload it.
|
||||
*/
|
||||
void
|
||||
load_file(char *filename)
|
||||
@@ -253,7 +184,6 @@ load_file(char *filename)
|
||||
DynamicFileList *file_scanner,
|
||||
*p;
|
||||
struct stat stat_buf;
|
||||
int done = 0;
|
||||
|
||||
/*
|
||||
* We need to do stat() in order to determine whether this is the same
|
||||
@@ -263,48 +193,32 @@ load_file(char *filename)
|
||||
if (stat(filename, &stat_buf) == -1)
|
||||
elog(ERROR, "LOAD: could not open file '%s': %m", filename);
|
||||
|
||||
if (file_list != (DynamicFileList *) NULL
|
||||
&& !NOT_EQUAL(stat_buf, *file_list))
|
||||
if (file_list != (DynamicFileList *) NULL)
|
||||
{
|
||||
file_scanner = file_list;
|
||||
file_list = file_list->next;
|
||||
pg_dlclose(file_scanner->handle);
|
||||
free((char *) file_scanner);
|
||||
}
|
||||
else if (file_list != (DynamicFileList *) NULL)
|
||||
{
|
||||
file_scanner = file_list;
|
||||
while (!done)
|
||||
if (SAME_INODE(stat_buf, *file_list))
|
||||
{
|
||||
if (file_scanner->next == (DynamicFileList *) NULL)
|
||||
done = 1;
|
||||
else if (!NOT_EQUAL(stat_buf, *(file_scanner->next)))
|
||||
done = 1;
|
||||
else
|
||||
file_scanner = file_scanner->next;
|
||||
}
|
||||
|
||||
if (file_scanner->next != (DynamicFileList *) NULL)
|
||||
{
|
||||
p = file_scanner->next;
|
||||
file_scanner->next = file_scanner->next->next;
|
||||
pg_dlclose(file_scanner->handle);
|
||||
p = file_list;
|
||||
file_list = p->next;
|
||||
pg_dlclose(p->handle);
|
||||
free((char *) p);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (file_scanner = file_list;
|
||||
file_scanner->next != (DynamicFileList *) NULL;
|
||||
file_scanner = file_scanner->next)
|
||||
{
|
||||
if (SAME_INODE(stat_buf, *(file_scanner->next)))
|
||||
{
|
||||
p = file_scanner->next;
|
||||
file_scanner->next = p->next;
|
||||
pg_dlclose(p->handle);
|
||||
free((char *) p);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
handle_load(filename, (char *) NULL);
|
||||
|
||||
load_external_function(filename, (char *) NULL);
|
||||
}
|
||||
|
||||
/* Is this used? bjm 1998/10/08 No. tgl 1999/02/07 */
|
||||
#ifdef NOT_USED
|
||||
func_ptr
|
||||
trigger_dynamic(char *filename, char *funcname)
|
||||
{
|
||||
func_ptr trigger_fn;
|
||||
|
||||
trigger_fn = handle_load(filename, funcname);
|
||||
|
||||
return trigger_fn;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.57 2000/04/12 17:16:02 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.58 2000/05/28 17:56:08 tgl Exp $
|
||||
*
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
@@ -30,6 +30,7 @@
|
||||
#include "storage/proc.h"
|
||||
#include "storage/sinval.h"
|
||||
#include "storage/smgr.h"
|
||||
#include "utils/fmgroids.h"
|
||||
#include "utils/inval.h"
|
||||
#include "utils/portal.h"
|
||||
#include "utils/relcache.h"
|
||||
|
||||
Reference in New Issue
Block a user