PostgreSQL Source Code  git master
execExpr.h File Reference
#include "executor/nodeAgg.h"
#include "nodes/execnodes.h"
Include dependency graph for execExpr.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ExprEvalRowtypeCache
 
struct  ExprEvalStep
 
struct  SubscriptingRefState
 
struct  SubscriptExecSteps
 
struct  JsonConstructorExprState
 

Macros

#define EEO_FLAG_INTERPRETER_INITIALIZED   (1 << 1)
 
#define EEO_FLAG_DIRECT_THREADED   (1 << 2)
 

Typedefs

typedef void(* ExecEvalSubroutine) (ExprState *state, struct ExprEvalStep *op, ExprContext *econtext)
 
typedef bool(* ExecEvalBoolSubroutine) (ExprState *state, struct ExprEvalStep *op, ExprContext *econtext)
 
typedef struct ExprEvalRowtypeCache ExprEvalRowtypeCache
 
typedef enum ExprEvalOp ExprEvalOp
 
typedef struct ExprEvalStep ExprEvalStep
 
typedef struct SubscriptingRefState SubscriptingRefState
 
typedef struct SubscriptExecSteps SubscriptExecSteps
 
typedef struct JsonConstructorExprState JsonConstructorExprState
 

Enumerations

enum  ExprEvalOp {
  EEOP_DONE , EEOP_INNER_FETCHSOME , EEOP_OUTER_FETCHSOME , EEOP_SCAN_FETCHSOME ,
  EEOP_INNER_VAR , EEOP_OUTER_VAR , EEOP_SCAN_VAR , EEOP_INNER_SYSVAR ,
  EEOP_OUTER_SYSVAR , EEOP_SCAN_SYSVAR , EEOP_WHOLEROW , EEOP_ASSIGN_INNER_VAR ,
  EEOP_ASSIGN_OUTER_VAR , EEOP_ASSIGN_SCAN_VAR , EEOP_ASSIGN_TMP , EEOP_ASSIGN_TMP_MAKE_RO ,
  EEOP_CONST , EEOP_FUNCEXPR , EEOP_FUNCEXPR_STRICT , EEOP_FUNCEXPR_FUSAGE ,
  EEOP_FUNCEXPR_STRICT_FUSAGE , EEOP_BOOL_AND_STEP_FIRST , EEOP_BOOL_AND_STEP , EEOP_BOOL_AND_STEP_LAST ,
  EEOP_BOOL_OR_STEP_FIRST , EEOP_BOOL_OR_STEP , EEOP_BOOL_OR_STEP_LAST , EEOP_BOOL_NOT_STEP ,
  EEOP_QUAL , EEOP_JUMP , EEOP_JUMP_IF_NULL , EEOP_JUMP_IF_NOT_NULL ,
  EEOP_JUMP_IF_NOT_TRUE , EEOP_NULLTEST_ISNULL , EEOP_NULLTEST_ISNOTNULL , EEOP_NULLTEST_ROWISNULL ,
  EEOP_NULLTEST_ROWISNOTNULL , EEOP_BOOLTEST_IS_TRUE , EEOP_BOOLTEST_IS_NOT_TRUE , EEOP_BOOLTEST_IS_FALSE ,
  EEOP_BOOLTEST_IS_NOT_FALSE , EEOP_PARAM_EXEC , EEOP_PARAM_EXTERN , EEOP_PARAM_CALLBACK ,
  EEOP_CASE_TESTVAL , EEOP_MAKE_READONLY , EEOP_IOCOERCE , EEOP_DISTINCT ,
  EEOP_NOT_DISTINCT , EEOP_NULLIF , EEOP_SQLVALUEFUNCTION , EEOP_CURRENTOFEXPR ,
  EEOP_NEXTVALUEEXPR , EEOP_ARRAYEXPR , EEOP_ARRAYCOERCE , EEOP_ROW ,
  EEOP_ROWCOMPARE_STEP , EEOP_ROWCOMPARE_FINAL , EEOP_MINMAX , EEOP_FIELDSELECT ,
  EEOP_FIELDSTORE_DEFORM , EEOP_FIELDSTORE_FORM , EEOP_SBSREF_SUBSCRIPTS , EEOP_SBSREF_OLD ,
  EEOP_SBSREF_ASSIGN , EEOP_SBSREF_FETCH , EEOP_DOMAIN_TESTVAL , EEOP_DOMAIN_NOTNULL ,
  EEOP_DOMAIN_CHECK , EEOP_CONVERT_ROWTYPE , EEOP_SCALARARRAYOP , EEOP_HASHED_SCALARARRAYOP ,
  EEOP_XMLEXPR , EEOP_JSON_CONSTRUCTOR , EEOP_IS_JSON , EEOP_AGGREF ,
  EEOP_GROUPING_FUNC , EEOP_WINDOW_FUNC , EEOP_SUBPLAN , EEOP_AGG_STRICT_DESERIALIZE ,
  EEOP_AGG_DESERIALIZE , EEOP_AGG_STRICT_INPUT_CHECK_ARGS , EEOP_AGG_STRICT_INPUT_CHECK_NULLS , EEOP_AGG_PLAIN_PERGROUP_NULLCHECK ,
  EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYVAL , EEOP_AGG_PLAIN_TRANS_STRICT_BYVAL , EEOP_AGG_PLAIN_TRANS_BYVAL , EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYREF ,
  EEOP_AGG_PLAIN_TRANS_STRICT_BYREF , EEOP_AGG_PLAIN_TRANS_BYREF , EEOP_AGG_PRESORTED_DISTINCT_SINGLE , EEOP_AGG_PRESORTED_DISTINCT_MULTI ,
  EEOP_AGG_ORDERED_TRANS_DATUM , EEOP_AGG_ORDERED_TRANS_TUPLE , EEOP_LAST
}
 

Functions

 StaticAssertDecl (sizeof(ExprEvalStep)<=64, "size of ExprEvalStep exceeds 64 bytes")
 
void ExprEvalPushStep (ExprState *es, const ExprEvalStep *s)
 
void ExecReadyInterpretedExpr (ExprState *state)
 
ExprEvalOp ExecEvalStepOp (ExprState *state, ExprEvalStep *op)
 
Datum ExecInterpExprStillValid (ExprState *state, ExprContext *econtext, bool *isNull)
 
void CheckExprStillValid (ExprState *state, ExprContext *econtext)
 
void ExecEvalFuncExprFusage (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalFuncExprStrictFusage (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalParamExec (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalParamExtern (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalSQLValueFunction (ExprState *state, ExprEvalStep *op)
 
void ExecEvalCurrentOfExpr (ExprState *state, ExprEvalStep *op)
 
void ExecEvalNextValueExpr (ExprState *state, ExprEvalStep *op)
 
void ExecEvalRowNull (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalRowNotNull (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalArrayExpr (ExprState *state, ExprEvalStep *op)
 
void ExecEvalArrayCoerce (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalRow (ExprState *state, ExprEvalStep *op)
 
void ExecEvalMinMax (ExprState *state, ExprEvalStep *op)
 
void ExecEvalFieldSelect (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalFieldStoreDeForm (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalFieldStoreForm (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalConvertRowtype (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalScalarArrayOp (ExprState *state, ExprEvalStep *op)
 
void ExecEvalHashedScalarArrayOp (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalConstraintNotNull (ExprState *state, ExprEvalStep *op)
 
void ExecEvalConstraintCheck (ExprState *state, ExprEvalStep *op)
 
void ExecEvalXmlExpr (ExprState *state, ExprEvalStep *op)
 
void ExecEvalJsonConstructor (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalJsonIsPredicate (ExprState *state, ExprEvalStep *op)
 
void ExecEvalGroupingFunc (ExprState *state, ExprEvalStep *op)
 
void ExecEvalSubPlan (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalWholeRowVar (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalSysVar (ExprState *state, ExprEvalStep *op, ExprContext *econtext, TupleTableSlot *slot)
 
void ExecAggInitGroup (AggState *aggstate, AggStatePerTrans pertrans, AggStatePerGroup pergroup, ExprContext *aggcontext)
 
Datum ExecAggCopyTransValue (AggState *aggstate, AggStatePerTrans pertrans, Datum newValue, bool newValueIsNull, Datum oldValue, bool oldValueIsNull)
 
bool ExecEvalPreOrderedDistinctSingle (AggState *aggstate, AggStatePerTrans pertrans)
 
bool ExecEvalPreOrderedDistinctMulti (AggState *aggstate, AggStatePerTrans pertrans)
 
void ExecEvalAggOrderedTransDatum (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalAggOrderedTransTuple (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 

Macro Definition Documentation

◆ EEO_FLAG_DIRECT_THREADED

#define EEO_FLAG_DIRECT_THREADED   (1 << 2)

Definition at line 30 of file execExpr.h.

◆ EEO_FLAG_INTERPRETER_INITIALIZED

#define EEO_FLAG_INTERPRETER_INITIALIZED   (1 << 1)

Definition at line 28 of file execExpr.h.

Typedef Documentation

◆ ExecEvalBoolSubroutine

typedef bool(* ExecEvalBoolSubroutine) (ExprState *state, struct ExprEvalStep *op, ExprContext *econtext)

Definition at line 38 of file execExpr.h.

◆ ExecEvalSubroutine

typedef void(* ExecEvalSubroutine) (ExprState *state, struct ExprEvalStep *op, ExprContext *econtext)

Definition at line 33 of file execExpr.h.

◆ ExprEvalOp

typedef enum ExprEvalOp ExprEvalOp

◆ ExprEvalRowtypeCache

◆ ExprEvalStep

typedef struct ExprEvalStep ExprEvalStep

◆ JsonConstructorExprState

◆ SubscriptExecSteps

◆ SubscriptingRefState

Enumeration Type Documentation

◆ ExprEvalOp

enum ExprEvalOp
Enumerator
EEOP_DONE 
EEOP_INNER_FETCHSOME 
EEOP_OUTER_FETCHSOME 
EEOP_SCAN_FETCHSOME 
EEOP_INNER_VAR 
EEOP_OUTER_VAR 
EEOP_SCAN_VAR 
EEOP_INNER_SYSVAR 
EEOP_OUTER_SYSVAR 
EEOP_SCAN_SYSVAR 
EEOP_WHOLEROW 
EEOP_ASSIGN_INNER_VAR 
EEOP_ASSIGN_OUTER_VAR 
EEOP_ASSIGN_SCAN_VAR 
EEOP_ASSIGN_TMP 
EEOP_ASSIGN_TMP_MAKE_RO 
EEOP_CONST 
EEOP_FUNCEXPR 
EEOP_FUNCEXPR_STRICT 
EEOP_FUNCEXPR_FUSAGE 
EEOP_FUNCEXPR_STRICT_FUSAGE 
EEOP_BOOL_AND_STEP_FIRST 
EEOP_BOOL_AND_STEP 
EEOP_BOOL_AND_STEP_LAST 
EEOP_BOOL_OR_STEP_FIRST 
EEOP_BOOL_OR_STEP 
EEOP_BOOL_OR_STEP_LAST 
EEOP_BOOL_NOT_STEP 
EEOP_QUAL 
EEOP_JUMP 
EEOP_JUMP_IF_NULL 
EEOP_JUMP_IF_NOT_NULL 
EEOP_JUMP_IF_NOT_TRUE 
EEOP_NULLTEST_ISNULL 
EEOP_NULLTEST_ISNOTNULL 
EEOP_NULLTEST_ROWISNULL 
EEOP_NULLTEST_ROWISNOTNULL 
EEOP_BOOLTEST_IS_TRUE 
EEOP_BOOLTEST_IS_NOT_TRUE 
EEOP_BOOLTEST_IS_FALSE 
EEOP_BOOLTEST_IS_NOT_FALSE 
EEOP_PARAM_EXEC 
EEOP_PARAM_EXTERN 
EEOP_PARAM_CALLBACK 
EEOP_CASE_TESTVAL 
EEOP_MAKE_READONLY 
EEOP_IOCOERCE 
EEOP_DISTINCT 
EEOP_NOT_DISTINCT 
EEOP_NULLIF 
EEOP_SQLVALUEFUNCTION 
EEOP_CURRENTOFEXPR 
EEOP_NEXTVALUEEXPR 
EEOP_ARRAYEXPR 
EEOP_ARRAYCOERCE 
EEOP_ROW 
EEOP_ROWCOMPARE_STEP 
EEOP_ROWCOMPARE_FINAL 
EEOP_MINMAX 
EEOP_FIELDSELECT 
EEOP_FIELDSTORE_DEFORM 
EEOP_FIELDSTORE_FORM 
EEOP_SBSREF_SUBSCRIPTS 
EEOP_SBSREF_OLD 
EEOP_SBSREF_ASSIGN 
EEOP_SBSREF_FETCH 
EEOP_DOMAIN_TESTVAL 
EEOP_DOMAIN_NOTNULL 
EEOP_DOMAIN_CHECK 
EEOP_CONVERT_ROWTYPE 
EEOP_SCALARARRAYOP 
EEOP_HASHED_SCALARARRAYOP 
EEOP_XMLEXPR 
EEOP_JSON_CONSTRUCTOR 
EEOP_IS_JSON 
EEOP_AGGREF 
EEOP_GROUPING_FUNC 
EEOP_WINDOW_FUNC 
EEOP_SUBPLAN 
EEOP_AGG_STRICT_DESERIALIZE 
EEOP_AGG_DESERIALIZE 
EEOP_AGG_STRICT_INPUT_CHECK_ARGS 
EEOP_AGG_STRICT_INPUT_CHECK_NULLS 
EEOP_AGG_PLAIN_PERGROUP_NULLCHECK 
EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYVAL 
EEOP_AGG_PLAIN_TRANS_STRICT_BYVAL 
EEOP_AGG_PLAIN_TRANS_BYVAL 
EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYREF 
EEOP_AGG_PLAIN_TRANS_STRICT_BYREF 
EEOP_AGG_PLAIN_TRANS_BYREF 
EEOP_AGG_PRESORTED_DISTINCT_SINGLE 
EEOP_AGG_PRESORTED_DISTINCT_MULTI 
EEOP_AGG_ORDERED_TRANS_DATUM 
EEOP_AGG_ORDERED_TRANS_TUPLE 
EEOP_LAST 

Definition at line 65 of file execExpr.h.

66 {
67  /* entire expression has been evaluated completely, return */
68  EEOP_DONE,
69 
70  /* apply slot_getsomeattrs on corresponding tuple slot */
74 
75  /* compute non-system Var value */
79 
80  /* compute system Var value */
84 
85  /* compute wholerow Var */
87 
88  /*
89  * Compute non-system Var value, assign it into ExprState's resultslot.
90  * These are not used if a CheckVarSlotCompatibility() check would be
91  * needed.
92  */
96 
97  /* assign ExprState's resvalue/resnull to a column of its resultslot */
99  /* ditto, applying MakeExpandedObjectReadOnly() */
101 
102  /* evaluate Const value */
103  EEOP_CONST,
104 
105  /*
106  * Evaluate function call (including OpExprs etc). For speed, we
107  * distinguish in the opcode whether the function is strict and/or
108  * requires usage stats tracking.
109  */
114 
115  /*
116  * Evaluate boolean AND expression, one step per subexpression. FIRST/LAST
117  * subexpressions are special-cased for performance. Since AND always has
118  * at least two subexpressions, FIRST and LAST never apply to the same
119  * subexpression.
120  */
124 
125  /* similarly for boolean OR expression */
129 
130  /* evaluate boolean NOT expression */
132 
133  /* simplified version of BOOL_AND_STEP for use by ExecQual() */
134  EEOP_QUAL,
135 
136  /* unconditional jump to another step */
137  EEOP_JUMP,
138 
139  /* conditional jumps based on current result value */
143 
144  /* perform NULL tests for scalar values */
147 
148  /* perform NULL tests for row values */
151 
152  /* evaluate a BooleanTest expression */
157 
158  /* evaluate PARAM_EXEC/EXTERN parameters */
162 
163  /* return CaseTestExpr value */
165 
166  /* apply MakeExpandedObjectReadOnly() to target value */
168 
169  /* evaluate assorted special-purpose expression types */
173  EEOP_NULLIF,
179  EEOP_ROW,
180 
181  /*
182  * Compare two individual elements of each of two compared ROW()
183  * expressions. Skip to ROWCOMPARE_FINAL if elements are not equal.
184  */
186 
187  /* evaluate boolean value based on previous ROWCOMPARE_STEP operations */
189 
190  /* evaluate GREATEST() or LEAST() */
191  EEOP_MINMAX,
192 
193  /* evaluate FieldSelect expression */
195 
196  /*
197  * Deform tuple before evaluating new values for individual fields in a
198  * FieldStore expression.
199  */
201 
202  /*
203  * Form the new tuple for a FieldStore expression. Individual fields will
204  * have been evaluated into columns of the tuple deformed by the preceding
205  * DEFORM step.
206  */
208 
209  /* Process container subscripts; possibly short-circuit result to NULL */
211 
212  /*
213  * Compute old container element/slice when a SubscriptingRef assignment
214  * expression contains SubscriptingRef/FieldStore subexpressions. Value is
215  * accessed using the CaseTest mechanism.
216  */
218 
219  /* compute new value for SubscriptingRef assignment expression */
221 
222  /* compute element/slice for SubscriptingRef fetch expression */
224 
225  /* evaluate value for CoerceToDomainValue */
227 
228  /* evaluate a domain's NOT NULL constraint */
230 
231  /* evaluate a single domain CHECK constraint */
233 
234  /* evaluate assorted special-purpose expression types */
238  EEOP_XMLEXPR,
240  EEOP_IS_JSON,
241  EEOP_AGGREF,
244  EEOP_SUBPLAN,
245 
246  /* aggregation related nodes */
262 
263  /* non-existent operation, used e.g. to check array lengths */
264  EEOP_LAST
265 } ExprEvalOp;
ExprEvalOp
Definition: execExpr.h:66
@ EEOP_ASSIGN_TMP
Definition: execExpr.h:98
@ EEOP_SUBPLAN
Definition: execExpr.h:244
@ EEOP_CONVERT_ROWTYPE
Definition: execExpr.h:235
@ EEOP_FUNCEXPR_STRICT_FUSAGE
Definition: execExpr.h:113
@ EEOP_ARRAYEXPR
Definition: execExpr.h:177
@ EEOP_NOT_DISTINCT
Definition: execExpr.h:172
@ EEOP_DOMAIN_TESTVAL
Definition: execExpr.h:226
@ EEOP_PARAM_EXTERN
Definition: execExpr.h:160
@ EEOP_BOOL_AND_STEP
Definition: execExpr.h:122
@ EEOP_WHOLEROW
Definition: execExpr.h:86
@ EEOP_AGGREF
Definition: execExpr.h:241
@ EEOP_INNER_VAR
Definition: execExpr.h:76
@ EEOP_AGG_PLAIN_PERGROUP_NULLCHECK
Definition: execExpr.h:251
@ EEOP_ROWCOMPARE_FINAL
Definition: execExpr.h:188
@ EEOP_AGG_STRICT_DESERIALIZE
Definition: execExpr.h:247
@ EEOP_IOCOERCE
Definition: execExpr.h:170
@ EEOP_GROUPING_FUNC
Definition: execExpr.h:242
@ EEOP_DOMAIN_CHECK
Definition: execExpr.h:232
@ EEOP_BOOLTEST_IS_NOT_FALSE
Definition: execExpr.h:156
@ EEOP_NEXTVALUEEXPR
Definition: execExpr.h:176
@ EEOP_DONE
Definition: execExpr.h:68
@ EEOP_AGG_PLAIN_TRANS_BYREF
Definition: execExpr.h:257
@ EEOP_QUAL
Definition: execExpr.h:134
@ EEOP_AGG_PRESORTED_DISTINCT_MULTI
Definition: execExpr.h:259
@ EEOP_AGG_PLAIN_TRANS_BYVAL
Definition: execExpr.h:254
@ EEOP_SCAN_VAR
Definition: execExpr.h:78
@ EEOP_BOOL_NOT_STEP
Definition: execExpr.h:131
@ EEOP_ASSIGN_SCAN_VAR
Definition: execExpr.h:95
@ EEOP_SCAN_SYSVAR
Definition: execExpr.h:83
@ EEOP_SCALARARRAYOP
Definition: execExpr.h:236
@ EEOP_DOMAIN_NOTNULL
Definition: execExpr.h:229
@ EEOP_WINDOW_FUNC
Definition: execExpr.h:243
@ EEOP_INNER_FETCHSOME
Definition: execExpr.h:71
@ EEOP_NULLTEST_ROWISNOTNULL
Definition: execExpr.h:150
@ EEOP_ASSIGN_OUTER_VAR
Definition: execExpr.h:94
@ EEOP_ROW
Definition: execExpr.h:179
@ EEOP_MAKE_READONLY
Definition: execExpr.h:167
@ EEOP_FIELDSTORE_FORM
Definition: execExpr.h:207
@ EEOP_SBSREF_SUBSCRIPTS
Definition: execExpr.h:210
@ EEOP_SBSREF_FETCH
Definition: execExpr.h:223
@ EEOP_FUNCEXPR_STRICT
Definition: execExpr.h:111
@ EEOP_NULLIF
Definition: execExpr.h:173
@ EEOP_CURRENTOFEXPR
Definition: execExpr.h:175
@ EEOP_INNER_SYSVAR
Definition: execExpr.h:81
@ EEOP_ASSIGN_TMP_MAKE_RO
Definition: execExpr.h:100
@ EEOP_CONST
Definition: execExpr.h:103
@ EEOP_BOOL_OR_STEP_LAST
Definition: execExpr.h:128
@ EEOP_BOOL_OR_STEP_FIRST
Definition: execExpr.h:126
@ EEOP_XMLEXPR
Definition: execExpr.h:238
@ EEOP_AGG_STRICT_INPUT_CHECK_NULLS
Definition: execExpr.h:250
@ EEOP_SBSREF_ASSIGN
Definition: execExpr.h:220
@ EEOP_OUTER_SYSVAR
Definition: execExpr.h:82
@ EEOP_ASSIGN_INNER_VAR
Definition: execExpr.h:93
@ EEOP_BOOL_OR_STEP
Definition: execExpr.h:127
@ EEOP_OUTER_FETCHSOME
Definition: execExpr.h:72
@ EEOP_AGG_STRICT_INPUT_CHECK_ARGS
Definition: execExpr.h:249
@ EEOP_NULLTEST_ROWISNULL
Definition: execExpr.h:149
@ EEOP_BOOLTEST_IS_TRUE
Definition: execExpr.h:153
@ EEOP_FUNCEXPR
Definition: execExpr.h:110
@ EEOP_NULLTEST_ISNOTNULL
Definition: execExpr.h:146
@ EEOP_ROWCOMPARE_STEP
Definition: execExpr.h:185
@ EEOP_AGG_DESERIALIZE
Definition: execExpr.h:248
@ EEOP_LAST
Definition: execExpr.h:264
@ EEOP_DISTINCT
Definition: execExpr.h:171
@ EEOP_JUMP_IF_NOT_TRUE
Definition: execExpr.h:142
@ EEOP_FUNCEXPR_FUSAGE
Definition: execExpr.h:112
@ EEOP_AGG_PRESORTED_DISTINCT_SINGLE
Definition: execExpr.h:258
@ EEOP_BOOL_AND_STEP_FIRST
Definition: execExpr.h:121
@ EEOP_JUMP
Definition: execExpr.h:137
@ EEOP_PARAM_CALLBACK
Definition: execExpr.h:161
@ EEOP_BOOL_AND_STEP_LAST
Definition: execExpr.h:123
@ EEOP_AGG_ORDERED_TRANS_DATUM
Definition: execExpr.h:260
@ EEOP_SBSREF_OLD
Definition: execExpr.h:217
@ EEOP_SQLVALUEFUNCTION
Definition: execExpr.h:174
@ EEOP_JUMP_IF_NOT_NULL
Definition: execExpr.h:141
@ EEOP_AGG_PLAIN_TRANS_STRICT_BYREF
Definition: execExpr.h:256
@ EEOP_FIELDSTORE_DEFORM
Definition: execExpr.h:200
@ EEOP_BOOLTEST_IS_FALSE
Definition: execExpr.h:155
@ EEOP_BOOLTEST_IS_NOT_TRUE
Definition: execExpr.h:154
@ EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYVAL
Definition: execExpr.h:252
@ EEOP_PARAM_EXEC
Definition: execExpr.h:159
@ EEOP_JSON_CONSTRUCTOR
Definition: execExpr.h:239
@ EEOP_AGG_PLAIN_TRANS_STRICT_BYVAL
Definition: execExpr.h:253
@ EEOP_NULLTEST_ISNULL
Definition: execExpr.h:145
@ EEOP_MINMAX
Definition: execExpr.h:191
@ EEOP_JUMP_IF_NULL
Definition: execExpr.h:140
@ EEOP_ARRAYCOERCE
Definition: execExpr.h:178
@ EEOP_FIELDSELECT
Definition: execExpr.h:194
@ EEOP_CASE_TESTVAL
Definition: execExpr.h:164
@ EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYREF
Definition: execExpr.h:255
@ EEOP_HASHED_SCALARARRAYOP
Definition: execExpr.h:237
@ EEOP_OUTER_VAR
Definition: execExpr.h:77
@ EEOP_AGG_ORDERED_TRANS_TUPLE
Definition: execExpr.h:261
@ EEOP_SCAN_FETCHSOME
Definition: execExpr.h:73
@ EEOP_IS_JSON
Definition: execExpr.h:240

Function Documentation

◆ CheckExprStillValid()

void CheckExprStillValid ( ExprState state,
ExprContext econtext 
)

Definition at line 1878 of file execExprInterp.c.

1879 {
1880  TupleTableSlot *innerslot;
1881  TupleTableSlot *outerslot;
1882  TupleTableSlot *scanslot;
1883 
1884  innerslot = econtext->ecxt_innertuple;
1885  outerslot = econtext->ecxt_outertuple;
1886  scanslot = econtext->ecxt_scantuple;
1887 
1888  for (int i = 0; i < state->steps_len; i++)
1889  {
1890  ExprEvalStep *op = &state->steps[i];
1891 
1892  switch (ExecEvalStepOp(state, op))
1893  {
1894  case EEOP_INNER_VAR:
1895  {
1896  int attnum = op->d.var.attnum;
1897 
1898  CheckVarSlotCompatibility(innerslot, attnum + 1, op->d.var.vartype);
1899  break;
1900  }
1901 
1902  case EEOP_OUTER_VAR:
1903  {
1904  int attnum = op->d.var.attnum;
1905 
1906  CheckVarSlotCompatibility(outerslot, attnum + 1, op->d.var.vartype);
1907  break;
1908  }
1909 
1910  case EEOP_SCAN_VAR:
1911  {
1912  int attnum = op->d.var.attnum;
1913 
1914  CheckVarSlotCompatibility(scanslot, attnum + 1, op->d.var.vartype);
1915  break;
1916  }
1917  default:
1918  break;
1919  }
1920  }
1921 }
static void CheckVarSlotCompatibility(TupleTableSlot *slot, int attnum, Oid vartype)
ExprEvalOp ExecEvalStepOp(ExprState *state, ExprEvalStep *op)
int i
Definition: isn.c:73
int16 attnum
Definition: pg_attribute.h:74
TupleTableSlot * ecxt_innertuple
Definition: execnodes.h:251
TupleTableSlot * ecxt_scantuple
Definition: execnodes.h:249
TupleTableSlot * ecxt_outertuple
Definition: execnodes.h:253
struct ExprEvalStep::@50::@52 var
union ExprEvalStep::@50 d
Definition: regguts.h:323

References attnum, CheckVarSlotCompatibility(), ExprContext::ecxt_innertuple, ExprContext::ecxt_outertuple, ExprContext::ecxt_scantuple, EEOP_INNER_VAR, EEOP_OUTER_VAR, EEOP_SCAN_VAR, ExecEvalStepOp(), i, and ExprEvalStep::op.

Referenced by ExecInterpExprStillValid(), and ExecRunCompiledExpr().

◆ ExecAggCopyTransValue()

Datum ExecAggCopyTransValue ( AggState aggstate,
AggStatePerTrans  pertrans,
Datum  newValue,
bool  newValueIsNull,
Datum  oldValue,
bool  oldValueIsNull 
)

Definition at line 4448 of file execExprInterp.c.

4451 {
4452  Assert(newValue != oldValue);
4453 
4454  if (!newValueIsNull)
4455  {
4457  if (DatumIsReadWriteExpandedObject(newValue,
4458  false,
4459  pertrans->transtypeLen) &&
4460  MemoryContextGetParent(DatumGetEOHP(newValue)->eoh_context) == CurrentMemoryContext)
4461  /* do nothing */ ;
4462  else
4463  newValue = datumCopy(newValue,
4464  pertrans->transtypeByVal,
4465  pertrans->transtypeLen);
4466  }
4467  else
4468  {
4469  /*
4470  * Ensure that AggStatePerGroup->transValue ends up being 0, so
4471  * callers can safely compare newValue/oldValue without having to
4472  * check their respective nullness.
4473  */
4474  newValue = (Datum) 0;
4475  }
4476 
4477  if (!oldValueIsNull)
4478  {
4479  if (DatumIsReadWriteExpandedObject(oldValue,
4480  false,
4481  pertrans->transtypeLen))
4482  DeleteExpandedObject(oldValue);
4483  else
4484  pfree(DatumGetPointer(oldValue));
4485  }
4486 
4487  return newValue;
4488 }
Datum datumCopy(Datum value, bool typByVal, int typLen)
Definition: datum.c:132
ExpandedObjectHeader * DatumGetEOHP(Datum d)
Definition: expandeddatum.c:29
void DeleteExpandedObject(Datum d)
#define DatumIsReadWriteExpandedObject(d, isnull, typlen)
Assert(fmt[strlen(fmt) - 1] !='\n')
void pfree(void *pointer)
Definition: mcxt.c:1456
MemoryContext CurrentMemoryContext
Definition: mcxt.c:135
MemoryContext MemoryContextGetParent(MemoryContext context)
Definition: mcxt.c:640
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:138
uintptr_t Datum
Definition: postgres.h:64
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:312
ExprContext * curaggcontext
Definition: execnodes.h:2394
MemoryContext ecxt_per_tuple_memory
Definition: execnodes.h:257

References Assert(), AggState::curaggcontext, CurrentMemoryContext, datumCopy(), DatumGetEOHP(), DatumGetPointer(), DatumIsReadWriteExpandedObject, DeleteExpandedObject(), ExprContext::ecxt_per_tuple_memory, MemoryContextGetParent(), MemoryContextSwitchTo(), ExprEvalStep::pertrans, pfree(), AggStatePerTransData::transtypeByVal, and AggStatePerTransData::transtypeLen.

Referenced by advance_transition_function(), and ExecAggPlainTransByRef().

◆ ExecAggInitGroup()

void ExecAggInitGroup ( AggState aggstate,
AggStatePerTrans  pertrans,
AggStatePerGroup  pergroup,
ExprContext aggcontext 
)

Definition at line 4395 of file execExprInterp.c.

4397 {
4398  FunctionCallInfo fcinfo = pertrans->transfn_fcinfo;
4399  MemoryContext oldContext;
4400 
4401  /*
4402  * We must copy the datum into aggcontext if it is pass-by-ref. We do not
4403  * need to pfree the old transValue, since it's NULL. (We already checked
4404  * that the agg's input type is binary-compatible with its transtype, so
4405  * straight copy here is OK.)
4406  */
4407  oldContext = MemoryContextSwitchTo(aggcontext->ecxt_per_tuple_memory);
4408  pergroup->transValue = datumCopy(fcinfo->args[1].value,
4409  pertrans->transtypeByVal,
4410  pertrans->transtypeLen);
4411  pergroup->transValueIsNull = false;
4412  pergroup->noTransValue = false;
4413  MemoryContextSwitchTo(oldContext);
4414 }
FunctionCallInfo transfn_fcinfo
Definition: nodeAgg.h:170
NullableDatum args[FLEXIBLE_ARRAY_MEMBER]
Definition: fmgr.h:95
Datum value
Definition: postgres.h:75

References ExprEvalStep::aggcontext, FunctionCallInfoBaseData::args, datumCopy(), ExprContext::ecxt_per_tuple_memory, MemoryContextSwitchTo(), AggStatePerGroupData::noTransValue, ExprEvalStep::pertrans, AggStatePerTransData::transfn_fcinfo, AggStatePerTransData::transtypeByVal, AggStatePerTransData::transtypeLen, AggStatePerGroupData::transValue, AggStatePerGroupData::transValueIsNull, and NullableDatum::value.

Referenced by ExecInterpExpr().

◆ ExecEvalAggOrderedTransDatum()

void ExecEvalAggOrderedTransDatum ( ExprState state,
ExprEvalStep op,
ExprContext econtext 
)

Definition at line 4573 of file execExprInterp.c.

4575 {
4576  AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
4577  int setno = op->d.agg_trans.setno;
4578 
4579  tuplesort_putdatum(pertrans->sortstates[setno],
4580  *op->resvalue, *op->resnull);
4581 }
Tuplesortstate ** sortstates
Definition: nodeAgg.h:162
Datum * resvalue
Definition: execExpr.h:278
struct ExprEvalStep::@50::@93 agg_trans
bool * resnull
Definition: execExpr.h:279
void tuplesort_putdatum(Tuplesortstate *state, Datum val, bool isNull)

References ExprEvalStep::op, ExprEvalStep::pertrans, ExprEvalStep::setno, AggStatePerTransData::sortstates, and tuplesort_putdatum().

Referenced by ExecInterpExpr().

◆ ExecEvalAggOrderedTransTuple()

void ExecEvalAggOrderedTransTuple ( ExprState state,
ExprEvalStep op,
ExprContext econtext 
)

Definition at line 4587 of file execExprInterp.c.

4589 {
4590  AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
4591  int setno = op->d.agg_trans.setno;
4592 
4593  ExecClearTuple(pertrans->sortslot);
4594  pertrans->sortslot->tts_nvalid = pertrans->numInputs;
4595  ExecStoreVirtualTuple(pertrans->sortslot);
4596  tuplesort_puttupleslot(pertrans->sortstates[setno], pertrans->sortslot);
4597 }
TupleTableSlot * ExecStoreVirtualTuple(TupleTableSlot *slot)
Definition: execTuples.c:1553
TupleTableSlot * sortslot
Definition: nodeAgg.h:141
AttrNumber tts_nvalid
Definition: tuptable.h:121
void tuplesort_puttupleslot(Tuplesortstate *state, TupleTableSlot *slot)
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:433

References ExecClearTuple(), ExecStoreVirtualTuple(), AggStatePerTransData::numInputs, ExprEvalStep::op, ExprEvalStep::pertrans, ExprEvalStep::setno, AggStatePerTransData::sortslot, AggStatePerTransData::sortstates, TupleTableSlot::tts_nvalid, and tuplesort_puttupleslot().

Referenced by ExecInterpExpr().

◆ ExecEvalArrayCoerce()

void ExecEvalArrayCoerce ( ExprState state,
ExprEvalStep op,
ExprContext econtext 
)

Definition at line 2936 of file execExprInterp.c.

2937 {
2938  Datum arraydatum;
2939 
2940  /* NULL array -> NULL result */
2941  if (*op->resnull)
2942  return;
2943 
2944  arraydatum = *op->resvalue;
2945 
2946  /*
2947  * If it's binary-compatible, modify the element type in the array header,
2948  * but otherwise leave the array as we received it.
2949  */
2950  if (op->d.arraycoerce.elemexprstate == NULL)
2951  {
2952  /* Detoast input array if necessary, and copy in any case */
2953  ArrayType *array = DatumGetArrayTypePCopy(arraydatum);
2954 
2955  ARR_ELEMTYPE(array) = op->d.arraycoerce.resultelemtype;
2956  *op->resvalue = PointerGetDatum(array);
2957  return;
2958  }
2959 
2960  /*
2961  * Use array_map to apply the sub-expression to each array element.
2962  */
2963  *op->resvalue = array_map(arraydatum,
2964  op->d.arraycoerce.elemexprstate,
2965  econtext,
2966  op->d.arraycoerce.resultelemtype,
2967  op->d.arraycoerce.amstate);
2968 }
#define DatumGetArrayTypePCopy(X)
Definition: array.h:255
#define ARR_ELEMTYPE(a)
Definition: array.h:285
Datum array_map(Datum arrayd, ExprState *exprstate, ExprContext *econtext, Oid retType, ArrayMapState *amstate)
Definition: arrayfuncs.c:3181
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:322
struct ExprEvalStep::@50::@70 arraycoerce

References ARR_ELEMTYPE, array_map(), DatumGetArrayTypePCopy, ExprEvalStep::op, and PointerGetDatum().

Referenced by ExecInterpExpr().

◆ ExecEvalArrayExpr()

void ExecEvalArrayExpr ( ExprState state,
ExprEvalStep op 
)

Definition at line 2722 of file execExprInterp.c.

2723 {
2724  ArrayType *result;
2725  Oid element_type = op->d.arrayexpr.elemtype;
2726  int nelems = op->d.arrayexpr.nelems;
2727  int ndims = 0;
2728  int dims[MAXDIM];
2729  int lbs[MAXDIM];
2730 
2731  /* Set non-null as default */
2732  *op->resnull = false;
2733 
2734  if (!op->d.arrayexpr.multidims)
2735  {
2736  /* Elements are presumably of scalar type */
2737  Datum *dvalues = op->d.arrayexpr.elemvalues;
2738  bool *dnulls = op->d.arrayexpr.elemnulls;
2739 
2740  /* setup for 1-D array of the given length */
2741  ndims = 1;
2742  dims[0] = nelems;
2743  lbs[0] = 1;
2744 
2745  result = construct_md_array(dvalues, dnulls, ndims, dims, lbs,
2746  element_type,
2747  op->d.arrayexpr.elemlength,
2748  op->d.arrayexpr.elembyval,
2749  op->d.arrayexpr.elemalign);
2750  }
2751  else
2752  {
2753  /* Must be nested array expressions */
2754  int nbytes = 0;
2755  int nitems;
2756  int outer_nelems = 0;
2757  int elem_ndims = 0;
2758  int *elem_dims = NULL;
2759  int *elem_lbs = NULL;
2760  bool firstone = true;
2761  bool havenulls = false;
2762  bool haveempty = false;
2763  char **subdata;
2764  bits8 **subbitmaps;
2765  int *subbytes;
2766  int *subnitems;
2767  int32 dataoffset;
2768  char *dat;
2769  int iitem;
2770 
2771  subdata = (char **) palloc(nelems * sizeof(char *));
2772  subbitmaps = (bits8 **) palloc(nelems * sizeof(bits8 *));
2773  subbytes = (int *) palloc(nelems * sizeof(int));
2774  subnitems = (int *) palloc(nelems * sizeof(int));
2775 
2776  /* loop through and get data area from each element */
2777  for (int elemoff = 0; elemoff < nelems; elemoff++)
2778  {
2779  Datum arraydatum;
2780  bool eisnull;
2781  ArrayType *array;
2782  int this_ndims;
2783 
2784  arraydatum = op->d.arrayexpr.elemvalues[elemoff];
2785  eisnull = op->d.arrayexpr.elemnulls[elemoff];
2786 
2787  /* temporarily ignore null subarrays */
2788  if (eisnull)
2789  {
2790  haveempty = true;
2791  continue;
2792  }
2793 
2794  array = DatumGetArrayTypeP(arraydatum);
2795 
2796  /* run-time double-check on element type */
2797  if (element_type != ARR_ELEMTYPE(array))
2798  ereport(ERROR,
2799  (errcode(ERRCODE_DATATYPE_MISMATCH),
2800  errmsg("cannot merge incompatible arrays"),
2801  errdetail("Array with element type %s cannot be "
2802  "included in ARRAY construct with element type %s.",
2803  format_type_be(ARR_ELEMTYPE(array)),
2804  format_type_be(element_type))));
2805 
2806  this_ndims = ARR_NDIM(array);
2807  /* temporarily ignore zero-dimensional subarrays */
2808  if (this_ndims <= 0)
2809  {
2810  haveempty = true;
2811  continue;
2812  }
2813 
2814  if (firstone)
2815  {
2816  /* Get sub-array details from first member */
2817  elem_ndims = this_ndims;
2818  ndims = elem_ndims + 1;
2819  if (ndims <= 0 || ndims > MAXDIM)
2820  ereport(ERROR,
2821  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
2822  errmsg("number of array dimensions (%d) exceeds the maximum allowed (%d)",
2823  ndims, MAXDIM)));
2824 
2825  elem_dims = (int *) palloc(elem_ndims * sizeof(int));
2826  memcpy(elem_dims, ARR_DIMS(array), elem_ndims * sizeof(int));
2827  elem_lbs = (int *) palloc(elem_ndims * sizeof(int));
2828  memcpy(elem_lbs, ARR_LBOUND(array), elem_ndims * sizeof(int));
2829 
2830  firstone = false;
2831  }
2832  else
2833  {
2834  /* Check other sub-arrays are compatible */
2835  if (elem_ndims != this_ndims ||
2836  memcmp(elem_dims, ARR_DIMS(array),
2837  elem_ndims * sizeof(int)) != 0 ||
2838  memcmp(elem_lbs, ARR_LBOUND(array),
2839  elem_ndims * sizeof(int)) != 0)
2840  ereport(ERROR,
2841  (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
2842  errmsg("multidimensional arrays must have array "
2843  "expressions with matching dimensions")));
2844  }
2845 
2846  subdata[outer_nelems] = ARR_DATA_PTR(array);
2847  subbitmaps[outer_nelems] = ARR_NULLBITMAP(array);
2848  subbytes[outer_nelems] = ARR_SIZE(array) - ARR_DATA_OFFSET(array);
2849  nbytes += subbytes[outer_nelems];
2850  /* check for overflow of total request */
2851  if (!AllocSizeIsValid(nbytes))
2852  ereport(ERROR,
2853  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
2854  errmsg("array size exceeds the maximum allowed (%d)",
2855  (int) MaxAllocSize)));
2856  subnitems[outer_nelems] = ArrayGetNItems(this_ndims,
2857  ARR_DIMS(array));
2858  havenulls |= ARR_HASNULL(array);
2859  outer_nelems++;
2860  }
2861 
2862  /*
2863  * If all items were null or empty arrays, return an empty array;
2864  * otherwise, if some were and some weren't, raise error. (Note: we
2865  * must special-case this somehow to avoid trying to generate a 1-D
2866  * array formed from empty arrays. It's not ideal...)
2867  */
2868  if (haveempty)
2869  {
2870  if (ndims == 0) /* didn't find any nonempty array */
2871  {
2872  *op->resvalue = PointerGetDatum(construct_empty_array(element_type));
2873  return;
2874  }
2875  ereport(ERROR,
2876  (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
2877  errmsg("multidimensional arrays must have array "
2878  "expressions with matching dimensions")));
2879  }
2880 
2881  /* setup for multi-D array */
2882  dims[0] = outer_nelems;
2883  lbs[0] = 1;
2884  for (int i = 1; i < ndims; i++)
2885  {
2886  dims[i] = elem_dims[i - 1];
2887  lbs[i] = elem_lbs[i - 1];
2888  }
2889 
2890  /* check for subscript overflow */
2891  nitems = ArrayGetNItems(ndims, dims);
2892  ArrayCheckBounds(ndims, dims, lbs);
2893 
2894  if (havenulls)
2895  {
2896  dataoffset = ARR_OVERHEAD_WITHNULLS(ndims, nitems);
2897  nbytes += dataoffset;
2898  }
2899  else
2900  {
2901  dataoffset = 0; /* marker for no null bitmap */
2902  nbytes += ARR_OVERHEAD_NONULLS(ndims);
2903  }
2904 
2905  result = (ArrayType *) palloc0(nbytes);
2906  SET_VARSIZE(result, nbytes);
2907  result->ndim = ndims;
2908  result->dataoffset = dataoffset;
2909  result->elemtype = element_type;
2910  memcpy(ARR_DIMS(result), dims, ndims * sizeof(int));
2911  memcpy(ARR_LBOUND(result), lbs, ndims * sizeof(int));
2912 
2913  dat = ARR_DATA_PTR(result);
2914  iitem = 0;
2915  for (int i = 0; i < outer_nelems; i++)
2916  {
2917  memcpy(dat, subdata[i], subbytes[i]);
2918  dat += subbytes[i];
2919  if (havenulls)
2920  array_bitmap_copy(ARR_NULLBITMAP(result), iitem,
2921  subbitmaps[i], 0,
2922  subnitems[i]);
2923  iitem += subnitems[i];
2924  }
2925  }
2926 
2927  *op->resvalue = PointerGetDatum(result);
2928 }
#define ARR_NDIM(a)
Definition: array.h:283
#define ARR_DATA_PTR(a)
Definition: array.h:315
#define MAXDIM
Definition: array.h:75
#define ARR_NULLBITMAP(a)
Definition: array.h:293
#define ARR_OVERHEAD_WITHNULLS(ndims, nitems)
Definition: array.h:305
#define DatumGetArrayTypeP(X)
Definition: array.h:254
#define ARR_SIZE(a)
Definition: array.h:282
#define ARR_OVERHEAD_NONULLS(ndims)
Definition: array.h:303
#define ARR_DATA_OFFSET(a)
Definition: array.h:309
#define ARR_DIMS(a)
Definition: array.h:287
#define ARR_HASNULL(a)
Definition: array.h:284
#define ARR_LBOUND(a)
Definition: array.h:289
ArrayType * construct_empty_array(Oid elmtype)
Definition: arrayfuncs.c:3548
ArrayType * construct_md_array(Datum *elems, bool *nulls, int ndims, int *dims, int *lbs, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3462
void array_bitmap_copy(bits8 *destbitmap, int destoffset, const bits8 *srcbitmap, int srcoffset, int nitems)
Definition: arrayfuncs.c:4934
int ArrayGetNItems(int ndim, const int *dims)
Definition: arrayutils.c:76
void ArrayCheckBounds(int ndim, const int *dims, const int *lb)
Definition: arrayutils.c:138
signed int int32
Definition: c.h:478
uint8 bits8
Definition: c.h:497
int errdetail(const char *fmt,...)
Definition: elog.c:1202
int errcode(int sqlerrcode)
Definition: elog.c:858
int errmsg(const char *fmt,...)
Definition: elog.c:1069
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
char * format_type_be(Oid type_oid)
Definition: format_type.c:339
#define nitems(x)
Definition: indent.h:31
void * palloc0(Size size)
Definition: mcxt.c:1257
void * palloc(Size size)
Definition: mcxt.c:1226
#define AllocSizeIsValid(size)
Definition: memutils.h:42
#define MaxAllocSize
Definition: memutils.h:40
unsigned int Oid
Definition: postgres_ext.h:31
Oid elemtype
Definition: array.h:90
int ndim
Definition: array.h:88
int32 dataoffset
Definition: array.h:89
struct ExprEvalStep::@50::@69 arrayexpr
#define SET_VARSIZE(PTR, len)
Definition: varatt.h:305

References AllocSizeIsValid, ARR_DATA_OFFSET, ARR_DATA_PTR, ARR_DIMS, ARR_ELEMTYPE, ARR_HASNULL, ARR_LBOUND, ARR_NDIM, ARR_NULLBITMAP, ARR_OVERHEAD_NONULLS, ARR_OVERHEAD_WITHNULLS, ARR_SIZE, array_bitmap_copy(), ArrayCheckBounds(), ArrayGetNItems(), construct_empty_array(), construct_md_array(), ArrayType::dataoffset, DatumGetArrayTypeP, ExprEvalStep::element_type, ArrayType::elemtype, ereport, errcode(), errdetail(), errmsg(), ERROR, format_type_be(), i, MaxAllocSize, MAXDIM, ArrayType::ndim, ExprEvalStep::nelems, nitems, ExprEvalStep::op, palloc(), palloc0(), PointerGetDatum(), and SET_VARSIZE.

Referenced by ExecInterpExpr().

◆ ExecEvalConstraintCheck()

void ExecEvalConstraintCheck ( ExprState state,
ExprEvalStep op 
)

Definition at line 3739 of file execExprInterp.c.

3740 {
3741  if (!*op->d.domaincheck.checknull &&
3742  !DatumGetBool(*op->d.domaincheck.checkvalue))
3743  ereport(ERROR,
3744  (errcode(ERRCODE_CHECK_VIOLATION),
3745  errmsg("value for domain %s violates check constraint \"%s\"",
3746  format_type_be(op->d.domaincheck.resulttype),
3747  op->d.domaincheck.constraintname),
3748  errdomainconstraint(op->d.domaincheck.resulttype,
3749  op->d.domaincheck.constraintname)));
3750 }
int errdomainconstraint(Oid datatypeOid, const char *conname)
Definition: domains.c:400
static bool DatumGetBool(Datum X)
Definition: postgres.h:90
struct ExprEvalStep::@50::@79 domaincheck

References DatumGetBool(), ereport, errcode(), errdomainconstraint(), errmsg(), ERROR, format_type_be(), and ExprEvalStep::op.

Referenced by ExecInterpExpr().

◆ ExecEvalConstraintNotNull()

void ExecEvalConstraintNotNull ( ExprState state,
ExprEvalStep op 
)

Definition at line 3725 of file execExprInterp.c.

3726 {
3727  if (*op->resnull)
3728  ereport(ERROR,
3729  (errcode(ERRCODE_NOT_NULL_VIOLATION),
3730  errmsg("domain %s does not allow null values",
3731  format_type_be(op->d.domaincheck.resulttype)),
3732  errdatatype(op->d.domaincheck.resulttype)));
3733 }
int errdatatype(Oid datatypeOid)
Definition: domains.c:376

References ereport, errcode(), errdatatype(), errmsg(), ERROR, format_type_be(), and ExprEvalStep::op.

Referenced by ExecInterpExpr().

◆ ExecEvalConvertRowtype()

void ExecEvalConvertRowtype ( ExprState state,
ExprEvalStep op,
ExprContext econtext 
)

Definition at line 3245 of file execExprInterp.c.

3246 {
3247  HeapTuple result;
3248  Datum tupDatum;
3249  HeapTupleHeader tuple;
3250  HeapTupleData tmptup;
3251  TupleDesc indesc,
3252  outdesc;
3253  bool changed = false;
3254 
3255  /* NULL in -> NULL out */
3256  if (*op->resnull)
3257  return;
3258 
3259  tupDatum = *op->resvalue;
3260  tuple = DatumGetHeapTupleHeader(tupDatum);
3261 
3262  /*
3263  * Lookup tupdescs if first time through or if type changes. We'd better
3264  * pin them since type conversion functions could do catalog lookups and
3265  * hence cause cache invalidation.
3266  */
3267  indesc = get_cached_rowtype(op->d.convert_rowtype.inputtype, -1,
3268  op->d.convert_rowtype.incache,
3269  &changed);
3270  IncrTupleDescRefCount(indesc);
3271  outdesc = get_cached_rowtype(op->d.convert_rowtype.outputtype, -1,
3272  op->d.convert_rowtype.outcache,
3273  &changed);
3274  IncrTupleDescRefCount(outdesc);
3275 
3276  /*
3277  * We used to be able to assert that incoming tuples are marked with
3278  * exactly the rowtype of indesc. However, now that ExecEvalWholeRowVar
3279  * might change the tuples' marking to plain RECORD due to inserting
3280  * aliases, we can only make this weak test:
3281  */
3282  Assert(HeapTupleHeaderGetTypeId(tuple) == indesc->tdtypeid ||
3283  HeapTupleHeaderGetTypeId(tuple) == RECORDOID);
3284 
3285  /* if first time through, or after change, initialize conversion map */
3286  if (changed)
3287  {
3288  MemoryContext old_cxt;
3289 
3290  /* allocate map in long-lived memory context */
3291  old_cxt = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
3292 
3293  /* prepare map from old to new attribute numbers */
3294  op->d.convert_rowtype.map = convert_tuples_by_name(indesc, outdesc);
3295 
3296  MemoryContextSwitchTo(old_cxt);
3297  }
3298 
3299  /* Following steps need a HeapTuple not a bare HeapTupleHeader */
3300  tmptup.t_len = HeapTupleHeaderGetDatumLength(tuple);
3301  tmptup.t_data = tuple;
3302 
3303  if (op->d.convert_rowtype.map != NULL)
3304  {
3305  /* Full conversion with attribute rearrangement needed */
3306  result = execute_attr_map_tuple(&tmptup, op->d.convert_rowtype.map);
3307  /* Result already has appropriate composite-datum header fields */
3308  *op->resvalue = HeapTupleGetDatum(result);
3309  }
3310  else
3311  {
3312  /*
3313  * The tuple is physically compatible as-is, but we need to insert the
3314  * destination rowtype OID in its composite-datum header field, so we
3315  * have to copy it anyway. heap_copy_tuple_as_datum() is convenient
3316  * for this since it will both make the physical copy and insert the
3317  * correct composite header fields. Note that we aren't expecting to
3318  * have to flatten any toasted fields: the input was a composite
3319  * datum, so it shouldn't contain any. So heap_copy_tuple_as_datum()
3320  * is overkill here, but its check for external fields is cheap.
3321  */
3322  *op->resvalue = heap_copy_tuple_as_datum(&tmptup, outdesc);
3323  }
3324 
3325  DecrTupleDescRefCount(indesc);
3326  DecrTupleDescRefCount(outdesc);
3327 }
static TupleDesc get_cached_rowtype(Oid type_id, int32 typmod, ExprEvalRowtypeCache *rowcache, bool *changed)
#define DatumGetHeapTupleHeader(X)
Definition: fmgr.h:295
static Datum HeapTupleGetDatum(const HeapTupleData *tuple)
Definition: funcapi.h:230
Datum heap_copy_tuple_as_datum(HeapTuple tuple, TupleDesc tupleDesc)
Definition: heaptuple.c:984
#define HeapTupleHeaderGetTypeId(tup)
Definition: htup_details.h:456
#define HeapTupleHeaderGetDatumLength(tup)
Definition: htup_details.h:450
MemoryContext ecxt_per_query_memory
Definition: execnodes.h:256
struct ExprEvalStep::@50::@80 convert_rowtype
uint32 t_len
Definition: htup.h:64
HeapTupleHeader t_data
Definition: htup.h:68
Oid tdtypeid
Definition: tupdesc.h:82
TupleConversionMap * convert_tuples_by_name(TupleDesc indesc, TupleDesc outdesc)
Definition: tupconvert.c:102
HeapTuple execute_attr_map_tuple(HeapTuple tuple, TupleConversionMap *map)
Definition: tupconvert.c:154
void DecrTupleDescRefCount(TupleDesc tupdesc)
Definition: tupdesc.c:384
void IncrTupleDescRefCount(TupleDesc tupdesc)
Definition: tupdesc.c:366

References Assert(), convert_tuples_by_name(), DatumGetHeapTupleHeader, DecrTupleDescRefCount(), ExprContext::ecxt_per_query_memory, execute_attr_map_tuple(), get_cached_rowtype(), heap_copy_tuple_as_datum(), HeapTupleGetDatum(), HeapTupleHeaderGetDatumLength, HeapTupleHeaderGetTypeId, IncrTupleDescRefCount(), MemoryContextSwitchTo(), ExprEvalStep::op, HeapTupleData::t_data, HeapTupleData::t_len, and TupleDescData::tdtypeid.

Referenced by ExecInterpExpr().

◆ ExecEvalCurrentOfExpr()

void ExecEvalCurrentOfExpr ( ExprState state,
ExprEvalStep op 
)

Definition at line 2583 of file execExprInterp.c.

2584 {
2585  ereport(ERROR,
2586  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2587  errmsg("WHERE CURRENT OF is not supported for this table type")));
2588 }

References ereport, errcode(), errmsg(), and ERROR.

Referenced by ExecInterpExpr().

◆ ExecEvalFieldSelect()

void ExecEvalFieldSelect ( ExprState state,
ExprEvalStep op,
ExprContext econtext 
)

Definition at line 3050 of file execExprInterp.c.

3051 {
3052  AttrNumber fieldnum = op->d.fieldselect.fieldnum;
3053  Datum tupDatum;
3054  HeapTupleHeader tuple;
3055  Oid tupType;
3056  int32 tupTypmod;
3057  TupleDesc tupDesc;
3058  Form_pg_attribute attr;
3059  HeapTupleData tmptup;
3060 
3061  /* NULL record -> NULL result */
3062  if (*op->resnull)
3063  return;
3064 
3065  tupDatum = *op->resvalue;
3066 
3067  /* We can special-case expanded records for speed */
3069  {
3071 
3072  Assert(erh->er_magic == ER_MAGIC);
3073 
3074  /* Extract record's TupleDesc */
3075  tupDesc = expanded_record_get_tupdesc(erh);
3076 
3077  /*
3078  * Find field's attr record. Note we don't support system columns
3079  * here: a datum tuple doesn't have valid values for most of the
3080  * interesting system columns anyway.
3081  */
3082  if (fieldnum <= 0) /* should never happen */
3083  elog(ERROR, "unsupported reference to system column %d in FieldSelect",
3084  fieldnum);
3085  if (fieldnum > tupDesc->natts) /* should never happen */
3086  elog(ERROR, "attribute number %d exceeds number of columns %d",
3087  fieldnum, tupDesc->natts);
3088  attr = TupleDescAttr(tupDesc, fieldnum - 1);
3089 
3090  /* Check for dropped column, and force a NULL result if so */
3091  if (attr->attisdropped)
3092  {
3093  *op->resnull = true;
3094  return;
3095  }
3096 
3097  /* Check for type mismatch --- possible after ALTER COLUMN TYPE? */
3098  /* As in CheckVarSlotCompatibility, we should but can't check typmod */
3099  if (op->d.fieldselect.resulttype != attr->atttypid)
3100  ereport(ERROR,
3101  (errcode(ERRCODE_DATATYPE_MISMATCH),
3102  errmsg("attribute %d has wrong type", fieldnum),
3103  errdetail("Table has type %s, but query expects %s.",
3104  format_type_be(attr->atttypid),
3105  format_type_be(op->d.fieldselect.resulttype))));
3106 
3107  /* extract the field */
3108  *op->resvalue = expanded_record_get_field(erh, fieldnum,
3109  op->resnull);
3110  }
3111  else
3112  {
3113  /* Get the composite datum and extract its type fields */
3114  tuple = DatumGetHeapTupleHeader(tupDatum);
3115 
3116  tupType = HeapTupleHeaderGetTypeId(tuple);
3117  tupTypmod = HeapTupleHeaderGetTypMod(tuple);
3118 
3119  /* Lookup tupdesc if first time through or if type changes */
3120  tupDesc = get_cached_rowtype(tupType, tupTypmod,
3121  &op->d.fieldselect.rowcache, NULL);
3122 
3123  /*
3124  * Find field's attr record. Note we don't support system columns
3125  * here: a datum tuple doesn't have valid values for most of the
3126  * interesting system columns anyway.
3127  */
3128  if (fieldnum <= 0) /* should never happen */
3129  elog(ERROR, "unsupported reference to system column %d in FieldSelect",
3130  fieldnum);
3131  if (fieldnum > tupDesc->natts) /* should never happen */
3132  elog(ERROR, "attribute number %d exceeds number of columns %d",
3133  fieldnum, tupDesc->natts);
3134  attr = TupleDescAttr(tupDesc, fieldnum - 1);
3135 
3136  /* Check for dropped column, and force a NULL result if so */
3137  if (attr->attisdropped)
3138  {
3139  *op->resnull = true;
3140  return;
3141  }
3142 
3143  /* Check for type mismatch --- possible after ALTER COLUMN TYPE? */
3144  /* As in CheckVarSlotCompatibility, we should but can't check typmod */
3145  if (op->d.fieldselect.resulttype != attr->atttypid)
3146  ereport(ERROR,
3147  (errcode(ERRCODE_DATATYPE_MISMATCH),
3148  errmsg("attribute %d has wrong type", fieldnum),
3149  errdetail("Table has type %s, but query expects %s.",
3150  format_type_be(attr->atttypid),
3151  format_type_be(op->d.fieldselect.resulttype))));
3152 
3153  /* heap_getattr needs a HeapTuple not a bare HeapTupleHeader */
3154  tmptup.t_len = HeapTupleHeaderGetDatumLength(tuple);
3155  tmptup.t_data = tuple;
3156 
3157  /* extract the field */
3158  *op->resvalue = heap_getattr(&tmptup,
3159  fieldnum,
3160  tupDesc,
3161  op->resnull);
3162  }
3163 }
int16 AttrNumber
Definition: attnum.h:21
static Datum expanded_record_get_field(ExpandedRecordHeader *erh, int fnumber, bool *isnull)
#define ER_MAGIC
static TupleDesc expanded_record_get_tupdesc(ExpandedRecordHeader *erh)
static Datum heap_getattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
Definition: htup_details.h:792
#define HeapTupleHeaderGetTypMod(tup)
Definition: htup_details.h:466
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:209
struct ExprEvalStep::@50::@75 fieldselect
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
#define VARATT_IS_EXTERNAL_EXPANDED(PTR)
Definition: varatt.h:298

References Assert(), DatumGetEOHP(), DatumGetHeapTupleHeader, DatumGetPointer(), elog(), ER_MAGIC, ExpandedRecordHeader::er_magic, ereport, errcode(), errdetail(), errmsg(), ERROR, expanded_record_get_field(), expanded_record_get_tupdesc(), ExprEvalStep::fieldnum, format_type_be(), get_cached_rowtype(), heap_getattr(), HeapTupleHeaderGetDatumLength, HeapTupleHeaderGetTypeId, HeapTupleHeaderGetTypMod, TupleDescData::natts, ExprEvalStep::op, HeapTupleData::t_data, HeapTupleData::t_len, TupleDescAttr, and VARATT_IS_EXTERNAL_EXPANDED.

Referenced by ExecInterpExpr().

◆ ExecEvalFieldStoreDeForm()

void ExecEvalFieldStoreDeForm ( ExprState state,
ExprEvalStep op,
ExprContext econtext 
)

Definition at line 3175 of file execExprInterp.c.

3176 {
3177  TupleDesc tupDesc;
3178 
3179  /* Lookup tupdesc if first time through or if type changes */
3180  tupDesc = get_cached_rowtype(op->d.fieldstore.fstore->resulttype, -1,
3181  op->d.fieldstore.rowcache, NULL);
3182 
3183  /* Check that current tupdesc doesn't have more fields than we allocated */
3184  if (unlikely(tupDesc->natts > op->d.fieldstore.ncolumns))
3185  elog(ERROR, "too many columns in composite type %u",
3186  op->d.fieldstore.fstore->resulttype);
3187 
3188  if (*op->resnull)
3189  {
3190  /* Convert null input tuple into an all-nulls row */
3191  memset(op->d.fieldstore.nulls, true,
3192  op->d.fieldstore.ncolumns * sizeof(bool));
3193  }
3194  else
3195  {
3196  /*
3197  * heap_deform_tuple needs a HeapTuple not a bare HeapTupleHeader. We
3198  * set all the fields in the struct just in case.
3199  */
3200  Datum tupDatum = *op->resvalue;
3201  HeapTupleHeader tuphdr;
3202  HeapTupleData tmptup;
3203 
3204  tuphdr = DatumGetHeapTupleHeader(tupDatum);
3205  tmptup.t_len = HeapTupleHeaderGetDatumLength(tuphdr);
3206  ItemPointerSetInvalid(&(tmptup.t_self));
3207  tmptup.t_tableOid = InvalidOid;
3208  tmptup.t_data = tuphdr;
3209 
3210  heap_deform_tuple(&tmptup, tupDesc,
3211  op->d.fieldstore.values,
3212  op->d.fieldstore.nulls);
3213  }
3214 }
#define unlikely(x)
Definition: c.h:295
void heap_deform_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *values, bool *isnull)
Definition: heaptuple.c:1249
static void ItemPointerSetInvalid(ItemPointerData *pointer)
Definition: itemptr.h:184
#define InvalidOid
Definition: postgres_ext.h:36
struct ExprEvalStep::@50::@76 fieldstore
ItemPointerData t_self
Definition: htup.h:65
Oid t_tableOid
Definition: htup.h:66

References DatumGetHeapTupleHeader, elog(), ERROR, get_cached_rowtype(), heap_deform_tuple(), HeapTupleHeaderGetDatumLength, InvalidOid, ItemPointerSetInvalid(), TupleDescData::natts, ExprEvalStep::op, HeapTupleData::t_data, HeapTupleData::t_len, HeapTupleData::t_self, HeapTupleData::t_tableOid, and unlikely.

Referenced by ExecInterpExpr().

◆ ExecEvalFieldStoreForm()

void ExecEvalFieldStoreForm ( ExprState state,
ExprEvalStep op,
ExprContext econtext 
)

Definition at line 3221 of file execExprInterp.c.

3222 {
3223  TupleDesc tupDesc;
3224  HeapTuple tuple;
3225 
3226  /* Lookup tupdesc (should be valid already) */
3227  tupDesc = get_cached_rowtype(op->d.fieldstore.fstore->resulttype, -1,
3228  op->d.fieldstore.rowcache, NULL);
3229 
3230  tuple = heap_form_tuple(tupDesc,
3231  op->d.fieldstore.values,
3232  op->d.fieldstore.nulls);
3233 
3234  *op->resvalue = HeapTupleGetDatum(tuple);
3235  *op->resnull = false;
3236 }
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1020

References get_cached_rowtype(), heap_form_tuple(), HeapTupleGetDatum(), and ExprEvalStep::op.

Referenced by ExecInterpExpr().

◆ ExecEvalFuncExprFusage()

void ExecEvalFuncExprFusage ( ExprState state,
ExprEvalStep op,
ExprContext econtext 
)

Definition at line 2394 of file execExprInterp.c.

2396 {
2397  FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
2398  PgStat_FunctionCallUsage fcusage;
2399  Datum d;
2400 
2401  pgstat_init_function_usage(fcinfo, &fcusage);
2402 
2403  fcinfo->isnull = false;
2404  d = op->d.func.fn_addr(fcinfo);
2405  *op->resvalue = d;
2406  *op->resnull = fcinfo->isnull;
2407 
2408  pgstat_end_function_usage(&fcusage, true);
2409 }
void pgstat_init_function_usage(FunctionCallInfo fcinfo, PgStat_FunctionCallUsage *fcu)
void pgstat_end_function_usage(PgStat_FunctionCallUsage *fcu, bool finalize)
struct ExprEvalStep::@50::@57 func

References ExprEvalStep::d, FunctionCallInfoBaseData::isnull, ExprEvalStep::op, pgstat_end_function_usage(), and pgstat_init_function_usage().

Referenced by ExecInterpExpr().

◆ ExecEvalFuncExprStrictFusage()

void ExecEvalFuncExprStrictFusage ( ExprState state,
ExprEvalStep op,
ExprContext econtext 
)

Definition at line 2415 of file execExprInterp.c.

2417 {
2418 
2419  FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
2420  PgStat_FunctionCallUsage fcusage;
2421  NullableDatum *args = fcinfo->args;
2422  int nargs = op->d.func.nargs;
2423  Datum d;
2424 
2425  /* strict function, so check for NULL args */
2426  for (int argno = 0; argno < nargs; argno++)
2427  {
2428  if (args[argno].isnull)
2429  {
2430  *op->resnull = true;
2431  return;
2432  }
2433  }
2434 
2435  pgstat_init_function_usage(fcinfo, &fcusage);
2436 
2437  fcinfo->isnull = false;
2438  d = op->d.func.fn_addr(fcinfo);
2439  *op->resvalue = d;
2440  *op->resnull = fcinfo->isnull;
2441 
2442  pgstat_end_function_usage(&fcusage, true);
2443 }

References generate_unaccent_rules::args, FunctionCallInfoBaseData::args, ExprEvalStep::d, ExprEvalStep::isnull, FunctionCallInfoBaseData::isnull, ExprEvalStep::nargs, ExprEvalStep::op, pgstat_end_function_usage(), and pgstat_init_function_usage().

Referenced by ExecInterpExpr().

◆ ExecEvalGroupingFunc()

void ExecEvalGroupingFunc ( ExprState state,
ExprEvalStep op 
)

Definition at line 4106 of file execExprInterp.c.

4107 {
4108  AggState *aggstate = castNode(AggState, state->parent);
4109  int result = 0;
4110  Bitmapset *grouped_cols = aggstate->grouped_cols;
4111  ListCell *lc;
4112 
4113  foreach(lc, op->d.grouping_func.clauses)
4114  {
4115  int attnum = lfirst_int(lc);
4116 
4117  result <<= 1;
4118 
4119  if (!bms_is_member(attnum, grouped_cols))
4120  result |= 1;
4121  }
4122 
4123  *op->resvalue = Int32GetDatum(result);
4124  *op->resnull = false;
4125 }
bool bms_is_member(int x, const Bitmapset *a)
Definition: bitmapset.c:444
#define castNode(_type_, nodeptr)
Definition: nodes.h:197
#define lfirst_int(lc)
Definition: pg_list.h:173
static Datum Int32GetDatum(int32 X)
Definition: postgres.h:212
Bitmapset * grouped_cols
Definition: execnodes.h:2403
struct ExprEvalStep::@50::@86 grouping_func

References attnum, bms_is_member(), castNode, AggState::grouped_cols, Int32GetDatum(), lfirst_int, and ExprEvalStep::op.

Referenced by ExecInterpExpr().

◆ ExecEvalHashedScalarArrayOp()

void ExecEvalHashedScalarArrayOp ( ExprState state,
ExprEvalStep op,
ExprContext econtext 
)

Definition at line 3543 of file execExprInterp.c.

3544 {
3545  ScalarArrayOpExprHashTable *elements_tab = op->d.hashedscalararrayop.elements_tab;
3546  FunctionCallInfo fcinfo = op->d.hashedscalararrayop.fcinfo_data;
3547  bool inclause = op->d.hashedscalararrayop.inclause;
3548  bool strictfunc = op->d.hashedscalararrayop.finfo->fn_strict;
3549  Datum scalar = fcinfo->args[0].value;
3550  bool scalar_isnull = fcinfo->args[0].isnull;
3551  Datum result;
3552  bool resultnull;
3553  bool hashfound;
3554 
3555  /* We don't setup a hashed scalar array op if the array const is null. */
3556  Assert(!*op->resnull);
3557 
3558  /*
3559  * If the scalar is NULL, and the function is strict, return NULL; no
3560  * point in executing the search.
3561  */
3562  if (fcinfo->args[0].isnull && strictfunc)
3563  {
3564  *op->resnull = true;
3565  return;
3566  }
3567 
3568  /* Build the hash table on first evaluation */
3569  if (elements_tab == NULL)
3570  {
3571  ScalarArrayOpExpr *saop;
3572  int16 typlen;
3573  bool typbyval;
3574  char typalign;
3575  int nitems;
3576  bool has_nulls = false;
3577  char *s;
3578  bits8 *bitmap;
3579  int bitmask;
3580  MemoryContext oldcontext;
3581  ArrayType *arr;
3582 
3583  saop = op->d.hashedscalararrayop.saop;
3584 
3585  arr = DatumGetArrayTypeP(*op->resvalue);
3586  nitems = ArrayGetNItems(ARR_NDIM(arr), ARR_DIMS(arr));
3587 
3589  &typlen,
3590  &typbyval,
3591  &typalign);
3592 
3593  oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
3594 
3595  elements_tab = (ScalarArrayOpExprHashTable *)
3596  palloc0(offsetof(ScalarArrayOpExprHashTable, hash_fcinfo_data) +
3598  op->d.hashedscalararrayop.elements_tab = elements_tab;
3599  elements_tab->op = op;
3600 
3601  fmgr_info(saop->hashfuncid, &elements_tab->hash_finfo);
3602  fmgr_info_set_expr((Node *) saop, &elements_tab->hash_finfo);
3603 
3605  &elements_tab->hash_finfo,
3606  1,
3607  saop->inputcollid,
3608  NULL,
3609  NULL);
3610 
3611  /*
3612  * Create the hash table sizing it according to the number of elements
3613  * in the array. This does assume that the array has no duplicates.
3614  * If the array happens to contain many duplicate values then it'll
3615  * just mean that we sized the table a bit on the large side.
3616  */
3617  elements_tab->hashtab = saophash_create(CurrentMemoryContext, nitems,
3618  elements_tab);
3619 
3620  MemoryContextSwitchTo(oldcontext);
3621 
3622  s = (char *) ARR_DATA_PTR(arr);
3623  bitmap = ARR_NULLBITMAP(arr);
3624  bitmask = 1;
3625  for (int i = 0; i < nitems; i++)
3626  {
3627  /* Get array element, checking for NULL. */
3628  if (bitmap && (*bitmap & bitmask) == 0)
3629  {
3630  has_nulls = true;
3631  }
3632  else
3633  {
3634  Datum element;
3635 
3636  element = fetch_att(s, typbyval, typlen);
3637  s = att_addlength_pointer(s, typlen, s);
3638  s = (char *) att_align_nominal(s, typalign);
3639 
3640  saophash_insert(elements_tab->hashtab, element, &hashfound);
3641  }
3642 
3643  /* Advance bitmap pointer if any. */
3644  if (bitmap)
3645  {
3646  bitmask <<= 1;
3647  if (bitmask == 0x100)
3648  {
3649  bitmap++;
3650  bitmask = 1;
3651  }
3652  }
3653  }
3654 
3655  /*
3656  * Remember if we had any nulls so that we know if we need to execute
3657  * non-strict functions with a null lhs value if no match is found.
3658  */
3659  op->d.hashedscalararrayop.has_nulls = has_nulls;
3660  }
3661 
3662  /* Check the hash to see if we have a match. */
3663  hashfound = NULL != saophash_lookup(elements_tab->hashtab, scalar);
3664 
3665  /* the result depends on if the clause is an IN or NOT IN clause */
3666  if (inclause)
3667  result = BoolGetDatum(hashfound); /* IN */
3668  else
3669  result = BoolGetDatum(!hashfound); /* NOT IN */
3670 
3671  resultnull = false;
3672 
3673  /*
3674  * If we didn't find a match in the array, we still might need to handle
3675  * the possibility of null values. We didn't put any NULLs into the
3676  * hashtable, but instead marked if we found any when building the table
3677  * in has_nulls.
3678  */
3679  if (!hashfound && op->d.hashedscalararrayop.has_nulls)
3680  {
3681  if (strictfunc)
3682  {
3683 
3684  /*
3685  * We have nulls in the array so a non-null lhs and no match must
3686  * yield NULL.
3687  */
3688  result = (Datum) 0;
3689  resultnull = true;
3690  }
3691  else
3692  {
3693  /*
3694  * Execute function will null rhs just once.
3695  *
3696  * The hash lookup path will have scribbled on the lhs argument so
3697  * we need to set it up also (even though we entered this function
3698  * with it already set).
3699  */
3700  fcinfo->args[0].value = scalar;
3701  fcinfo->args[0].isnull = scalar_isnull;
3702  fcinfo->args[1].value = (Datum) 0;
3703  fcinfo->args[1].isnull = true;
3704 
3705  result = op->d.hashedscalararrayop.finfo->fn_addr(fcinfo);
3706  resultnull = fcinfo->isnull;
3707 
3708  /*
3709  * Reverse the result for NOT IN clauses since the above function
3710  * is the equality function and we need not-equals.
3711  */
3712  if (!inclause)
3713  result = !result;
3714  }
3715  }
3716 
3717  *op->resvalue = result;
3718  *op->resnull = resultnull;
3719 }
signed short int16
Definition: c.h:477
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:127
#define SizeForFunctionCallInfo(nargs)
Definition: fmgr.h:102
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#define fmgr_info_set_expr(expr, finfo)
Definition: fmgr.h:135
void get_typlenbyvalalign(Oid typid, int16 *typlen, bool *typbyval, char *typalign)
Definition: lsyscache.c:2229
char typalign
Definition: pg_type.h:176
static Datum BoolGetDatum(bool X)
Definition: postgres.h:102
static chr element(struct vars *v, const chr *startp, const chr *endp)
Definition: regc_locale.c:376
struct ExprEvalStep::@50::@82 hashedscalararrayop
Definition: nodes.h:129
bool isnull
Definition: postgres.h:77
FunctionCallInfoBaseData hash_fcinfo_data
struct ExprEvalStep * op
#define att_align_nominal(cur_offset, attalign)
Definition: tupmacs.h:129
#define att_addlength_pointer(cur_offset, attlen, attptr)
Definition: tupmacs.h:157
static Datum fetch_att(const void *T, bool attbyval, int attlen)
Definition: tupmacs.h:52

References FunctionCallInfoBaseData::args, ARR_DATA_PTR, ARR_DIMS, ARR_ELEMTYPE, ARR_NDIM, ARR_NULLBITMAP, ArrayGetNItems(), Assert(), att_addlength_pointer, att_align_nominal, BoolGetDatum(), CurrentMemoryContext, DatumGetArrayTypeP, ExprContext::ecxt_per_query_memory, element(), ExprEvalStep::elements_tab, fetch_att(), fmgr_info(), fmgr_info_set_expr, get_typlenbyvalalign(), ExprEvalStep::has_nulls, ScalarArrayOpExprHashTable::hash_fcinfo_data, ScalarArrayOpExprHashTable::hash_finfo, ScalarArrayOpExprHashTable::hashtab, i, ExprEvalStep::inclause, InitFunctionCallInfoData, FunctionCallInfoBaseData::isnull, NullableDatum::isnull, MemoryContextSwitchTo(), nitems, ScalarArrayOpExprHashTable::op, ExprEvalStep::op, palloc0(), ExprEvalStep::saop, SizeForFunctionCallInfo, typalign, ExprEvalStep::typbyval, ExprEvalStep::typlen, and NullableDatum::value.

Referenced by ExecInterpExpr().

◆ ExecEvalJsonConstructor()

void ExecEvalJsonConstructor ( ExprState state,
ExprEvalStep op,
ExprContext econtext 
)

Definition at line 3974 of file execExprInterp.c.

3976 {
3977  Datum res;
3978  JsonConstructorExprState *jcstate = op->d.json_constructor.jcstate;
3979  JsonConstructorExpr *ctor = jcstate->constructor;
3980  bool is_jsonb = ctor->returning->format->format_type == JS_FORMAT_JSONB;
3981  bool isnull = false;
3982 
3983  if (ctor->type == JSCTOR_JSON_ARRAY)
3984  res = (is_jsonb ?
3986  json_build_array_worker) (jcstate->nargs,
3987  jcstate->arg_values,
3988  jcstate->arg_nulls,
3989  jcstate->arg_types,
3990  jcstate->constructor->absent_on_null);
3991  else if (ctor->type == JSCTOR_JSON_OBJECT)
3992  res = (is_jsonb ?
3994  json_build_object_worker) (jcstate->nargs,
3995  jcstate->arg_values,
3996  jcstate->arg_nulls,
3997  jcstate->arg_types,
3998  jcstate->constructor->absent_on_null,
3999  jcstate->constructor->unique);
4000  else
4001  elog(ERROR, "invalid JsonConstructorExpr type %d", ctor->type);
4002 
4003  *op->resvalue = res;
4004  *op->resnull = isnull;
4005 }
Datum json_build_array_worker(int nargs, Datum *args, bool *nulls, Oid *types, bool absent_on_null)
Definition: json.c:1399
Datum json_build_object_worker(int nargs, Datum *args, bool *nulls, Oid *types, bool absent_on_null, bool unique_keys)
Definition: json.c:1286
Datum jsonb_build_array_worker(int nargs, Datum *args, bool *nulls, Oid *types, bool absent_on_null)
Definition: jsonb.c:1309
Datum jsonb_build_object_worker(int nargs, Datum *args, bool *nulls, Oid *types, bool absent_on_null, bool unique_keys)
Definition: jsonb.c:1224
@ JS_FORMAT_JSONB
Definition: primnodes.h:1565
@ JSCTOR_JSON_OBJECT
Definition: primnodes.h:1607
@ JSCTOR_JSON_ARRAY
Definition: primnodes.h:1608
struct ExprEvalStep::@50::@84 json_constructor
JsonConstructorExpr * constructor
Definition: execExpr.h:743
JsonReturning * returning
Definition: primnodes.h:1624
JsonConstructorType type
Definition: primnodes.h:1620
JsonFormatType format_type
Definition: primnodes.h:1576
JsonFormat * format
Definition: primnodes.h:1588

References JsonConstructorExpr::absent_on_null, JsonConstructorExprState::arg_nulls, JsonConstructorExprState::arg_types, JsonConstructorExprState::arg_values, JsonConstructorExprState::constructor, elog(), ERROR, JsonReturning::format, JsonFormat::format_type, ExprEvalStep::isnull, ExprEvalStep::jcstate, JS_FORMAT_JSONB, JSCTOR_JSON_ARRAY, JSCTOR_JSON_OBJECT, json_build_array_worker(), json_build_object_worker(), jsonb_build_array_worker(), jsonb_build_object_worker(), JsonConstructorExprState::nargs, ExprEvalStep::op, res, JsonConstructorExpr::returning, JsonConstructorExpr::type, and JsonConstructorExpr::unique.

Referenced by ExecInterpExpr().

◆ ExecEvalJsonIsPredicate()

void ExecEvalJsonIsPredicate ( ExprState state,
ExprEvalStep op 
)

Definition at line 4011 of file execExprInterp.c.

4012 {
4013  JsonIsPredicate *pred = op->d.is_json.pred;
4014  Datum js = *op->resvalue;
4015  Oid exprtype;
4016  bool res;
4017 
4018  if (*op->resnull)
4019  {
4020  *op->resvalue = BoolGetDatum(false);
4021  return;
4022  }
4023 
4024  exprtype = exprType(pred->expr);
4025 
4026  if (exprtype == TEXTOID || exprtype == JSONOID)
4027  {
4028  text *json = DatumGetTextP(js);
4029 
4030  if (pred->item_type == JS_TYPE_ANY)
4031  res = true;
4032  else
4033  {
4034  switch (json_get_first_token(json, false))
4035  {
4037  res = pred->item_type == JS_TYPE_OBJECT;
4038  break;
4040  res = pred->item_type == JS_TYPE_ARRAY;
4041  break;
4042  case JSON_TOKEN_STRING:
4043  case JSON_TOKEN_NUMBER:
4044  case JSON_TOKEN_TRUE:
4045  case JSON_TOKEN_FALSE:
4046  case JSON_TOKEN_NULL:
4047  res = pred->item_type == JS_TYPE_SCALAR;
4048  break;
4049  default:
4050  res = false;
4051  break;
4052  }
4053  }
4054 
4055  /*
4056  * Do full parsing pass only for uniqueness check or for JSON text
4057  * validation.
4058  */
4059  if (res && (pred->unique_keys || exprtype == TEXTOID))
4060  res = json_validate(json, pred->unique_keys, false);
4061  }
4062  else if (exprtype == JSONBOID)
4063  {
4064  if (pred->item_type == JS_TYPE_ANY)
4065  res = true;
4066  else
4067  {
4068  Jsonb *jb = DatumGetJsonbP(js);
4069 
4070  switch (pred->item_type)
4071  {
4072  case JS_TYPE_OBJECT:
4073  res = JB_ROOT_IS_OBJECT(jb);
4074  break;
4075  case JS_TYPE_ARRAY:
4076  res = JB_ROOT_IS_ARRAY(jb) && !JB_ROOT_IS_SCALAR(jb);
4077  break;
4078  case JS_TYPE_SCALAR:
4079  res = JB_ROOT_IS_ARRAY(jb) && JB_ROOT_IS_SCALAR(jb);
4080  break;
4081  default:
4082  res = false;
4083  break;
4084  }
4085  }
4086 
4087  /* Key uniqueness check is redundant for jsonb */
4088  }
4089  else
4090  res = false;
4091 
4092  *op->resvalue = BoolGetDatum(res);
4093 }
#define DatumGetTextP(X)
Definition: fmgr.h:332
bool json_validate(text *json, bool check_unique_keys, bool throw_error)
Definition: json.c:1728
@ JSON_TOKEN_FALSE
Definition: jsonapi.h:31
@ JSON_TOKEN_TRUE
Definition: jsonapi.h:30
@ JSON_TOKEN_NULL
Definition: jsonapi.h:32
@ JSON_TOKEN_OBJECT_START
Definition: jsonapi.h:24
@ JSON_TOKEN_NUMBER
Definition: jsonapi.h:23
@ JSON_TOKEN_STRING
Definition: jsonapi.h:22
@ JSON_TOKEN_ARRAY_START
Definition: jsonapi.h:26
static Jsonb * DatumGetJsonbP(Datum d)
Definition: jsonb.h:374
#define JB_ROOT_IS_OBJECT(jbp_)
Definition: jsonb.h:221
#define JB_ROOT_IS_ARRAY(jbp_)
Definition: jsonb.h:222
#define JB_ROOT_IS_SCALAR(jbp_)
Definition: jsonb.h:220
JsonTokenType json_get_first_token(text *json, bool throw_error)
Definition: jsonfuncs.c:5670
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:43
@ JS_TYPE_ANY
Definition: primnodes.h:1636
@ JS_TYPE_ARRAY
Definition: primnodes.h:1638
@ JS_TYPE_OBJECT
Definition: primnodes.h:1637
@ JS_TYPE_SCALAR
Definition: primnodes.h:1639
struct ExprEvalStep::@50::@94 is_json
JsonValueType item_type
Definition: primnodes.h:1651
Definition: jsonb.h:213
Definition: c.h:671

References BoolGetDatum(), DatumGetJsonbP(), DatumGetTextP, JsonIsPredicate::expr, exprType(), JsonIsPredicate::item_type, JB_ROOT_IS_ARRAY, JB_ROOT_IS_OBJECT, JB_ROOT_IS_SCALAR, JS_TYPE_ANY, JS_TYPE_ARRAY, JS_TYPE_OBJECT, JS_TYPE_SCALAR, json_get_first_token(), JSON_TOKEN_ARRAY_START, JSON_TOKEN_FALSE, JSON_TOKEN_NULL, JSON_TOKEN_NUMBER, JSON_TOKEN_OBJECT_START, JSON_TOKEN_STRING, JSON_TOKEN_TRUE, json_validate(), ExprEvalStep::op, ExprEvalStep::pred, res, and JsonIsPredicate::unique_keys.

Referenced by ExecInterpExpr().

◆ ExecEvalMinMax()

void ExecEvalMinMax ( ExprState state,
ExprEvalStep op 
)

Definition at line 2997 of file execExprInterp.c.

2998 {
2999  Datum *values = op->d.minmax.values;
3000  bool *nulls = op->d.minmax.nulls;
3001  FunctionCallInfo fcinfo = op->d.minmax.fcinfo_data;
3002  MinMaxOp operator = op->d.minmax.op;
3003 
3004  /* set at initialization */
3005  Assert(fcinfo->args[0].isnull == false);
3006  Assert(fcinfo->args[1].isnull == false);
3007 
3008  /* default to null result */
3009  *op->resnull = true;
3010 
3011  for (int off = 0; off < op->d.minmax.nelems; off++)
3012  {
3013  /* ignore NULL inputs */
3014  if (nulls[off])
3015  continue;
3016 
3017  if (*op->resnull)
3018  {
3019  /* first nonnull input, adopt value */
3020  *op->resvalue = values[off];
3021  *op->resnull = false;
3022  }
3023  else
3024  {
3025  int cmpresult;
3026 
3027  /* apply comparison function */
3028  fcinfo->args[0].value = *op->resvalue;
3029  fcinfo->args[1].value = values[off];
3030 
3031  fcinfo->isnull = false;
3032  cmpresult = DatumGetInt32(FunctionCallInvoke(fcinfo));
3033  if (fcinfo->isnull) /* probably should not happen */
3034  continue;
3035 
3036  if (cmpresult > 0 && operator == IS_LEAST)
3037  *op->resvalue = values[off];
3038  else if (cmpresult < 0 && operator == IS_GREATEST)
3039  *op->resvalue = values[off];
3040  }
3041  }
3042 }
static Datum values[MAXATTR]
Definition: bootstrap.c:156
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:172
static int32 DatumGetInt32(Datum X)
Definition: postgres.h:202
MinMaxOp
Definition: primnodes.h:1426
@ IS_LEAST
Definition: primnodes.h:1428
@ IS_GREATEST
Definition: primnodes.h:1427
struct ExprEvalStep::@50::@74 minmax

References FunctionCallInfoBaseData::args, Assert(), DatumGetInt32(), FunctionCallInvoke, IS_GREATEST, IS_LEAST, FunctionCallInfoBaseData::isnull, NullableDatum::isnull, ExprEvalStep::nulls, ExprEvalStep::op, NullableDatum::value, and values.

Referenced by ExecInterpExpr().

◆ ExecEvalNextValueExpr()

void ExecEvalNextValueExpr ( ExprState state,
ExprEvalStep op 
)

Definition at line 2594 of file execExprInterp.c.

2595 {
2596  int64 newval = nextval_internal(op->d.nextvalueexpr.seqid, false);
2597 
2598  switch (op->d.nextvalueexpr.seqtypid)
2599  {
2600  case INT2OID:
2601  *op->resvalue = Int16GetDatum((int16) newval);
2602  break;
2603  case INT4OID:
2604  *op->resvalue = Int32GetDatum((int32) newval);
2605  break;
2606  case INT8OID:
2607  *op->resvalue = Int64GetDatum((int64) newval);
2608  break;
2609  default:
2610  elog(ERROR, "unsupported sequence type %u",
2611  op->d.nextvalueexpr.seqtypid);
2612  }
2613  *op->resnull = false;
2614 }
Datum Int64GetDatum(int64 X)
Definition: fmgr.c:1778
#define newval
static Datum Int16GetDatum(int16 X)
Definition: postgres.h:172
int64 nextval_internal(Oid relid, bool check_permissions)
Definition: sequence.c:628
struct ExprEvalStep::@50::@68 nextvalueexpr

References elog(), ERROR, Int16GetDatum(), Int32GetDatum(), Int64GetDatum(), newval, nextval_internal(), and ExprEvalStep::op.

Referenced by ExecInterpExpr().

◆ ExecEvalParamExec()

void ExecEvalParamExec ( ExprState state,
ExprEvalStep op,
ExprContext econtext 
)

Definition at line 2452 of file execExprInterp.c.

2453 {
2454  ParamExecData *prm;
2455 
2456  prm = &(econtext->ecxt_param_exec_vals[op->d.param.paramid]);
2457  if (unlikely(prm->execPlan != NULL))
2458  {
2459  /* Parameter not evaluated yet, so go do it */
2460  ExecSetParamPlan(prm->execPlan, econtext);
2461  /* ExecSetParamPlan should have processed this param... */
2462  Assert(prm->execPlan == NULL);
2463  }
2464  *op->resvalue = prm->value;
2465  *op->resnull = prm->isnull;
2466 }
void ExecSetParamPlan(SubPlanState *node, ExprContext *econtext)
Definition: nodeSubplan.c:1092
ParamExecData * ecxt_param_exec_vals
Definition: execnodes.h:260
struct ExprEvalStep::@50::@62 param
bool isnull
Definition: params.h:150
Datum value
Definition: params.h:149
void * execPlan
Definition: params.h:148

References Assert(), ExprContext::ecxt_param_exec_vals, ParamExecData::execPlan, ExecSetParamPlan(), ParamExecData::isnull, ExprEvalStep::op, unlikely, and ParamExecData::value.

Referenced by ExecInterpExpr().

◆ ExecEvalParamExtern()

void ExecEvalParamExtern ( ExprState state,
ExprEvalStep op,
ExprContext econtext 
)

Definition at line 2474 of file execExprInterp.c.

2475 {
2476  ParamListInfo paramInfo = econtext->ecxt_param_list_info;
2477  int paramId = op->d.param.paramid;
2478 
2479  if (likely(paramInfo &&
2480  paramId > 0 && paramId <= paramInfo->numParams))
2481  {
2482  ParamExternData *prm;
2483  ParamExternData prmdata;
2484 
2485  /* give hook a chance in case parameter is dynamic */
2486  if (paramInfo->paramFetch != NULL)
2487  prm = paramInfo->paramFetch(paramInfo, paramId, false, &prmdata);
2488  else
2489  prm = &paramInfo->params[paramId - 1];
2490 
2491  if (likely(OidIsValid(prm->ptype)))
2492  {
2493  /* safety check in case hook did something unexpected */
2494  if (unlikely(prm->ptype != op->d.param.paramtype))
2495  ereport(ERROR,
2496  (errcode(ERRCODE_DATATYPE_MISMATCH),
2497  errmsg("type of parameter %d (%s) does not match that when preparing the plan (%s)",
2498  paramId,
2499  format_type_be(prm->ptype),
2500  format_type_be(op->d.param.paramtype))));
2501  *op->resvalue = prm->value;
2502  *op->resnull = prm->isnull;
2503  return;
2504  }
2505  }
2506 
2507  ereport(ERROR,
2508  (errcode(ERRCODE_UNDEFINED_OBJECT),
2509  errmsg("no value found for parameter %d", paramId)));
2510 }
#define likely(x)
Definition: c.h:294
#define OidIsValid(objectId)
Definition: c.h:759
ParamListInfo ecxt_param_list_info
Definition: execnodes.h:261
bool isnull
Definition: params.h:93
Datum value
Definition: params.h:92
ParamExternData params[FLEXIBLE_ARRAY_MEMBER]
Definition: params.h:125
ParamFetchHook paramFetch
Definition: params.h:112

References ExprContext::ecxt_param_list_info, ereport, errcode(), errmsg(), ERROR, format_type_be(), ParamExternData::isnull, likely, OidIsValid, ExprEvalStep::op, ParamListInfoData::paramFetch, ParamListInfoData::params, ParamExternData::ptype, unlikely, and ParamExternData::value.

Referenced by ExecInterpExpr().

◆ ExecEvalPreOrderedDistinctMulti()

bool ExecEvalPreOrderedDistinctMulti ( AggState aggstate,
AggStatePerTrans  pertrans 
)

Definition at line 4539 of file execExprInterp.c.

4540 {
4541  ExprContext *tmpcontext = aggstate->tmpcontext;
4542 
4543  for (int i = 0; i < pertrans->numTransInputs; i++)
4544  {
4545  pertrans->sortslot->tts_values[i] = pertrans->transfn_fcinfo->args[i + 1].value;
4546  pertrans->sortslot->tts_isnull[i] = pertrans->transfn_fcinfo->args[i + 1].isnull;
4547  }
4548 
4549  ExecClearTuple(pertrans->sortslot);
4550  pertrans->sortslot->tts_nvalid = pertrans->numInputs;
4551  ExecStoreVirtualTuple(pertrans->sortslot);
4552 
4553  tmpcontext->ecxt_outertuple = pertrans->sortslot;
4554  tmpcontext->ecxt_innertuple = pertrans->uniqslot;
4555 
4556  if (!pertrans->haslast ||
4557  !ExecQual(pertrans->equalfnMulti, tmpcontext))
4558  {
4559  if (pertrans->haslast)
4560  ExecClearTuple(pertrans->uniqslot);
4561 
4562  pertrans->haslast = true;
4563  ExecCopySlot(pertrans->uniqslot, pertrans->sortslot);
4564  return true;
4565  }
4566  return false;
4567 }
static bool ExecQual(ExprState *state, ExprContext *econtext)
Definition: executor.h:412
ExprState * equalfnMulti
Definition: nodeAgg.h:116
TupleTableSlot * uniqslot
Definition: nodeAgg.h:142
ExprContext * tmpcontext
Definition: execnodes.h:2392
bool * tts_isnull
Definition: tuptable.h:128
Datum * tts_values
Definition: tuptable.h:126
static TupleTableSlot * ExecCopySlot(TupleTableSlot *dstslot, TupleTableSlot *srcslot)
Definition: tuptable.h:483

References FunctionCallInfoBaseData::args, ExprContext::ecxt_innertuple, ExprContext::ecxt_outertuple, AggStatePerTransData::equalfnMulti, ExecClearTuple(), ExecCopySlot(), ExecQual(), ExecStoreVirtualTuple(), AggStatePerTransData::haslast, i, NullableDatum::isnull, AggStatePerTransData::numInputs, AggStatePerTransData::numTransInputs, ExprEvalStep::pertrans, AggStatePerTransData::sortslot, AggState::tmpcontext, AggStatePerTransData::transfn_fcinfo, TupleTableSlot::tts_isnull, TupleTableSlot::tts_nvalid, TupleTableSlot::tts_values, AggStatePerTransData::uniqslot, and NullableDatum::value.

Referenced by ExecInterpExpr().

◆ ExecEvalPreOrderedDistinctSingle()

bool ExecEvalPreOrderedDistinctSingle ( AggState aggstate,
AggStatePerTrans  pertrans 
)

Definition at line 4497 of file execExprInterp.c.

4498 {
4499  Datum value = pertrans->transfn_fcinfo->args[1].value;
4500  bool isnull = pertrans->transfn_fcinfo->args[1].isnull;
4501 
4502  if (!pertrans->haslast ||
4503  pertrans->lastisnull != isnull ||
4504  (!isnull && !DatumGetBool(FunctionCall2Coll(&pertrans->equalfnOne,
4505  pertrans->aggCollation,
4506  pertrans->lastdatum, value))))
4507  {
4508  if (pertrans->haslast && !pertrans->inputtypeByVal &&
4509  !pertrans->lastisnull)
4510  pfree(DatumGetPointer(pertrans->lastdatum));
4511 
4512  pertrans->haslast = true;
4513  if (!isnull)
4514  {
4515  MemoryContext oldContext;
4516 
4518 
4519  pertrans->lastdatum = datumCopy(value, pertrans->inputtypeByVal,
4520  pertrans->inputtypeLen);
4521 
4522  MemoryContextSwitchTo(oldContext);
4523  }
4524  else
4525  pertrans->lastdatum = (Datum) 0;
4526  pertrans->lastisnull = isnull;
4527  return true;
4528  }
4529 
4530  return false;
4531 }
Datum FunctionCall2Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2)
Definition: fmgr.c:1120
static struct @147 value
FmgrInfo equalfnOne
Definition: nodeAgg.h:115

References AggStatePerTransData::aggCollation, FunctionCallInfoBaseData::args, AggState::curaggcontext, datumCopy(), DatumGetBool(), DatumGetPointer(), ExprContext::ecxt_per_tuple_memory, AggStatePerTransData::equalfnOne, FunctionCall2Coll(), AggStatePerTransData::haslast, AggStatePerTransData::inputtypeByVal, AggStatePerTransData::inputtypeLen, ExprEvalStep::isnull, NullableDatum::isnull, AggStatePerTransData::lastdatum, AggStatePerTransData::lastisnull, MemoryContextSwitchTo(), ExprEvalStep::pertrans, pfree(), AggStatePerTransData::transfn_fcinfo, NullableDatum::value, and value.

Referenced by ExecInterpExpr().

◆ ExecEvalRow()

void ExecEvalRow ( ExprState state,
ExprEvalStep op 
)

Definition at line 2977 of file execExprInterp.c.

2978 {
2979  HeapTuple tuple;
2980 
2981  /* build tuple from evaluated field values */
2982  tuple = heap_form_tuple(op->d.row.tupdesc,
2983  op->d.row.elemvalues,
2984  op->d.row.elemnulls);
2985 
2986  *op->resvalue = HeapTupleGetDatum(tuple);
2987  *op->resnull = false;
2988 }
struct ExprEvalStep::@50::@71 row

References heap_form_tuple(), HeapTupleGetDatum(), and ExprEvalStep::op.

Referenced by ExecInterpExpr().

◆ ExecEvalRowNotNull()

void ExecEvalRowNotNull ( ExprState state,
ExprEvalStep op,
ExprContext econtext 
)

Definition at line 2629 of file execExprInterp.c.

2630 {
2631  ExecEvalRowNullInt(state, op, econtext, false);
2632 }
static void ExecEvalRowNullInt(ExprState *state, ExprEvalStep *op, ExprContext *econtext, bool checkisnull)

References ExecEvalRowNullInt(), and ExprEvalStep::op.

Referenced by ExecInterpExpr().

◆ ExecEvalRowNull()

void ExecEvalRowNull ( ExprState state,
ExprEvalStep op,
ExprContext econtext 
)

Definition at line 2620 of file execExprInterp.c.

2621 {
2622  ExecEvalRowNullInt(state, op, econtext, true);
2623 }

References ExecEvalRowNullInt(), and ExprEvalStep::op.

Referenced by ExecInterpExpr().

◆ ExecEvalScalarArrayOp()

void ExecEvalScalarArrayOp ( ExprState state,
ExprEvalStep op 
)

Definition at line 3340 of file execExprInterp.c.

3341 {
3342  FunctionCallInfo fcinfo = op->d.scalararrayop.fcinfo_data;
3343  bool useOr = op->d.scalararrayop.useOr;
3344  bool strictfunc = op->d.scalararrayop.finfo->fn_strict;
3345  ArrayType *arr;
3346  int nitems;
3347  Datum result;
3348  bool resultnull;
3349  int16 typlen;
3350  bool typbyval;
3351  char typalign;
3352  char *s;
3353  bits8 *bitmap;
3354  int bitmask;
3355 
3356  /*
3357  * If the array is NULL then we return NULL --- it's not very meaningful
3358  * to do anything else, even if the operator isn't strict.
3359  */
3360  if (*op->resnull)
3361  return;
3362 
3363  /* Else okay to fetch and detoast the array */
3364  arr = DatumGetArrayTypeP(*op->resvalue);
3365 
3366  /*
3367  * If the array is empty, we return either FALSE or TRUE per the useOr
3368  * flag. This is correct even if the scalar is NULL; since we would
3369  * evaluate the operator zero times, it matters not whether it would want
3370  * to return NULL.
3371  */
3372  nitems = ArrayGetNItems(ARR_NDIM(arr), ARR_DIMS(arr));
3373  if (nitems <= 0)
3374  {
3375  *op->resvalue = BoolGetDatum(!useOr);
3376  *op->resnull = false;
3377  return;
3378  }
3379 
3380  /*
3381  * If the scalar is NULL, and the function is strict, return NULL; no
3382  * point in iterating the loop.
3383  */
3384  if (fcinfo->args[0].isnull && strictfunc)
3385  {
3386  *op->resnull = true;
3387  return;
3388  }
3389 
3390  /*
3391  * We arrange to look up info about the element type only once per series
3392  * of calls, assuming the element type doesn't change underneath us.
3393  */
3394  if (op->d.scalararrayop.element_type != ARR_ELEMTYPE(arr))
3395  {
3397  &op->d.scalararrayop.typlen,
3398  &op->d.scalararrayop.typbyval,
3399  &op->d.scalararrayop.typalign);
3400  op->d.scalararrayop.element_type = ARR_ELEMTYPE(arr);
3401  }
3402 
3403  typlen = op->d.scalararrayop.typlen;
3404  typbyval = op->d.scalararrayop.typbyval;
3405  typalign = op->d.scalararrayop.typalign;
3406 
3407  /* Initialize result appropriately depending on useOr */
3408  result = BoolGetDatum(!useOr);
3409  resultnull = false;
3410 
3411  /* Loop over the array elements */
3412  s = (char *) ARR_DATA_PTR(arr);
3413  bitmap = ARR_NULLBITMAP(arr);
3414  bitmask = 1;
3415 
3416  for (int i = 0; i < nitems; i++)
3417  {
3418  Datum elt;
3419  Datum thisresult;
3420 
3421  /* Get array element, checking for NULL */
3422  if (bitmap && (*bitmap & bitmask) == 0)
3423  {
3424  fcinfo->args[1].value = (Datum) 0;
3425  fcinfo->args[1].isnull = true;
3426  }
3427  else
3428  {
3429  elt = fetch_att(s, typbyval, typlen);
3430  s = att_addlength_pointer(s, typlen, s);
3431  s = (char *) att_align_nominal(s, typalign);
3432  fcinfo->args[1].value = elt;
3433  fcinfo->args[1].isnull = false;
3434  }
3435 
3436  /* Call comparison function */
3437  if (fcinfo->args[1].isnull && strictfunc)
3438  {
3439  fcinfo->isnull = true;
3440  thisresult = (Datum) 0;
3441  }
3442  else
3443  {
3444  fcinfo->isnull = false;
3445  thisresult = op->d.scalararrayop.fn_addr(fcinfo);
3446  }
3447 
3448  /* Combine results per OR or AND semantics */
3449  if (fcinfo->isnull)
3450  resultnull = true;
3451  else if (useOr)
3452  {
3453  if (DatumGetBool(thisresult))
3454  {
3455  result = BoolGetDatum(true);
3456  resultnull = false;
3457  break; /* needn't look at any more elements */
3458  }
3459  }
3460  else
3461  {
3462  if (!DatumGetBool(thisresult))
3463  {
3464  result = BoolGetDatum(false);
3465  resultnull = false;
3466  break; /* needn't look at any more elements */
3467  }
3468  }
3469 
3470  /* advance bitmap pointer if any */
3471  if (bitmap)
3472  {
3473  bitmask <<= 1;
3474  if (bitmask == 0x100)
3475  {
3476  bitmap++;
3477  bitmask = 1;
3478  }
3479  }
3480  }
3481 
3482  *op->resvalue = result;
3483  *op->resnull = resultnull;
3484 }
struct ExprEvalStep::@50::@81 scalararrayop

References FunctionCallInfoBaseData::args, ARR_DATA_PTR, ARR_DIMS, ARR_ELEMTYPE, ARR_NDIM, ARR_NULLBITMAP, ArrayGetNItems(), att_addlength_pointer, att_align_nominal, BoolGetDatum(), DatumGetArrayTypeP, DatumGetBool(), fetch_att(), get_typlenbyvalalign(), i, FunctionCallInfoBaseData::isnull, NullableDatum::isnull, nitems, ExprEvalStep::op, typalign, ExprEvalStep::typbyval, ExprEvalStep::typlen, ExprEvalStep::useOr, and NullableDatum::value.

Referenced by ExecInterpExpr().

◆ ExecEvalSQLValueFunction()

void ExecEvalSQLValueFunction ( ExprState state,
ExprEvalStep op 
)

Definition at line 2516 of file execExprInterp.c.

2517 {
2518  LOCAL_FCINFO(fcinfo, 0);
2519  SQLValueFunction *svf = op->d.sqlvaluefunction.svf;
2520 
2521  *op->resnull = false;
2522 
2523  /*
2524  * Note: current_schema() can return NULL. current_user() etc currently
2525  * cannot, but might as well code those cases the same way for safety.
2526  */
2527  switch (svf->op)
2528  {
2529  case SVFOP_CURRENT_DATE:
2531  break;
2532  case SVFOP_CURRENT_TIME:
2533  case SVFOP_CURRENT_TIME_N:
2535  break;
2539  break;
2540  case SVFOP_LOCALTIME:
2541  case SVFOP_LOCALTIME_N:
2543  break;
2544  case SVFOP_LOCALTIMESTAMP:
2547  break;
2548  case SVFOP_CURRENT_ROLE:
2549  case SVFOP_CURRENT_USER:
2550  case SVFOP_USER:
2551  InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
2552  *op->resvalue = current_user(fcinfo);
2553  *op->resnull = fcinfo->isnull;
2554  break;
2555  case SVFOP_SESSION_USER:
2556  InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
2557  *op->resvalue = session_user(fcinfo);
2558  *op->resnull = fcinfo->isnull;
2559  break;
2560  case SVFOP_CURRENT_CATALOG:
2561  InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
2562  *op->resvalue = current_database(fcinfo);
2563  *op->resnull = fcinfo->isnull;
2564  break;
2565  case SVFOP_CURRENT_SCHEMA:
2566  InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
2567  *op->resvalue = current_schema(fcinfo);
2568  *op->resnull = fcinfo->isnull;
2569  break;
2570  }
2571 }
Datum current_database(PG_FUNCTION_ARGS)
Definition: misc.c:195
Timestamp GetSQLLocalTimestamp(int32 typmod)
Definition: timestamp.c:1615
TimestampTz GetSQLCurrentTimestamp(int32 typmod)
Definition: timestamp.c:1601
TimeTzADT * GetSQLCurrentTime(int32 typmod)
Definition: date.c:341
TimeADT GetSQLLocalTime(int32 typmod)
Definition: date.c:361
DateADT GetSQLCurrentDate(void)
Definition: date.c:308
static Datum DateADTGetDatum(DateADT X)
Definition: date.h:72
static Datum TimeTzADTPGetDatum(const TimeTzADT *X)
Definition: date.h:84
static Datum TimeADTGetDatum(TimeADT X)
Definition: date.h:78
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
Datum current_user(PG_FUNCTION_ARGS)
Definition: name.c:263
Datum session_user(PG_FUNCTION_ARGS)
Definition: name.c:269
Datum current_schema(PG_FUNCTION_ARGS)
Definition: name.c:279
@ SVFOP_CURRENT_CATALOG
Definition: primnodes.h:1474
@ SVFOP_LOCALTIME_N
Definition: primnodes.h:1467
@ SVFOP_CURRENT_TIMESTAMP
Definition: primnodes.h:1464
@ SVFOP_LOCALTIME
Definition: primnodes.h:1466
@ SVFOP_CURRENT_TIMESTAMP_N
Definition: primnodes.h:1465
@ SVFOP_CURRENT_ROLE
Definition: primnodes.h:1470
@ SVFOP_USER
Definition: primnodes.h:1472
@ SVFOP_CURRENT_SCHEMA
Definition: primnodes.h:1475
@ SVFOP_LOCALTIMESTAMP_N
Definition: primnodes.h:1469
@ SVFOP_CURRENT_DATE
Definition: primnodes.h:1461
@ SVFOP_CURRENT_TIME_N
Definition: primnodes.h:1463
@ SVFOP_CURRENT_TIME
Definition: primnodes.h:1462
@ SVFOP_LOCALTIMESTAMP
Definition: primnodes.h:1468
@ SVFOP_CURRENT_USER
Definition: primnodes.h:1471
@ SVFOP_SESSION_USER
Definition: primnodes.h:1473
struct ExprEvalStep::@50::@67 sqlvaluefunction
SQLValueFunctionOp op
Definition: primnodes.h:1481
static Datum TimestampTzGetDatum(TimestampTz X)
Definition: timestamp.h:52
static Datum TimestampGetDatum(Timestamp X)
Definition: timestamp.h:46

References current_database(), current_schema(), current_user(), DateADTGetDatum(), GetSQLCurrentDate(), GetSQLCurrentTime(), GetSQLCurrentTimestamp(), GetSQLLocalTime(), GetSQLLocalTimestamp(), InitFunctionCallInfoData, InvalidOid, LOCAL_FCINFO, ExprEvalStep::op, SQLValueFunction::op, session_user(), ExprEvalStep::svf, SVFOP_CURRENT_CATALOG, SVFOP_CURRENT_DATE, SVFOP_CURRENT_ROLE, SVFOP_CURRENT_SCHEMA, SVFOP_CURRENT_TIME, SVFOP_CURRENT_TIME_N, SVFOP_CURRENT_TIMESTAMP, SVFOP_CURRENT_TIMESTAMP_N, SVFOP_CURRENT_USER, SVFOP_LOCALTIME, SVFOP_LOCALTIME_N, SVFOP_LOCALTIMESTAMP, SVFOP_LOCALTIMESTAMP_N, SVFOP_SESSION_USER, SVFOP_USER, TimeADTGetDatum(), TimestampGetDatum(), TimestampTzGetDatum(), TimeTzADTPGetDatum(), and SQLValueFunction::typmod.

Referenced by ExecInterpExpr().

◆ ExecEvalStepOp()

ExprEvalOp ExecEvalStepOp ( ExprState state,
ExprEvalStep op 
)

Definition at line 2364 of file execExprInterp.c.

2365 {
2366 #if defined(EEO_USE_COMPUTED_GOTO)
2367  if (state->flags & EEO_FLAG_DIRECT_THREADED)
2368  {
2369  ExprEvalOpLookup key;
2370  ExprEvalOpLookup *res;
2371 
2372  key.opcode = (void *) op->opcode;
2373  res = bsearch(&key,
2374  reverse_dispatch_table,
2375  EEOP_LAST /* nmembers */ ,
2376  sizeof(ExprEvalOpLookup),
2377  dispatch_compare_ptr);
2378  Assert(res); /* unknown ops shouldn't get looked up */
2379  return res->op;
2380  }
2381 #endif
2382  return (ExprEvalOp) op->opcode;
2383 }
#define EEO_FLAG_DIRECT_THREADED
Definition: execExpr.h:30
intptr_t opcode
Definition: execExpr.h:275

References Assert(), EEO_FLAG_DIRECT_THREADED, EEOP_LAST, sort-test::key, ExprEvalStep::op, and res.

Referenced by CheckExprStillValid().

◆ ExecEvalSubPlan()

void ExecEvalSubPlan ( ExprState state,
ExprEvalStep op,
ExprContext econtext 
)

Definition at line 4131 of file execExprInterp.c.

4132 {
4133  SubPlanState *sstate = op->d.subplan.sstate;
4134 
4135  /* could potentially be nested, so make sure there's enough stack */
4137 
4138  *op->resvalue = ExecSubPlan(sstate, econtext, op->resnull);
4139 }
Datum ExecSubPlan(SubPlanState *node, ExprContext *econtext, bool *isNull)
Definition: nodeSubplan.c:62
void check_stack_depth(void)
Definition: postgres.c:3508
struct ExprEvalStep::@50::@88 subplan

References check_stack_depth(), ExecSubPlan(), ExprEvalStep::op, and ExprEvalStep::sstate.

Referenced by ExecInterpExpr().

◆ ExecEvalSysVar()

void ExecEvalSysVar ( ExprState state,
ExprEvalStep op,
ExprContext econtext,
TupleTableSlot slot 
)

Definition at line 4375 of file execExprInterp.c.

4377 {
4378  Datum d;
4379 
4380  /* slot_getsysattr has sufficient defenses against bad attnums */
4381  d = slot_getsysattr(slot,
4382  op->d.var.attnum,
4383  op->resnull);
4384  *op->resvalue = d;
4385  /* this ought to be unreachable, but it's cheap enough to check */
4386  if (unlikely(*op->resnull))
4387  elog(ERROR, "failed to fetch attribute from slot");
4388 }
static Datum slot_getsysattr(TupleTableSlot *slot, int attnum, bool *isnull)
Definition: tuptable.h:410

References ExprEvalStep::d, elog(), ERROR, ExprEvalStep::op, slot_getsysattr(), and unlikely.

Referenced by ExecInterpExpr().

◆ ExecEvalWholeRowVar()

void ExecEvalWholeRowVar ( ExprState state,
ExprEvalStep op,
ExprContext econtext 
)

Definition at line 4148 of file execExprInterp.c.

4149 {
4150  Var *variable = op->d.wholerow.var;
4151  TupleTableSlot *slot;
4152  TupleDesc output_tupdesc;
4153  MemoryContext oldcontext;
4154  HeapTupleHeader dtuple;
4155  HeapTuple tuple;
4156 
4157  /* This was checked by ExecInitExpr */
4158  Assert(variable->varattno == InvalidAttrNumber);
4159 
4160  /* Get the input slot we want */
4161  switch (variable->varno)
4162  {
4163  case INNER_VAR:
4164  /* get the tuple from the inner node */
4165  slot = econtext->ecxt_innertuple;
4166  break;
4167 
4168  case OUTER_VAR:
4169  /* get the tuple from the outer node */
4170  slot = econtext->ecxt_outertuple;
4171  break;
4172 
4173  /* INDEX_VAR is handled by default case */
4174 
4175  default:
4176  /* get the tuple from the relation being scanned */
4177  slot = econtext->ecxt_scantuple;
4178  break;
4179  }
4180 
4181  /* Apply the junkfilter if any */
4182  if (op->d.wholerow.junkFilter != NULL)
4183  slot = ExecFilterJunk(op->d.wholerow.junkFilter, slot);
4184 
4185  /*
4186  * If first time through, obtain tuple descriptor and check compatibility.
4187  *
4188  * XXX: It'd be great if this could be moved to the expression
4189  * initialization phase, but due to using slots that's currently not
4190  * feasible.
4191  */
4192  if (op->d.wholerow.first)
4193  {
4194  /* optimistically assume we don't need slow path */
4195  op->d.wholerow.slow = false;
4196 
4197  /*
4198  * If the Var identifies a named composite type, we must check that
4199  * the actual tuple type is compatible with it.
4200  */
4201  if (variable->vartype != RECORDOID)
4202  {
4203  TupleDesc var_tupdesc;
4204  TupleDesc slot_tupdesc;
4205 
4206  /*
4207  * We really only care about numbers of attributes and data types.
4208  * Also, we can ignore type mismatch on columns that are dropped
4209  * in the destination type, so long as (1) the physical storage
4210  * matches or (2) the actual column value is NULL. Case (1) is
4211  * helpful in some cases involving out-of-date cached plans, while
4212  * case (2) is expected behavior in situations such as an INSERT
4213  * into a table with dropped columns (the planner typically
4214  * generates an INT4 NULL regardless of the dropped column type).
4215  * If we find a dropped column and cannot verify that case (1)
4216  * holds, we have to use the slow path to check (2) for each row.
4217  *
4218  * If vartype is a domain over composite, just look through that
4219  * to the base composite type.
4220  */
4221  var_tupdesc = lookup_rowtype_tupdesc_domain(variable->vartype,
4222  -1, false);
4223 
4224  slot_tupdesc = slot->tts_tupleDescriptor;
4225 
4226  if (var_tupdesc->natts != slot_tupdesc->natts)
4227  ereport(ERROR,
4228  (errcode(ERRCODE_DATATYPE_MISMATCH),
4229  errmsg("table row type and query-specified row type do not match"),
4230  errdetail_plural("Table row contains %d attribute, but query expects %d.",
4231  "Table row contains %d attributes, but query expects %d.",
4232  slot_tupdesc->natts,
4233  slot_tupdesc->natts,
4234  var_tupdesc->natts)));
4235 
4236  for (int i = 0; i < var_tupdesc->natts; i++)
4237  {
4238  Form_pg_attribute vattr = TupleDescAttr(var_tupdesc, i);
4239  Form_pg_attribute sattr = TupleDescAttr(slot_tupdesc, i);
4240 
4241  if (vattr->atttypid == sattr->atttypid)
4242  continue; /* no worries */
4243  if (!vattr->attisdropped)
4244  ereport(ERROR,
4245  (errcode(ERRCODE_DATATYPE_MISMATCH),
4246  errmsg("table row type and query-specified row type do not match"),
4247  errdetail("Table has type %s at ordinal position %d, but query expects %s.",
4248  format_type_be(sattr->atttypid),
4249  i + 1,
4250  format_type_be(vattr->atttypid))));
4251 
4252  if (vattr->attlen != sattr->attlen ||
4253  vattr->attalign != sattr->attalign)
4254  op->d.wholerow.slow = true; /* need to check for nulls */
4255  }
4256 
4257  /*
4258  * Use the variable's declared rowtype as the descriptor for the
4259  * output values. In particular, we *must* absorb any
4260  * attisdropped markings.
4261  */
4262  oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
4263  output_tupdesc = CreateTupleDescCopy(var_tupdesc);
4264  MemoryContextSwitchTo(oldcontext);
4265 
4266  ReleaseTupleDesc(var_tupdesc);
4267  }
4268  else
4269  {
4270  /*
4271  * In the RECORD case, we use the input slot's rowtype as the
4272  * descriptor for the output values, modulo possibly assigning new
4273  * column names below.
4274  */
4275  oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
4276  output_tupdesc = CreateTupleDescCopy(slot->tts_tupleDescriptor);
4277  MemoryContextSwitchTo(oldcontext);
4278 
4279  /*
4280  * It's possible that the input slot is a relation scan slot and
4281  * so is marked with that relation's rowtype. But we're supposed
4282  * to be returning RECORD, so reset to that.
4283  */
4284  output_tupdesc->tdtypeid = RECORDOID;
4285  output_tupdesc->tdtypmod = -1;
4286 
4287  /*
4288  * We already got the correct physical datatype info above, but
4289  * now we should try to find the source RTE and adopt its column
4290  * aliases, since it's unlikely that the input slot has the
4291  * desired names.
4292  *
4293  * If we can't locate the RTE, assume the column names we've got
4294  * are OK. (As of this writing, the only cases where we can't
4295  * locate the RTE are in execution of trigger WHEN clauses, and
4296  * then the Var will have the trigger's relation's rowtype, so its
4297  * names are fine.) Also, if the creator of the RTE didn't bother
4298  * to fill in an eref field, assume our column names are OK. (This
4299  * happens in COPY, and perhaps other places.)
4300  */
4301  if (econtext->ecxt_estate &&
4302  variable->varno <= econtext->ecxt_estate->es_range_table_size)
4303  {
4304  RangeTblEntry *rte = exec_rt_fetch(variable->varno,
4305  econtext->ecxt_estate);
4306 
4307  if (rte->eref)
4308  ExecTypeSetColNames(output_tupdesc, rte->eref->colnames);
4309  }
4310  }
4311 
4312  /* Bless the tupdesc if needed, and save it in the execution state */
4313  op->d.wholerow.tupdesc = BlessTupleDesc(output_tupdesc);
4314 
4315  op->d.wholerow.first = false;
4316  }
4317 
4318  /*
4319  * Make sure all columns of the slot are accessible in the slot's
4320  * Datum/isnull arrays.
4321  */
4322  slot_getallattrs(slot);
4323 
4324  if (op->d.wholerow.slow)
4325  {
4326  /* Check to see if any dropped attributes are non-null */
4327  TupleDesc tupleDesc = slot->tts_tupleDescriptor;
4328  TupleDesc var_tupdesc = op->d.wholerow.tupdesc;
4329 
4330  Assert(var_tupdesc->natts == tupleDesc->natts);
4331 
4332  for (int i = 0; i < var_tupdesc->natts; i++)
4333  {
4334  Form_pg_attribute vattr = TupleDescAttr(var_tupdesc, i);
4335  Form_pg_attribute sattr = TupleDescAttr(tupleDesc, i);
4336 
4337  if (!vattr->attisdropped)
4338  continue; /* already checked non-dropped cols */
4339  if (slot->tts_isnull[i])
4340  continue; /* null is always okay */
4341  if (vattr->attlen != sattr->attlen ||
4342  vattr->attalign != sattr->attalign)
4343  ereport(ERROR,
4344  (errcode(ERRCODE_DATATYPE_MISMATCH),
4345  errmsg("table row type and query-specified row type do not match"),
4346  errdetail("Physical storage mismatch on dropped attribute at ordinal position %d.",
4347  i + 1)));
4348  }
4349  }
4350 
4351  /*
4352  * Build a composite datum, making sure any toasted fields get detoasted.
4353  *
4354  * (Note: it is critical that we not change the slot's state here.)
4355  */
4357  slot->tts_values,
4358  slot->tts_isnull);
4359  dtuple = tuple->t_data;
4360 
4361  /*
4362  * Label the datum with the composite type info we identified before.
4363  *
4364  * (Note: we could skip doing this by passing op->d.wholerow.tupdesc to
4365  * the tuple build step; but that seems a tad risky so let's not.)
4366  */
4367  HeapTupleHeaderSetTypeId(dtuple, op->d.wholerow.tupdesc->tdtypeid);
4368  HeapTupleHeaderSetTypMod(dtuple, op->d.wholerow.tupdesc->tdtypmod);
4369 
4370  *op->resvalue = PointerGetDatum(dtuple);
4371  *op->resnull = false;
4372 }
#define InvalidAttrNumber
Definition: attnum.h:23
int errdetail_plural(const char *fmt_singular, const char *fmt_plural, unsigned long n,...)
Definition: elog.c:1294
TupleTableSlot * ExecFilterJunk(JunkFilter *junkfilter, TupleTableSlot *slot)
Definition: execJunk.c:247
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:2072
void ExecTypeSetColNames(TupleDesc typeInfo, List *namesList)
Definition: execTuples.c:2031
static RangeTblEntry * exec_rt_fetch(Index rti, EState *estate)
Definition: executor.h:587
HeapTuple toast_build_flattened_tuple(TupleDesc tupleDesc, Datum *values, bool *isnull)
Definition: heaptoast.c:563
#define HeapTupleHeaderSetTypMod(tup, typmod)
Definition: htup_details.h:471
#define HeapTupleHeaderSetTypeId(tup, typeid)
Definition: htup_details.h:461
#define OUTER_VAR
Definition: primnodes.h:215
#define INNER_VAR
Definition: primnodes.h:214
List * colnames
Definition: primnodes.h:43
Index es_range_table_size
Definition: execnodes.h:619
struct EState * ecxt_estate
Definition: execnodes.h:285
struct ExprEvalStep::@50::@53 wholerow
Alias * eref
Definition: parsenodes.h:1200
int32 tdtypmod
Definition: tupdesc.h:83
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
Definition: primnodes.h:226
TupleDesc CreateTupleDescCopy(TupleDesc tupdesc)
Definition: tupdesc.c:111
#define ReleaseTupleDesc(tupdesc)
Definition: tupdesc.h:122
static void slot_getallattrs(TupleTableSlot *slot)
Definition: tuptable.h:362
TupleDesc lookup_rowtype_tupdesc_domain(Oid type_id, int32 typmod, bool noError)
Definition: typcache.c:1880

References Assert(), BlessTupleDesc(), Alias::colnames, CreateTupleDescCopy(), ExprContext::ecxt_estate, ExprContext::ecxt_innertuple, ExprContext::ecxt_outertuple, ExprContext::ecxt_per_query_memory, ExprContext::ecxt_scantuple, RangeTblEntry::eref, ereport, errcode(), errdetail(), errdetail_plural(), errmsg(), ERROR, EState::es_range_table_size, exec_rt_fetch(), ExecFilterJunk(), ExecTypeSetColNames(), format_type_be(), HeapTupleHeaderSetTypeId, HeapTupleHeaderSetTypMod, i, INNER_VAR, InvalidAttrNumber, lookup_rowtype_tupdesc_domain(), MemoryContextSwitchTo(), TupleDescData::natts, ExprEvalStep::op, OUTER_VAR, PointerGetDatum(), ReleaseTupleDesc, slot_getallattrs(), HeapTupleData::t_data, TupleDescData::tdtypeid, TupleDescData::tdtypmod, toast_build_flattened_tuple(), TupleTableSlot::tts_isnull, TupleTableSlot::tts_tupleDescriptor, TupleTableSlot::tts_values, and TupleDescAttr.

Referenced by ExecInterpExpr().

◆ ExecEvalXmlExpr()

void ExecEvalXmlExpr ( ExprState state,
ExprEvalStep op 
)

Definition at line 3759 of file execExprInterp.c.

3760 {
3761  XmlExpr *xexpr = op->d.xmlexpr.xexpr;
3762  Datum value;
3763 
3764  *op->resnull = true; /* until we get a result */
3765  *op->resvalue = (Datum) 0;
3766 
3767  switch (xexpr->op)
3768  {
3769  case IS_XMLCONCAT:
3770  {
3771  Datum *argvalue = op->d.xmlexpr.argvalue;
3772  bool *argnull = op->d.xmlexpr.argnull;
3773  List *values = NIL;
3774 
3775  for (int i = 0; i < list_length(xexpr->args); i++)
3776  {
3777  if (!argnull[i])
3778  values = lappend(values, DatumGetPointer(argvalue[i]));
3779  }
3780 
3781  if (values != NIL)
3782  {
3784  *op->resnull = false;
3785  }
3786  }
3787  break;
3788 
3789  case IS_XMLFOREST:
3790  {
3791  Datum *argvalue = op->d.xmlexpr.named_argvalue;
3792  bool *argnull = op->d.xmlexpr.named_argnull;
3794  ListCell *lc;
3795  ListCell *lc2;
3796  int i;
3797 
3798  initStringInfo(&buf);
3799 
3800  i = 0;
3801  forboth(lc, xexpr->named_args, lc2, xexpr->arg_names)
3802  {
3803  Expr *e = (Expr *) lfirst(lc);
3804  char *argname = strVal(lfirst(lc2));
3805 
3806  if (!argnull[i])
3807  {
3808  value = argvalue[i];
3809  appendStringInfo(&buf, "<%s>%s</%s>",
3810  argname,
3812  exprType((Node *) e), true),
3813  argname);
3814  *op->resnull = false;
3815  }
3816  i++;
3817  }
3818 
3819  if (!*op->resnull)
3820  {
3821  text *result;
3822 
3823  result = cstring_to_text_with_len(buf.data, buf.len);
3824  *op->resvalue = PointerGetDatum(result);
3825  }
3826 
3827  pfree(buf.data);
3828  }
3829  break;
3830 
3831  case IS_XMLELEMENT:
3832  *op->resvalue = PointerGetDatum(xmlelement(xexpr,
3833  op->d.xmlexpr.named_argvalue,
3834  op->d.xmlexpr.named_argnull,
3835  op->d.xmlexpr.argvalue,
3836  op->d.xmlexpr.argnull));
3837  *op->resnull = false;
3838  break;
3839 
3840  case IS_XMLPARSE:
3841  {
3842  Datum *argvalue = op->d.xmlexpr.argvalue;
3843  bool *argnull = op->d.xmlexpr.argnull;
3844  text *data;
3845  bool preserve_whitespace;
3846 
3847  /* arguments are known to be text, bool */
3848  Assert(list_length(xexpr->args) == 2);
3849 
3850  if (argnull[0])
3851  return;
3852  value = argvalue[0];
3854 
3855  if (argnull[1]) /* probably can't happen */
3856  return;
3857  value = argvalue[1];
3858  preserve_whitespace = DatumGetBool(value);
3859 
3861  xexpr->xmloption,
3862  preserve_whitespace));
3863  *op->resnull = false;
3864  }
3865  break;
3866 
3867  case IS_XMLPI:
3868  {
3869  text *arg;
3870  bool isnull;
3871 
3872  /* optional argument is known to be text */
3873  Assert(list_length(xexpr->args) <= 1);
3874 
3875  if (xexpr->args)
3876  {
3877  isnull = op->d.xmlexpr.argnull[0];
3878  if (isnull)
3879  arg = NULL;
3880  else
3881  arg = DatumGetTextPP(op->d.xmlexpr.argvalue[0]);
3882  }
3883  else
3884  {
3885  arg = NULL;
3886  isnull = false;
3887  }
3888 
3889  *op->resvalue = PointerGetDatum(xmlpi(xexpr->name,
3890  arg,
3891  isnull,
3892  op->resnull));
3893  }
3894  break;
3895 
3896  case IS_XMLROOT:
3897  {
3898  Datum *argvalue = op->d.xmlexpr.argvalue;
3899  bool *argnull = op->d.xmlexpr.argnull;
3900  xmltype *data;
3901  text *version;
3902  int standalone;
3903 
3904  /* arguments are known to be xml, text, int */
3905  Assert(list_length(xexpr->args) == 3);
3906 
3907  if (argnull[0])
3908  return;
3909  data = DatumGetXmlP(argvalue[0]);
3910 
3911  if (argnull[1])
3912  version = NULL;
3913  else
3914  version = DatumGetTextPP(argvalue[1]);
3915 
3916  Assert(!argnull[2]); /* always present */
3917  standalone = DatumGetInt32(argvalue[2]);
3918 
3920  version,
3921  standalone));
3922  *op->resnull = false;
3923  }
3924  break;
3925 
3926  case IS_XMLSERIALIZE:
3927  {
3928  Datum *argvalue = op->d.xmlexpr.argvalue;
3929  bool *argnull = op->d.xmlexpr.argnull;
3930 
3931  /* argument type is known to be xml */
3932  Assert(list_length(xexpr->args) == 1);
3933 
3934  if (argnull[0])
3935  return;
3936  value = argvalue[0];
3937 
3938  *op->resvalue =
3940  xexpr->xmloption,
3941  xexpr->indent));
3942  *op->resnull = false;
3943  }
3944  break;
3945 
3946  case IS_DOCUMENT:
3947  {
3948  Datum *argvalue = op->d.xmlexpr.argvalue;
3949  bool *argnull = op->d.xmlexpr.argnull;
3950 
3951  /* optional argument is known to be xml */
3952  Assert(list_length(xexpr->args) == 1);
3953 
3954  if (argnull[0])
3955  return;
3956  value = argvalue[0];
3957 
3958  *op->resvalue =
3960  *op->resnull = false;
3961  }
3962  break;
3963 
3964  default:
3965  elog(ERROR, "unrecognized XML operation");
3966  break;
3967  }
3968 }
#define DatumGetTextPP(X)
Definition: fmgr.h:292
List * lappend(List *list, void *datum)
Definition: list.c:338
void * arg
const void * data
#define lfirst(lc)
Definition: pg_list.h:172
static int list_length(const List *l)
Definition: pg_list.h:152
#define NIL
Definition: pg_list.h:68
#define forboth(cell1, list1, cell2, list2)
Definition: pg_list.h:467
static char * buf
Definition: pg_test_fsync.c:67
e
Definition: preproc-init.c:82
@ IS_DOCUMENT
Definition: primnodes.h:1512
@ IS_XMLFOREST
Definition: primnodes.h:1507
@ IS_XMLCONCAT
Definition: primnodes.h:1505
@ IS_XMLPI
Definition: primnodes.h:1509
@ IS_XMLPARSE
Definition: primnodes.h:1508
@ IS_XMLSERIALIZE
Definition: primnodes.h:1511
@ IS_XMLROOT
Definition: primnodes.h:1510
@ IS_XMLELEMENT
Definition: primnodes.h:1506
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:91
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
struct ExprEvalStep::@50::@83 xmlexpr
Definition: pg_list.h:54
List * args
Definition: primnodes.h:1533
bool indent
Definition: primnodes.h:1537
List * named_args
Definition: primnodes.h:1529
XmlExprOp op
Definition: primnodes.h:1525
#define strVal(v)
Definition: value.h:82
text * cstring_to_text_with_len(const char *s, int len)
Definition: varlena.c:194
xmltype * xmlconcat(List *args)
Definition: xml.c:522
text * xmltotext_with_options(xmltype *data, XmlOptionType xmloption_arg, bool indent)
Definition: xml.c:625
xmltype * xmlparse(text *data, XmlOptionType xmloption_arg, bool preserve_whitespace)
Definition: xml.c:929
bool xml_is_document(xmltype *arg)
Definition: xml.c:1065
xmltype * xmlpi(const char *target, text *arg, bool arg_is_null, bool *result_is_null)
Definition: xml.c:947
char * map_sql_value_to_xml_value(Datum value, Oid type, bool xml_escape_strings)
Definition: xml.c:2384
xmltype * xmlelement(XmlExpr *xexpr, Datum *named_argvalue, bool *named_argnull, Datum *argvalue, bool *argnull)
Definition: xml.c:805
xmltype * xmlroot(xmltype *data, text *version, int standalone)
Definition: xml.c:999
static xmltype * DatumGetXmlP(Datum X)
Definition: xml.h:51

References appendStringInfo(), arg, ExprEvalStep::argnull, XmlExpr::args, ExprEvalStep::argvalue, Assert(), BoolGetDatum(), buf, cstring_to_text_with_len(), data, DatumGetBool(), DatumGetInt32(), DatumGetPointer(), DatumGetTextPP, DatumGetXmlP(), elog(), ERROR, exprType(), forboth, i, XmlExpr::indent, initStringInfo(), IS_DOCUMENT, IS_XMLCONCAT, IS_XMLELEMENT, IS_XMLFOREST, IS_XMLPARSE, IS_XMLPI, IS_XMLROOT, IS_XMLSERIALIZE, ExprEvalStep::isnull, lappend(), lfirst, list_length(), map_sql_value_to_xml_value(), XmlExpr::named_args, NIL, ExprEvalStep::op, XmlExpr::op, pfree(), PointerGetDatum(), strVal, value, values, ExprEvalStep::xexpr, xml_is_document(), xmlconcat(), xmlelement(), xmlparse(), xmlpi(), xmlroot(), and xmltotext_with_options().

Referenced by ExecInterpExpr().

◆ ExecInterpExprStillValid()

Datum ExecInterpExprStillValid ( ExprState state,
ExprContext econtext,
bool isNull 
)

Definition at line 1858 of file execExprInterp.c.

1859 {
1860  /*
1861  * First time through, check whether attribute matches Var. Might not be
1862  * ok anymore, due to schema changes.
1863  */
1864  CheckExprStillValid(state, econtext);
1865 
1866  /* skip the check during further executions */
1867  state->evalfunc = (ExprStateEvalFunc) state->evalfunc_private;
1868 
1869  /* and actually execute */
1870  return state->evalfunc(state, econtext, isNull);
1871 }
void CheckExprStillValid(ExprState *state, ExprContext *econtext)
Datum(* ExprStateEvalFunc)(struct ExprState *expression, struct ExprContext *econtext, bool *isNull)
Definition: execnodes.h:69

References CheckExprStillValid().

Referenced by ExecReadyInterpretedExpr().

◆ ExecReadyInterpretedExpr()

void ExecReadyInterpretedExpr ( ExprState state)

Definition at line 235 of file execExprInterp.c.

236 {
237  /* Ensure one-time interpreter setup has been done */
239 
240  /* Simple validity checks on expression */
241  Assert(state->steps_len >= 1);
242  Assert(state->steps[state->steps_len - 1].opcode == EEOP_DONE);
243 
244  /*
245  * Don't perform redundant initialization. This is unreachable in current
246  * cases, but might be hit if there's additional expression evaluation
247  * methods that rely on interpreted execution to work.
248  */
250  return;
251 
252  /*
253  * First time through, check whether attribute matches Var. Might not be
254  * ok anymore, due to schema changes. We do that by setting up a callback
255  * that does checking on the first call, which then sets the evalfunc
256  * callback to the actual method of execution.
257  */
258  state->evalfunc = ExecInterpExprStillValid;
259 
260  /* DIRECT_THREADED should not already be set */
261  Assert((state->flags & EEO_FLAG_DIRECT_THREADED) == 0);
262 
263  /*
264  * There shouldn't be any errors before the expression is fully
265  * initialized, and even if so, it'd lead to the expression being
266  * abandoned. So we can set the flag now and save some code.
267  */
269 
270  /*
271  * Select fast-path evalfuncs for very simple expressions. "Starting up"
272  * the full interpreter is a measurable overhead for these, and these
273  * patterns occur often enough to be worth optimizing.
274  */
275  if (state->steps_len == 3)
276  {
277  ExprEvalOp step0 = state->steps[0].opcode;
278  ExprEvalOp step1 = state->steps[1].opcode;
279 
280  if (step0 == EEOP_INNER_FETCHSOME &&
281  step1 == EEOP_INNER_VAR)
282  {
283  state->evalfunc_private = (void *) ExecJustInnerVar;
284  return;
285  }
286  else if (step0 == EEOP_OUTER_FETCHSOME &&
287  step1 == EEOP_OUTER_VAR)
288  {
289  state->evalfunc_private = (void *) ExecJustOuterVar;
290  return;
291  }
292  else if (step0 == EEOP_SCAN_FETCHSOME &&
293  step1 == EEOP_SCAN_VAR)
294  {
295  state->evalfunc_private = (void *) ExecJustScanVar;
296  return;
297  }
298  else if (step0 == EEOP_INNER_FETCHSOME &&
299  step1 == EEOP_ASSIGN_INNER_VAR)
300  {
301  state->evalfunc_private = (void *) ExecJustAssignInnerVar;
302  return;
303  }
304  else if (step0 == EEOP_OUTER_FETCHSOME &&
305  step1 == EEOP_ASSIGN_OUTER_VAR)
306  {
307  state->evalfunc_private = (void *) ExecJustAssignOuterVar;
308  return;
309  }
310  else if (step0 == EEOP_SCAN_FETCHSOME &&
311  step1 == EEOP_ASSIGN_SCAN_VAR)
312  {
313  state->evalfunc_private = (void *) ExecJustAssignScanVar;
314  return;
315  }
316  else if (step0 == EEOP_CASE_TESTVAL &&
317  step1 == EEOP_FUNCEXPR_STRICT &&
318  state->steps[0].d.casetest.value)
319  {
320  state->evalfunc_private = (void *) ExecJustApplyFuncToCase;
321  return;
322  }
323  }
324  else if (state->steps_len == 2)
325  {
326  ExprEvalOp step0 = state->steps[0].opcode;
327 
328  if (step0 == EEOP_CONST)
329  {
330  state->evalfunc_private = (void *) ExecJustConst;
331  return;
332  }
333  else if (step0 == EEOP_INNER_VAR)
334  {
335  state->evalfunc_private = (void *) ExecJustInnerVarVirt;
336  return;
337  }
338  else if (step0 == EEOP_OUTER_VAR)
339  {
340  state->evalfunc_private = (void *) ExecJustOuterVarVirt;
341  return;
342  }
343  else if (step0 == EEOP_SCAN_VAR)
344  {
345  state->evalfunc_private = (void *) ExecJustScanVarVirt;
346  return;
347  }
348  else if (step0 == EEOP_ASSIGN_INNER_VAR)
349  {
350  state->evalfunc_private = (void *) ExecJustAssignInnerVarVirt;
351  return;
352  }
353  else if (step0 == EEOP_ASSIGN_OUTER_VAR)
354  {
355  state->evalfunc_private = (void *) ExecJustAssignOuterVarVirt;
356  return;
357  }
358  else if (step0 == EEOP_ASSIGN_SCAN_VAR)
359  {
360  state->evalfunc_private = (void *) ExecJustAssignScanVarVirt;
361  return;
362  }
363  }
364 
365 #if defined(EEO_USE_COMPUTED_GOTO)
366 
367  /*
368  * In the direct-threaded implementation, replace each opcode with the
369  * address to jump to. (Use ExecEvalStepOp() to get back the opcode.)
370  */
371  for (int off = 0; off < state->steps_len; off++)
372  {
373  ExprEvalStep *op = &state->steps[off];
374 
375  op->opcode = EEO_OPCODE(op->opcode);
376  }
377 
379 #endif /* EEO_USE_COMPUTED_GOTO */
380 
381  state->evalfunc_private = (void *) ExecInterpExpr;
382 }
static Datum ExecJustAssignInnerVarVirt(ExprState *state, ExprContext *econtext, bool *isnull)
static Datum ExecJustScanVarVirt(ExprState *state, ExprContext *econtext, bool *isnull)
static Datum ExecJustApplyFuncToCase(ExprState *state, ExprContext *econtext, bool *isnull)
Datum ExecInterpExprStillValid(ExprState *state, ExprContext *econtext, bool *isNull)
static Datum ExecJustAssignScanVar(ExprState *state, ExprContext *econtext, bool *isnull)
static Datum ExecJustInnerVarVirt(ExprState *state, ExprContext *econtext, bool *isnull)
static void ExecInitInterpreter(void)
static Datum ExecJustConst(ExprState *state, ExprContext *econtext, bool *isnull)
static Datum ExecJustOuterVar(ExprState *state, ExprContext *econtext, bool *isnull)
static Datum ExecJustInnerVar(ExprState *state, ExprContext *econtext, bool *isnull)
static Datum ExecJustAssignInnerVar(ExprState *state, ExprContext *econtext, bool *isnull)
static Datum ExecJustAssignScanVarVirt(ExprState *state, ExprContext *econtext, bool *isnull)
static Datum ExecJustAssignOuterVar(ExprState *state, ExprContext *econtext, bool *isnull)
static Datum ExecJustAssignOuterVarVirt(ExprState *state, ExprContext *econtext, bool *isnull)
static Datum ExecJustOuterVarVirt(ExprState *state, ExprContext *econtext, bool *isnull)
static Datum ExecJustScanVar(ExprState *state, ExprContext *econtext, bool *isnull)
static Datum ExecInterpExpr(ExprState *state, ExprContext *econtext, bool *isnull)
#define EEO_OPCODE(opcode)
#define EEO_FLAG_INTERPRETER_INITIALIZED
Definition: execExpr.h:28

References Assert(), EEO_FLAG_DIRECT_THREADED, EEO_FLAG_INTERPRETER_INITIALIZED, EEO_OPCODE, EEOP_ASSIGN_INNER_VAR, EEOP_ASSIGN_OUTER_VAR, EEOP_ASSIGN_SCAN_VAR, EEOP_CASE_TESTVAL, EEOP_CONST, EEOP_DONE, EEOP_FUNCEXPR_STRICT, EEOP_INNER_FETCHSOME, EEOP_INNER_VAR, EEOP_OUTER_FETCHSOME, EEOP_OUTER_VAR, EEOP_SCAN_FETCHSOME, EEOP_SCAN_VAR, ExecInitInterpreter(), ExecInterpExpr(), ExecInterpExprStillValid(), ExecJustApplyFuncToCase(), ExecJustAssignInnerVar(), ExecJustAssignInnerVarVirt(), ExecJustAssignOuterVar(), ExecJustAssignOuterVarVirt(), ExecJustAssignScanVar(), ExecJustAssignScanVarVirt(), ExecJustConst(), ExecJustInnerVar(), ExecJustInnerVarVirt(), ExecJustOuterVar(), ExecJustOuterVarVirt(), ExecJustScanVar(), ExecJustScanVarVirt(), and ExprEvalStep::op.

Referenced by ExecReadyExpr().

◆ ExprEvalPushStep()

void ExprEvalPushStep ( ExprState es,
const ExprEvalStep s 
)

Definition at line 2536 of file execExpr.c.

2537 {
2538  if (es->steps_alloc == 0)
2539  {
2540  es->steps_alloc = 16;
2541  es->steps = palloc(sizeof(ExprEvalStep) * es->steps_alloc);
2542  }
2543  else if (es->steps_alloc == es->steps_len)
2544  {
2545  es->steps_alloc *= 2;
2546  es->steps = repalloc(es->steps,
2547  sizeof(ExprEvalStep) * es->steps_alloc);
2548  }
2549 
2550  memcpy(&es->steps[es->steps_len++], s, sizeof(ExprEvalStep));
2551 }
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:1476
struct ExprEvalStep * steps
Definition: execnodes.h:101
int steps_alloc
Definition: execnodes.h:121
int steps_len
Definition: execnodes.h:120

References palloc(), repalloc(), ExprState::steps, ExprState::steps_alloc, and ExprState::steps_len.

Referenced by ExecBuildAggTrans(), ExecBuildAggTransCall(), ExecBuildGroupingEqual(), ExecBuildParamSetEqual(), ExecBuildProjectionInfo(), ExecBuildUpdateProjection(), ExecInitCoerceToDomain(), ExecInitExpr(), ExecInitExprRec(), ExecInitExprWithParams(), ExecInitQual(), ExecInitSubscriptingRef(), ExecPushExprSetupSteps(), and plpgsql_param_compile().

◆ StaticAssertDecl()

StaticAssertDecl ( sizeof(ExprEvalStep)<=  64,
"size of ExprEvalStep exceeds 64 bytes"   
)