PostgreSQL Source Code  git master
params.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ParamExternData
 
struct  ParamListInfoData
 
struct  ParamExecData
 

Macros

#define PARAM_FLAG_CONST   0x0001 /* parameter is constant */
 

Typedefs

typedef struct ParamExternData ParamExternData
 
typedef struct ParamListInfoDataParamListInfo
 
typedef ParamExternData *(* ParamFetchHook) (ParamListInfo params, int paramid, bool speculative, ParamExternData *workspace)
 
typedef void(* ParamCompileHook) (ParamListInfo params, struct Param *param, struct ExprState *state, Datum *resv, bool *resnull)
 
typedef void(* ParserSetupHook) (struct ParseState *pstate, void *arg)
 
typedef struct ParamListInfoData ParamListInfoData
 
typedef struct ParamExecData ParamExecData
 

Functions

ParamListInfo makeParamList (int numParams)
 
ParamListInfo copyParamList (ParamListInfo from)
 
Size EstimateParamListSpace (ParamListInfo paramLI)
 
void SerializeParamList (ParamListInfo paramLI, char **start_address)
 
ParamListInfo RestoreParamList (char **start_address)
 

Macro Definition Documentation

◆ PARAM_FLAG_CONST

#define PARAM_FLAG_CONST   0x0001 /* parameter is constant */

Typedef Documentation

◆ ParamCompileHook

typedef void(* ParamCompileHook) (ParamListInfo params, struct Param *param, struct ExprState *state, Datum *resv, bool *resnull)

Definition at line 104 of file params.h.

◆ ParamExecData

typedef struct ParamExecData ParamExecData

◆ ParamExternData

◆ ParamFetchHook

typedef ParamExternData*(* ParamFetchHook) (ParamListInfo params, int paramid, bool speculative, ParamExternData *workspace)

Definition at line 100 of file params.h.

◆ ParamListInfo

Definition at line 98 of file params.h.

◆ ParamListInfoData

◆ ParserSetupHook

typedef void(* ParserSetupHook) (struct ParseState *pstate, void *arg)

Definition at line 108 of file params.h.

Function Documentation

◆ copyParamList()

ParamListInfo copyParamList ( ParamListInfo  from)

Definition at line 63 of file params.c.

References datumCopy(), get_typlenbyval(), i, ParamExternData::isnull, makeParamList(), ParamListInfoData::numParams, OidIsValid, ParamListInfoData::paramFetch, ParamListInfoData::params, ParamExternData::ptype, and ParamExternData::value.

Referenced by PerformCursorOpen(), and SPI_cursor_open_internal().

64 {
65  ParamListInfo retval;
66 
67  if (from == NULL || from->numParams <= 0)
68  return NULL;
69 
70  retval = makeParamList(from->numParams);
71 
72  for (int i = 0; i < from->numParams; i++)
73  {
74  ParamExternData *oprm;
75  ParamExternData *nprm = &retval->params[i];
76  ParamExternData prmdata;
77  int16 typLen;
78  bool typByVal;
79 
80  /* give hook a chance in case parameter is dynamic */
81  if (from->paramFetch != NULL)
82  oprm = from->paramFetch(from, i + 1, false, &prmdata);
83  else
84  oprm = &from->params[i];
85 
86  /* flat-copy the parameter info */
87  *nprm = *oprm;
88 
89  /* need datumCopy in case it's a pass-by-reference datatype */
90  if (nprm->isnull || !OidIsValid(nprm->ptype))
91  continue;
92  get_typlenbyval(nprm->ptype, &typLen, &typByVal);
93  nprm->value = datumCopy(nprm->value, typByVal, typLen);
94  }
95 
96  return retval;
97 }
signed short int16
Definition: c.h:346
ParamExternData params[FLEXIBLE_ARRAY_MEMBER]
Definition: params.h:124
Datum value
Definition: params.h:92
ParamListInfo makeParamList(int numParams)
Definition: params.c:32
#define OidIsValid(objectId)
Definition: c.h:639
ParamFetchHook paramFetch
Definition: params.h:112
Datum datumCopy(Datum value, bool typByVal, int typLen)
Definition: datum.c:130
void get_typlenbyval(Oid typid, int16 *typlen, bool *typbyval)
Definition: lsyscache.c:2029
int i
bool isnull
Definition: params.h:93

◆ EstimateParamListSpace()

Size EstimateParamListSpace ( ParamListInfo  paramLI)

Definition at line 103 of file params.c.

References add_size(), datumEstimateSpace(), get_typlenbyval(), i, ParamExternData::isnull, ParamListInfoData::numParams, OidIsValid, ParamListInfoData::paramFetch, ParamListInfoData::params, ParamExternData::ptype, and ParamExternData::value.

Referenced by ExecInitParallelPlan().

104 {
105  int i;
106  Size sz = sizeof(int);
107 
108  if (paramLI == NULL || paramLI->numParams <= 0)
109  return sz;
110 
111  for (i = 0; i < paramLI->numParams; i++)
112  {
113  ParamExternData *prm;
114  ParamExternData prmdata;
115  Oid typeOid;
116  int16 typLen;
117  bool typByVal;
118 
119  /* give hook a chance in case parameter is dynamic */
120  if (paramLI->paramFetch != NULL)
121  prm = paramLI->paramFetch(paramLI, i + 1, false, &prmdata);
122  else
123  prm = &paramLI->params[i];
124 
125  typeOid = prm->ptype;
126 
127  sz = add_size(sz, sizeof(Oid)); /* space for type OID */
128  sz = add_size(sz, sizeof(uint16)); /* space for pflags */
129 
130  /* space for datum/isnull */
131  if (OidIsValid(typeOid))
132  get_typlenbyval(typeOid, &typLen, &typByVal);
133  else
134  {
135  /* If no type OID, assume by-value, like copyParamList does. */
136  typLen = sizeof(Datum);
137  typByVal = true;
138  }
139  sz = add_size(sz,
140  datumEstimateSpace(prm->value, prm->isnull, typByVal, typLen));
141  }
142 
143  return sz;
144 }
signed short int16
Definition: c.h:346
ParamExternData params[FLEXIBLE_ARRAY_MEMBER]
Definition: params.h:124
Datum value
Definition: params.h:92
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:639
ParamFetchHook paramFetch
Definition: params.h:112
unsigned short uint16
Definition: c.h:358
Size datumEstimateSpace(Datum value, bool isnull, bool typByVal, int typLen)
Definition: datum.c:334
uintptr_t Datum
Definition: postgres.h:367
Size add_size(Size s1, Size s2)
Definition: shmem.c:475
size_t Size
Definition: c.h:467
void get_typlenbyval(Oid typid, int16 *typlen, bool *typbyval)
Definition: lsyscache.c:2029
int i
bool isnull
Definition: params.h:93

◆ makeParamList()

ParamListInfo makeParamList ( int  numParams)

Definition at line 32 of file params.c.

References offsetof, and palloc().

Referenced by _SPI_convert_params(), copyParamList(), EvaluateParams(), exec_bind_message(), plpgsql_estate_setup(), postquel_sub_params(), and RestoreParamList().

33 {
34  ParamListInfo retval;
35  Size size;
36 
37  size = offsetof(ParamListInfoData, params) +
38  numParams * sizeof(ParamExternData);
39 
40  retval = (ParamListInfo) palloc(size);
41  retval->paramFetch = NULL;
42  retval->paramFetchArg = NULL;
43  retval->paramCompile = NULL;
44  retval->paramCompileArg = NULL;
45  retval->parserSetup = NULL;
46  retval->parserSetupArg = NULL;
47  retval->numParams = numParams;
48 
49  return retval;
50 }
struct ParamListInfoData * ParamListInfo
Definition: params.h:98
struct ParamExternData ParamExternData
size_t Size
Definition: c.h:467
void * palloc(Size size)
Definition: mcxt.c:949
#define offsetof(type, field)
Definition: c.h:656

◆ RestoreParamList()

ParamListInfo RestoreParamList ( char **  start_address)

Definition at line 226 of file params.c.

References datumRestore(), i, ParamExternData::isnull, makeParamList(), ParamListInfoData::params, ParamExternData::pflags, ParamExternData::ptype, and ParamExternData::value.

Referenced by ExecParallelGetQueryDesc().

227 {
228  ParamListInfo paramLI;
229  int nparams;
230 
231  memcpy(&nparams, *start_address, sizeof(int));
232  *start_address += sizeof(int);
233 
234  paramLI = makeParamList(nparams);
235 
236  for (int i = 0; i < nparams; i++)
237  {
238  ParamExternData *prm = &paramLI->params[i];
239 
240  /* Read type OID. */
241  memcpy(&prm->ptype, *start_address, sizeof(Oid));
242  *start_address += sizeof(Oid);
243 
244  /* Read flags. */
245  memcpy(&prm->pflags, *start_address, sizeof(uint16));
246  *start_address += sizeof(uint16);
247 
248  /* Read datum/isnull. */
249  prm->value = datumRestore(start_address, &prm->isnull);
250  }
251 
252  return paramLI;
253 }
ParamExternData params[FLEXIBLE_ARRAY_MEMBER]
Definition: params.h:124
Datum value
Definition: params.h:92
unsigned int Oid
Definition: postgres_ext.h:31
ParamListInfo makeParamList(int numParams)
Definition: params.c:32
unsigned short uint16
Definition: c.h:358
Datum datumRestore(char **start_address, bool *isnull)
Definition: datum.c:443
uint16 pflags
Definition: params.h:94
int i
bool isnull
Definition: params.h:93

◆ SerializeParamList()

void SerializeParamList ( ParamListInfo  paramLI,
char **  start_address 
)

Definition at line 163 of file params.c.

References datumSerialize(), get_typlenbyval(), i, ParamExternData::isnull, ParamListInfoData::numParams, OidIsValid, ParamListInfoData::paramFetch, ParamListInfoData::params, ParamExternData::pflags, ParamExternData::ptype, and ParamExternData::value.

Referenced by ExecInitParallelPlan().

164 {
165  int nparams;
166  int i;
167 
168  /* Write number of parameters. */
169  if (paramLI == NULL || paramLI->numParams <= 0)
170  nparams = 0;
171  else
172  nparams = paramLI->numParams;
173  memcpy(*start_address, &nparams, sizeof(int));
174  *start_address += sizeof(int);
175 
176  /* Write each parameter in turn. */
177  for (i = 0; i < nparams; i++)
178  {
179  ParamExternData *prm;
180  ParamExternData prmdata;
181  Oid typeOid;
182  int16 typLen;
183  bool typByVal;
184 
185  /* give hook a chance in case parameter is dynamic */
186  if (paramLI->paramFetch != NULL)
187  prm = paramLI->paramFetch(paramLI, i + 1, false, &prmdata);
188  else
189  prm = &paramLI->params[i];
190 
191  typeOid = prm->ptype;
192 
193  /* Write type OID. */
194  memcpy(*start_address, &typeOid, sizeof(Oid));
195  *start_address += sizeof(Oid);
196 
197  /* Write flags. */
198  memcpy(*start_address, &prm->pflags, sizeof(uint16));
199  *start_address += sizeof(uint16);
200 
201  /* Write datum/isnull. */
202  if (OidIsValid(typeOid))
203  get_typlenbyval(typeOid, &typLen, &typByVal);
204  else
205  {
206  /* If no type OID, assume by-value, like copyParamList does. */
207  typLen = sizeof(Datum);
208  typByVal = true;
209  }
210  datumSerialize(prm->value, prm->isnull, typByVal, typLen,
211  start_address);
212  }
213 }
signed short int16
Definition: c.h:346
ParamExternData params[FLEXIBLE_ARRAY_MEMBER]
Definition: params.h:124
Datum value
Definition: params.h:92
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:639
ParamFetchHook paramFetch
Definition: params.h:112
unsigned short uint16
Definition: c.h:358
uintptr_t Datum
Definition: postgres.h:367
uint16 pflags
Definition: params.h:94
void get_typlenbyval(Oid typid, int16 *typlen, bool *typbyval)
Definition: lsyscache.c:2029
int i
void datumSerialize(Datum value, bool isnull, bool typByVal, int typLen, char **start_address)
Definition: datum.c:381
bool isnull
Definition: params.h:93