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 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

◆ 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 36 of file params.c.

References datumCopy(), get_typlenbyval(), i, ParamExternData::isnull, ParamListInfoData::numParams, offsetof, OidIsValid, palloc(), ParamListInfoData::paramCompile, ParamListInfoData::paramCompileArg, ParamListInfoData::paramFetch, ParamListInfoData::paramFetchArg, ParamListInfoData::params, ParamListInfoData::parserSetup, ParamListInfoData::parserSetupArg, ParamExternData::ptype, and ParamExternData::value.

Referenced by PerformCursorOpen(), and SPI_cursor_open_internal().

37 {
38  ParamListInfo retval;
39  Size size;
40  int i;
41 
42  if (from == NULL || from->numParams <= 0)
43  return NULL;
44 
45  size = offsetof(ParamListInfoData, params) +
46  from->numParams * sizeof(ParamExternData);
47 
48  retval = (ParamListInfo) palloc(size);
49  retval->paramFetch = NULL;
50  retval->paramFetchArg = NULL;
51  retval->paramCompile = NULL;
52  retval->paramCompileArg = NULL;
53  retval->parserSetup = NULL;
54  retval->parserSetupArg = NULL;
55  retval->numParams = from->numParams;
56 
57  for (i = 0; i < from->numParams; i++)
58  {
59  ParamExternData *oprm;
60  ParamExternData *nprm = &retval->params[i];
61  ParamExternData prmdata;
62  int16 typLen;
63  bool typByVal;
64 
65  /* give hook a chance in case parameter is dynamic */
66  if (from->paramFetch != NULL)
67  oprm = from->paramFetch(from, i + 1, false, &prmdata);
68  else
69  oprm = &from->params[i];
70 
71  /* flat-copy the parameter info */
72  *nprm = *oprm;
73 
74  /* need datumCopy in case it's a pass-by-reference datatype */
75  if (nprm->isnull || !OidIsValid(nprm->ptype))
76  continue;
77  get_typlenbyval(nprm->ptype, &typLen, &typByVal);
78  nprm->value = datumCopy(nprm->value, typByVal, typLen);
79  }
80 
81  return retval;
82 }
signed short int16
Definition: c.h:293
ParamExternData params[FLEXIBLE_ARRAY_MEMBER]
Definition: params.h:124
Datum value
Definition: params.h:92
void * parserSetupArg
Definition: params.h:117
ParserSetupHook parserSetup
Definition: params.h:116
struct ParamListInfoData * ParamListInfo
Definition: params.h:98
#define OidIsValid(objectId)
Definition: c.h:586
void * paramFetchArg
Definition: params.h:113
ParamCompileHook paramCompile
Definition: params.h:114
ParamFetchHook paramFetch
Definition: params.h:112
Datum datumCopy(Datum value, bool typByVal, int typLen)
Definition: datum.c:128
struct ParamExternData ParamExternData
size_t Size
Definition: c.h:414
void get_typlenbyval(Oid typid, int16 *typlen, bool *typbyval)
Definition: lsyscache.c:2020
void * paramCompileArg
Definition: params.h:115
void * palloc(Size size)
Definition: mcxt.c:835
int i
bool isnull
Definition: params.h:93
#define offsetof(type, field)
Definition: c.h:603

◆ EstimateParamListSpace()

Size EstimateParamListSpace ( ParamListInfo  paramLI)

Definition at line 88 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().

89 {
90  int i;
91  Size sz = sizeof(int);
92 
93  if (paramLI == NULL || paramLI->numParams <= 0)
94  return sz;
95 
96  for (i = 0; i < paramLI->numParams; i++)
97  {
98  ParamExternData *prm;
99  ParamExternData prmdata;
100  Oid typeOid;
101  int16 typLen;
102  bool typByVal;
103 
104  /* give hook a chance in case parameter is dynamic */
105  if (paramLI->paramFetch != NULL)
106  prm = paramLI->paramFetch(paramLI, i + 1, false, &prmdata);
107  else
108  prm = &paramLI->params[i];
109 
110  typeOid = prm->ptype;
111 
112  sz = add_size(sz, sizeof(Oid)); /* space for type OID */
113  sz = add_size(sz, sizeof(uint16)); /* space for pflags */
114 
115  /* space for datum/isnull */
116  if (OidIsValid(typeOid))
117  get_typlenbyval(typeOid, &typLen, &typByVal);
118  else
119  {
120  /* If no type OID, assume by-value, like copyParamList does. */
121  typLen = sizeof(Datum);
122  typByVal = true;
123  }
124  sz = add_size(sz,
125  datumEstimateSpace(prm->value, prm->isnull, typByVal, typLen));
126  }
127 
128  return sz;
129 }
signed short int16
Definition: c.h:293
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:586
ParamFetchHook paramFetch
Definition: params.h:112
unsigned short uint16
Definition: c.h:305
Size datumEstimateSpace(Datum value, bool isnull, bool typByVal, int typLen)
Definition: datum.c:262
uintptr_t Datum
Definition: postgres.h:372
Size add_size(Size s1, Size s2)
Definition: shmem.c:475
size_t Size
Definition: c.h:414
void get_typlenbyval(Oid typid, int16 *typlen, bool *typbyval)
Definition: lsyscache.c:2020
int i
bool isnull
Definition: params.h:93

◆ RestoreParamList()

ParamListInfo RestoreParamList ( char **  start_address)

Definition at line 211 of file params.c.

References datumRestore(), i, ParamExternData::isnull, offsetof, palloc(), ParamExternData::pflags, ParamExternData::ptype, and ParamExternData::value.

Referenced by ExecParallelGetQueryDesc().

212 {
213  ParamListInfo paramLI;
214  Size size;
215  int i;
216  int nparams;
217 
218  memcpy(&nparams, *start_address, sizeof(int));
219  *start_address += sizeof(int);
220 
221  size = offsetof(ParamListInfoData, params) +
222  nparams * sizeof(ParamExternData);
223 
224  paramLI = (ParamListInfo) palloc(size);
225  paramLI->paramFetch = NULL;
226  paramLI->paramFetchArg = NULL;
227  paramLI->paramCompile = NULL;
228  paramLI->paramCompileArg = NULL;
229  paramLI->parserSetup = NULL;
230  paramLI->parserSetupArg = NULL;
231  paramLI->numParams = nparams;
232 
233  for (i = 0; i < nparams; i++)
234  {
235  ParamExternData *prm = &paramLI->params[i];
236 
237  /* Read type OID. */
238  memcpy(&prm->ptype, *start_address, sizeof(Oid));
239  *start_address += sizeof(Oid);
240 
241  /* Read flags. */
242  memcpy(&prm->pflags, *start_address, sizeof(uint16));
243  *start_address += sizeof(uint16);
244 
245  /* Read datum/isnull. */
246  prm->value = datumRestore(start_address, &prm->isnull);
247  }
248 
249  return paramLI;
250 }
Datum value
Definition: params.h:92
struct ParamListInfoData * ParamListInfo
Definition: params.h:98
unsigned int Oid
Definition: postgres_ext.h:31
unsigned short uint16
Definition: c.h:305
struct ParamExternData ParamExternData
Datum datumRestore(char **start_address, bool *isnull)
Definition: datum.c:360
uint16 pflags
Definition: params.h:94
size_t Size
Definition: c.h:414
void * palloc(Size size)
Definition: mcxt.c:835
int i
bool isnull
Definition: params.h:93
#define offsetof(type, field)
Definition: c.h:603

◆ SerializeParamList()

void SerializeParamList ( ParamListInfo  paramLI,
char **  start_address 
)

Definition at line 148 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().

149 {
150  int nparams;
151  int i;
152 
153  /* Write number of parameters. */
154  if (paramLI == NULL || paramLI->numParams <= 0)
155  nparams = 0;
156  else
157  nparams = paramLI->numParams;
158  memcpy(*start_address, &nparams, sizeof(int));
159  *start_address += sizeof(int);
160 
161  /* Write each parameter in turn. */
162  for (i = 0; i < nparams; i++)
163  {
164  ParamExternData *prm;
165  ParamExternData prmdata;
166  Oid typeOid;
167  int16 typLen;
168  bool typByVal;
169 
170  /* give hook a chance in case parameter is dynamic */
171  if (paramLI->paramFetch != NULL)
172  prm = paramLI->paramFetch(paramLI, i + 1, false, &prmdata);
173  else
174  prm = &paramLI->params[i];
175 
176  typeOid = prm->ptype;
177 
178  /* Write type OID. */
179  memcpy(*start_address, &typeOid, sizeof(Oid));
180  *start_address += sizeof(Oid);
181 
182  /* Write flags. */
183  memcpy(*start_address, &prm->pflags, sizeof(uint16));
184  *start_address += sizeof(uint16);
185 
186  /* Write datum/isnull. */
187  if (OidIsValid(typeOid))
188  get_typlenbyval(typeOid, &typLen, &typByVal);
189  else
190  {
191  /* If no type OID, assume by-value, like copyParamList does. */
192  typLen = sizeof(Datum);
193  typByVal = true;
194  }
195  datumSerialize(prm->value, prm->isnull, typByVal, typLen,
196  start_address);
197  }
198 }
signed short int16
Definition: c.h:293
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:586
ParamFetchHook paramFetch
Definition: params.h:112
unsigned short uint16
Definition: c.h:305
uintptr_t Datum
Definition: postgres.h:372
uint16 pflags
Definition: params.h:94
void get_typlenbyval(Oid typid, int16 *typlen, bool *typbyval)
Definition: lsyscache.c:2020
int i
void datumSerialize(Datum value, bool isnull, bool typByVal, int typLen, char **start_address)
Definition: datum.c:309
bool isnull
Definition: params.h:93