]> granicus.if.org Git - postgresql/blobdiff - src/include/fmgr.h
Revise collation derivation method and expression-tree representation.
[postgresql] / src / include / fmgr.h
index e18624efc3ebaad83086adaee24dcd01440e2504..9e5224d374da46f6535dd68282f91f6ec8deea7f 100644 (file)
@@ -8,10 +8,10 @@
  * or call fmgr-callable functions.
  *
  *
- * Portions Copyright (c) 1996-2007, 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.54 2007/09/22 04:41:19 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
 {
@@ -49,6 +54,8 @@ typedef struct FmgrInfo
                                                                 * count */
        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 */
@@ -82,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
  */
@@ -134,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.
  */
@@ -154,11 +173,11 @@ extern void fmgr_info_copy(FmgrInfo *dstinfo, FmgrInfo *srcinfo,
  * checked for null inputs first, if necessary.
  *
  * pg_detoast_datum_packed() will return packed (1-byte header) datums
- * unmodified.  It will still expand an externally toasted or compressed datum.
+ * unmodified. It will still expand an externally toasted or compressed datum.
  * The resulting datum can be accessed using VARSIZE_ANY() and VARDATA_ANY()
  * (beware of multiple evaluations in those macros!)
  *
- * WARNING: It is only safe to use PG_DETOAST_DATUM_UNPACKED() and
+ * WARNING: It is only safe to use pg_detoast_datum_packed() and
  * VARDATA_ANY() if you really don't care about the alignment. Either because
  * you're working with something like text where the alignment doesn't matter
  * or because you're not going to access its constituent parts and just use
@@ -327,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) \
 { \
@@ -353,6 +372,12 @@ extern int no_such_variable
  * are custom-configurable and especially likely to break dynamically loaded
  * modules if they were compiled with other values.  Also, the length field
  * can be used to detect definition changes.
+ *
+ * Note: we compare magic blocks with memcmp(), so there had better not be
+ * any alignment pad bytes in them.
+ *
+ * Note: when changing the contents of magic blocks, be sure to adjust the
+ * incompatible_module_error() function in dfmgr.c.
  *-------------------------------------------------------------------------
  */
 
@@ -364,6 +389,8 @@ typedef struct
        int                     funcmaxargs;    /* FUNC_MAX_ARGS */
        int                     indexmaxkeys;   /* INDEX_MAX_KEYS */
        int                     namedatalen;    /* NAMEDATALEN */
+       int                     float4byval;    /* FLOAT4PASSBYVAL */
+       int                     float8byval;    /* FLOAT8PASSBYVAL */
 } Pg_magic_struct;
 
 /* The actual data block contents */
@@ -373,7 +400,9 @@ typedef struct
        PG_VERSION_NUM / 100, \
        FUNC_MAX_ARGS, \
        INDEX_MAX_KEYS, \
-       NAMEDATALEN \
+       NAMEDATALEN, \
+       FLOAT4PASSBYVAL, \
+       FLOAT8PASSBYVAL \
 }
 
 /*
@@ -386,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) \
 { \
@@ -427,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.
@@ -459,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,
@@ -505,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
@@ -517,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 !!!