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
 

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
 

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_AGGREF , EEOP_GROUPING_FUNC , EEOP_WINDOW_FUNC ,
  EEOP_SUBPLAN , EEOP_JSON_CONSTRUCTOR , EEOP_IS_JSON , EEOP_JSONEXPR ,
  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_ORDERED_TRANS_DATUM ,
  EEOP_AGG_ORDERED_TRANS_TUPLE , EEOP_LAST
}
 

Functions

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 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 ExecEvalJsonConstructor (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalJson (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
Datum ExecPrepareJsonItemCoercion (struct JsonbValue *item, JsonReturning *returning, struct JsonCoercionsState *coercions, struct JsonCoercionState **pjcstate)
 
bool ExecEvalJsonNeedsSubTransaction (JsonExpr *jsexpr, struct JsonCoercionsState *)
 
Datum ExecEvalExprPassingCaseValue (ExprState *estate, ExprContext *econtext, bool *isnull, Datum caseval_datum, bool caseval_isnull)
 
void ExecAggInitGroup (AggState *aggstate, AggStatePerTrans pertrans, AggStatePerGroup pergroup, ExprContext *aggcontext)
 
Datum ExecAggTransReparent (AggState *aggstate, AggStatePerTrans pertrans, Datum newValue, bool newValueIsNull, Datum oldValue, bool oldValueIsNull)
 
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

◆ 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_AGGREF 
EEOP_GROUPING_FUNC 
EEOP_WINDOW_FUNC 
EEOP_SUBPLAN 
EEOP_JSON_CONSTRUCTOR 
EEOP_IS_JSON 
EEOP_JSONEXPR 
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_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,
239  EEOP_AGGREF,
242  EEOP_SUBPLAN,
244  EEOP_IS_JSON,
246 
247  /* aggregation related nodes */
261 
262  /* non-existent operation, used e.g. to check array lengths */
263  EEOP_LAST
264 } ExprEvalOp;
ExprEvalOp
Definition: execExpr.h:66
@ EEOP_ASSIGN_TMP
Definition: execExpr.h:98
@ EEOP_SUBPLAN
Definition: execExpr.h:242
@ 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:239
@ EEOP_INNER_VAR
Definition: execExpr.h:76
@ EEOP_AGG_PLAIN_PERGROUP_NULLCHECK
Definition: execExpr.h:252
@ EEOP_ROWCOMPARE_FINAL
Definition: execExpr.h:188
@ EEOP_AGG_STRICT_DESERIALIZE
Definition: execExpr.h:248
@ EEOP_IOCOERCE
Definition: execExpr.h:170
@ EEOP_GROUPING_FUNC
Definition: execExpr.h:240
@ 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:258
@ EEOP_QUAL
Definition: execExpr.h:134
@ EEOP_AGG_PLAIN_TRANS_BYVAL
Definition: execExpr.h:255
@ 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:241
@ 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_JSONEXPR
Definition: execExpr.h:245
@ EEOP_BOOL_OR_STEP_FIRST
Definition: execExpr.h:126
@ EEOP_XMLEXPR
Definition: execExpr.h:238
@ EEOP_AGG_STRICT_INPUT_CHECK_NULLS
Definition: execExpr.h:251
@ 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:250
@ 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:249
@ EEOP_LAST
Definition: execExpr.h:263
@ EEOP_DISTINCT
Definition: execExpr.h:171
@ EEOP_JUMP_IF_NOT_TRUE
Definition: execExpr.h:142
@ EEOP_FUNCEXPR_FUSAGE
Definition: execExpr.h:112
@ 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:259
@ 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:257
@ 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:253
@ EEOP_PARAM_EXEC
Definition: execExpr.h:159
@ EEOP_JSON_CONSTRUCTOR
Definition: execExpr.h:243
@ EEOP_AGG_PLAIN_TRANS_STRICT_BYVAL
Definition: execExpr.h:254
@ 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:256
@ EEOP_HASHED_SCALARARRAYOP
Definition: execExpr.h:237
@ EEOP_OUTER_VAR
Definition: execExpr.h:77
@ EEOP_AGG_ORDERED_TRANS_TUPLE
Definition: execExpr.h:260
@ EEOP_SCAN_FETCHSOME
Definition: execExpr.h:73
@ EEOP_IS_JSON
Definition: execExpr.h:244

Function Documentation

◆ CheckExprStillValid()

void CheckExprStillValid ( ExprState state,
ExprContext econtext 
)

Definition at line 1864 of file execExprInterp.c.

1865 {
1866  TupleTableSlot *innerslot;
1867  TupleTableSlot *outerslot;
1868  TupleTableSlot *scanslot;
1869 
1870  innerslot = econtext->ecxt_innertuple;
1871  outerslot = econtext->ecxt_outertuple;
1872  scanslot = econtext->ecxt_scantuple;
1873 
1874  for (int i = 0; i < state->steps_len; i++)
1875  {
1876  ExprEvalStep *op = &state->steps[i];
1877 
1878  switch (ExecEvalStepOp(state, op))
1879  {
1880  case EEOP_INNER_VAR:
1881  {
1882  int attnum = op->d.var.attnum;
1883 
1884  CheckVarSlotCompatibility(innerslot, attnum + 1, op->d.var.vartype);
1885  break;
1886  }
1887 
1888  case EEOP_OUTER_VAR:
1889  {
1890  int attnum = op->d.var.attnum;
1891 
1892  CheckVarSlotCompatibility(outerslot, attnum + 1, op->d.var.vartype);
1893  break;
1894  }
1895 
1896  case EEOP_SCAN_VAR:
1897  {
1898  int attnum = op->d.var.attnum;
1899 
1900  CheckVarSlotCompatibility(scanslot, attnum + 1, op->d.var.vartype);
1901  break;
1902  }
1903  default:
1904  break;
1905  }
1906  }
1907 }
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:83
TupleTableSlot * ecxt_innertuple
Definition: execnodes.h:234
TupleTableSlot * ecxt_scantuple
Definition: execnodes.h:232
TupleTableSlot * ecxt_outertuple
Definition: execnodes.h:236
struct ExprEvalStep::@52::@54 var
union ExprEvalStep::@52 d
Definition: regguts.h:318

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().

◆ ExecAggInitGroup()

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

Definition at line 4319 of file execExprInterp.c.

4321 {
4322  FunctionCallInfo fcinfo = pertrans->transfn_fcinfo;
4323  MemoryContext oldContext;
4324 
4325  /*
4326  * We must copy the datum into aggcontext if it is pass-by-ref. We do not
4327  * need to pfree the old transValue, since it's NULL. (We already checked
4328  * that the agg's input type is binary-compatible with its transtype, so
4329  * straight copy here is OK.)
4330  */
4331  oldContext = MemoryContextSwitchTo(aggcontext->ecxt_per_tuple_memory);
4332  pergroup->transValue = datumCopy(fcinfo->args[1].value,
4333  pertrans->transtypeByVal,
4334  pertrans->transtypeLen);
4335  pergroup->transValueIsNull = false;
4336  pergroup->noTransValue = false;
4337  MemoryContextSwitchTo(oldContext);
4338 }
Datum datumCopy(Datum value, bool typByVal, int typLen)
Definition: datum.c:132
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
FunctionCallInfo transfn_fcinfo
Definition: nodeAgg.h:162
MemoryContext ecxt_per_tuple_memory
Definition: execnodes.h:240
NullableDatum args[FLEXIBLE_ARRAY_MEMBER]
Definition: fmgr.h:95
Datum value
Definition: postgres.h:422

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().

◆ ExecAggTransReparent()

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

Definition at line 4347 of file execExprInterp.c.

4350 {
4351  Assert(newValue != oldValue);
4352 
4353  if (!newValueIsNull)
4354  {
4356  if (DatumIsReadWriteExpandedObject(newValue,
4357  false,
4358  pertrans->transtypeLen) &&
4359  MemoryContextGetParent(DatumGetEOHP(newValue)->eoh_context) == CurrentMemoryContext)
4360  /* do nothing */ ;
4361  else
4362  newValue = datumCopy(newValue,
4363  pertrans->transtypeByVal,
4364  pertrans->transtypeLen);
4365  }
4366  else
4367  {
4368  /*
4369  * Ensure that AggStatePerGroup->transValue ends up being 0, so
4370  * callers can safely compare newValue/oldValue without having to
4371  * check their respective nullness.
4372  */
4373  newValue = (Datum) 0;
4374  }
4375 
4376  if (!oldValueIsNull)
4377  {
4378  if (DatumIsReadWriteExpandedObject(oldValue,
4379  false,
4380  pertrans->transtypeLen))
4381  DeleteExpandedObject(oldValue);
4382  else
4383  pfree(DatumGetPointer(oldValue));
4384  }
4385 
4386  return newValue;
4387 }
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:1175
MemoryContext CurrentMemoryContext
Definition: mcxt.c:42
MemoryContext MemoryContextGetParent(MemoryContext context)
Definition: mcxt.c:446
uintptr_t Datum
Definition: postgres.h:411
#define DatumGetPointer(X)
Definition: postgres.h:593
ExprContext * curaggcontext
Definition: execnodes.h:2341

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().

◆ ExecEvalAggOrderedTransDatum()

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

Definition at line 4393 of file execExprInterp.c.

4395 {
4396  AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
4397  int setno = op->d.agg_trans.setno;
4398 
4399  tuplesort_putdatum(pertrans->sortstates[setno],
4400  *op->resvalue, *op->resnull);
4401 }
Tuplesortstate ** sortstates
Definition: nodeAgg.h:154
struct ExprEvalStep::@52::@93 agg_trans
Datum * resvalue
Definition: execExpr.h:277
bool * resnull
Definition: execExpr.h:278
void tuplesort_putdatum(Tuplesortstate *state, Datum val, bool isNull)
Definition: tuplesort.c:1961

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 4407 of file execExprInterp.c.

4409 {
4410  AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
4411  int setno = op->d.agg_trans.setno;
4412 
4413  ExecClearTuple(pertrans->sortslot);
4414  pertrans->sortslot->tts_nvalid = pertrans->numInputs;
4415  ExecStoreVirtualTuple(pertrans->sortslot);
4416  tuplesort_puttupleslot(pertrans->sortstates[setno], pertrans->sortslot);
4417 }
TupleTableSlot * ExecStoreVirtualTuple(TupleTableSlot *slot)
Definition: execTuples.c:1552
TupleTableSlot * sortslot
Definition: nodeAgg.h:136
AttrNumber tts_nvalid
Definition: tuptable.h:121
void tuplesort_puttupleslot(Tuplesortstate *state, TupleTableSlot *slot)
Definition: tuplesort.c:1840
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:425

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 2917 of file execExprInterp.c.

2918 {
2919  Datum arraydatum;
2920 
2921  /* NULL array -> NULL result */
2922  if (*op->resnull)
2923  return;
2924 
2925  arraydatum = *op->resvalue;
2926 
2927  /*
2928  * If it's binary-compatible, modify the element type in the array header,
2929  * but otherwise leave the array as we received it.
2930  */
2931  if (op->d.arraycoerce.elemexprstate == NULL)
2932  {
2933  /* Detoast input array if necessary, and copy in any case */
2934  ArrayType *array = DatumGetArrayTypePCopy(arraydatum);
2935 
2936  ARR_ELEMTYPE(array) = op->d.arraycoerce.resultelemtype;
2937  *op->resvalue = PointerGetDatum(array);
2938  return;
2939  }
2940 
2941  /*
2942  * Use array_map to apply the sub-expression to each array element.
2943  */
2944  *op->resvalue = array_map(arraydatum,
2945  op->d.arraycoerce.elemexprstate,
2946  econtext,
2947  op->d.arraycoerce.resultelemtype,
2948  op->d.arraycoerce.amstate);
2949 }
#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:3159
#define PointerGetDatum(X)
Definition: postgres.h:600
struct ExprEvalStep::@52::@72 arraycoerce

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

Referenced by ExecInterpExpr().

◆ ExecEvalArrayExpr()

void ExecEvalArrayExpr ( ExprState state,
ExprEvalStep op 
)

Definition at line 2708 of file execExprInterp.c.

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

References 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, MAXDIM, ArrayType::ndim, ExprEvalStep::nelems, ExprEvalStep::op, palloc(), PointerGetDatum, and SET_VARSIZE.

Referenced by ExecInterpExpr().

◆ ExecEvalConstraintCheck()

void ExecEvalConstraintCheck ( ExprState state,
ExprEvalStep op 
)

Definition at line 3706 of file execExprInterp.c.

3707 {
3708  if (!*op->d.domaincheck.checknull &&
3709  !DatumGetBool(*op->d.domaincheck.checkvalue))
3710  ereport(ERROR,
3711  (errcode(ERRCODE_CHECK_VIOLATION),
3712  errmsg("value for domain %s violates check constraint \"%s\"",
3713  format_type_be(op->d.domaincheck.resulttype),
3714  op->d.domaincheck.constraintname),
3715  errdomainconstraint(op->d.domaincheck.resulttype,
3716  op->d.domaincheck.constraintname)));
3717 }
int errdomainconstraint(Oid datatypeOid, const char *conname)
Definition: domains.c:384
#define DatumGetBool(X)
Definition: postgres.h:437
struct ExprEvalStep::@52::@81 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 3692 of file execExprInterp.c.

3693 {
3694  if (*op->resnull)
3695  ereport(ERROR,
3696  (errcode(ERRCODE_NOT_NULL_VIOLATION),
3697  errmsg("domain %s does not allow null values",
3698  format_type_be(op->d.domaincheck.resulttype)),
3699  errdatatype(op->d.domaincheck.resulttype)));
3700 }
int errdatatype(Oid datatypeOid)
Definition: domains.c:360

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 3226 of file execExprInterp.c.

3227 {
3228  HeapTuple result;
3229  Datum tupDatum;
3230  HeapTupleHeader tuple;
3231  HeapTupleData tmptup;
3232  TupleDesc indesc,
3233  outdesc;
3234  bool changed = false;
3235 
3236  /* NULL in -> NULL out */
3237  if (*op->resnull)
3238  return;
3239 
3240  tupDatum = *op->resvalue;
3241  tuple = DatumGetHeapTupleHeader(tupDatum);
3242 
3243  /*
3244  * Lookup tupdescs if first time through or if type changes. We'd better
3245  * pin them since type conversion functions could do catalog lookups and
3246  * hence cause cache invalidation.
3247  */
3248  indesc = get_cached_rowtype(op->d.convert_rowtype.inputtype, -1,
3249  op->d.convert_rowtype.incache,
3250  &changed);
3251  IncrTupleDescRefCount(indesc);
3252  outdesc = get_cached_rowtype(op->d.convert_rowtype.outputtype, -1,
3253  op->d.convert_rowtype.outcache,
3254  &changed);
3255  IncrTupleDescRefCount(outdesc);
3256 
3257  /*
3258  * We used to be able to assert that incoming tuples are marked with
3259  * exactly the rowtype of indesc. However, now that ExecEvalWholeRowVar
3260  * might change the tuples' marking to plain RECORD due to inserting
3261  * aliases, we can only make this weak test:
3262  */
3263  Assert(HeapTupleHeaderGetTypeId(tuple) == indesc->tdtypeid ||
3264  HeapTupleHeaderGetTypeId(tuple) == RECORDOID);
3265 
3266  /* if first time through, or after change, initialize conversion map */
3267  if (changed)
3268  {
3269  MemoryContext old_cxt;
3270 
3271  /* allocate map in long-lived memory context */
3272  old_cxt = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
3273 
3274  /* prepare map from old to new attribute numbers */
3275  op->d.convert_rowtype.map = convert_tuples_by_name(indesc, outdesc);
3276 
3277  MemoryContextSwitchTo(old_cxt);
3278  }
3279 
3280  /* Following steps need a HeapTuple not a bare HeapTupleHeader */
3281  tmptup.t_len = HeapTupleHeaderGetDatumLength(tuple);
3282  tmptup.t_data = tuple;
3283 
3284  if (op->d.convert_rowtype.map != NULL)
3285  {
3286  /* Full conversion with attribute rearrangement needed */
3287  result = execute_attr_map_tuple(&tmptup, op->d.convert_rowtype.map);
3288  /* Result already has appropriate composite-datum header fields */
3289  *op->resvalue = HeapTupleGetDatum(result);
3290  }
3291  else
3292  {
3293  /*
3294  * The tuple is physically compatible as-is, but we need to insert the
3295  * destination rowtype OID in its composite-datum header field, so we
3296  * have to copy it anyway. heap_copy_tuple_as_datum() is convenient
3297  * for this since it will both make the physical copy and insert the
3298  * correct composite header fields. Note that we aren't expecting to
3299  * have to flatten any toasted fields: the input was a composite
3300  * datum, so it shouldn't contain any. So heap_copy_tuple_as_datum()
3301  * is overkill here, but its check for external fields is cheap.
3302  */
3303  *op->resvalue = heap_copy_tuple_as_datum(&tmptup, outdesc);
3304  }
3305 
3306  DecrTupleDescRefCount(indesc);
3307  DecrTupleDescRefCount(outdesc);
3308 }
static TupleDesc get_cached_rowtype(Oid type_id, int32 typmod, ExprEvalRowtypeCache *rowcache, bool *changed)
#define DatumGetHeapTupleHeader(X)
Definition: fmgr.h:295
#define HeapTupleGetDatum(tuple)
Definition: funcapi.h:220
Datum heap_copy_tuple_as_datum(HeapTuple tuple, TupleDesc tupleDesc)
Definition: heaptuple.c:984
#define HeapTupleHeaderGetTypeId(tup)
Definition: htup_details.h:452
#define HeapTupleHeaderGetDatumLength(tup)
Definition: htup_details.h:446
MemoryContext ecxt_per_query_memory
Definition: execnodes.h:239
struct ExprEvalStep::@52::@82 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:139
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 2569 of file execExprInterp.c.

2570 {
2571  ereport(ERROR,
2572  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2573  errmsg("WHERE CURRENT OF is not supported for this table type")));
2574 }

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

Referenced by ExecInterpExpr().

◆ ExecEvalExprPassingCaseValue()

Datum ExecEvalExprPassingCaseValue ( ExprState estate,
ExprContext econtext,
bool isnull,
Datum  caseval_datum,
bool  caseval_isnull 
)

◆ ExecEvalFieldSelect()

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

Definition at line 3031 of file execExprInterp.c.

3032 {
3033  AttrNumber fieldnum = op->d.fieldselect.fieldnum;
3034  Datum tupDatum;
3035  HeapTupleHeader tuple;
3036  Oid tupType;
3037  int32 tupTypmod;
3038  TupleDesc tupDesc;
3039  Form_pg_attribute attr;
3040  HeapTupleData tmptup;
3041 
3042  /* NULL record -> NULL result */
3043  if (*op->resnull)
3044  return;
3045 
3046  tupDatum = *op->resvalue;
3047 
3048  /* We can special-case expanded records for speed */
3050  {
3052 
3053  Assert(erh->er_magic == ER_MAGIC);
3054 
3055  /* Extract record's TupleDesc */
3056  tupDesc = expanded_record_get_tupdesc(erh);
3057 
3058  /*
3059  * Find field's attr record. Note we don't support system columns
3060  * here: a datum tuple doesn't have valid values for most of the
3061  * interesting system columns anyway.
3062  */
3063  if (fieldnum <= 0) /* should never happen */
3064  elog(ERROR, "unsupported reference to system column %d in FieldSelect",
3065  fieldnum);
3066  if (fieldnum > tupDesc->natts) /* should never happen */
3067  elog(ERROR, "attribute number %d exceeds number of columns %d",
3068  fieldnum, tupDesc->natts);
3069  attr = TupleDescAttr(tupDesc, fieldnum - 1);
3070 
3071  /* Check for dropped column, and force a NULL result if so */
3072  if (attr->attisdropped)
3073  {
3074  *op->resnull = true;
3075  return;
3076  }
3077 
3078  /* Check for type mismatch --- possible after ALTER COLUMN TYPE? */
3079  /* As in CheckVarSlotCompatibility, we should but can't check typmod */
3080  if (op->d.fieldselect.resulttype != attr->atttypid)
3081  ereport(ERROR,
3082  (errcode(ERRCODE_DATATYPE_MISMATCH),
3083  errmsg("attribute %d has wrong type", fieldnum),
3084  errdetail("Table has type %s, but query expects %s.",
3085  format_type_be(attr->atttypid),
3086  format_type_be(op->d.fieldselect.resulttype))));
3087 
3088  /* extract the field */
3089  *op->resvalue = expanded_record_get_field(erh, fieldnum,
3090  op->resnull);
3091  }
3092  else
3093  {
3094  /* Get the composite datum and extract its type fields */
3095  tuple = DatumGetHeapTupleHeader(tupDatum);
3096 
3097  tupType = HeapTupleHeaderGetTypeId(tuple);
3098  tupTypmod = HeapTupleHeaderGetTypMod(tuple);
3099 
3100  /* Lookup tupdesc if first time through or if type changes */
3101  tupDesc = get_cached_rowtype(tupType, tupTypmod,
3102  &op->d.fieldselect.rowcache, NULL);
3103 
3104  /*
3105  * Find field's attr record. Note we don't support system columns
3106  * here: a datum tuple doesn't have valid values for most of the
3107  * interesting system columns anyway.
3108  */
3109  if (fieldnum <= 0) /* should never happen */
3110  elog(ERROR, "unsupported reference to system column %d in FieldSelect",
3111  fieldnum);
3112  if (fieldnum > tupDesc->natts) /* should never happen */
3113  elog(ERROR, "attribute number %d exceeds number of columns %d",
3114  fieldnum, tupDesc->natts);
3115  attr = TupleDescAttr(tupDesc, fieldnum - 1);
3116 
3117  /* Check for dropped column, and force a NULL result if so */
3118  if (attr->attisdropped)
3119  {
3120  *op->resnull = true;
3121  return;
3122  }
3123 
3124  /* Check for type mismatch --- possible after ALTER COLUMN TYPE? */
3125  /* As in CheckVarSlotCompatibility, we should but can't check typmod */
3126  if (op->d.fieldselect.resulttype != attr->atttypid)
3127  ereport(ERROR,
3128  (errcode(ERRCODE_DATATYPE_MISMATCH),
3129  errmsg("attribute %d has wrong type", fieldnum),
3130  errdetail("Table has type %s, but query expects %s.",
3131  format_type_be(attr->atttypid),
3132  format_type_be(op->d.fieldselect.resulttype))));
3133 
3134  /* heap_getattr needs a HeapTuple not a bare HeapTupleHeader */
3135  tmptup.t_len = HeapTupleHeaderGetDatumLength(tuple);
3136  tmptup.t_data = tuple;
3137 
3138  /* extract the field */
3139  *op->resvalue = heap_getattr(&tmptup,
3140  fieldnum,
3141  tupDesc,
3142  op->resnull);
3143  }
3144 }
int16 AttrNumber
Definition: attnum.h:21
#define elog(elevel,...)
Definition: elog.h:218
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:788
#define HeapTupleHeaderGetTypMod(tup)
Definition: htup_details.h:462
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:207
#define VARATT_IS_EXTERNAL_EXPANDED(PTR)
Definition: postgres.h:335
struct ExprEvalStep::@52::@77 fieldselect
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92

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 3156 of file execExprInterp.c.

3157 {
3158  TupleDesc tupDesc;
3159 
3160  /* Lookup tupdesc if first time through or if type changes */
3161  tupDesc = get_cached_rowtype(op->d.fieldstore.fstore->resulttype, -1,
3162  op->d.fieldstore.rowcache, NULL);
3163 
3164  /* Check that current tupdesc doesn't have more fields than we allocated */
3165  if (unlikely(tupDesc->natts > op->d.fieldstore.ncolumns))
3166  elog(ERROR, "too many columns in composite type %u",
3167  op->d.fieldstore.fstore->resulttype);
3168 
3169  if (*op->resnull)
3170  {
3171  /* Convert null input tuple into an all-nulls row */
3172  memset(op->d.fieldstore.nulls, true,
3173  op->d.fieldstore.ncolumns * sizeof(bool));
3174  }
3175  else
3176  {
3177  /*
3178  * heap_deform_tuple needs a HeapTuple not a bare HeapTupleHeader. We
3179  * set all the fields in the struct just in case.
3180  */
3181  Datum tupDatum = *op->resvalue;
3182  HeapTupleHeader tuphdr;
3183  HeapTupleData tmptup;
3184 
3185  tuphdr = DatumGetHeapTupleHeader(tupDatum);
3186  tmptup.t_len = HeapTupleHeaderGetDatumLength(tuphdr);
3187  ItemPointerSetInvalid(&(tmptup.t_self));
3188  tmptup.t_tableOid = InvalidOid;
3189  tmptup.t_data = tuphdr;
3190 
3191  heap_deform_tuple(&tmptup, tupDesc,
3192  op->d.fieldstore.values,
3193  op->d.fieldstore.nulls);
3194  }
3195 }
#define unlikely(x)
Definition: c.h:273
void heap_deform_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *values, bool *isnull)
Definition: heaptuple.c:1249
#define ItemPointerSetInvalid(pointer)
Definition: itemptr.h:172
#define InvalidOid
Definition: postgres_ext.h:36
struct ExprEvalStep::@52::@78 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 3202 of file execExprInterp.c.

3203 {
3204  TupleDesc tupDesc;
3205  HeapTuple tuple;
3206 
3207  /* Lookup tupdesc (should be valid already) */
3208  tupDesc = get_cached_rowtype(op->d.fieldstore.fstore->resulttype, -1,
3209  op->d.fieldstore.rowcache, NULL);
3210 
3211  tuple = heap_form_tuple(tupDesc,
3212  op->d.fieldstore.values,
3213  op->d.fieldstore.nulls);
3214 
3215  *op->resvalue = HeapTupleGetDatum(tuple);
3216  *op->resnull = false;
3217 }
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 2380 of file execExprInterp.c.

2382 {
2383  FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
2384  PgStat_FunctionCallUsage fcusage;
2385  Datum d;
2386 
2387  pgstat_init_function_usage(fcinfo, &fcusage);
2388 
2389  fcinfo->isnull = false;
2390  d = op->d.func.fn_addr(fcinfo);
2391  *op->resvalue = d;
2392  *op->resnull = fcinfo->isnull;
2393 
2394  pgstat_end_function_usage(&fcusage, true);
2395 }
void pgstat_init_function_usage(FunctionCallInfo fcinfo, PgStat_FunctionCallUsage *fcu)
void pgstat_end_function_usage(PgStat_FunctionCallUsage *fcu, bool finalize)
struct ExprEvalStep::@52::@59 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 2401 of file execExprInterp.c.

2403 {
2404 
2405  FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
2406  PgStat_FunctionCallUsage fcusage;
2407  NullableDatum *args = fcinfo->args;
2408  int nargs = op->d.func.nargs;
2409  Datum d;
2410 
2411  /* strict function, so check for NULL args */
2412  for (int argno = 0; argno < nargs; argno++)
2413  {
2414  if (args[argno].isnull)
2415  {
2416  *op->resnull = true;
2417  return;
2418  }
2419  }
2420 
2421  pgstat_init_function_usage(fcinfo, &fcusage);
2422 
2423  fcinfo->isnull = false;
2424  d = op->d.func.fn_addr(fcinfo);
2425  *op->resvalue = d;
2426  *op->resnull = fcinfo->isnull;
2427 
2428  pgstat_end_function_usage(&fcusage, true);
2429 }

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 4030 of file execExprInterp.c.

4031 {
4032  AggState *aggstate = castNode(AggState, state->parent);
4033  int result = 0;
4034  Bitmapset *grouped_cols = aggstate->grouped_cols;
4035  ListCell *lc;
4036 
4037  foreach(lc, op->d.grouping_func.clauses)
4038  {
4039  int attnum = lfirst_int(lc);
4040 
4041  result <<= 1;
4042 
4043  if (!bms_is_member(attnum, grouped_cols))
4044  result |= 1;
4045  }
4046 
4047  *op->resvalue = Int32GetDatum(result);
4048  *op->resnull = false;
4049 }
bool bms_is_member(int x, const Bitmapset *a)
Definition: bitmapset.c:427
#define castNode(_type_, nodeptr)
Definition: nodes.h:642
#define lfirst_int(lc)
Definition: pg_list.h:170
#define Int32GetDatum(X)
Definition: postgres.h:523
Bitmapset * grouped_cols
Definition: execnodes.h:2350
struct ExprEvalStep::@52::@87 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 3524 of file execExprInterp.c.

3525 {
3526  ScalarArrayOpExprHashTable *elements_tab = op->d.hashedscalararrayop.elements_tab;
3527  FunctionCallInfo fcinfo = op->d.hashedscalararrayop.fcinfo_data;
3528  bool inclause = op->d.hashedscalararrayop.inclause;
3529  bool strictfunc = op->d.hashedscalararrayop.finfo->fn_strict;
3530  Datum scalar = fcinfo->args[0].value;
3531  bool scalar_isnull = fcinfo->args[0].isnull;
3532  Datum result;
3533  bool resultnull;
3534  bool hashfound;
3535 
3536  /* We don't setup a hashed scalar array op if the array const is null. */
3537  Assert(!*op->resnull);
3538 
3539  /*
3540  * If the scalar is NULL, and the function is strict, return NULL; no
3541  * point in executing the search.
3542  */
3543  if (fcinfo->args[0].isnull && strictfunc)
3544  {
3545  *op->resnull = true;
3546  return;
3547  }
3548 
3549  /* Build the hash table on first evaluation */
3550  if (elements_tab == NULL)
3551  {
3552  int16 typlen;
3553  bool typbyval;
3554  char typalign;
3555  int nitems;
3556  bool has_nulls = false;
3557  char *s;
3558  bits8 *bitmap;
3559  int bitmask;
3560  MemoryContext oldcontext;
3561  ArrayType *arr;
3562 
3563  arr = DatumGetArrayTypeP(*op->resvalue);
3564  nitems = ArrayGetNItems(ARR_NDIM(arr), ARR_DIMS(arr));
3565 
3567  &typlen,
3568  &typbyval,
3569  &typalign);
3570 
3571  oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
3572 
3573  elements_tab = (ScalarArrayOpExprHashTable *)
3575  op->d.hashedscalararrayop.elements_tab = elements_tab;
3576  elements_tab->op = op;
3577 
3578  /*
3579  * Create the hash table sizing it according to the number of elements
3580  * in the array. This does assume that the array has no duplicates.
3581  * If the array happens to contain many duplicate values then it'll
3582  * just mean that we sized the table a bit on the large side.
3583  */
3584  elements_tab->hashtab = saophash_create(CurrentMemoryContext, nitems,
3585  elements_tab);
3586 
3587  MemoryContextSwitchTo(oldcontext);
3588 
3589  s = (char *) ARR_DATA_PTR(arr);
3590  bitmap = ARR_NULLBITMAP(arr);
3591  bitmask = 1;
3592  for (int i = 0; i < nitems; i++)
3593  {
3594  /* Get array element, checking for NULL. */
3595  if (bitmap && (*bitmap & bitmask) == 0)
3596  {
3597  has_nulls = true;
3598  }
3599  else
3600  {
3601  Datum element;
3602 
3603  element = fetch_att(s, typbyval, typlen);
3604  s = att_addlength_pointer(s, typlen, s);
3605  s = (char *) att_align_nominal(s, typalign);
3606 
3607  saophash_insert(elements_tab->hashtab, element, &hashfound);
3608  }
3609 
3610  /* Advance bitmap pointer if any. */
3611  if (bitmap)
3612  {
3613  bitmask <<= 1;
3614  if (bitmask == 0x100)
3615  {
3616  bitmap++;
3617  bitmask = 1;
3618  }
3619  }
3620  }
3621 
3622  /*
3623  * Remember if we had any nulls so that we know if we need to execute
3624  * non-strict functions with a null lhs value if no match is found.
3625  */
3626  op->d.hashedscalararrayop.has_nulls = has_nulls;
3627  }
3628 
3629  /* Check the hash to see if we have a match. */
3630  hashfound = NULL != saophash_lookup(elements_tab->hashtab, scalar);
3631 
3632  /* the result depends on if the clause is an IN or NOT IN clause */
3633  if (inclause)
3634  result = BoolGetDatum(hashfound); /* IN */
3635  else
3636  result = BoolGetDatum(!hashfound); /* NOT IN */
3637 
3638  resultnull = false;
3639 
3640  /*
3641  * If we didn't find a match in the array, we still might need to handle
3642  * the possibility of null values. We didn't put any NULLs into the
3643  * hashtable, but instead marked if we found any when building the table
3644  * in has_nulls.
3645  */
3646  if (!hashfound && op->d.hashedscalararrayop.has_nulls)
3647  {
3648  if (strictfunc)
3649  {
3650 
3651  /*
3652  * We have nulls in the array so a non-null lhs and no match must
3653  * yield NULL.
3654  */
3655  result = (Datum) 0;
3656  resultnull = true;
3657  }
3658  else
3659  {
3660  /*
3661  * Execute function will null rhs just once.
3662  *
3663  * The hash lookup path will have scribbled on the lhs argument so
3664  * we need to set it up also (even though we entered this function
3665  * with it already set).
3666  */
3667  fcinfo->args[0].value = scalar;
3668  fcinfo->args[0].isnull = scalar_isnull;
3669  fcinfo->args[1].value = (Datum) 0;
3670  fcinfo->args[1].isnull = true;
3671 
3672  result = op->d.hashedscalararrayop.fn_addr(fcinfo);
3673  resultnull = fcinfo->isnull;
3674 
3675  /*
3676  * Reverse the result for NOT IN clauses since the above function
3677  * is the equality function and we need not-equals.
3678  */
3679  if (!inclause)
3680  result = !result;
3681  }
3682  }
3683 
3684  *op->resvalue = result;
3685  *op->resnull = resultnull;
3686 }
signed short int16
Definition: c.h:428
void get_typlenbyvalalign(Oid typid, int16 *typlen, bool *typbyval, char *typalign)
Definition: lsyscache.c:2228
char typalign
Definition: pg_type.h:176
#define BoolGetDatum(X)
Definition: postgres.h:446
static chr element(struct vars *v, const chr *startp, const chr *endp)
Definition: regc_locale.c:376
struct ExprEvalStep::@52::@84 hashedscalararrayop
struct ExprEvalStep * op
#define att_align_nominal(cur_offset, attalign)
Definition: tupmacs.h:148
#define att_addlength_pointer(cur_offset, attlen, attptr)
Definition: tupmacs.h:176
#define fetch_att(T, attbyval, attlen)
Definition: tupmacs.h:75

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, get_typlenbyvalalign(), ExprEvalStep::has_nulls, ScalarArrayOpExprHashTable::hashtab, i, ExprEvalStep::inclause, FunctionCallInfoBaseData::isnull, NullableDatum::isnull, MemoryContextSwitchTo(), ScalarArrayOpExprHashTable::op, ExprEvalStep::op, palloc(), typalign, ExprEvalStep::typbyval, ExprEvalStep::typlen, and NullableDatum::value.

Referenced by ExecInterpExpr().

◆ ExecEvalJson()

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

Definition at line 5066 of file execExprInterp.c.

5067 {
5069  JsonExpr *jexpr = op->d.jsonexpr.jsexpr;
5070  Datum item;
5071  Datum res = (Datum) 0;
5072  JsonPath *path;
5073  ListCell *lc;
5074  bool error = false;
5075  bool needSubtrans;
5076  bool throwErrors = jexpr->on_error->btype == JSON_BEHAVIOR_ERROR;
5077 
5078  *op->resnull = true; /* until we get a result */
5079  *op->resvalue = (Datum) 0;
5080 
5081  if (op->d.jsonexpr.formatted_expr->isnull || op->d.jsonexpr.pathspec->isnull)
5082  {
5083  /* execute domain checks for NULLs */
5084  (void) ExecEvalJsonExprCoercion(op, econtext, res, op->resnull,
5085  NULL, NULL);
5086 
5087  Assert(*op->resnull);
5088  return;
5089  }
5090 
5091  item = op->d.jsonexpr.formatted_expr->value;
5092  path = DatumGetJsonPathP(op->d.jsonexpr.pathspec->value);
5093 
5094  /* reset JSON path variable contexts */
5095  foreach(lc, op->d.jsonexpr.args)
5096  {
5098 
5099  var->econtext = econtext;
5100  var->evaluated = false;
5101  }
5102 
5103  needSubtrans = ExecEvalJsonNeedsSubTransaction(jexpr, &op->d.jsonexpr.coercions);
5104 
5105  cxt.path = path;
5106  cxt.error = throwErrors ? NULL : &error;
5107  cxt.coercionInSubtrans = !needSubtrans && !throwErrors;
5108  Assert(!needSubtrans || cxt.error);
5109 
5110  res = ExecEvalJsonExprSubtrans(ExecEvalJsonExpr, op, econtext, item,
5111  op->resnull, &cxt, cxt.error,
5112  needSubtrans);
5113 
5114  if (error)
5115  {
5116  /* Execute ON ERROR behavior */
5117  res = ExecEvalJsonBehavior(econtext, jexpr->on_error,
5118  op->d.jsonexpr.default_on_error,
5119  op->resnull);
5120 
5121  /* result is already coerced in DEFAULT behavior case */
5122  if (jexpr->on_error->btype != JSON_BEHAVIOR_DEFAULT)
5123  res = ExecEvalJsonExprCoercion(op, econtext, res,
5124  op->resnull,
5125  NULL, NULL);
5126  }
5127 
5128  *op->resvalue = res;
5129 }
static Datum ExecEvalJsonExprCoercion(ExprEvalStep *op, ExprContext *econtext, Datum res, bool *isNull, void *p, bool *error)
static Datum ExecEvalJsonExpr(ExprEvalStep *op, ExprContext *econtext, Datum item, bool *resnull, void *pcxt, bool *error)
bool ExecEvalJsonNeedsSubTransaction(JsonExpr *jsexpr, struct JsonCoercionsState *coercions)
static Datum ExecEvalJsonBehavior(ExprContext *econtext, JsonBehavior *behavior, ExprState *default_estate, bool *is_null)
static Datum ExecEvalJsonExprSubtrans(JsonFunc func, ExprEvalStep *op, ExprContext *econtext, Datum res, bool *resnull, void *p, bool *error, bool subtrans)
#define DatumGetJsonPathP(d)
Definition: jsonpath.h:35
#define lfirst(lc)
Definition: pg_list.h:169
@ JSON_BEHAVIOR_ERROR
Definition: primnodes.h:1291
@ JSON_BEHAVIOR_DEFAULT
Definition: primnodes.h:1298
static void error(void)
Definition: sql-dyntest.c:147
struct ExprEvalStep::@52::@96 jsonexpr
JsonBehaviorType btype
Definition: primnodes.h:1409
JsonBehavior * on_error
Definition: primnodes.h:1462
struct ExprContext * econtext
Definition: jsonpath.h:265

References Assert(), JsonBehavior::btype, ExecEvalJsonExprContext::coercionInSubtrans, ExprEvalStep::d, DatumGetJsonPathP, JsonPathVariableEvalContext::econtext, ExecEvalJsonExprContext::error, error(), JsonPathVariableEvalContext::evaluated, ExecEvalJsonBehavior(), ExecEvalJsonExpr(), ExecEvalJsonExprCoercion(), ExecEvalJsonExprSubtrans(), ExecEvalJsonNeedsSubTransaction(), JSON_BEHAVIOR_DEFAULT, JSON_BEHAVIOR_ERROR, ExprEvalStep::jsonexpr, lfirst, JsonExpr::on_error, ExecEvalJsonExprContext::path, res, ExprEvalStep::resnull, and ExprEvalStep::resvalue.

Referenced by ExecInterpExpr().

◆ ExecEvalJsonConstructor()

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

Definition at line 4509 of file execExprInterp.c.

4511 {
4512  Datum res;
4513  JsonConstructorExpr *ctor = op->d.json_constructor.constructor;
4514  bool is_jsonb = ctor->returning->format->format_type == JS_FORMAT_JSONB;
4515  bool isnull = false;
4516 
4517  if (ctor->type == JSCTOR_JSON_ARRAY)
4518  res = (is_jsonb ?
4521  op->d.json_constructor.arg_values,
4522  op->d.json_constructor.arg_nulls,
4523  op->d.json_constructor.arg_types,
4524  op->d.json_constructor.constructor->absent_on_null);
4525  else if (ctor->type == JSCTOR_JSON_OBJECT)
4526  res = (is_jsonb ?
4529  op->d.json_constructor.arg_values,
4530  op->d.json_constructor.arg_nulls,
4531  op->d.json_constructor.arg_types,
4532  op->d.json_constructor.constructor->absent_on_null,
4533  op->d.json_constructor.constructor->unique);
4534  else if (ctor->type == JSCTOR_JSON_SCALAR)
4535  {
4536  if (op->d.json_constructor.arg_nulls[0])
4537  {
4538  res = (Datum) 0;
4539  isnull = true;
4540  }
4541  else
4542  {
4543  Datum value = op->d.json_constructor.arg_values[0];
4544  int category = op->d.json_constructor.arg_type_cache[0].category;
4545  Oid outfuncid = op->d.json_constructor.arg_type_cache[0].outfuncid;
4546 
4547  if (is_jsonb)
4548  res = to_jsonb_worker(value, category, outfuncid);
4549  else
4550  res = to_json_worker(value, category, outfuncid);
4551  }
4552  }
4553  else if (ctor->type == JSCTOR_JSON_PARSE)
4554  {
4555  if (op->d.json_constructor.arg_nulls[0])
4556  {
4557  res = (Datum) 0;
4558  isnull = true;
4559  }
4560  else
4561  {
4562  Datum value = op->d.json_constructor.arg_values[0];
4563  text *js = DatumGetTextP(value);
4564 
4565  if (is_jsonb)
4566  res = jsonb_from_text(js, true);
4567  else
4568  {
4569  (void) json_validate(js, true, true);
4570  res = value;
4571  }
4572  }
4573  }
4574  else
4575  {
4576  res = (Datum) 0;
4577  elog(ERROR, "invalid JsonConstructorExpr type %d", ctor->type);
4578  }
4579 
4580  *op->resvalue = res;
4581  *op->resnull = isnull;
4582 }
#define DatumGetTextP(X)
Definition: fmgr.h:332
static struct @151 value
Datum json_build_array_worker(int nargs, Datum *args, bool *nulls, Oid *types, bool absent_on_null)
Definition: json.c:1352
Datum json_build_object_worker(int nargs, Datum *args, bool *nulls, Oid *types, bool absent_on_null, bool unique_keys)
Definition: json.c:1238
bool json_validate(text *json, bool check_unique_keys, bool throw_error)
Definition: json.c:1677
Datum to_json_worker(Datum val, JsonTypeCategory tcategory, Oid outfuncoid)
Definition: json.c:748
Datum jsonb_from_text(text *js, bool unique_keys)
Definition: jsonb.c:146
Datum to_jsonb_worker(Datum val, JsonbTypeCategory tcategory, Oid outfuncoid)
Definition: jsonb.c:1119
Datum jsonb_build_array_worker(int nargs, Datum *args, bool *nulls, Oid *types, bool absent_on_null)
Definition: jsonb.c:1271
Datum jsonb_build_object_worker(int nargs, Datum *args, bool *nulls, Oid *types, bool absent_on_null, bool unique_keys)
Definition: jsonb.c:1186
@ JS_FORMAT_JSONB
Definition: primnodes.h:1277
@ JSCTOR_JSON_PARSE
Definition: primnodes.h:1356
@ JSCTOR_JSON_OBJECT
Definition: primnodes.h:1350
@ JSCTOR_JSON_SCALAR
Definition: primnodes.h:1354
@ JSCTOR_JSON_ARRAY
Definition: primnodes.h:1351
struct ExprEvalStep::@52::@94 json_constructor
JsonReturning * returning
Definition: primnodes.h:1370
JsonConstructorType type
Definition: primnodes.h:1366
JsonFormatType format_type
Definition: primnodes.h:1319
JsonFormat * format
Definition: primnodes.h:1331
Definition: c.h:622

References ExprEvalStep::category, DatumGetTextP, elog, ERROR, JsonReturning::format, JsonFormat::format_type, ExprEvalStep::isnull, JS_FORMAT_JSONB, JSCTOR_JSON_ARRAY, JSCTOR_JSON_OBJECT, JSCTOR_JSON_PARSE, JSCTOR_JSON_SCALAR, json_build_array_worker(), json_build_object_worker(), json_validate(), jsonb_build_array_worker(), jsonb_build_object_worker(), jsonb_from_text(), ExprEvalStep::op, ExprEvalStep::outfuncid, res, JsonConstructorExpr::returning, to_json_worker(), to_jsonb_worker(), JsonConstructorExpr::type, and value.

Referenced by ExecInterpExpr().

◆ ExecEvalJsonIsPredicate()

void ExecEvalJsonIsPredicate ( ExprState state,
ExprEvalStep op 
)

Definition at line 3936 of file execExprInterp.c.

3937 {
3938  JsonIsPredicate *pred = op->d.is_json.pred;
3939  Datum js = *op->resvalue;
3940  Oid exprtype;
3941  bool res;
3942 
3943  if (*op->resnull)
3944  {
3945  *op->resvalue = BoolGetDatum(false);
3946  return;
3947  }
3948 
3949  exprtype = exprType(pred->expr);
3950 
3951  if (exprtype == TEXTOID || exprtype == JSONOID)
3952  {
3953  text *json = DatumGetTextP(js);
3954 
3955  if (pred->item_type == JS_TYPE_ANY)
3956  res = true;
3957  else
3958  {
3959  switch (json_get_first_token(json, false))
3960  {
3962  res = pred->item_type == JS_TYPE_OBJECT;
3963  break;
3965  res = pred->item_type == JS_TYPE_ARRAY;
3966  break;
3967  case JSON_TOKEN_STRING:
3968  case JSON_TOKEN_NUMBER:
3969  case JSON_TOKEN_TRUE:
3970  case JSON_TOKEN_FALSE:
3971  case JSON_TOKEN_NULL:
3972  res = pred->item_type == JS_TYPE_SCALAR;
3973  break;
3974  default:
3975  res = false;
3976  break;
3977  }
3978  }
3979 
3980  /*
3981  * Do full parsing pass only for uniqueness check or for JSON text
3982  * validation.
3983  */
3984  if (res && (pred->unique_keys || exprtype == TEXTOID))
3985  res = json_validate(json, pred->unique_keys, false);
3986  }
3987  else if (exprtype == JSONBOID)
3988  {
3989  if (pred->item_type == JS_TYPE_ANY)
3990  res = true;
3991  else
3992  {
3993  Jsonb *jb = DatumGetJsonbP(js);
3994 
3995  switch (pred->item_type)
3996  {
3997  case JS_TYPE_OBJECT:
3998  res = JB_ROOT_IS_OBJECT(jb);
3999  break;
4000  case JS_TYPE_ARRAY:
4001  res = JB_ROOT_IS_ARRAY(jb) && !JB_ROOT_IS_SCALAR(jb);
4002  break;
4003  case JS_TYPE_SCALAR:
4004  res = JB_ROOT_IS_ARRAY(jb) && JB_ROOT_IS_SCALAR(jb);
4005  break;
4006  default:
4007  res = false;
4008  break;
4009  }
4010  }
4011 
4012  /* Key uniqueness check is redundant for jsonb */
4013  }
4014  else
4015  res = false;
4016 
4017  *op->resvalue = BoolGetDatum(res);
4018 }
@ 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
#define JB_ROOT_IS_OBJECT(jbp_)
Definition: jsonb.h:229
#define JB_ROOT_IS_ARRAY(jbp_)
Definition: jsonb.h:230
#define JB_ROOT_IS_SCALAR(jbp_)
Definition: jsonb.h:228
#define DatumGetJsonbP(d)
Definition: jsonb.h:71
JsonTokenType json_get_first_token(text *json, bool throw_error)
Definition: jsonfuncs.c:5571
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:41
@ JS_TYPE_ANY
Definition: primnodes.h:1382
@ JS_TYPE_ARRAY
Definition: primnodes.h:1384
@ JS_TYPE_OBJECT
Definition: primnodes.h:1383
@ JS_TYPE_SCALAR
Definition: primnodes.h:1385
struct ExprEvalStep::@52::@95 is_json
JsonValueType item_type
Definition: primnodes.h:1397
Definition: jsonb.h:221

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().

◆ ExecEvalJsonNeedsSubTransaction()

bool ExecEvalJsonNeedsSubTransaction ( JsonExpr jsexpr,
struct JsonCoercionsState *  coercions 
)

Definition at line 5046 of file execExprInterp.c.

5048 {
5049  if (jsexpr->on_error->btype == JSON_BEHAVIOR_ERROR)
5050  return false;
5051 
5052  if (jsexpr->op == JSON_EXISTS_OP && !jsexpr->result_coercion)
5053  return false;
5054 
5055  if (!coercions)
5056  return true;
5057 
5058  return false;
5059 }
@ JSON_EXISTS_OP
Definition: primnodes.h:1253
JsonCoercion * result_coercion
Definition: primnodes.h:1455
JsonExprOp op
Definition: primnodes.h:1453

References JsonBehavior::btype, JSON_BEHAVIOR_ERROR, JSON_EXISTS_OP, JsonExpr::on_error, JsonExpr::op, and JsonExpr::result_coercion.

Referenced by ExecEvalJson(), and max_parallel_hazard_walker().

◆ ExecEvalMinMax()

void ExecEvalMinMax ( ExprState state,
ExprEvalStep op 
)

Definition at line 2978 of file execExprInterp.c.

2979 {
2980  Datum *values = op->d.minmax.values;
2981  bool *nulls = op->d.minmax.nulls;
2982  FunctionCallInfo fcinfo = op->d.minmax.fcinfo_data;
2983  MinMaxOp operator = op->d.minmax.op;
2984 
2985  /* set at initialization */
2986  Assert(fcinfo->args[0].isnull == false);
2987  Assert(fcinfo->args[1].isnull == false);
2988 
2989  /* default to null result */
2990  *op->resnull = true;
2991 
2992  for (int off = 0; off < op->d.minmax.nelems; off++)
2993  {
2994  /* ignore NULL inputs */
2995  if (nulls[off])
2996  continue;
2997 
2998  if (*op->resnull)
2999  {
3000  /* first nonnull input, adopt value */
3001  *op->resvalue = values[off];
3002  *op->resnull = false;
3003  }
3004  else
3005  {
3006  int cmpresult;
3007 
3008  /* apply comparison function */
3009  fcinfo->args[0].value = *op->resvalue;
3010  fcinfo->args[1].value = values[off];
3011 
3012  fcinfo->isnull = false;
3013  cmpresult = DatumGetInt32(FunctionCallInvoke(fcinfo));
3014  if (fcinfo->isnull) /* probably should not happen */
3015  continue;
3016 
3017  if (cmpresult > 0 && operator == IS_LEAST)
3018  *op->resvalue = values[off];
3019  else if (cmpresult < 0 && operator == IS_GREATEST)
3020  *op->resvalue = values[off];
3021  }
3022  }
3023 }
static Datum values[MAXATTR]
Definition: bootstrap.c:156
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:172
#define DatumGetInt32(X)
Definition: postgres.h:516
MinMaxOp
Definition: primnodes.h:1147
@ IS_LEAST
Definition: primnodes.h:1149
@ IS_GREATEST
Definition: primnodes.h:1148
struct ExprEvalStep::@52::@76 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 2580 of file execExprInterp.c.

2581 {
2582  int64 newval = nextval_internal(op->d.nextvalueexpr.seqid, false);
2583 
2584  switch (op->d.nextvalueexpr.seqtypid)
2585  {
2586  case INT2OID:
2587  *op->resvalue = Int16GetDatum((int16) newval);
2588  break;
2589  case INT4OID:
2590  *op->resvalue = Int32GetDatum((int32) newval);
2591  break;
2592  case INT8OID:
2593  *op->resvalue = Int64GetDatum((int64) newval);
2594  break;
2595  default:
2596  elog(ERROR, "unsupported sequence type %u",
2597  op->d.nextvalueexpr.seqtypid);
2598  }
2599  *op->resnull = false;
2600 }
Datum Int64GetDatum(int64 X)
Definition: fmgr.c:1683
#define newval
#define Int16GetDatum(X)
Definition: postgres.h:495
int64 nextval_internal(Oid relid, bool check_permissions)
Definition: sequence.c:621
struct ExprEvalStep::@52::@70 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 2438 of file execExprInterp.c.

2439 {
2440  ParamExecData *prm;
2441 
2442  prm = &(econtext->ecxt_param_exec_vals[op->d.param.paramid]);
2443  if (unlikely(prm->execPlan != NULL))
2444  {
2445  /* Parameter not evaluated yet, so go do it */
2446  ExecSetParamPlan(prm->execPlan, econtext);
2447  /* ExecSetParamPlan should have processed this param... */
2448  Assert(prm->execPlan == NULL);
2449  }
2450  *op->resvalue = prm->value;
2451  *op->resnull = prm->isnull;
2452 }
void ExecSetParamPlan(SubPlanState *node, ExprContext *econtext)
Definition: nodeSubplan.c:1058
ParamExecData * ecxt_param_exec_vals
Definition: execnodes.h:243
struct ExprEvalStep::@52::@64 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 2460 of file execExprInterp.c.

2461 {
2462  ParamListInfo paramInfo = econtext->ecxt_param_list_info;
2463  int paramId = op->d.param.paramid;
2464 
2465  if (likely(paramInfo &&
2466  paramId > 0 && paramId <= paramInfo->numParams))
2467  {
2468  ParamExternData *prm;
2469  ParamExternData prmdata;
2470 
2471  /* give hook a chance in case parameter is dynamic */
2472  if (paramInfo->paramFetch != NULL)
2473  prm = paramInfo->paramFetch(paramInfo, paramId, false, &prmdata);
2474  else
2475  prm = &paramInfo->params[paramId - 1];
2476 
2477  if (likely(OidIsValid(prm->ptype)))
2478  {
2479  /* safety check in case hook did something unexpected */
2480  if (unlikely(prm->ptype != op->d.param.paramtype))
2481  ereport(ERROR,
2482  (errcode(ERRCODE_DATATYPE_MISMATCH),
2483  errmsg("type of parameter %d (%s) does not match that when preparing the plan (%s)",
2484  paramId,
2485  format_type_be(prm->ptype),
2486  format_type_be(op->d.param.paramtype))));
2487  *op->resvalue = prm->value;
2488  *op->resnull = prm->isnull;
2489  return;
2490  }
2491  }
2492 
2493  ereport(ERROR,
2494  (errcode(ERRCODE_UNDEFINED_OBJECT),
2495  errmsg("no value found for parameter %d", paramId)));
2496 }
#define likely(x)
Definition: c.h:272
#define OidIsValid(objectId)
Definition: c.h:710
ParamListInfo ecxt_param_list_info
Definition: execnodes.h:244
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().

◆ ExecEvalRow()

void ExecEvalRow ( ExprState state,
ExprEvalStep op 
)

Definition at line 2958 of file execExprInterp.c.

2959 {
2960  HeapTuple tuple;
2961 
2962  /* build tuple from evaluated field values */
2963  tuple = heap_form_tuple(op->d.row.tupdesc,
2964  op->d.row.elemvalues,
2965  op->d.row.elemnulls);
2966 
2967  *op->resvalue = HeapTupleGetDatum(tuple);
2968  *op->resnull = false;
2969 }
struct ExprEvalStep::@52::@73 row

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

Referenced by ExecInterpExpr().

◆ ExecEvalRowNotNull()

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

Definition at line 2615 of file execExprInterp.c.

2616 {
2617  ExecEvalRowNullInt(state, op, econtext, false);
2618 }
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 2606 of file execExprInterp.c.

2607 {
2608  ExecEvalRowNullInt(state, op, econtext, true);
2609 }

References ExecEvalRowNullInt(), and ExprEvalStep::op.

Referenced by ExecInterpExpr().

◆ ExecEvalScalarArrayOp()

void ExecEvalScalarArrayOp ( ExprState state,
ExprEvalStep op 
)

Definition at line 3321 of file execExprInterp.c.

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

2503 {
2504  LOCAL_FCINFO(fcinfo, 0);
2505  SQLValueFunction *svf = op->d.sqlvaluefunction.svf;
2506 
2507  *op->resnull = false;
2508 
2509  /*
2510  * Note: current_schema() can return NULL. current_user() etc currently
2511  * cannot, but might as well code those cases the same way for safety.
2512  */
2513  switch (svf->op)
2514  {
2515  case SVFOP_CURRENT_DATE:
2517  break;
2518  case SVFOP_CURRENT_TIME:
2519  case SVFOP_CURRENT_TIME_N:
2521  break;
2525  break;
2526  case SVFOP_LOCALTIME:
2527  case SVFOP_LOCALTIME_N:
2529  break;
2530  case SVFOP_LOCALTIMESTAMP:
2533  break;
2534  case SVFOP_CURRENT_ROLE:
2535  case SVFOP_CURRENT_USER:
2536  case SVFOP_USER:
2537  InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
2538  *op->resvalue = current_user(fcinfo);
2539  *op->resnull = fcinfo->isnull;
2540  break;
2541  case SVFOP_SESSION_USER:
2542  InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
2543  *op->resvalue = session_user(fcinfo);
2544  *op->resnull = fcinfo->isnull;
2545  break;
2546  case SVFOP_CURRENT_CATALOG:
2547  InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
2548  *op->resvalue = current_database(fcinfo);
2549  *op->resnull = fcinfo->isnull;
2550  break;
2551  case SVFOP_CURRENT_SCHEMA:
2552  InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
2553  *op->resvalue = current_schema(fcinfo);
2554  *op->resnull = fcinfo->isnull;
2555  break;
2556  }
2557 }
Datum current_database(PG_FUNCTION_ARGS)
Definition: misc.c:174
Timestamp GetSQLLocalTimestamp(int32 typmod)
Definition: timestamp.c:1606
TimestampTz GetSQLCurrentTimestamp(int32 typmod)
Definition: timestamp.c:1592
TimeTzADT * GetSQLCurrentTime(int32 typmod)
Definition: date.c:335
TimeADT GetSQLLocalTime(int32 typmod)
Definition: date.c:355
DateADT GetSQLCurrentDate(void)
Definition: date.c:302
#define TimeTzADTPGetDatum(X)
Definition: date.h:59
#define DateADTGetDatum(X)
Definition: date.h:57
#define TimeADTGetDatum(X)
Definition: date.h:58
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#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:1189
@ SVFOP_LOCALTIME_N
Definition: primnodes.h:1182
@ SVFOP_CURRENT_TIMESTAMP
Definition: primnodes.h:1179
@ SVFOP_LOCALTIME
Definition: primnodes.h:1181
@ SVFOP_CURRENT_TIMESTAMP_N
Definition: primnodes.h:1180
@ SVFOP_CURRENT_ROLE
Definition: primnodes.h:1185
@ SVFOP_USER
Definition: primnodes.h:1187
@ SVFOP_CURRENT_SCHEMA
Definition: primnodes.h:1190
@ SVFOP_LOCALTIMESTAMP_N
Definition: primnodes.h:1184
@ SVFOP_CURRENT_DATE
Definition: primnodes.h:1176
@ SVFOP_CURRENT_TIME_N
Definition: primnodes.h:1178
@ SVFOP_CURRENT_TIME
Definition: primnodes.h:1177
@ SVFOP_LOCALTIMESTAMP
Definition: primnodes.h:1183
@ SVFOP_CURRENT_USER
Definition: primnodes.h:1186
@ SVFOP_SESSION_USER
Definition: primnodes.h:1188
struct ExprEvalStep::@52::@69 sqlvaluefunction
SQLValueFunctionOp op
Definition: primnodes.h:1196
#define TimestampTzGetDatum(X)
Definition: timestamp.h:32
#define TimestampGetDatum(X)
Definition: timestamp.h:31

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 2350 of file execExprInterp.c.

2351 {
2352 #if defined(EEO_USE_COMPUTED_GOTO)
2353  if (state->flags & EEO_FLAG_DIRECT_THREADED)
2354  {
2355  ExprEvalOpLookup key;
2356  ExprEvalOpLookup *res;
2357 
2358  key.opcode = (void *) op->opcode;
2359  res = bsearch(&key,
2360  reverse_dispatch_table,
2361  EEOP_LAST /* nmembers */ ,
2362  sizeof(ExprEvalOpLookup),
2363  dispatch_compare_ptr);
2364  Assert(res); /* unknown ops shouldn't get looked up */
2365  return res->op;
2366  }
2367 #endif
2368  return (ExprEvalOp) op->opcode;
2369 }
#define EEO_FLAG_DIRECT_THREADED
Definition: execExpr.h:30
intptr_t opcode
Definition: execExpr.h:274

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 4055 of file execExprInterp.c.

4056 {
4057  SubPlanState *sstate = op->d.subplan.sstate;
4058 
4059  /* could potentially be nested, so make sure there's enough stack */
4061 
4062  *op->resvalue = ExecSubPlan(sstate, econtext, op->resnull);
4063 }
Datum ExecSubPlan(SubPlanState *node, ExprContext *econtext, bool *isNull)
Definition: nodeSubplan.c:62
void check_stack_depth(void)
Definition: postgres.c:3500
struct ExprEvalStep::@52::@89 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 4299 of file execExprInterp.c.

4301 {
4302  Datum d;
4303 
4304  /* slot_getsysattr has sufficient defenses against bad attnums */
4305  d = slot_getsysattr(slot,
4306  op->d.var.attnum,
4307  op->resnull);
4308  *op->resvalue = d;
4309  /* this ought to be unreachable, but it's cheap enough to check */
4310  if (unlikely(*op->resnull))
4311  elog(ERROR, "failed to fetch attribute from slot");
4312 }
static Datum slot_getsysattr(TupleTableSlot *slot, int attnum, bool *isnull)
Definition: tuptable.h:402

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 4072 of file execExprInterp.c.

4073 {
4074  Var *variable = op->d.wholerow.var;
4075  TupleTableSlot *slot;
4076  TupleDesc output_tupdesc;
4077  MemoryContext oldcontext;
4078  HeapTupleHeader dtuple;
4079  HeapTuple tuple;
4080 
4081  /* This was checked by ExecInitExpr */
4082  Assert(variable->varattno == InvalidAttrNumber);
4083 
4084  /* Get the input slot we want */
4085  switch (variable->varno)
4086  {
4087  case INNER_VAR:
4088  /* get the tuple from the inner node */
4089  slot = econtext->ecxt_innertuple;
4090  break;
4091 
4092  case OUTER_VAR:
4093  /* get the tuple from the outer node */
4094  slot = econtext->ecxt_outertuple;
4095  break;
4096 
4097  /* INDEX_VAR is handled by default case */
4098 
4099  default:
4100  /* get the tuple from the relation being scanned */
4101  slot = econtext->ecxt_scantuple;
4102  break;
4103  }
4104 
4105  /* Apply the junkfilter if any */
4106  if (op->d.wholerow.junkFilter != NULL)
4107  slot = ExecFilterJunk(op->d.wholerow.junkFilter, slot);
4108 
4109  /*
4110  * If first time through, obtain tuple descriptor and check compatibility.
4111  *
4112  * XXX: It'd be great if this could be moved to the expression
4113  * initialization phase, but due to using slots that's currently not
4114  * feasible.
4115  */
4116  if (op->d.wholerow.first)
4117  {
4118  /* optimistically assume we don't need slow path */
4119  op->d.wholerow.slow = false;
4120 
4121  /*
4122  * If the Var identifies a named composite type, we must check that
4123  * the actual tuple type is compatible with it.
4124  */
4125  if (variable->vartype != RECORDOID)
4126  {
4127  TupleDesc var_tupdesc;
4128  TupleDesc slot_tupdesc;
4129 
4130  /*
4131  * We really only care about numbers of attributes and data types.
4132  * Also, we can ignore type mismatch on columns that are dropped
4133  * in the destination type, so long as (1) the physical storage
4134  * matches or (2) the actual column value is NULL. Case (1) is
4135  * helpful in some cases involving out-of-date cached plans, while
4136  * case (2) is expected behavior in situations such as an INSERT
4137  * into a table with dropped columns (the planner typically
4138  * generates an INT4 NULL regardless of the dropped column type).
4139  * If we find a dropped column and cannot verify that case (1)
4140  * holds, we have to use the slow path to check (2) for each row.
4141  *
4142  * If vartype is a domain over composite, just look through that
4143  * to the base composite type.
4144  */
4145  var_tupdesc = lookup_rowtype_tupdesc_domain(variable->vartype,
4146  -1, false);
4147 
4148  slot_tupdesc = slot->tts_tupleDescriptor;
4149 
4150  if (var_tupdesc->natts != slot_tupdesc->natts)
4151  ereport(ERROR,
4152  (errcode(ERRCODE_DATATYPE_MISMATCH),
4153  errmsg("table row type and query-specified row type do not match"),
4154  errdetail_plural("Table row contains %d attribute, but query expects %d.",
4155  "Table row contains %d attributes, but query expects %d.",
4156  slot_tupdesc->natts,
4157  slot_tupdesc->natts,
4158  var_tupdesc->natts)));
4159 
4160  for (int i = 0; i < var_tupdesc->natts; i++)
4161  {
4162  Form_pg_attribute vattr = TupleDescAttr(var_tupdesc, i);
4163  Form_pg_attribute sattr = TupleDescAttr(slot_tupdesc, i);
4164 
4165  if (vattr->atttypid == sattr->atttypid)
4166  continue; /* no worries */
4167  if (!vattr->attisdropped)
4168  ereport(ERROR,
4169  (errcode(ERRCODE_DATATYPE_MISMATCH),
4170  errmsg("table row type and query-specified row type do not match"),
4171  errdetail("Table has type %s at ordinal position %d, but query expects %s.",
4172  format_type_be(sattr->atttypid),
4173  i + 1,
4174  format_type_be(vattr->atttypid))));
4175 
4176  if (vattr->attlen != sattr->attlen ||
4177  vattr->attalign != sattr->attalign)
4178  op->d.wholerow.slow = true; /* need to check for nulls */
4179  }
4180 
4181  /*
4182  * Use the variable's declared rowtype as the descriptor for the
4183  * output values. In particular, we *must* absorb any
4184  * attisdropped markings.
4185  */
4186  oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
4187  output_tupdesc = CreateTupleDescCopy(var_tupdesc);
4188  MemoryContextSwitchTo(oldcontext);
4189 
4190  ReleaseTupleDesc(var_tupdesc);
4191  }
4192  else
4193  {
4194  /*
4195  * In the RECORD case, we use the input slot's rowtype as the
4196  * descriptor for the output values, modulo possibly assigning new
4197  * column names below.
4198  */
4199  oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
4200  output_tupdesc = CreateTupleDescCopy(slot->tts_tupleDescriptor);
4201  MemoryContextSwitchTo(oldcontext);
4202 
4203  /*
4204  * It's possible that the input slot is a relation scan slot and
4205  * so is marked with that relation's rowtype. But we're supposed
4206  * to be returning RECORD, so reset to that.
4207  */
4208  output_tupdesc->tdtypeid = RECORDOID;
4209  output_tupdesc->tdtypmod = -1;
4210 
4211  /*
4212  * We already got the correct physical datatype info above, but
4213  * now we should try to find the source RTE and adopt its column
4214  * aliases, since it's unlikely that the input slot has the
4215  * desired names.
4216  *
4217  * If we can't locate the RTE, assume the column names we've got
4218  * are OK. (As of this writing, the only cases where we can't
4219  * locate the RTE are in execution of trigger WHEN clauses, and
4220  * then the Var will have the trigger's relation's rowtype, so its
4221  * names are fine.) Also, if the creator of the RTE didn't bother
4222  * to fill in an eref field, assume our column names are OK. (This
4223  * happens in COPY, and perhaps other places.)
4224  */
4225  if (econtext->ecxt_estate &&
4226  variable->varno <= econtext->ecxt_estate->es_range_table_size)
4227  {
4228  RangeTblEntry *rte = exec_rt_fetch(variable->varno,
4229  econtext->ecxt_estate);
4230 
4231  if (rte->eref)
4232  ExecTypeSetColNames(output_tupdesc, rte->eref->colnames);
4233  }
4234  }
4235 
4236  /* Bless the tupdesc if needed, and save it in the execution state */
4237  op->d.wholerow.tupdesc = BlessTupleDesc(output_tupdesc);
4238 
4239  op->d.wholerow.first = false;
4240  }
4241 
4242  /*
4243  * Make sure all columns of the slot are accessible in the slot's
4244  * Datum/isnull arrays.
4245  */
4246  slot_getallattrs(slot);
4247 
4248  if (op->d.wholerow.slow)
4249  {
4250  /* Check to see if any dropped attributes are non-null */
4251  TupleDesc tupleDesc = slot->tts_tupleDescriptor;
4252  TupleDesc var_tupdesc = op->d.wholerow.tupdesc;
4253 
4254  Assert(var_tupdesc->natts == tupleDesc->natts);
4255 
4256  for (int i = 0; i < var_tupdesc->natts; i++)
4257  {
4258  Form_pg_attribute vattr = TupleDescAttr(var_tupdesc, i);
4259  Form_pg_attribute sattr = TupleDescAttr(tupleDesc, i);
4260 
4261  if (!vattr->attisdropped)
4262  continue; /* already checked non-dropped cols */
4263  if (slot->tts_isnull[i])
4264  continue; /* null is always okay */
4265  if (vattr->attlen != sattr->attlen ||
4266  vattr->attalign != sattr->attalign)
4267  ereport(ERROR,
4268  (errcode(ERRCODE_DATATYPE_MISMATCH),
4269  errmsg("table row type and query-specified row type do not match"),
4270  errdetail("Physical storage mismatch on dropped attribute at ordinal position %d.",
4271  i + 1)));
4272  }
4273  }
4274 
4275  /*
4276  * Build a composite datum, making sure any toasted fields get detoasted.
4277  *
4278  * (Note: it is critical that we not change the slot's state here.)
4279  */
4281  slot->tts_values,
4282  slot->tts_isnull);
4283  dtuple = tuple->t_data;
4284 
4285  /*
4286  * Label the datum with the composite type info we identified before.
4287  *
4288  * (Note: we could skip doing this by passing op->d.wholerow.tupdesc to
4289  * the tuple build step; but that seems a tad risky so let's not.)
4290  */
4291  HeapTupleHeaderSetTypeId(dtuple, op->d.wholerow.tupdesc->tdtypeid);
4292  HeapTupleHeaderSetTypMod(dtuple, op->d.wholerow.tupdesc->tdtypmod);
4293 
4294  *op->resvalue = PointerGetDatum(dtuple);
4295  *op->resnull = false;
4296 }
#define InvalidAttrNumber
Definition: attnum.h:23
int errdetail_plural(const char *fmt_singular, const char *fmt_plural, unsigned long n,...)
Definition: elog.c:1129
TupleTableSlot * ExecFilterJunk(JunkFilter *junkfilter, TupleTableSlot *slot)
Definition: execJunk.c:247
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:2071
void ExecTypeSetColNames(TupleDesc typeInfo, List *namesList)
Definition: execTuples.c:2030
static RangeTblEntry * exec_rt_fetch(Index rti, EState *estate)
Definition: executor.h:575
HeapTuple toast_build_flattened_tuple(TupleDesc tupleDesc, Datum *values, bool *isnull)
Definition: heaptoast.c:563
#define HeapTupleHeaderSetTypMod(tup, typmod)
Definition: htup_details.h:467
#define HeapTupleHeaderSetTypeId(tup, typeid)
Definition: htup_details.h:457
#define OUTER_VAR
Definition: primnodes.h:185
#define INNER_VAR
Definition: primnodes.h:184
List * colnames
Definition: primnodes.h:43
Index es_range_table_size
Definition: execnodes.h:593
struct EState * ecxt_estate
Definition: execnodes.h:268
struct ExprEvalStep::@52::@55 wholerow
Alias * eref
Definition: parsenodes.h:1161
int32 tdtypmod
Definition: tupdesc.h:83
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
bool * tts_isnull
Definition: tuptable.h:128
Datum * tts_values
Definition: tuptable.h:126
Definition: primnodes.h:196
TupleDesc CreateTupleDescCopy(TupleDesc tupdesc)
Definition: tupdesc.c:111
#define ReleaseTupleDesc(tupdesc)
Definition: tupdesc.h:122
static void slot_getallattrs(TupleTableSlot *slot)
Definition: tuptable.h:354
TupleDesc lookup_rowtype_tupdesc_domain(Oid type_id, int32 typmod, bool noError)
Definition: typcache.c:1886

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 3726 of file execExprInterp.c.

3727 {
3728  XmlExpr *xexpr = op->d.xmlexpr.xexpr;
3729  Datum value;
3730 
3731  *op->resnull = true; /* until we get a result */
3732  *op->resvalue = (Datum) 0;
3733 
3734  switch (xexpr->op)
3735  {
3736  case IS_XMLCONCAT:
3737  {
3738  Datum *argvalue = op->d.xmlexpr.argvalue;
3739  bool *argnull = op->d.xmlexpr.argnull;
3740  List *values = NIL;
3741 
3742  for (int i = 0; i < list_length(xexpr->args); i++)
3743  {
3744  if (!argnull[i])
3745  values = lappend(values, DatumGetPointer(argvalue[i]));
3746  }
3747 
3748  if (values != NIL)
3749  {
3751  *op->resnull = false;
3752  }
3753  }
3754  break;
3755 
3756  case IS_XMLFOREST:
3757  {
3758  Datum *argvalue = op->d.xmlexpr.named_argvalue;
3759  bool *argnull = op->d.xmlexpr.named_argnull;
3761  ListCell *lc;
3762  ListCell *lc2;
3763  int i;
3764 
3765  initStringInfo(&buf);
3766 
3767  i = 0;
3768  forboth(lc, xexpr->named_args, lc2, xexpr->arg_names)
3769  {
3770  Expr *e = (Expr *) lfirst(lc);
3771  char *argname = strVal(lfirst(lc2));
3772 
3773  if (!argnull[i])
3774  {
3775  value = argvalue[i];
3776  appendStringInfo(&buf, "<%s>%s</%s>",
3777  argname,
3779  exprType((Node *) e), true),
3780  argname);
3781  *op->resnull = false;
3782  }
3783  i++;
3784  }
3785 
3786  if (!*op->resnull)
3787  {
3788  text *result;
3789 
3790  result = cstring_to_text_with_len(buf.data, buf.len);
3791  *op->resvalue = PointerGetDatum(result);
3792  }
3793 
3794  pfree(buf.data);
3795  }
3796  break;
3797 
3798  case IS_XMLELEMENT:
3799  *op->resvalue = PointerGetDatum(xmlelement(xexpr,
3800  op->d.xmlexpr.named_argvalue,
3801  op->d.xmlexpr.named_argnull,
3802  op->d.xmlexpr.argvalue,
3803  op->d.xmlexpr.argnull));
3804  *op->resnull = false;
3805  break;
3806 
3807  case IS_XMLPARSE:
3808  {
3809  Datum *argvalue = op->d.xmlexpr.argvalue;
3810  bool *argnull = op->d.xmlexpr.argnull;
3811  text *data;
3812  bool preserve_whitespace;
3813 
3814  /* arguments are known to be text, bool */
3815  Assert(list_length(xexpr->args) == 2);
3816 
3817  if (argnull[0])
3818  return;
3819  value = argvalue[0];
3821 
3822  if (argnull[1]) /* probably can't happen */
3823  return;
3824  value = argvalue[1];
3825  preserve_whitespace = DatumGetBool(value);
3826 
3828  xexpr->xmloption,
3829  preserve_whitespace));
3830  *op->resnull = false;
3831  }
3832  break;
3833 
3834  case IS_XMLPI:
3835  {
3836  text *arg;
3837  bool isnull;
3838 
3839  /* optional argument is known to be text */
3840  Assert(list_length(xexpr->args) <= 1);
3841 
3842  if (xexpr->args)
3843  {
3844  isnull = op->d.xmlexpr.argnull[0];
3845  if (isnull)
3846  arg = NULL;
3847  else
3848  arg = DatumGetTextPP(op->d.xmlexpr.argvalue[0]);
3849  }
3850  else
3851  {
3852  arg = NULL;
3853  isnull = false;
3854  }
3855 
3856  *op->resvalue = PointerGetDatum(xmlpi(xexpr->name,
3857  arg,
3858  isnull,
3859  op->resnull));
3860  }
3861  break;
3862 
3863  case IS_XMLROOT:
3864  {
3865  Datum *argvalue = op->d.xmlexpr.argvalue;
3866  bool *argnull = op->d.xmlexpr.argnull;
3867  xmltype *data;
3868  text *version;
3869  int standalone;
3870 
3871  /* arguments are known to be xml, text, int */
3872  Assert(list_length(xexpr->args) == 3);
3873 
3874  if (argnull[0])
3875  return;
3876  data = DatumGetXmlP(argvalue[0]);
3877 
3878  if (argnull[1])
3879  version = NULL;
3880  else
3881  version = DatumGetTextPP(argvalue[1]);
3882 
3883  Assert(!argnull[2]); /* always present */
3884  standalone = DatumGetInt32(argvalue[2]);
3885 
3887  version,
3888  standalone));
3889  *op->resnull = false;
3890  }
3891  break;
3892 
3893  case IS_XMLSERIALIZE:
3894  {
3895  Datum *argvalue = op->d.xmlexpr.argvalue;
3896  bool *argnull = op->d.xmlexpr.argnull;
3897 
3898  /* argument type is known to be xml */
3899  Assert(list_length(xexpr->args) == 1);
3900 
3901  if (argnull[0])
3902  return;
3903  value = argvalue[0];
3904 
3906  xexpr->xmloption));
3907  *op->resnull = false;
3908  }
3909  break;
3910 
3911  case IS_DOCUMENT:
3912  {
3913  Datum *argvalue = op->d.xmlexpr.argvalue;
3914  bool *argnull = op->d.xmlexpr.argnull;
3915 
3916  /* optional argument is known to be xml */
3917  Assert(list_length(xexpr->args) == 1);
3918 
3919  if (argnull[0])
3920  return;
3921  value = argvalue[0];
3922 
3923  *op->resvalue =
3925  *op->resnull = false;
3926  }
3927  break;
3928 
3929  default:
3930  elog(ERROR, "unrecognized XML operation");
3931  break;
3932  }
3933 }
#define DatumGetTextPP(X)
Definition: fmgr.h:292
List * lappend(List *list, void *datum)
Definition: list.c:336
void * arg
const void * data
static int list_length(const List *l)
Definition: pg_list.h:149
#define NIL
Definition: pg_list.h:65
#define forboth(cell1, list1, cell2, list2)
Definition: pg_list.h:446
static char * buf
Definition: pg_test_fsync.c:67
e
Definition: preproc-init.c:82
@ IS_DOCUMENT
Definition: primnodes.h:1222
@ IS_XMLFOREST
Definition: primnodes.h:1217
@ IS_XMLCONCAT
Definition: primnodes.h:1215
@ IS_XMLPI
Definition: primnodes.h:1219
@ IS_XMLPARSE
Definition: primnodes.h:1218
@ IS_XMLSERIALIZE
Definition: primnodes.h:1221
@ IS_XMLROOT
Definition: primnodes.h:1220
@ IS_XMLELEMENT
Definition: primnodes.h:1216
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:91
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
struct ExprEvalStep::@52::@85 xmlexpr
Definition: pg_list.h:51
Definition: nodes.h:574
List * args
Definition: primnodes.h:1238
char * name
Definition: primnodes.h:1235
List * arg_names
Definition: primnodes.h:1237
List * named_args
Definition: primnodes.h:1236
XmlExprOp op
Definition: primnodes.h:1234
XmlOptionType xmloption
Definition: primnodes.h:1239
#define strVal(v)
Definition: value.h:72
text * cstring_to_text_with_len(const char *s, int len)
Definition: varlena.c:200
xmltype * xmlconcat(List *args)
Definition: xml.c:511
xmltype * xmlparse(text *data, XmlOptionType xmloption_arg, bool preserve_whitespace)
Definition: xml.c:751
text * xmltotext_with_xmloption(xmltype *data, XmlOptionType xmloption_arg)
Definition: xml.c:614
bool xml_is_document(xmltype *arg)
Definition: xml.c:887
xmltype * xmlpi(const char *target, text *arg, bool arg_is_null, bool *result_is_null)
Definition: xml.c:769
char * map_sql_value_to_xml_value(Datum value, Oid type, bool xml_escape_strings)
Definition: xml.c:2133
xmltype * xmlelement(XmlExpr *xexpr, Datum *named_argvalue, bool *named_argnull, Datum *argvalue, bool *argnull)
Definition: xml.c:627
xmltype * xmlroot(xmltype *data, text *version, int standalone)
Definition: xml.c:821
#define DatumGetXmlP(X)
Definition: xml.h:50

References appendStringInfo(), arg, XmlExpr::arg_names, 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, 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::name, XmlExpr::named_args, NIL, ExprEvalStep::op, XmlExpr::op, pfree(), PointerGetDatum, strVal, value, values, ExprEvalStep::xexpr, xml_is_document(), xmlconcat(), xmlelement(), XmlExpr::xmloption, xmlparse(), xmlpi(), xmlroot(), and xmltotext_with_xmloption().

Referenced by ExecInterpExpr().

◆ ExecInterpExprStillValid()

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

Definition at line 1844 of file execExprInterp.c.

1845 {
1846  /*
1847  * First time through, check whether attribute matches Var. Might not be
1848  * ok anymore, due to schema changes.
1849  */
1850  CheckExprStillValid(state, econtext);
1851 
1852  /* skip the check during further executions */
1853  state->evalfunc = (ExprStateEvalFunc) state->evalfunc_private;
1854 
1855  /* and actually execute */
1856  return state->evalfunc(state, econtext, isNull);
1857 }
void CheckExprStillValid(ExprState *state, ExprContext *econtext)
Datum(* ExprStateEvalFunc)(struct ExprState *expression, struct ExprContext *econtext, bool *isNull)
Definition: execnodes.h:54

References CheckExprStillValid().

Referenced by ExecReadyInterpretedExpr().

◆ ExecPrepareJsonItemCoercion()

Datum ExecPrepareJsonItemCoercion ( struct JsonbValue item,
JsonReturning returning,
struct JsonCoercionsState *  coercions,
struct JsonCoercionState **  pjcstate 
)

Definition at line 4729 of file execExprInterp.c.

4733 {
4734  struct JsonCoercionState *coercion;
4735  Datum res;
4736  JsonbValue buf;
4737 
4738  if (item->type == jbvBinary &&
4739  JsonContainerIsScalar(item->val.binary.data))
4740  {
4742 
4743  res = JsonbExtractScalar(item->val.binary.data, &buf);
4744  item = &buf;
4745  Assert(res);
4746  }
4747 
4748  /* get coercion state reference and datum of the corresponding SQL type */
4749  switch (item->type)
4750  {
4751  case jbvNull:
4752  coercion = &coercions->null;
4753  res = (Datum) 0;
4754  break;
4755 
4756  case jbvString:
4757  coercion = &coercions->string;
4758  res = PointerGetDatum(cstring_to_text_with_len(item->val.string.val,
4759  item->val.string.len));
4760  break;
4761 
4762  case jbvNumeric:
4763  coercion = &coercions->numeric;
4764  res = NumericGetDatum(item->val.numeric);
4765  break;
4766 
4767  case jbvBool:
4768  coercion = &coercions->boolean;
4769  res = BoolGetDatum(item->val.boolean);
4770  break;
4771 
4772  case jbvDatetime:
4773  res = item->val.datetime.value;
4774  switch (item->val.datetime.typid)
4775  {
4776  case DATEOID:
4777  coercion = &coercions->date;
4778  break;
4779  case TIMEOID:
4780  coercion = &coercions->time;
4781  break;
4782  case TIMETZOID:
4783  coercion = &coercions->timetz;
4784  break;
4785  case TIMESTAMPOID:
4786  coercion = &coercions->timestamp;
4787  break;
4788  case TIMESTAMPTZOID:
4789  coercion = &coercions->timestamptz;
4790  break;
4791  default:
4792  elog(ERROR, "unexpected jsonb datetime type oid %u",
4793  item->val.datetime.typid);
4794  return (Datum) 0;
4795  }
4796  break;
4797 
4798  case jbvArray:
4799  case jbvObject:
4800  case jbvBinary:
4801  coercion = &coercions->composite;
4803  break;
4804 
4805  default:
4806  elog(ERROR, "unexpected jsonb value type %d", item->type);
4807  return (Datum) 0;
4808  }
4809 
4810  *pcoercion = coercion;
4811 
4812  return res;
4813 }
#define PG_USED_FOR_ASSERTS_ONLY
Definition: c.h:155
bool JsonbExtractScalar(JsonbContainer *jbc, JsonbValue *res)
Definition: jsonb.c:2027
@ jbvObject
Definition: jsonb.h:242
@ jbvNumeric
Definition: jsonb.h:238
@ jbvBool
Definition: jsonb.h:239
@ jbvArray
Definition: jsonb.h:241
@ jbvBinary
Definition: jsonb.h:244
@ jbvNull
Definition: jsonb.h:236
@ jbvDatetime
Definition: jsonb.h:252
@ jbvString
Definition: jsonb.h:237
#define JsonContainerIsScalar(jc)
Definition: jsonb.h:215
#define JsonbPGetDatum(p)
Definition: jsonb.h:73
Jsonb * JsonbValueToJsonb(JsonbValue *val)
Definition: jsonb_util.c:94
#define NumericGetDatum(X)
Definition: numeric.h:61
enum jbvType type
Definition: jsonb.h:263
char * val
Definition: jsonb.h:272

References Assert(), BoolGetDatum, buf, cstring_to_text_with_len(), elog, ERROR, jbvArray, jbvBinary, jbvBool, jbvDatetime, jbvNull, jbvNumeric, jbvObject, jbvString, JsonbExtractScalar(), JsonbPGetDatum, JsonbValueToJsonb(), JsonContainerIsScalar, NumericGetDatum, PG_USED_FOR_ASSERTS_ONLY, PointerGetDatum, res, JsonbValue::type, and JsonbValue::val.

Referenced by ExecEvalJsonExpr().

◆ ExecReadyInterpretedExpr()

void ExecReadyInterpretedExpr ( ExprState state)

Definition at line 239 of file execExprInterp.c.

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

2694 {
2695  if (es->steps_alloc == 0)
2696  {
2697  es->steps_alloc = 16;
2698  es->steps = palloc(sizeof(ExprEvalStep) * es->steps_alloc);
2699  }
2700  else if (es->steps_alloc == es->steps_len)
2701  {
2702  es->steps_alloc *= 2;
2703  es->steps = repalloc(es->steps,
2704  sizeof(ExprEvalStep) * es->steps_alloc);
2705  }
2706 
2707  memcpy(&es->steps[es->steps_len++], s, sizeof(ExprEvalStep));
2708 }
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:1188
struct ExprEvalStep * steps
Definition: execnodes.h:86
int steps_alloc
Definition: execnodes.h:106
int steps_len
Definition: execnodes.h:105

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

Referenced by ExecBuildAggTrans(), ExecBuildAggTransCall(), ExecBuildGroupingEqual(), ExecBuildParamSetEqual(), ExecBuildProjectionInfo(), ExecBuildUpdateProjection(), ExecInitCoerceToDomain(), ExecInitExprInternal(), ExecInitExprRec(), ExecInitQual(), ExecInitSubscriptingRef(), ExecPushExprSlots(), and plpgsql_param_compile().