1 /*-------------------------------------------------------------------------
4 * Support for finding the values associated with Param nodes.
7 * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * $PostgreSQL: pgsql/src/include/nodes/params.h,v 1.39 2009/11/04 22:26:06 tgl Exp $
12 *-------------------------------------------------------------------------
17 /* To avoid including a pile of parser headers, reference ParseState thus: */
24 * ParamListInfo arrays are used to pass parameters into the executor
25 * for parameterized plans. Each entry in the array defines the value
26 * to be substituted for a PARAM_EXTERN parameter. The "paramid"
27 * of a PARAM_EXTERN Param can range from 1 to numParams.
29 * Although parameter numbers are normally consecutive, we allow
30 * ptype == InvalidOid to signal an unused array entry.
32 * pflags is a flags field. Currently the only used bit is:
33 * PARAM_FLAG_CONST signals the planner that it may treat this parameter
34 * as a constant (i.e., generate a plan that works only for this value
37 * There are two hook functions that can be associated with a ParamListInfo
38 * array to support dynamic parameter handling. First, if paramFetch
39 * isn't null and the executor requires a value for an invalid parameter
40 * (one with ptype == InvalidOid), the paramFetch hook is called to give
41 * it a chance to fill in the parameter value. Second, a parserSetup
42 * hook can be supplied to re-instantiate the original parsing hooks if
43 * a query needs to be re-parsed/planned (as a substitute for supposing
44 * that the current ptype values represent a fixed set of parameter types).
46 * Although the data structure is really an array, not a list, we keep
47 * the old typedef name to avoid unnecessary code changes.
51 #define PARAM_FLAG_CONST 0x0001 /* parameter is constant */
53 typedef struct ParamExternData
55 Datum value; /* parameter value */
56 bool isnull; /* is it NULL? */
57 uint16 pflags; /* flag bits, see above */
58 Oid ptype; /* parameter's datatype, or 0 */
61 typedef struct ParamListInfoData *ParamListInfo;
63 typedef void (*ParamFetchHook) (ParamListInfo params, int paramid);
65 typedef void (*ParserSetupHook) (struct ParseState *pstate, void *arg);
67 typedef struct ParamListInfoData
69 ParamFetchHook paramFetch; /* parameter fetch hook */
71 ParserSetupHook parserSetup; /* parser setup hook */
73 int numParams; /* number of ParamExternDatas following */
74 ParamExternData params[1]; /* VARIABLE LENGTH ARRAY */
81 * ParamExecData entries are used for executor internal parameters
82 * (that is, values being passed into or out of a sub-query). The
83 * paramid of a PARAM_EXEC Param is a (zero-based) index into an
84 * array of ParamExecData records, which is referenced through
85 * es_param_exec_vals or ecxt_param_exec_vals.
87 * If execPlan is not NULL, it points to a SubPlanState node that needs
88 * to be executed to produce the value. (This is done so that we can have
89 * lazy evaluation of InitPlans: they aren't executed until/unless a
90 * result value is needed.) Otherwise the value is assumed to be valid
95 typedef struct ParamExecData
97 void *execPlan; /* should be "SubPlanState *" */
103 /* Functions found in src/backend/nodes/params.c */
104 extern ParamListInfo copyParamList(ParamListInfo from);
106 extern void setupParserWithParamList(struct ParseState *pstate,
107 ParamListInfo params);
109 #endif /* PARAMS_H */