PostgreSQL Source Code: src/include/nodes/params.h Source File

PostgreSQL Source Code git master
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-2025, 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/* to avoid including other headers */
18 typedef struct ExprState ExprState;
19 typedef struct Param Param;
20 typedef struct ParseState ParseState;
21
22
23/*
24 * ParamListInfo
25 *
26 * ParamListInfo structures are used to pass parameters into the executor
27 * for parameterized plans. We support two basic approaches to supplying
28 * parameter values, the "static" way and the "dynamic" way.
29 *
30 * In the static approach, per-parameter data is stored in an array of
31 * ParamExternData structs appended to the ParamListInfo struct.
32 * Each entry in the array defines the value to be substituted for a
33 * PARAM_EXTERN parameter. The "paramid" of a PARAM_EXTERN Param
34 * can range from 1 to numParams.
35 *
36 * Although parameter numbers are normally consecutive, we allow
37 * ptype == InvalidOid to signal an unused array entry.
38 *
39 * pflags is a flags field. Currently the only used bit is:
40 * PARAM_FLAG_CONST signals the planner that it may treat this parameter
41 * as a constant (i.e., generate a plan that works only for this value
42 * of the parameter).
43 *
44 * In the dynamic approach, all access to parameter values is done through
45 * hook functions found in the ParamListInfo struct. In this case,
46 * the ParamExternData array is typically unused and not allocated;
47 * but the legal range of paramid is still 1 to numParams.
48 *
49 * Although the data structure is really an array, not a list, we keep
50 * the old typedef name to avoid unnecessary code changes.
51 *
52 * There are 3 hook functions that can be associated with a ParamListInfo
53 * structure:
54 *
55 * If paramFetch isn't null, it is called to fetch the ParamExternData
56 * for a particular param ID, rather than accessing the relevant element
57 * of the ParamExternData array. This supports the case where the array
58 * isn't there at all, as well as cases where the data in the array
59 * might be obsolete or lazily evaluated. paramFetch must return the
60 * address of a ParamExternData struct describing the specified param ID;
61 * the convention above about ptype == InvalidOid signaling an invalid
62 * param ID still applies. The returned struct can either be placed in
63 * the "workspace" supplied by the caller, or it can be in storage
64 * controlled by the paramFetch hook if that's more convenient.
65 * (In either case, the struct is not expected to be long-lived.)
66 * If "speculative" is true, the paramFetch hook should not risk errors
67 * in trying to fetch the parameter value, and should report an invalid
68 * parameter instead.
69 *
70 * If paramCompile isn't null, then it controls what execExpr.c compiles
71 * for PARAM_EXTERN Param nodes --- typically, this hook would emit a
72 * EEOP_PARAM_CALLBACK step. This allows unnecessary work to be
73 * optimized away in compiled expressions.
74 *
75 * If parserSetup isn't null, then it is called to re-instantiate the
76 * original parsing hooks when a query needs to be re-parsed/planned.
77 * This is especially useful if the types of parameters might change
78 * from time to time, since it can replace the need to supply a fixed
79 * list of parameter types to the parser.
80 *
81 * Notice that the paramFetch and paramCompile hooks are actually passed
82 * the ParamListInfo struct's address; they can therefore access all
83 * three of the "arg" fields, and the distinction between paramFetchArg
84 * and paramCompileArg is rather arbitrary.
85 */
86
87 #define PARAM_FLAG_CONST 0x0001 /* parameter is constant */
88
89 typedef struct ParamExternData
90{
91 Datum value; /* parameter value */
92 bool isnull; /* is it NULL? */
93 uint16 pflags; /* flag bits, see above */
94 Oid ptype; /* parameter's datatype, or 0 */
95 } ParamExternData;
96
97 typedef struct ParamListInfoData *ParamListInfo;
98
99 typedef ParamExternData *(*ParamFetchHook) (ParamListInfo params,
100 int paramid, bool speculative,
101 ParamExternData *workspace);
102
103 typedef void (*ParamCompileHook) (ParamListInfo params, Param *param,
104 ExprState *state,
105 Datum *resv, bool *resnull);
106
107 typedef void (*ParserSetupHook) (ParseState *pstate, void *arg);
108
109 typedef struct ParamListInfoData
110{
111 ParamFetchHook paramFetch; /* parameter fetch hook */
112 void *paramFetchArg;
113 ParamCompileHook paramCompile; /* parameter compile hook */
114 void *paramCompileArg;
115 ParserSetupHook parserSetup; /* parser setup hook */
116 void *parserSetupArg;
117 char *paramValuesStr; /* params as a single string for errors */
118 int numParams; /* nominal/maximum # of Params represented */
119
120 /*
121 * params[] may be of length zero if paramFetch is supplied; otherwise it
122 * must be of length numParams.
123 */
124 ParamExternData params[FLEXIBLE_ARRAY_MEMBER];
125 } ParamListInfoData;
126
127
128/* ----------------
129 * ParamExecData
130 *
131 * ParamExecData entries are used for executor internal parameters
132 * (that is, values being passed into or out of a sub-query). The
133 * paramid of a PARAM_EXEC Param is a (zero-based) index into an
134 * array of ParamExecData records, which is referenced through
135 * es_param_exec_vals or ecxt_param_exec_vals.
136 *
137 * If execPlan is not NULL, it points to a SubPlanState node that needs
138 * to be executed to produce the value. (This is done so that we can have
139 * lazy evaluation of InitPlans: they aren't executed until/unless a
140 * result value is needed.) Otherwise the value is assumed to be valid
141 * when needed.
142 * ----------------
143 */
144
145 typedef struct ParamExecData
146{
147 void *execPlan; /* should be "SubPlanState *" */
148 Datum value;
149 bool isnull;
150 } ParamExecData;
151
152/* type of argument for ParamsErrorCallback */
153 typedef struct ParamsErrorCbData
154{
155 const char *portalName;
156 ParamListInfo params;
157 } ParamsErrorCbData;
158
159/* Functions found in src/backend/nodes/params.c */
160extern ParamListInfo makeParamList(int numParams);
161extern ParamListInfo copyParamList(ParamListInfo from);
162extern Size EstimateParamListSpace(ParamListInfo paramLI);
163extern void SerializeParamList(ParamListInfo paramLI, char **start_address);
164extern ParamListInfo RestoreParamList(char **start_address);
165extern char *BuildParamLogString(ParamListInfo params, char **knownTextValues,
166 int maxlen);
167extern void ParamsErrorCallback(void *arg);
168
169#endif /* PARAMS_H */
#define FLEXIBLE_ARRAY_MEMBER
Definition: c.h:470
uint16_t uint16
Definition: c.h:537
size_t Size
Definition: c.h:610
ParamListInfo makeParamList(int numParams)
Definition: params.c:44
ParamListInfo copyParamList(ParamListInfo from)
Definition: params.c:78
struct ParamListInfoData ParamListInfoData
void(* ParamCompileHook)(ParamListInfo params, Param *param, ExprState *state, Datum *resv, bool *resnull)
Definition: params.h:103
struct ParamListInfoData * ParamListInfo
Definition: params.h:97
struct ParamsErrorCbData ParamsErrorCbData
Size EstimateParamListSpace(ParamListInfo paramLI)
Definition: params.c:167
char * BuildParamLogString(ParamListInfo params, char **knownTextValues, int maxlen)
Definition: params.c:335
void SerializeParamList(ParamListInfo paramLI, char **start_address)
Definition: params.c:229
struct ParamExternData ParamExternData
ParamExternData *(* ParamFetchHook)(ParamListInfo params, int paramid, bool speculative, ParamExternData *workspace)
Definition: params.h:99
void(* ParserSetupHook)(ParseState *pstate, void *arg)
Definition: params.h:107
void ParamsErrorCallback(void *arg)
Definition: params.c:407
ParamListInfo RestoreParamList(char **start_address)
Definition: params.c:292
struct ParamExecData ParamExecData
void * arg
uint64_t Datum
Definition: postgres.h:70
unsigned int Oid
Definition: postgres_ext.h:32
bool isnull
Definition: params.h:149
Datum value
Definition: params.h:148
void * execPlan
Definition: params.h:147
bool isnull
Definition: params.h:92
uint16 pflags
Definition: params.h:93
Oid ptype
Definition: params.h:94
Datum value
Definition: params.h:91
ParamExternData params[FLEXIBLE_ARRAY_MEMBER]
Definition: params.h:124
char * paramValuesStr
Definition: params.h:117
ParserSetupHook parserSetup
Definition: params.h:115
ParamCompileHook paramCompile
Definition: params.h:113
void * parserSetupArg
Definition: params.h:116
void * paramCompileArg
Definition: params.h:114
ParamFetchHook paramFetch
Definition: params.h:111
void * paramFetchArg
Definition: params.h:112
int numParams
Definition: params.h:118
Definition: primnodes.h:391
ParamListInfo params
Definition: params.h:156
const char * portalName
Definition: params.h:155
Definition: regguts.h:323

AltStyle によって変換されたページ (->オリジナル) /