PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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 void(* ParamFetchHook )(ParamListInfo params, int paramid)
 
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

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

Typedef Documentation

typedef void(* ParamFetchHook)(ParamListInfo params, int paramid)

Definition at line 64 of file params.h.

Definition at line 62 of file params.h.

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

Definition at line 66 of file params.h.

Function Documentation

ParamListInfo copyParamList ( ParamListInfo  from)

Definition at line 36 of file params.c.

References bms_is_member(), datumCopy(), get_typlenbyval(), i, InvalidOid, ParamExternData::isnull, NULL, ParamListInfoData::numParams, offsetof, OidIsValid, palloc(), ParamListInfoData::paramFetch, ParamListInfoData::paramFetchArg, ParamListInfoData::paramMask, ParamListInfoData::params, ParamListInfoData::parserSetup, ParamListInfoData::parserSetupArg, ParamExternData::pflags, 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->parserSetup = NULL;
52  retval->parserSetupArg = NULL;
53  retval->numParams = from->numParams;
54  retval->paramMask = NULL;
55 
56  for (i = 0; i < from->numParams; i++)
57  {
58  ParamExternData *oprm = &from->params[i];
59  ParamExternData *nprm = &retval->params[i];
60  int16 typLen;
61  bool typByVal;
62 
63  /* Ignore parameters we don't need, to save cycles and space. */
64  if (from->paramMask != NULL &&
65  !bms_is_member(i, from->paramMask))
66  {
67  nprm->value = (Datum) 0;
68  nprm->isnull = true;
69  nprm->pflags = 0;
70  nprm->ptype = InvalidOid;
71  continue;
72  }
73 
74  /* give hook a chance in case parameter is dynamic */
75  if (!OidIsValid(oprm->ptype) && from->paramFetch != NULL)
76  (*from->paramFetch) (from, i + 1);
77 
78  /* flat-copy the parameter info */
79  *nprm = *oprm;
80 
81  /* need datumCopy in case it's a pass-by-reference datatype */
82  if (nprm->isnull || !OidIsValid(nprm->ptype))
83  continue;
84  get_typlenbyval(nprm->ptype, &typLen, &typByVal);
85  nprm->value = datumCopy(nprm->value, typByVal, typLen);
86  }
87 
88  return retval;
89 }
signed short int16
Definition: c.h:255
ParamExternData params[FLEXIBLE_ARRAY_MEMBER]
Definition: params.h:76
Datum value
Definition: params.h:56
void * parserSetupArg
Definition: params.h:73
ParserSetupHook parserSetup
Definition: params.h:72
struct ParamListInfoData * ParamListInfo
Definition: params.h:62
#define OidIsValid(objectId)
Definition: c.h:538
void * paramFetchArg
Definition: params.h:71
ParamFetchHook paramFetch
Definition: params.h:70
struct Bitmapset * paramMask
Definition: params.h:75
Datum datumCopy(Datum value, bool typByVal, int typLen)
Definition: datum.c:128
struct ParamExternData ParamExternData
uintptr_t Datum
Definition: postgres.h:372
#define InvalidOid
Definition: postgres_ext.h:36
#define NULL
Definition: c.h:229
uint16 pflags
Definition: params.h:58
size_t Size
Definition: c.h:356
void get_typlenbyval(Oid typid, int16 *typlen, bool *typbyval)
Definition: lsyscache.c:2001
void * palloc(Size size)
Definition: mcxt.c:849
int i
bool isnull
Definition: params.h:57
bool bms_is_member(int x, const Bitmapset *a)
Definition: bitmapset.c:420
#define offsetof(type, field)
Definition: c.h:555
Size EstimateParamListSpace ( ParamListInfo  paramLI)

Definition at line 95 of file params.c.

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

Referenced by ExecInitParallelPlan().

96 {
97  int i;
98  Size sz = sizeof(int);
99 
100  if (paramLI == NULL || paramLI->numParams <= 0)
101  return sz;
102 
103  for (i = 0; i < paramLI->numParams; i++)
104  {
105  ParamExternData *prm = &paramLI->params[i];
106  Oid typeOid;
107  int16 typLen;
108  bool typByVal;
109 
110  /* Ignore parameters we don't need, to save cycles and space. */
111  if (paramLI->paramMask != NULL &&
112  !bms_is_member(i, paramLI->paramMask))
113  typeOid = InvalidOid;
114  else
115  {
116  /* give hook a chance in case parameter is dynamic */
117  if (!OidIsValid(prm->ptype) && paramLI->paramFetch != NULL)
118  (*paramLI->paramFetch) (paramLI, i + 1);
119  typeOid = prm->ptype;
120  }
121 
122  sz = add_size(sz, sizeof(Oid)); /* space for type OID */
123  sz = add_size(sz, sizeof(uint16)); /* space for pflags */
124 
125  /* space for datum/isnull */
126  if (OidIsValid(typeOid))
127  get_typlenbyval(typeOid, &typLen, &typByVal);
128  else
129  {
130  /* If no type OID, assume by-value, like copyParamList does. */
131  typLen = sizeof(Datum);
132  typByVal = true;
133  }
134  sz = add_size(sz,
135  datumEstimateSpace(prm->value, prm->isnull, typByVal, typLen));
136  }
137 
138  return sz;
139 }
signed short int16
Definition: c.h:255
ParamExternData params[FLEXIBLE_ARRAY_MEMBER]
Definition: params.h:76
Datum value
Definition: params.h:56
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:538
ParamFetchHook paramFetch
Definition: params.h:70
unsigned short uint16
Definition: c.h:267
struct Bitmapset * paramMask
Definition: params.h:75
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
#define InvalidOid
Definition: postgres_ext.h:36
#define NULL
Definition: c.h:229
size_t Size
Definition: c.h:356
void get_typlenbyval(Oid typid, int16 *typlen, bool *typbyval)
Definition: lsyscache.c:2001
int i
bool isnull
Definition: params.h:57
bool bms_is_member(int x, const Bitmapset *a)
Definition: bitmapset.c:420
ParamListInfo RestoreParamList ( char **  start_address)

Definition at line 224 of file params.c.

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

Referenced by ExecParallelGetQueryDesc().

225 {
226  ParamListInfo paramLI;
227  Size size;
228  int i;
229  int nparams;
230 
231  memcpy(&nparams, *start_address, sizeof(int));
232  *start_address += sizeof(int);
233 
234  size = offsetof(ParamListInfoData, params) +
235  nparams * sizeof(ParamExternData);
236 
237  paramLI = (ParamListInfo) palloc(size);
238  paramLI->paramFetch = NULL;
239  paramLI->paramFetchArg = NULL;
240  paramLI->parserSetup = NULL;
241  paramLI->parserSetupArg = NULL;
242  paramLI->numParams = nparams;
243  paramLI->paramMask = NULL;
244 
245  for (i = 0; i < nparams; i++)
246  {
247  ParamExternData *prm = &paramLI->params[i];
248 
249  /* Read type OID. */
250  memcpy(&prm->ptype, *start_address, sizeof(Oid));
251  *start_address += sizeof(Oid);
252 
253  /* Read flags. */
254  memcpy(&prm->pflags, *start_address, sizeof(uint16));
255  *start_address += sizeof(uint16);
256 
257  /* Read datum/isnull. */
258  prm->value = datumRestore(start_address, &prm->isnull);
259  }
260 
261  return paramLI;
262 }
Datum value
Definition: params.h:56
struct ParamListInfoData * ParamListInfo
Definition: params.h:62
unsigned int Oid
Definition: postgres_ext.h:31
unsigned short uint16
Definition: c.h:267
struct ParamExternData ParamExternData
Datum datumRestore(char **start_address, bool *isnull)
Definition: datum.c:352
#define NULL
Definition: c.h:229
uint16 pflags
Definition: params.h:58
size_t Size
Definition: c.h:356
void * palloc(Size size)
Definition: mcxt.c:849
int i
bool isnull
Definition: params.h:57
#define offsetof(type, field)
Definition: c.h:555
void SerializeParamList ( ParamListInfo  paramLI,
char **  start_address 
)

Definition at line 158 of file params.c.

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

Referenced by ExecInitParallelPlan().

159 {
160  int nparams;
161  int i;
162 
163  /* Write number of parameters. */
164  if (paramLI == NULL || paramLI->numParams <= 0)
165  nparams = 0;
166  else
167  nparams = paramLI->numParams;
168  memcpy(*start_address, &nparams, sizeof(int));
169  *start_address += sizeof(int);
170 
171  /* Write each parameter in turn. */
172  for (i = 0; i < nparams; i++)
173  {
174  ParamExternData *prm = &paramLI->params[i];
175  Oid typeOid;
176  int16 typLen;
177  bool typByVal;
178 
179  /* Ignore parameters we don't need, to save cycles and space. */
180  if (paramLI->paramMask != NULL &&
181  !bms_is_member(i, paramLI->paramMask))
182  typeOid = InvalidOid;
183  else
184  {
185  /* give hook a chance in case parameter is dynamic */
186  if (!OidIsValid(prm->ptype) && paramLI->paramFetch != NULL)
187  (*paramLI->paramFetch) (paramLI, i + 1);
188  typeOid = prm->ptype;
189  }
190 
191  /* Write type OID. */
192  memcpy(*start_address, &typeOid, sizeof(Oid));
193  *start_address += sizeof(Oid);
194 
195  /* Write flags. */
196  memcpy(*start_address, &prm->pflags, sizeof(uint16));
197  *start_address += sizeof(uint16);
198 
199  /* Write datum/isnull. */
200  if (OidIsValid(typeOid))
201  get_typlenbyval(typeOid, &typLen, &typByVal);
202  else
203  {
204  /* If no type OID, assume by-value, like copyParamList does. */
205  typLen = sizeof(Datum);
206  typByVal = true;
207  }
208  datumSerialize(prm->value, prm->isnull, typByVal, typLen,
209  start_address);
210  }
211 }
signed short int16
Definition: c.h:255
ParamExternData params[FLEXIBLE_ARRAY_MEMBER]
Definition: params.h:76
Datum value
Definition: params.h:56
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:538
ParamFetchHook paramFetch
Definition: params.h:70
unsigned short uint16
Definition: c.h:267
struct Bitmapset * paramMask
Definition: params.h:75
uintptr_t Datum
Definition: postgres.h:372
#define InvalidOid
Definition: postgres_ext.h:36
#define NULL
Definition: c.h:229
uint16 pflags
Definition: params.h:58
void get_typlenbyval(Oid typid, int16 *typlen, bool *typbyval)
Definition: lsyscache.c:2001
int i
void datumSerialize(Datum value, bool isnull, bool typByVal, int typLen, char **start_address)
Definition: datum.c:302
bool isnull
Definition: params.h:57
bool bms_is_member(int x, const Bitmapset *a)
Definition: bitmapset.c:420