]> granicus.if.org Git - postgresql/blobdiff - src/include/fmgr.h
Revise collation derivation method and expression-tree representation.
[postgresql] / src / include / fmgr.h
index c348086fbc8e3770658504dd8d7e08217b959e61..9e5224d374da46f6535dd68282f91f6ec8deea7f 100644 (file)
@@ -8,10 +8,10 @@
  * or call fmgr-callable functions.
  *
  *
- * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/fmgr.h,v 1.60 2008/09/03 22:34:50 tgl Exp $
+ * src/include/fmgr.h
  *
  *-------------------------------------------------------------------------
  */
@@ -40,6 +40,11 @@ typedef Datum (*PGFunction) (FunctionCallInfo fcinfo);
  * before a function can be called through fmgr.  If the same function is
  * to be called multiple times, the lookup need be done only once and the
  * info struct saved for re-use.
+ *
+ * Note that fn_collation and fn_expr really are parse-time-determined
+ * information about the arguments, rather than about the function itself.
+ * But it's convenient to store them here rather than in FunctionCallInfoData,
+ * where they might more logically belong.
  */
 typedef struct FmgrInfo
 {
@@ -50,6 +55,7 @@ typedef struct FmgrInfo
        bool            fn_strict;              /* function is "strict" (NULL in => NULL out) */
        bool            fn_retset;              /* function returns a set */
        unsigned char fn_stats;         /* collect stats if track_functions > this */
+       Oid                     fn_collation;   /* collation that function should use */
        void       *fn_extra;           /* extra space for use by handler */
        MemoryContext fn_mcxt;          /* memory context to store fn_extra in */
        fmNodePtr       fn_expr;                /* expression parse tree for call, or NULL */
@@ -83,6 +89,12 @@ extern void fmgr_info(Oid functionId, FmgrInfo *finfo);
 extern void fmgr_info_cxt(Oid functionId, FmgrInfo *finfo,
                          MemoryContext mcxt);
 
+/* Macros for setting the fn_collation and fn_expr fields */
+#define fmgr_info_set_collation(collationId, finfo) \
+       ((finfo)->fn_collation = (collationId))
+#define fmgr_info_set_expr(expr, finfo) \
+       ((finfo)->fn_expr = (expr))
+
 /*
  * Copy an FmgrInfo struct
  */
@@ -135,6 +147,12 @@ extern void fmgr_info_copy(FmgrInfo *dstinfo, FmgrInfo *srcinfo,
 /* Standard parameter list for fmgr-compatible functions */
 #define PG_FUNCTION_ARGS       FunctionCallInfo fcinfo
 
+/*
+ * Get collation function should use.
+ */
+#define PG_GET_COLLATION() \
+       (fcinfo->flinfo ? fcinfo->flinfo->fn_collation : InvalidOid)
+
 /*
  * Get number of arguments passed to function.
  */
@@ -328,7 +346,7 @@ typedef const Pg_finfo_record *(*PGFInfoFunction) (void);
  *     doesn't hurt to add PGDLLIMPORT in case they don't.
  */
 #define PG_FUNCTION_INFO_V1(funcname) \
-extern PGDLLIMPORT const Pg_finfo_record * CppConcat(pg_finfo_,funcname)(void); \
+extern PGDLLEXPORT const Pg_finfo_record * CppConcat(pg_finfo_,funcname)(void); \
 const Pg_finfo_record * \
 CppConcat(pg_finfo_,funcname) (void) \
 { \
@@ -397,7 +415,7 @@ typedef const Pg_magic_struct *(*PGModuleMagicFunction) (void);
 #define PG_MAGIC_FUNCTION_NAME_STRING "Pg_magic_func"
 
 #define PG_MODULE_MAGIC \
-extern PGDLLIMPORT const Pg_magic_struct *PG_MAGIC_FUNCTION_NAME(void); \
+extern PGDLLEXPORT const Pg_magic_struct *PG_MAGIC_FUNCTION_NAME(void); \
 const Pg_magic_struct * \
 PG_MAGIC_FUNCTION_NAME(void) \
 { \
@@ -438,6 +456,12 @@ extern Datum DirectFunctionCall9(PGFunction func, Datum arg1, Datum arg2,
                                        Datum arg6, Datum arg7, Datum arg8,
                                        Datum arg9);
 
+/* The same, but passing a collation to use */
+extern Datum DirectFunctionCall1WithCollation(PGFunction func, Oid collation,
+                                                                                         Datum arg1);
+extern Datum DirectFunctionCall2WithCollation(PGFunction func, Oid collation,
+                                                                                         Datum arg1, Datum arg2);
+
 /* These are for invocation of a previously-looked-up function with a
  * directly-computed parameter list.  Note that neither arguments nor result
  * are allowed to be NULL.
@@ -470,6 +494,7 @@ extern Datum FunctionCall9(FmgrInfo *flinfo, Datum arg1, Datum arg2,
  * by FunctionCallN(). If the same function is to be invoked repeatedly,
  * do the FunctionLookup() once and then use FunctionCallN().
  */
+extern Datum OidFunctionCall0(Oid functionId);
 extern Datum OidFunctionCall1(Oid functionId, Datum arg1);
 extern Datum OidFunctionCall2(Oid functionId, Datum arg1, Datum arg2);
 extern Datum OidFunctionCall3(Oid functionId, Datum arg1, Datum arg2,
@@ -516,6 +541,8 @@ extern Oid  fmgr_internal_function(const char *proname);
 extern Oid     get_fn_expr_rettype(FmgrInfo *flinfo);
 extern Oid     get_fn_expr_argtype(FmgrInfo *flinfo, int argnum);
 extern Oid     get_call_expr_argtype(fmNodePtr expr, int argnum);
+extern bool get_fn_expr_arg_stable(FmgrInfo *flinfo, int argnum);
+extern bool get_call_expr_arg_stable(fmNodePtr expr, int argnum);
 
 /*
  * Routines in dfmgr.c
@@ -528,6 +555,46 @@ extern PGFunction lookup_external_function(void *filehandle, char *funcname);
 extern void load_file(const char *filename, bool restricted);
 extern void **find_rendezvous_variable(const char *varName);
 
+/*
+ * Support for aggregate functions
+ *
+ * This is actually in executor/nodeAgg.c, but we declare it here since the
+ * whole point is for callers of it to not be overly friendly with nodeAgg.
+ */
+
+/* AggCheckCallContext can return one of the following codes, or 0: */
+#define AGG_CONTEXT_AGGREGATE  1               /* regular aggregate */
+#define AGG_CONTEXT_WINDOW             2               /* window function */
+
+extern int AggCheckCallContext(FunctionCallInfo fcinfo,
+                                       MemoryContext *aggcontext);
+
+/*
+ * We allow plugin modules to hook function entry/exit.  This is intended
+ * as support for loadable security policy modules, which may want to
+ * perform additional privilege checks on function entry or exit, or to do
+ * other internal bookkeeping.  To make this possible, such modules must be
+ * able not only to support normal function entry and exit, but also to trap
+ * the case where we bail out due to an error; and they must also be able to
+ * prevent inlining.
+ */
+typedef enum FmgrHookEventType
+{
+       FHET_START,
+       FHET_END,
+       FHET_ABORT
+} FmgrHookEventType;
+
+typedef bool (*needs_fmgr_hook_type)(Oid fn_oid);
+
+typedef void (*fmgr_hook_type)(FmgrHookEventType event,
+                                                          FmgrInfo *flinfo, Datum *arg);
+
+extern PGDLLIMPORT needs_fmgr_hook_type        needs_fmgr_hook;
+extern PGDLLIMPORT fmgr_hook_type              fmgr_hook;
+
+#define FmgrHookIsNeeded(fn_oid)                                                       \
+       (!needs_fmgr_hook ? false : (*needs_fmgr_hook)(fn_oid))
 
 /*
  * !!! OLD INTERFACE !!!