PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
params.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * params.h
4  * Support for finding the values associated with Param nodes.
5  *
6  *
7  * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * src/include/nodes/params.h
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef PARAMS_H
15 #define PARAMS_H
16 
17 /* Forward declarations, to avoid including other headers */
18 struct Bitmapset;
19 struct ParseState;
20 
21 
22 /* ----------------
23  * ParamListInfo
24  *
25  * ParamListInfo arrays are used to pass parameters into the executor
26  * for parameterized plans. Each entry in the array defines the value
27  * to be substituted for a PARAM_EXTERN parameter. The "paramid"
28  * of a PARAM_EXTERN Param can range from 1 to numParams.
29  *
30  * Although parameter numbers are normally consecutive, we allow
31  * ptype == InvalidOid to signal an unused array entry.
32  *
33  * pflags is a flags field. Currently the only used bit is:
34  * PARAM_FLAG_CONST signals the planner that it may treat this parameter
35  * as a constant (i.e., generate a plan that works only for this value
36  * of the parameter).
37  *
38  * There are two hook functions that can be associated with a ParamListInfo
39  * array to support dynamic parameter handling. First, if paramFetch
40  * isn't null and the executor requires a value for an invalid parameter
41  * (one with ptype == InvalidOid), the paramFetch hook is called to give
42  * it a chance to fill in the parameter value. Second, a parserSetup
43  * hook can be supplied to re-instantiate the original parsing hooks if
44  * a query needs to be re-parsed/planned (as a substitute for supposing
45  * that the current ptype values represent a fixed set of parameter types).
46 
47  * Although the data structure is really an array, not a list, we keep
48  * the old typedef name to avoid unnecessary code changes.
49  * ----------------
50  */
51 
52 #define PARAM_FLAG_CONST 0x0001 /* parameter is constant */
53 
54 typedef struct ParamExternData
55 {
56  Datum value; /* parameter value */
57  bool isnull; /* is it NULL? */
58  uint16 pflags; /* flag bits, see above */
59  Oid ptype; /* parameter's datatype, or 0 */
61 
63 
64 typedef void (*ParamFetchHook) (ParamListInfo params, int paramid);
65 
66 typedef void (*ParserSetupHook) (struct ParseState *pstate, void *arg);
67 
68 typedef struct ParamListInfoData
69 {
70  ParamFetchHook paramFetch; /* parameter fetch hook */
72  ParserSetupHook parserSetup; /* parser setup hook */
74  int numParams; /* number of ParamExternDatas following */
75  struct Bitmapset *paramMask; /* if non-NULL, can ignore omitted params */
76  ParamExternData params[FLEXIBLE_ARRAY_MEMBER];
78 
79 
80 /* ----------------
81  * ParamExecData
82  *
83  * ParamExecData entries are used for executor internal parameters
84  * (that is, values being passed into or out of a sub-query). The
85  * paramid of a PARAM_EXEC Param is a (zero-based) index into an
86  * array of ParamExecData records, which is referenced through
87  * es_param_exec_vals or ecxt_param_exec_vals.
88  *
89  * If execPlan is not NULL, it points to a SubPlanState node that needs
90  * to be executed to produce the value. (This is done so that we can have
91  * lazy evaluation of InitPlans: they aren't executed until/unless a
92  * result value is needed.) Otherwise the value is assumed to be valid
93  * when needed.
94  * ----------------
95  */
96 
97 typedef struct ParamExecData
98 {
99  void *execPlan; /* should be "SubPlanState *" */
101  bool isnull;
102 } ParamExecData;
103 
104 
105 /* Functions found in src/backend/nodes/params.c */
106 extern ParamListInfo copyParamList(ParamListInfo from);
107 extern Size EstimateParamListSpace(ParamListInfo paramLI);
108 extern void SerializeParamList(ParamListInfo paramLI, char **start_address);
109 extern ParamListInfo RestoreParamList(char **start_address);
110 
111 #endif /* PARAMS_H */
ParamExternData params[FLEXIBLE_ARRAY_MEMBER]
Definition: params.h:76
Datum value
Definition: params.h:56
void * execPlan
Definition: params.h:99
void * parserSetupArg
Definition: params.h:73
ParamListInfo copyParamList(ParamListInfo from)
Definition: params.c:36
ParserSetupHook parserSetup
Definition: params.h:72
struct ParamListInfoData * ParamListInfo
Definition: params.h:62
unsigned int Oid
Definition: postgres_ext.h:31
ParamListInfo RestoreParamList(char **start_address)
Definition: params.c:224
struct ParamListInfoData ParamListInfoData
void * paramFetchArg
Definition: params.h:71
ParamFetchHook paramFetch
Definition: params.h:70
unsigned short uint16
Definition: c.h:267
bool isnull
Definition: params.h:101
struct ParamExecData ParamExecData
void(* ParserSetupHook)(struct ParseState *pstate, void *arg)
Definition: params.h:66
struct Bitmapset * paramMask
Definition: params.h:75
void(* ParamFetchHook)(ParamListInfo params, int paramid)
Definition: params.h:64
struct ParamExternData ParamExternData
uintptr_t Datum
Definition: postgres.h:372
Size EstimateParamListSpace(ParamListInfo paramLI)
Definition: params.c:95
uint16 pflags
Definition: params.h:58
size_t Size
Definition: c.h:356
Datum value
Definition: params.h:100
void * arg
bool isnull
Definition: params.h:57
void SerializeParamList(ParamListInfo paramLI, char **start_address)
Definition: params.c:158