summaryrefslogtreecommitdiff
path: root/src/include/utils
diff options
context:
space:
mode:
authorTom Lane2000-08-24 03:29:15 +0000
committerTom Lane2000-08-24 03:29:15 +0000
commit782c16c6a154e760bf1608d633488538cd52da93 (patch)
tree902da787593da21a979bd2f74b0b44acf9c427b0 /src/include/utils
parent87523ab8db34859ae3fb980a3fab9f29dfc4c97a (diff)
SQL-language functions are now callable in ordinary fmgr contexts ...
for example, an SQL function can be used in a functional index. (I make no promises about speed, but it'll work ;-).) Clean up and simplify handling of functions returning sets.
Diffstat (limited to 'src/include/utils')
-rw-r--r--src/include/utils/builtins.h3
-rw-r--r--src/include/utils/fcache.h75
-rw-r--r--src/include/utils/fcache2.h21
-rw-r--r--src/include/utils/sets.h7
4 files changed, 46 insertions, 60 deletions
diff --git a/src/include/utils/builtins.h b/src/include/utils/builtins.h
index 1e16af6874f..f1ebe40b590 100644
--- a/src/include/utils/builtins.h
+++ b/src/include/utils/builtins.h
@@ -7,13 +7,14 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: builtins.h,v 1.133 2000/08/23 06:04:49 thomas Exp $
+ * $Id: builtins.h,v 1.134 2000/08/24 03:29:14 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#ifndef BUILTINS_H
#define BUILTINS_H
+#include "fmgr.h"
#include "nodes/relation.h" /* for amcostestimate parameters */
#include "storage/itemptr.h"
#include "utils/numeric.h"
diff --git a/src/include/utils/fcache.h b/src/include/utils/fcache.h
index efae7613959..a30c7283608 100644
--- a/src/include/utils/fcache.h
+++ b/src/include/utils/fcache.h
@@ -11,7 +11,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: fcache.h,v 1.13 2000/08/08 15:43:12 tgl Exp $
+ * $Id: fcache.h,v 1.14 2000/08/24 03:29:14 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -19,45 +19,50 @@
#define FCACHE_H
#include "fmgr.h"
+#include "nodes/execnodes.h"
+/*
+ * A FunctionCache record is built for all functions regardless of language.
+ *
+ * We store the fmgr lookup info to avoid recomputing it on each call.
+ * We also store a prebuilt FunctionCallInfo struct. When evaluating a
+ * function-returning-set, fcinfo holds the argument values across calls
+ * so that we need not re-evaluate the arguments for each call. Even for
+ * non-set functions, fcinfo saves a few cycles per call by allowing us to
+ * avoid redundant setup of its fields.
+ */
-typedef struct
+typedef struct FunctionCache
{
- FmgrInfo func; /* info for fmgr call mechanism */
- Oid foid; /* oid of the function in pg_proc */
- Oid language; /* oid of the language in pg_language */
- int typlen; /* length of the return type */
- bool typbyval; /* true if return type is pass by value */
-
- bool returnsTuple; /* true if return type is a tuple */
- bool returnsSet; /* true if func returns a set (multi rows) */
-
- bool hasSetArg; /* true if func is part of a nested dot
- * expr whose argument is func returning a
- * set ugh! */
-
- /* If additional info is added to an existing fcache, be sure to
- * allocate it in the fcacheCxt.
+ /*
+ * Function manager's lookup info for the target function.
*/
- MemoryContext fcacheCxt; /* context the fcache lives in */
-
- int nargs; /* actual number of arguments */
- Oid *argOidVect; /* oids of all the argument types */
-
- char *src; /* source code of the function */
- char *bin; /* binary object code ?? */
- char *func_state; /* function_state struct for execution */
-
- Pointer funcSlot; /* if one result we need to copy it before
- * we end execution of the function and
- * free stuff */
-
- Datum setArg; /* current argument for nested dot
- * execution Nested dot expressions mean
- * we have funcs whose argument is a set
- * of tuples */
+ FmgrInfo func;
+ /*
+ * Per-call info for calling the target function. Unvarying fields
+ * are set up by init_fcache(). Argument values are filled in as needed.
+ */
+ FunctionCallInfoData fcinfo;
+ /*
+ * "Resultinfo" node --- used only if target function returns a set.
+ */
+ ReturnSetInfo rsinfo;
+ /*
+ * argsValid is true when we are evaluating a set-valued function and
+ * we are in the middle of a call series; we want to pass the same
+ * argument values to the function again (and again, until it returns
+ * ExprEndResult).
+ */
+ bool argsValid; /* TRUE if fcinfo contains valid arguments */
+ /*
+ * hasSetArg is true if we found a set-valued argument to the function.
+ * This causes the function result to be a set as well.
+ */
+ bool hasSetArg; /* some argument returns a set */
} FunctionCache;
-typedef FunctionCache *FunctionCachePtr;
+
+extern FunctionCachePtr init_fcache(Oid foid, int nargs,
+ MemoryContext fcacheCxt);
#endif /* FCACHE_H */
diff --git a/src/include/utils/fcache2.h b/src/include/utils/fcache2.h
deleted file mode 100644
index 984edde4929..00000000000
--- a/src/include/utils/fcache2.h
+++ /dev/null
@@ -1,21 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * fcache2.h
- *
- *
- *
- * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
- * Portions Copyright (c) 1994, Regents of the University of California
- *
- * $Id: fcache2.h,v 1.10 2000/01/26 05:58:38 momjian Exp $
- *
- *-------------------------------------------------------------------------
- */
-#ifndef FCACHE2_H
-#define FCACHE2_H
-
-#include "nodes/execnodes.h"
-
-extern void setFcache(Node *node, Oid foid, List *argList, ExprContext *econtext);
-
-#endif /* FCACHE2_H */
diff --git a/src/include/utils/sets.h b/src/include/utils/sets.h
index a7b5d6826e2..7f284ac3467 100644
--- a/src/include/utils/sets.h
+++ b/src/include/utils/sets.h
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: sets.h,v 1.7 2000/06/09 01:11:15 tgl Exp $
+ * $Id: sets.h,v 1.8 2000/08/24 03:29:14 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -17,10 +17,11 @@
#include "fmgr.h"
-/* Temporary name of set, before SetDefine changes it. */
-#define GENERICSETNAME "zyxset"
+/* Temporary name of a set function, before SetDefine changes it. */
+#define GENERICSETNAME "ZYX#Set#ZYX"
extern Oid SetDefine(char *querystr, char *typename);
+
extern Datum seteval(PG_FUNCTION_ARGS);
#endif /* SETS_H */