Header And Logo

PostgreSQL
| The world's most advanced open source database.

params.h

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * params.h
00004  *    Support for finding the values associated with Param nodes.
00005  *
00006  *
00007  * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
00008  * Portions Copyright (c) 1994, Regents of the University of California
00009  *
00010  * src/include/nodes/params.h
00011  *
00012  *-------------------------------------------------------------------------
00013  */
00014 #ifndef PARAMS_H
00015 #define PARAMS_H
00016 
00017 /* To avoid including a pile of parser headers, reference ParseState thus: */
00018 struct ParseState;
00019 
00020 
00021 /* ----------------
00022  *    ParamListInfo
00023  *
00024  *    ParamListInfo arrays are used to pass parameters into the executor
00025  *    for parameterized plans.  Each entry in the array defines the value
00026  *    to be substituted for a PARAM_EXTERN parameter.  The "paramid"
00027  *    of a PARAM_EXTERN Param can range from 1 to numParams.
00028  *
00029  *    Although parameter numbers are normally consecutive, we allow
00030  *    ptype == InvalidOid to signal an unused array entry.
00031  *
00032  *    pflags is a flags field.  Currently the only used bit is:
00033  *    PARAM_FLAG_CONST signals the planner that it may treat this parameter
00034  *    as a constant (i.e., generate a plan that works only for this value
00035  *    of the parameter).
00036  *
00037  *    There are two hook functions that can be associated with a ParamListInfo
00038  *    array to support dynamic parameter handling.  First, if paramFetch
00039  *    isn't null and the executor requires a value for an invalid parameter
00040  *    (one with ptype == InvalidOid), the paramFetch hook is called to give
00041  *    it a chance to fill in the parameter value.  Second, a parserSetup
00042  *    hook can be supplied to re-instantiate the original parsing hooks if
00043  *    a query needs to be re-parsed/planned (as a substitute for supposing
00044  *    that the current ptype values represent a fixed set of parameter types).
00045 
00046  *    Although the data structure is really an array, not a list, we keep
00047  *    the old typedef name to avoid unnecessary code changes.
00048  * ----------------
00049  */
00050 
00051 #define PARAM_FLAG_CONST    0x0001      /* parameter is constant */
00052 
00053 typedef struct ParamExternData
00054 {
00055     Datum       value;          /* parameter value */
00056     bool        isnull;         /* is it NULL? */
00057     uint16      pflags;         /* flag bits, see above */
00058     Oid         ptype;          /* parameter's datatype, or 0 */
00059 } ParamExternData;
00060 
00061 typedef struct ParamListInfoData *ParamListInfo;
00062 
00063 typedef void (*ParamFetchHook) (ParamListInfo params, int paramid);
00064 
00065 typedef void (*ParserSetupHook) (struct ParseState *pstate, void *arg);
00066 
00067 typedef struct ParamListInfoData
00068 {
00069     ParamFetchHook paramFetch;  /* parameter fetch hook */
00070     void       *paramFetchArg;
00071     ParserSetupHook parserSetup;    /* parser setup hook */
00072     void       *parserSetupArg;
00073     int         numParams;      /* number of ParamExternDatas following */
00074     ParamExternData params[1];  /* VARIABLE LENGTH ARRAY */
00075 }   ParamListInfoData;
00076 
00077 
00078 /* ----------------
00079  *    ParamExecData
00080  *
00081  *    ParamExecData entries are used for executor internal parameters
00082  *    (that is, values being passed into or out of a sub-query).  The
00083  *    paramid of a PARAM_EXEC Param is a (zero-based) index into an
00084  *    array of ParamExecData records, which is referenced through
00085  *    es_param_exec_vals or ecxt_param_exec_vals.
00086  *
00087  *    If execPlan is not NULL, it points to a SubPlanState node that needs
00088  *    to be executed to produce the value.  (This is done so that we can have
00089  *    lazy evaluation of InitPlans: they aren't executed until/unless a
00090  *    result value is needed.)  Otherwise the value is assumed to be valid
00091  *    when needed.
00092  * ----------------
00093  */
00094 
00095 typedef struct ParamExecData
00096 {
00097     void       *execPlan;       /* should be "SubPlanState *" */
00098     Datum       value;
00099     bool        isnull;
00100 } ParamExecData;
00101 
00102 
00103 /* Functions found in src/backend/nodes/params.c */
00104 extern ParamListInfo copyParamList(ParamListInfo from);
00105 
00106 #endif   /* PARAMS_H */