PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
execExpr.h File Reference
#include "executor/nodeAgg.h"
#include "nodes/execnodes.h"
#include "nodes/miscnodes.h"
Include dependency graph for execExpr.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ExprEvalRowtypeCache
 
struct  ExprEvalStep
 
struct  SubscriptingRefState
 
struct  SubscriptExecSteps
 
struct  JsonConstructorExprState
 

Macros

#define EEO_FLAG_INTERPRETER_INITIALIZED   (1 << 5)
 
#define EEO_FLAG_DIRECT_THREADED   (1 << 6)
 

Typedefs

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

Enumerations

enum  ExprEvalOp {
  EEOP_DONE , EEOP_INNER_FETCHSOME , EEOP_OUTER_FETCHSOME , EEOP_SCAN_FETCHSOME ,
  EEOP_OLD_FETCHSOME , EEOP_NEW_FETCHSOME , EEOP_INNER_VAR , EEOP_OUTER_VAR ,
  EEOP_SCAN_VAR , EEOP_OLD_VAR , EEOP_NEW_VAR , EEOP_INNER_SYSVAR ,
  EEOP_OUTER_SYSVAR , EEOP_SCAN_SYSVAR , EEOP_OLD_SYSVAR , EEOP_NEW_SYSVAR ,
  EEOP_WHOLEROW , EEOP_ASSIGN_INNER_VAR , EEOP_ASSIGN_OUTER_VAR , EEOP_ASSIGN_SCAN_VAR ,
  EEOP_ASSIGN_OLD_VAR , EEOP_ASSIGN_NEW_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_PARAM_SET , EEOP_CASE_TESTVAL , EEOP_MAKE_READONLY , EEOP_IOCOERCE ,
  EEOP_IOCOERCE_SAFE , EEOP_DISTINCT , EEOP_NOT_DISTINCT , EEOP_NULLIF ,
  EEOP_SQLVALUEFUNCTION , EEOP_CURRENTOFEXPR , EEOP_NEXTVALUEEXPR , EEOP_RETURNINGEXPR ,
  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_HASHDATUM_SET_INITVAL , EEOP_HASHDATUM_FIRST , EEOP_HASHDATUM_FIRST_STRICT , EEOP_HASHDATUM_NEXT32 ,
  EEOP_HASHDATUM_NEXT32_STRICT , EEOP_CONVERT_ROWTYPE , EEOP_SCALARARRAYOP , EEOP_HASHED_SCALARARRAYOP ,
  EEOP_XMLEXPR , EEOP_JSON_CONSTRUCTOR , EEOP_IS_JSON , EEOP_JSONEXPR_PATH ,
  EEOP_JSONEXPR_COERCION , EEOP_JSONEXPR_COERCION_FINISH , EEOP_AGGREF , EEOP_GROUPING_FUNC ,
  EEOP_WINDOW_FUNC , EEOP_MERGE_SUPPORT_FUNC , EEOP_SUBPLAN , EEOP_AGG_STRICT_DESERIALIZE ,
  EEOP_AGG_DESERIALIZE , EEOP_AGG_STRICT_INPUT_CHECK_ARGS , EEOP_AGG_STRICT_INPUT_CHECK_NULLS , EEOP_AGG_PLAIN_PERGROUP_NULLCHECK ,
  EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYVAL , EEOP_AGG_PLAIN_TRANS_STRICT_BYVAL , EEOP_AGG_PLAIN_TRANS_BYVAL , EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYREF ,
  EEOP_AGG_PLAIN_TRANS_STRICT_BYREF , EEOP_AGG_PLAIN_TRANS_BYREF , EEOP_AGG_PRESORTED_DISTINCT_SINGLE , EEOP_AGG_PRESORTED_DISTINCT_MULTI ,
  EEOP_AGG_ORDERED_TRANS_DATUM , EEOP_AGG_ORDERED_TRANS_TUPLE , EEOP_LAST
}
 

Functions

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

Macro Definition Documentation

◆ EEO_FLAG_DIRECT_THREADED

#define EEO_FLAG_DIRECT_THREADED   (1 << 6)

Definition at line 31 of file execExpr.h.

◆ EEO_FLAG_INTERPRETER_INITIALIZED

#define EEO_FLAG_INTERPRETER_INITIALIZED   (1 << 5)

Definition at line 29 of file execExpr.h.

Typedef Documentation

◆ ExecEvalBoolSubroutine

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

Definition at line 39 of file execExpr.h.

◆ ExecEvalSubroutine

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

Definition at line 34 of file execExpr.h.

◆ ExprEvalOp

typedef enum ExprEvalOp ExprEvalOp

◆ ExprEvalRowtypeCache

◆ ExprEvalStep

typedef struct ExprEvalStep ExprEvalStep

◆ JsonConstructorExprState

◆ SubscriptExecSteps

◆ SubscriptingRefState

Enumeration Type Documentation

◆ ExprEvalOp

enum ExprEvalOp
Enumerator
EEOP_DONE 
EEOP_INNER_FETCHSOME 
EEOP_OUTER_FETCHSOME 
EEOP_SCAN_FETCHSOME 
EEOP_OLD_FETCHSOME 
EEOP_NEW_FETCHSOME 
EEOP_INNER_VAR 
EEOP_OUTER_VAR 
EEOP_SCAN_VAR 
EEOP_OLD_VAR 
EEOP_NEW_VAR 
EEOP_INNER_SYSVAR 
EEOP_OUTER_SYSVAR 
EEOP_SCAN_SYSVAR 
EEOP_OLD_SYSVAR 
EEOP_NEW_SYSVAR 
EEOP_WHOLEROW 
EEOP_ASSIGN_INNER_VAR 
EEOP_ASSIGN_OUTER_VAR 
EEOP_ASSIGN_SCAN_VAR 
EEOP_ASSIGN_OLD_VAR 
EEOP_ASSIGN_NEW_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_PARAM_SET 
EEOP_CASE_TESTVAL 
EEOP_MAKE_READONLY 
EEOP_IOCOERCE 
EEOP_IOCOERCE_SAFE 
EEOP_DISTINCT 
EEOP_NOT_DISTINCT 
EEOP_NULLIF 
EEOP_SQLVALUEFUNCTION 
EEOP_CURRENTOFEXPR 
EEOP_NEXTVALUEEXPR 
EEOP_RETURNINGEXPR 
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_HASHDATUM_SET_INITVAL 
EEOP_HASHDATUM_FIRST 
EEOP_HASHDATUM_FIRST_STRICT 
EEOP_HASHDATUM_NEXT32 
EEOP_HASHDATUM_NEXT32_STRICT 
EEOP_CONVERT_ROWTYPE 
EEOP_SCALARARRAYOP 
EEOP_HASHED_SCALARARRAYOP 
EEOP_XMLEXPR 
EEOP_JSON_CONSTRUCTOR 
EEOP_IS_JSON 
EEOP_JSONEXPR_PATH 
EEOP_JSONEXPR_COERCION 
EEOP_JSONEXPR_COERCION_FINISH 
EEOP_AGGREF 
EEOP_GROUPING_FUNC 
EEOP_WINDOW_FUNC 
EEOP_MERGE_SUPPORT_FUNC 
EEOP_SUBPLAN 
EEOP_AGG_STRICT_DESERIALIZE 
EEOP_AGG_DESERIALIZE 
EEOP_AGG_STRICT_INPUT_CHECK_ARGS 
EEOP_AGG_STRICT_INPUT_CHECK_NULLS 
EEOP_AGG_PLAIN_PERGROUP_NULLCHECK 
EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYVAL 
EEOP_AGG_PLAIN_TRANS_STRICT_BYVAL 
EEOP_AGG_PLAIN_TRANS_BYVAL 
EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYREF 
EEOP_AGG_PLAIN_TRANS_STRICT_BYREF 
EEOP_AGG_PLAIN_TRANS_BYREF 
EEOP_AGG_PRESORTED_DISTINCT_SINGLE 
EEOP_AGG_PRESORTED_DISTINCT_MULTI 
EEOP_AGG_ORDERED_TRANS_DATUM 
EEOP_AGG_ORDERED_TRANS_TUPLE 
EEOP_LAST 

Definition at line 66 of file execExpr.h.

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

Function Documentation

◆ CheckExprStillValid()

void CheckExprStillValid ( ExprState state,
ExprContext econtext 
)

Definition at line 2237 of file execExprInterp.c.

2238{
2239 TupleTableSlot *innerslot;
2240 TupleTableSlot *outerslot;
2241 TupleTableSlot *scanslot;
2242 TupleTableSlot *oldslot;
2243 TupleTableSlot *newslot;
2244
2245 innerslot = econtext->ecxt_innertuple;
2246 outerslot = econtext->ecxt_outertuple;
2247 scanslot = econtext->ecxt_scantuple;
2248 oldslot = econtext->ecxt_oldtuple;
2249 newslot = econtext->ecxt_newtuple;
2250
2251 for (int i = 0; i < state->steps_len; i++)
2252 {
2253 ExprEvalStep *op = &state->steps[i];
2254
2255 switch (ExecEvalStepOp(state, op))
2256 {
2257 case EEOP_INNER_VAR:
2258 {
2259 int attnum = op->d.var.attnum;
2260
2261 CheckVarSlotCompatibility(innerslot, attnum + 1, op->d.var.vartype);
2262 break;
2263 }
2264
2265 case EEOP_OUTER_VAR:
2266 {
2267 int attnum = op->d.var.attnum;
2268
2269 CheckVarSlotCompatibility(outerslot, attnum + 1, op->d.var.vartype);
2270 break;
2271 }
2272
2273 case EEOP_SCAN_VAR:
2274 {
2275 int attnum = op->d.var.attnum;
2276
2277 CheckVarSlotCompatibility(scanslot, attnum + 1, op->d.var.vartype);
2278 break;
2279 }
2280
2281 case EEOP_OLD_VAR:
2282 {
2283 int attnum = op->d.var.attnum;
2284
2285 CheckVarSlotCompatibility(oldslot, attnum + 1, op->d.var.vartype);
2286 break;
2287 }
2288
2289 case EEOP_NEW_VAR:
2290 {
2291 int attnum = op->d.var.attnum;
2292
2293 CheckVarSlotCompatibility(newslot, attnum + 1, op->d.var.vartype);
2294 break;
2295 }
2296 default:
2297 break;
2298 }
2299 }
2300}
static void CheckVarSlotCompatibility(TupleTableSlot *slot, int attnum, Oid vartype)
ExprEvalOp ExecEvalStepOp(ExprState *state, ExprEvalStep *op)
int i
Definition: isn.c:72
int16 attnum
Definition: pg_attribute.h:74
TupleTableSlot * ecxt_innertuple
Definition: execnodes.h:269
TupleTableSlot * ecxt_newtuple
Definition: execnodes.h:306
TupleTableSlot * ecxt_scantuple
Definition: execnodes.h:267
TupleTableSlot * ecxt_oldtuple
Definition: execnodes.h:304
TupleTableSlot * ecxt_outertuple
Definition: execnodes.h:271
struct ExprEvalStep::@55::@57 var
union ExprEvalStep::@55 d
Definition: regguts.h:323

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

Referenced by ExecInterpExprStillValid(), and ExecRunCompiledExpr().

◆ ExecAggCopyTransValue()

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

Definition at line 5596 of file execExprInterp.c.

5599{
5600 Assert(newValue != oldValue);
5601
5602 if (!newValueIsNull)
5603 {
5605 if (DatumIsReadWriteExpandedObject(newValue,
5606 false,
5607 pertrans->transtypeLen) &&
5608 MemoryContextGetParent(DatumGetEOHP(newValue)->eoh_context) == CurrentMemoryContext)
5609 /* do nothing */ ;
5610 else
5611 newValue = datumCopy(newValue,
5612 pertrans->transtypeByVal,
5613 pertrans->transtypeLen);
5614 }
5615 else
5616 {
5617 /*
5618 * Ensure that AggStatePerGroup->transValue ends up being 0, so
5619 * callers can safely compare newValue/oldValue without having to
5620 * check their respective nullness.
5621 */
5622 newValue = (Datum) 0;
5623 }
5624
5625 if (!oldValueIsNull)
5626 {
5627 if (DatumIsReadWriteExpandedObject(oldValue,
5628 false,
5629 pertrans->transtypeLen))
5630 DeleteExpandedObject(oldValue);
5631 else
5632 pfree(DatumGetPointer(oldValue));
5633 }
5634
5635 return newValue;
5636}
#define Assert(condition)
Definition: c.h:815
Datum datumCopy(Datum value, bool typByVal, int typLen)
Definition: datum.c:132
ExpandedObjectHeader * DatumGetEOHP(Datum d)
Definition: expandeddatum.c:29
void DeleteExpandedObject(Datum d)
#define DatumIsReadWriteExpandedObject(d, isnull, typlen)
void pfree(void *pointer)
Definition: mcxt.c:1521
MemoryContext CurrentMemoryContext
Definition: mcxt.c:143
MemoryContext MemoryContextGetParent(MemoryContext context)
Definition: mcxt.c:731
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:124
uintptr_t Datum
Definition: postgres.h:69
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:317
ExprContext * curaggcontext
Definition: execnodes.h:2524
MemoryContext ecxt_per_tuple_memory
Definition: execnodes.h:275

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

Referenced by advance_transition_function(), and ExecAggPlainTransByRef().

◆ ExecAggInitGroup()

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

Definition at line 5543 of file execExprInterp.c.

5545{
5546 FunctionCallInfo fcinfo = pertrans->transfn_fcinfo;
5547 MemoryContext oldContext;
5548
5549 /*
5550 * We must copy the datum into aggcontext if it is pass-by-ref. We do not
5551 * need to pfree the old transValue, since it's NULL. (We already checked
5552 * that the agg's input type is binary-compatible with its transtype, so
5553 * straight copy here is OK.)
5554 */
5555 oldContext = MemoryContextSwitchTo(aggcontext->ecxt_per_tuple_memory);
5556 pergroup->transValue = datumCopy(fcinfo->args[1].value,
5557 pertrans->transtypeByVal,
5558 pertrans->transtypeLen);
5559 pergroup->transValueIsNull = false;
5560 pergroup->noTransValue = false;
5561 MemoryContextSwitchTo(oldContext);
5562}
FunctionCallInfo transfn_fcinfo
Definition: nodeAgg.h:170
NullableDatum args[FLEXIBLE_ARRAY_MEMBER]
Definition: fmgr.h:95
Datum value
Definition: postgres.h:80

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

Referenced by ExecInterpExpr().

◆ ExecEvalAggOrderedTransDatum()

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

Definition at line 5735 of file execExprInterp.c.

5737{
5738 AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
5739 int setno = op->d.agg_trans.setno;
5740
5741 tuplesort_putdatum(pertrans->sortstates[setno],
5742 *op->resvalue, *op->resnull);
5743}
Tuplesortstate ** sortstates
Definition: nodeAgg.h:162
AggStatePerTrans pertrans
Definition: execExpr.h:722
Datum * resvalue
Definition: execExpr.h:302
bool * resnull
Definition: execExpr.h:303
struct ExprEvalStep::@55::@101 agg_trans
void tuplesort_putdatum(Tuplesortstate *state, Datum val, bool isNull)

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

Referenced by ExecInterpExpr().

◆ ExecEvalAggOrderedTransTuple()

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

Definition at line 5749 of file execExprInterp.c.

5751{
5752 AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
5753 int setno = op->d.agg_trans.setno;
5754
5755 ExecClearTuple(pertrans->sortslot);
5756 pertrans->sortslot->tts_nvalid = pertrans->numInputs;
5758 tuplesort_puttupleslot(pertrans->sortstates[setno], pertrans->sortslot);
5759}
TupleTableSlot * ExecStoreVirtualTuple(TupleTableSlot *slot)
Definition: execTuples.c:1739
TupleTableSlot * sortslot
Definition: nodeAgg.h:141
AttrNumber tts_nvalid
Definition: tuptable.h:120
void tuplesort_puttupleslot(Tuplesortstate *state, TupleTableSlot *slot)
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:454

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

3542{
3543 Datum arraydatum;
3544
3545 /* NULL array -> NULL result */
3546 if (*op->resnull)
3547 return;
3548
3549 arraydatum = *op->resvalue;
3550
3551 /*
3552 * If it's binary-compatible, modify the element type in the array header,
3553 * but otherwise leave the array as we received it.
3554 */
3555 if (op->d.arraycoerce.elemexprstate == NULL)
3556 {
3557 /* Detoast input array if necessary, and copy in any case */
3558 ArrayType *array = DatumGetArrayTypePCopy(arraydatum);
3559
3561 *op->resvalue = PointerGetDatum(array);
3562 return;
3563 }
3564
3565 /*
3566 * Use array_map to apply the sub-expression to each array element.
3567 */
3568 *op->resvalue = array_map(arraydatum,
3570 econtext,
3572 op->d.arraycoerce.amstate);
3573}
#define DatumGetArrayTypePCopy(X)
Definition: array.h:262
#define ARR_ELEMTYPE(a)
Definition: array.h:292
Datum array_map(Datum arrayd, ExprState *exprstate, ExprContext *econtext, Oid retType, ArrayMapState *amstate)
Definition: arrayfuncs.c:3201
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:327
ExprState * elemexprstate
Definition: execExpr.h:484
Oid resultelemtype
Definition: execExpr.h:485
struct ArrayMapState * amstate
Definition: execExpr.h:486
struct ExprEvalStep::@55::@76 arraycoerce

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

Referenced by ExecInterpExpr().

◆ ExecEvalArrayExpr()

void ExecEvalArrayExpr ( ExprState state,
ExprEvalStep op 
)

Definition at line 3327 of file execExprInterp.c.

3328{
3329 ArrayType *result;
3330 Oid element_type = op->d.arrayexpr.elemtype;
3331 int nelems = op->d.arrayexpr.nelems;
3332 int ndims = 0;
3333 int dims[MAXDIM];
3334 int lbs[MAXDIM];
3335
3336 /* Set non-null as default */
3337 *op->resnull = false;
3338
3339 if (!op->d.arrayexpr.multidims)
3340 {
3341 /* Elements are presumably of scalar type */
3342 Datum *dvalues = op->d.arrayexpr.elemvalues;
3343 bool *dnulls = op->d.arrayexpr.elemnulls;
3344
3345 /* setup for 1-D array of the given length */
3346 ndims = 1;
3347 dims[0] = nelems;
3348 lbs[0] = 1;
3349
3350 result = construct_md_array(dvalues, dnulls, ndims, dims, lbs,
3351 element_type,
3353 op->d.arrayexpr.elembyval,
3354 op->d.arrayexpr.elemalign);
3355 }
3356 else
3357 {
3358 /* Must be nested array expressions */
3359 int nbytes = 0;
3360 int nitems;
3361 int outer_nelems = 0;
3362 int elem_ndims = 0;
3363 int *elem_dims = NULL;
3364 int *elem_lbs = NULL;
3365 bool firstone = true;
3366 bool havenulls = false;
3367 bool haveempty = false;
3368 char **subdata;
3369 bits8 **subbitmaps;
3370 int *subbytes;
3371 int *subnitems;
3372 int32 dataoffset;
3373 char *dat;
3374 int iitem;
3375
3376 subdata = (char **) palloc(nelems * sizeof(char *));
3377 subbitmaps = (bits8 **) palloc(nelems * sizeof(bits8 *));
3378 subbytes = (int *) palloc(nelems * sizeof(int));
3379 subnitems = (int *) palloc(nelems * sizeof(int));
3380
3381 /* loop through and get data area from each element */
3382 for (int elemoff = 0; elemoff < nelems; elemoff++)
3383 {
3384 Datum arraydatum;
3385 bool eisnull;
3386 ArrayType *array;
3387 int this_ndims;
3388
3389 arraydatum = op->d.arrayexpr.elemvalues[elemoff];
3390 eisnull = op->d.arrayexpr.elemnulls[elemoff];
3391
3392 /* temporarily ignore null subarrays */
3393 if (eisnull)
3394 {
3395 haveempty = true;
3396 continue;
3397 }
3398
3399 array = DatumGetArrayTypeP(arraydatum);
3400
3401 /* run-time double-check on element type */
3402 if (element_type != ARR_ELEMTYPE(array))
3403 ereport(ERROR,
3404 (errcode(ERRCODE_DATATYPE_MISMATCH),
3405 errmsg("cannot merge incompatible arrays"),
3406 errdetail("Array with element type %s cannot be "
3407 "included in ARRAY construct with element type %s.",
3409 format_type_be(element_type))));
3410
3411 this_ndims = ARR_NDIM(array);
3412 /* temporarily ignore zero-dimensional subarrays */
3413 if (this_ndims <= 0)
3414 {
3415 haveempty = true;
3416 continue;
3417 }
3418
3419 if (firstone)
3420 {
3421 /* Get sub-array details from first member */
3422 elem_ndims = this_ndims;
3423 ndims = elem_ndims + 1;
3424 if (ndims <= 0 || ndims > MAXDIM)
3425 ereport(ERROR,
3426 (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
3427 errmsg("number of array dimensions (%d) exceeds the maximum allowed (%d)",
3428 ndims, MAXDIM)));
3429
3430 elem_dims = (int *) palloc(elem_ndims * sizeof(int));
3431 memcpy(elem_dims, ARR_DIMS(array), elem_ndims * sizeof(int));
3432 elem_lbs = (int *) palloc(elem_ndims * sizeof(int));
3433 memcpy(elem_lbs, ARR_LBOUND(array), elem_ndims * sizeof(int));
3434
3435 firstone = false;
3436 }
3437 else
3438 {
3439 /* Check other sub-arrays are compatible */
3440 if (elem_ndims != this_ndims ||
3441 memcmp(elem_dims, ARR_DIMS(array),
3442 elem_ndims * sizeof(int)) != 0 ||
3443 memcmp(elem_lbs, ARR_LBOUND(array),
3444 elem_ndims * sizeof(int)) != 0)
3445 ereport(ERROR,
3446 (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
3447 errmsg("multidimensional arrays must have array "
3448 "expressions with matching dimensions")));
3449 }
3450
3451 subdata[outer_nelems] = ARR_DATA_PTR(array);
3452 subbitmaps[outer_nelems] = ARR_NULLBITMAP(array);
3453 subbytes[outer_nelems] = ARR_SIZE(array) - ARR_DATA_OFFSET(array);
3454 nbytes += subbytes[outer_nelems];
3455 /* check for overflow of total request */
3456 if (!AllocSizeIsValid(nbytes))
3457 ereport(ERROR,
3458 (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
3459 errmsg("array size exceeds the maximum allowed (%d)",
3460 (int) MaxAllocSize)));
3461 subnitems[outer_nelems] = ArrayGetNItems(this_ndims,
3462 ARR_DIMS(array));
3463 havenulls |= ARR_HASNULL(array);
3464 outer_nelems++;
3465 }
3466
3467 /*
3468 * If all items were null or empty arrays, return an empty array;
3469 * otherwise, if some were and some weren't, raise error. (Note: we
3470 * must special-case this somehow to avoid trying to generate a 1-D
3471 * array formed from empty arrays. It's not ideal...)
3472 */
3473 if (haveempty)
3474 {
3475 if (ndims == 0) /* didn't find any nonempty array */
3476 {
3477 *op->resvalue = PointerGetDatum(construct_empty_array(element_type));
3478 return;
3479 }
3480 ereport(ERROR,
3481 (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
3482 errmsg("multidimensional arrays must have array "
3483 "expressions with matching dimensions")));
3484 }
3485
3486 /* setup for multi-D array */
3487 dims[0] = outer_nelems;
3488 lbs[0] = 1;
3489 for (int i = 1; i < ndims; i++)
3490 {
3491 dims[i] = elem_dims[i - 1];
3492 lbs[i] = elem_lbs[i - 1];
3493 }
3494
3495 /* check for subscript overflow */
3496 nitems = ArrayGetNItems(ndims, dims);
3497 ArrayCheckBounds(ndims, dims, lbs);
3498
3499 if (havenulls)
3500 {
3501 dataoffset = ARR_OVERHEAD_WITHNULLS(ndims, nitems);
3502 nbytes += dataoffset;
3503 }
3504 else
3505 {
3506 dataoffset = 0; /* marker for no null bitmap */
3507 nbytes += ARR_OVERHEAD_NONULLS(ndims);
3508 }
3509
3510 result = (ArrayType *) palloc0(nbytes);
3511 SET_VARSIZE(result, nbytes);
3512 result->ndim = ndims;
3513 result->dataoffset = dataoffset;
3514 result->elemtype = element_type;
3515 memcpy(ARR_DIMS(result), dims, ndims * sizeof(int));
3516 memcpy(ARR_LBOUND(result), lbs, ndims * sizeof(int));
3517
3518 dat = ARR_DATA_PTR(result);
3519 iitem = 0;
3520 for (int i = 0; i < outer_nelems; i++)
3521 {
3522 memcpy(dat, subdata[i], subbytes[i]);
3523 dat += subbytes[i];
3524 if (havenulls)
3525 array_bitmap_copy(ARR_NULLBITMAP(result), iitem,
3526 subbitmaps[i], 0,
3527 subnitems[i]);
3528 iitem += subnitems[i];
3529 }
3530 }
3531
3532 *op->resvalue = PointerGetDatum(result);
3533}
#define ARR_NDIM(a)
Definition: array.h:290
#define ARR_DATA_PTR(a)
Definition: array.h:322
#define MAXDIM
Definition: array.h:75
#define ARR_NULLBITMAP(a)
Definition: array.h:300
#define ARR_OVERHEAD_WITHNULLS(ndims, nitems)
Definition: array.h:312
#define DatumGetArrayTypeP(X)
Definition: array.h:261
#define ARR_SIZE(a)
Definition: array.h:289
#define ARR_OVERHEAD_NONULLS(ndims)
Definition: array.h:310
#define ARR_DATA_OFFSET(a)
Definition: array.h:316
#define ARR_DIMS(a)
Definition: array.h:294
#define ARR_HASNULL(a)
Definition: array.h:291
#define ARR_LBOUND(a)
Definition: array.h:296
ArrayType * construct_empty_array(Oid elmtype)
Definition: arrayfuncs.c:3580
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:3494
void array_bitmap_copy(bits8 *destbitmap, int destoffset, const bits8 *srcbitmap, int srcoffset, int nitems)
Definition: arrayfuncs.c:4966
int ArrayGetNItems(int ndim, const int *dims)
Definition: arrayutils.c:57
void ArrayCheckBounds(int ndim, const int *dims, const int *lb)
Definition: arrayutils.c:117
uint8 bits8
Definition: c.h:495
int32_t int32
Definition: c.h:484
int errdetail(const char *fmt,...)
Definition: elog.c:1203
int errcode(int sqlerrcode)
Definition: elog.c:853
int errmsg(const char *fmt,...)
Definition: elog.c:1070
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
#define MaxAllocSize
Definition: fe_memutils.h:22
char * format_type_be(Oid type_oid)
Definition: format_type.c:343
#define nitems(x)
Definition: indent.h:31
void * palloc0(Size size)
Definition: mcxt.c:1347
void * palloc(Size size)
Definition: mcxt.c:1317
#define AllocSizeIsValid(size)
Definition: memutils.h:42
unsigned int Oid
Definition: postgres_ext.h:32
Oid elemtype
Definition: array.h:97
int ndim
Definition: array.h:95
int32 dataoffset
Definition: array.h:96
char elemalign
Definition: execExpr.h:477
bool * elemnulls
Definition: execExpr.h:472
bool multidims
Definition: execExpr.h:478
int16 elemlength
Definition: execExpr.h:475
bool elembyval
Definition: execExpr.h:476
Datum * elemvalues
Definition: execExpr.h:471
struct ExprEvalStep::@55::@75 arrayexpr
Oid elemtype
Definition: execExpr.h:474
#define SET_VARSIZE(PTR, len)
Definition: varatt.h:305

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

Referenced by ExecInterpExpr().

◆ ExecEvalCoerceViaIOSafe()

void ExecEvalCoerceViaIOSafe ( ExprState state,
ExprEvalStep op 
)

Definition at line 3061 of file execExprInterp.c.

3062{
3063 char *str;
3064
3065 /* call output function (similar to OutputFunctionCall) */
3066 if (*op->resnull)
3067 {
3068 /* output functions are not called on nulls */
3069 str = NULL;
3070 }
3071 else
3072 {
3073 FunctionCallInfo fcinfo_out;
3074
3075 fcinfo_out = op->d.iocoerce.fcinfo_data_out;
3076 fcinfo_out->args[0].value = *op->resvalue;
3077 fcinfo_out->args[0].isnull = false;
3078
3079 fcinfo_out->isnull = false;
3080 str = DatumGetCString(FunctionCallInvoke(fcinfo_out));
3081
3082 /* OutputFunctionCall assumes result isn't null */
3083 Assert(!fcinfo_out->isnull);
3084 }
3085
3086 /* call input function (similar to InputFunctionCallSafe) */
3087 if (!op->d.iocoerce.finfo_in->fn_strict || str != NULL)
3088 {
3089 FunctionCallInfo fcinfo_in;
3090
3091 fcinfo_in = op->d.iocoerce.fcinfo_data_in;
3092 fcinfo_in->args[0].value = PointerGetDatum(str);
3093 fcinfo_in->args[0].isnull = *op->resnull;
3094 /* second and third arguments are already set up */
3095
3096 /* ErrorSaveContext must be present. */
3097 Assert(IsA(fcinfo_in->context, ErrorSaveContext));
3098
3099 fcinfo_in->isnull = false;
3100 *op->resvalue = FunctionCallInvoke(fcinfo_in);
3101
3102 if (SOFT_ERROR_OCCURRED(fcinfo_in->context))
3103 {
3104 *op->resnull = true;
3105 *op->resvalue = (Datum) 0;
3106 return;
3107 }
3108
3109 /* Should get null result if and only if str is NULL */
3110 if (str == NULL)
3111 Assert(*op->resnull);
3112 else
3113 Assert(!*op->resnull);
3114 }
3115}
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:172
const char * str
#define SOFT_ERROR_OCCURRED(escontext)
Definition: miscnodes.h:53
#define IsA(nodeptr, _type_)
Definition: nodes.h:158
static char * DatumGetCString(Datum X)
Definition: postgres.h:340
FunctionCallInfo fcinfo_data_in
Definition: execExpr.h:452
FmgrInfo * finfo_in
Definition: execExpr.h:451
struct ExprEvalStep::@55::@72 iocoerce
FunctionCallInfo fcinfo_data_out
Definition: execExpr.h:449
bool fn_strict
Definition: fmgr.h:61
fmNodePtr context
Definition: fmgr.h:88
bool isnull
Definition: postgres.h:82

References FunctionCallInfoBaseData::args, Assert, FunctionCallInfoBaseData::context, DatumGetCString(), FunctionCallInvoke, IsA, FunctionCallInfoBaseData::isnull, NullableDatum::isnull, ExprEvalStep::op, PointerGetDatum(), SOFT_ERROR_OCCURRED, str, and NullableDatum::value.

Referenced by ExecInterpExpr().

◆ ExecEvalConstraintCheck()

void ExecEvalConstraintCheck ( ExprState state,
ExprEvalStep op 
)

Definition at line 4348 of file execExprInterp.c.

4349{
4350 if (!*op->d.domaincheck.checknull &&
4353 (errcode(ERRCODE_CHECK_VIOLATION),
4354 errmsg("value for domain %s violates check constraint \"%s\"",
4359}
int errdomainconstraint(Oid datatypeOid, const char *conname)
Definition: domains.c:431
#define errsave(context,...)
Definition: elog.h:261
static bool DatumGetBool(Datum X)
Definition: postgres.h:95
bool * checknull
Definition: execExpr.h:580
struct ExprEvalStep::@55::@85 domaincheck
Oid resulttype
Definition: execExpr.h:535
Datum * checkvalue
Definition: execExpr.h:579
ErrorSaveContext * escontext
Definition: execExpr.h:583
char * constraintname
Definition: execExpr.h:577
Definition: nodes.h:129

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

Referenced by ExecInterpExpr().

◆ ExecEvalConstraintNotNull()

void ExecEvalConstraintNotNull ( ExprState state,
ExprEvalStep op 
)

Definition at line 4334 of file execExprInterp.c.

4335{
4336 if (*op->resnull)
4338 (errcode(ERRCODE_NOT_NULL_VIOLATION),
4339 errmsg("domain %s does not allow null values",
4342}
int errdatatype(Oid datatypeOid)
Definition: domains.c:407

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

Referenced by ExecInterpExpr().

◆ ExecEvalConvertRowtype()

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

Definition at line 3854 of file execExprInterp.c.

3855{
3856 HeapTuple result;
3857 Datum tupDatum;
3858 HeapTupleHeader tuple;
3859 HeapTupleData tmptup;
3860 TupleDesc indesc,
3861 outdesc;
3862 bool changed = false;
3863
3864 /* NULL in -> NULL out */
3865 if (*op->resnull)
3866 return;
3867
3868 tupDatum = *op->resvalue;
3869 tuple = DatumGetHeapTupleHeader(tupDatum);
3870
3871 /*
3872 * Lookup tupdescs if first time through or if type changes. We'd better
3873 * pin them since type conversion functions could do catalog lookups and
3874 * hence cause cache invalidation.
3875 */
3878 &changed);
3879 IncrTupleDescRefCount(indesc);
3882 &changed);
3883 IncrTupleDescRefCount(outdesc);
3884
3885 /*
3886 * We used to be able to assert that incoming tuples are marked with
3887 * exactly the rowtype of indesc. However, now that ExecEvalWholeRowVar
3888 * might change the tuples' marking to plain RECORD due to inserting
3889 * aliases, we can only make this weak test:
3890 */
3891 Assert(HeapTupleHeaderGetTypeId(tuple) == indesc->tdtypeid ||
3892 HeapTupleHeaderGetTypeId(tuple) == RECORDOID);
3893
3894 /* if first time through, or after change, initialize conversion map */
3895 if (changed)
3896 {
3897 MemoryContext old_cxt;
3898
3899 /* allocate map in long-lived memory context */
3900 old_cxt = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
3901
3902 /* prepare map from old to new attribute numbers */
3903 op->d.convert_rowtype.map = convert_tuples_by_name(indesc, outdesc);
3904
3905 MemoryContextSwitchTo(old_cxt);
3906 }
3907
3908 /* Following steps need a HeapTuple not a bare HeapTupleHeader */
3909 tmptup.t_len = HeapTupleHeaderGetDatumLength(tuple);
3910 tmptup.t_data = tuple;
3911
3912 if (op->d.convert_rowtype.map != NULL)
3913 {
3914 /* Full conversion with attribute rearrangement needed */
3915 result = execute_attr_map_tuple(&tmptup, op->d.convert_rowtype.map);
3916 /* Result already has appropriate composite-datum header fields */
3917 *op->resvalue = HeapTupleGetDatum(result);
3918 }
3919 else
3920 {
3921 /*
3922 * The tuple is physically compatible as-is, but we need to insert the
3923 * destination rowtype OID in its composite-datum header field, so we
3924 * have to copy it anyway. heap_copy_tuple_as_datum() is convenient
3925 * for this since it will both make the physical copy and insert the
3926 * correct composite header fields. Note that we aren't expecting to
3927 * have to flatten any toasted fields: the input was a composite
3928 * datum, so it shouldn't contain any. So heap_copy_tuple_as_datum()
3929 * is overkill here, but its check for external fields is cheap.
3930 */
3931 *op->resvalue = heap_copy_tuple_as_datum(&tmptup, outdesc);
3932 }
3933
3934 DecrTupleDescRefCount(indesc);
3935 DecrTupleDescRefCount(outdesc);
3936}
static TupleDesc get_cached_rowtype(Oid type_id, int32 typmod, ExprEvalRowtypeCache *rowcache, bool *changed)
#define DatumGetHeapTupleHeader(X)
Definition: fmgr.h:295
static Datum HeapTupleGetDatum(const HeapTupleData *tuple)
Definition: funcapi.h:230
Datum heap_copy_tuple_as_datum(HeapTuple tuple, TupleDesc tupleDesc)
Definition: heaptuple.c:1081
#define HeapTupleHeaderGetTypeId(tup)
Definition: htup_details.h:456
#define HeapTupleHeaderGetDatumLength(tup)
Definition: htup_details.h:450
MemoryContext ecxt_per_query_memory
Definition: execnodes.h:274
Oid outputtype
Definition: execExpr.h:608
TupleConversionMap * map
Definition: execExpr.h:612
Oid inputtype
Definition: execExpr.h:607
ExprEvalRowtypeCache * incache
Definition: execExpr.h:610
struct ExprEvalStep::@55::@88 convert_rowtype
ExprEvalRowtypeCache * outcache
Definition: execExpr.h:611
uint32 t_len
Definition: htup.h:64
HeapTupleHeader t_data
Definition: htup.h:68
Oid tdtypeid
Definition: tupdesc.h:131
TupleConversionMap * convert_tuples_by_name(TupleDesc indesc, TupleDesc outdesc)
Definition: tupconvert.c:102
HeapTuple execute_attr_map_tuple(HeapTuple tuple, TupleConversionMap *map)
Definition: tupconvert.c:154
void DecrTupleDescRefCount(TupleDesc tupdesc)
Definition: tupdesc.c:553
void IncrTupleDescRefCount(TupleDesc tupdesc)
Definition: tupdesc.c:535

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

3189{
3190 ereport(ERROR,
3191 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3192 errmsg("WHERE CURRENT OF is not supported for this table type")));
3193}

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

Referenced by ExecInterpExpr().

◆ ExecEvalFieldSelect()

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

Definition at line 3655 of file execExprInterp.c.

3656{
3657 AttrNumber fieldnum = op->d.fieldselect.fieldnum;
3658 Datum tupDatum;
3659 HeapTupleHeader tuple;
3660 Oid tupType;
3661 int32 tupTypmod;
3662 TupleDesc tupDesc;
3663 Form_pg_attribute attr;
3664 HeapTupleData tmptup;
3665
3666 /* NULL record -> NULL result */
3667 if (*op->resnull)
3668 return;
3669
3670 tupDatum = *op->resvalue;
3671
3672 /* We can special-case expanded records for speed */
3674 {
3676
3677 Assert(erh->er_magic == ER_MAGIC);
3678
3679 /* Extract record's TupleDesc */
3680 tupDesc = expanded_record_get_tupdesc(erh);
3681
3682 /*
3683 * Find field's attr record. Note we don't support system columns
3684 * here: a datum tuple doesn't have valid values for most of the
3685 * interesting system columns anyway.
3686 */
3687 if (fieldnum <= 0) /* should never happen */
3688 elog(ERROR, "unsupported reference to system column %d in FieldSelect",
3689 fieldnum);
3690 if (fieldnum > tupDesc->natts) /* should never happen */
3691 elog(ERROR, "attribute number %d exceeds number of columns %d",
3692 fieldnum, tupDesc->natts);
3693 attr = TupleDescAttr(tupDesc, fieldnum - 1);
3694
3695 /* Check for dropped column, and force a NULL result if so */
3696 if (attr->attisdropped)
3697 {
3698 *op->resnull = true;
3699 return;
3700 }
3701
3702 /* Check for type mismatch --- possible after ALTER COLUMN TYPE? */
3703 /* As in CheckVarSlotCompatibility, we should but can't check typmod */
3704 if (op->d.fieldselect.resulttype != attr->atttypid)
3705 ereport(ERROR,
3706 (errcode(ERRCODE_DATATYPE_MISMATCH),
3707 errmsg("attribute %d has wrong type", fieldnum),
3708 errdetail("Table has type %s, but query expects %s.",
3709 format_type_be(attr->atttypid),
3711
3712 /* extract the field */
3713 *op->resvalue = expanded_record_get_field(erh, fieldnum,
3714 op->resnull);
3715 }
3716 else
3717 {
3718 /* Get the composite datum and extract its type fields */
3719 tuple = DatumGetHeapTupleHeader(tupDatum);
3720
3721 tupType = HeapTupleHeaderGetTypeId(tuple);
3722 tupTypmod = HeapTupleHeaderGetTypMod(tuple);
3723
3724 /* Lookup tupdesc if first time through or if type changes */
3725 tupDesc = get_cached_rowtype(tupType, tupTypmod,
3726 &op->d.fieldselect.rowcache, NULL);
3727
3728 /*
3729 * Find field's attr record. Note we don't support system columns
3730 * here: a datum tuple doesn't have valid values for most of the
3731 * interesting system columns anyway.
3732 */
3733 if (fieldnum <= 0) /* should never happen */
3734 elog(ERROR, "unsupported reference to system column %d in FieldSelect",
3735 fieldnum);
3736 if (fieldnum > tupDesc->natts) /* should never happen */
3737 elog(ERROR, "attribute number %d exceeds number of columns %d",
3738 fieldnum, tupDesc->natts);
3739 attr = TupleDescAttr(tupDesc, fieldnum - 1);
3740
3741 /* Check for dropped column, and force a NULL result if so */
3742 if (attr->attisdropped)
3743 {
3744 *op->resnull = true;
3745 return;
3746 }
3747
3748 /* Check for type mismatch --- possible after ALTER COLUMN TYPE? */
3749 /* As in CheckVarSlotCompatibility, we should but can't check typmod */
3750 if (op->d.fieldselect.resulttype != attr->atttypid)
3751 ereport(ERROR,
3752 (errcode(ERRCODE_DATATYPE_MISMATCH),
3753 errmsg("attribute %d has wrong type", fieldnum),
3754 errdetail("Table has type %s, but query expects %s.",
3755 format_type_be(attr->atttypid),
3757
3758 /* heap_getattr needs a HeapTuple not a bare HeapTupleHeader */
3759 tmptup.t_len = HeapTupleHeaderGetDatumLength(tuple);
3760 tmptup.t_data = tuple;
3761
3762 /* extract the field */
3763 *op->resvalue = heap_getattr(&tmptup,
3764 fieldnum,
3765 tupDesc,
3766 op->resnull);
3767 }
3768}
int16 AttrNumber
Definition: attnum.h:21
#define elog(elevel,...)
Definition: elog.h:225
static Datum expanded_record_get_field(ExpandedRecordHeader *erh, int fnumber, bool *isnull)
#define ER_MAGIC
static TupleDesc expanded_record_get_tupdesc(ExpandedRecordHeader *erh)
static Datum heap_getattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
Definition: htup_details.h:792
#define HeapTupleHeaderGetTypMod(tup)
Definition: htup_details.h:466
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:200
struct ExprEvalStep::@55::@81 fieldselect
AttrNumber fieldnum
Definition: execExpr.h:534
ExprEvalRowtypeCache rowcache
Definition: execExpr.h:411
static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)
Definition: tupdesc.h:153
#define VARATT_IS_EXTERNAL_EXPANDED(PTR)
Definition: varatt.h:298

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

Referenced by ExecInterpExpr().

◆ ExecEvalFieldStoreDeForm()

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

Definition at line 3780 of file execExprInterp.c.

3781{
3782 if (*op->resnull)
3783 {
3784 /* Convert null input tuple into an all-nulls row */
3785 memset(op->d.fieldstore.nulls, true,
3786 op->d.fieldstore.ncolumns * sizeof(bool));
3787 }
3788 else
3789 {
3790 /*
3791 * heap_deform_tuple needs a HeapTuple not a bare HeapTupleHeader. We
3792 * set all the fields in the struct just in case.
3793 */
3794 Datum tupDatum = *op->resvalue;
3795 HeapTupleHeader tuphdr;
3796 HeapTupleData tmptup;
3797 TupleDesc tupDesc;
3798
3799 tuphdr = DatumGetHeapTupleHeader(tupDatum);
3800 tmptup.t_len = HeapTupleHeaderGetDatumLength(tuphdr);
3801 ItemPointerSetInvalid(&(tmptup.t_self));
3802 tmptup.t_tableOid = InvalidOid;
3803 tmptup.t_data = tuphdr;
3804
3805 /*
3806 * Lookup tupdesc if first time through or if type changes. Because
3807 * we don't pin the tupdesc, we must not do this lookup until after
3808 * doing DatumGetHeapTupleHeader: that could do database access while
3809 * detoasting the datum.
3810 */
3811 tupDesc = get_cached_rowtype(op->d.fieldstore.fstore->resulttype, -1,
3812 op->d.fieldstore.rowcache, NULL);
3813
3814 /* Check that current tupdesc doesn't have more fields than allocated */
3815 if (unlikely(tupDesc->natts > op->d.fieldstore.ncolumns))
3816 elog(ERROR, "too many columns in composite type %u",
3817 op->d.fieldstore.fstore->resulttype);
3818
3819 heap_deform_tuple(&tmptup, tupDesc,
3820 op->d.fieldstore.values,
3821 op->d.fieldstore.nulls);
3822 }
3823}
#define unlikely(x)
Definition: c.h:333
void heap_deform_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *values, bool *isnull)
Definition: heaptuple.c:1346
static void ItemPointerSetInvalid(ItemPointerData *pointer)
Definition: itemptr.h:184
#define InvalidOid
Definition: postgres_ext.h:37
Datum * values
Definition: execExpr.h:521
int ncolumns
Definition: execExpr.h:553
struct ExprEvalStep::@55::@82 fieldstore
bool * nulls
Definition: execExpr.h:522
FieldStore * fstore
Definition: execExpr.h:544
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 3830 of file execExprInterp.c.

3831{
3832 TupleDesc tupDesc;
3833 HeapTuple tuple;
3834
3835 /* Lookup tupdesc (should be valid already) */
3836 tupDesc = get_cached_rowtype(op->d.fieldstore.fstore->resulttype, -1,
3837 op->d.fieldstore.rowcache, NULL);
3838
3839 tuple = heap_form_tuple(tupDesc,
3840 op->d.fieldstore.values,
3841 op->d.fieldstore.nulls);
3842
3843 *op->resvalue = HeapTupleGetDatum(tuple);
3844 *op->resnull = false;
3845}
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
Definition: heaptuple.c:1117

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

2918{
2919 FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
2921 Datum d;
2922
2923 pgstat_init_function_usage(fcinfo, &fcusage);
2924
2925 fcinfo->isnull = false;
2926 d = op->d.func.fn_addr(fcinfo);
2927 *op->resvalue = d;
2928 *op->resnull = fcinfo->isnull;
2929
2930 pgstat_end_function_usage(&fcusage, true);
2931}
void pgstat_init_function_usage(FunctionCallInfo fcinfo, PgStat_FunctionCallUsage *fcu)
void pgstat_end_function_usage(PgStat_FunctionCallUsage *fcu, bool finalize)
PGFunction fn_addr
Definition: execExpr.h:383
FunctionCallInfo fcinfo_data
Definition: execExpr.h:381
struct ExprEvalStep::@55::@63 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 2937 of file execExprInterp.c.

2939{
2940
2941 FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
2943 NullableDatum *args = fcinfo->args;
2944 int nargs = op->d.func.nargs;
2945 Datum d;
2946
2947 /* strict function, so check for NULL args */
2948 for (int argno = 0; argno < nargs; argno++)
2949 {
2950 if (args[argno].isnull)
2951 {
2952 *op->resnull = true;
2953 return;
2954 }
2955 }
2956
2957 pgstat_init_function_usage(fcinfo, &fcusage);
2958
2959 fcinfo->isnull = false;
2960 d = op->d.func.fn_addr(fcinfo);
2961 *op->resvalue = d;
2962 *op->resnull = fcinfo->isnull;
2963
2964 pgstat_end_function_usage(&fcusage, true);
2965}

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

5173{
5174 AggState *aggstate = castNode(AggState, state->parent);
5175 int result = 0;
5176 Bitmapset *grouped_cols = aggstate->grouped_cols;
5177 ListCell *lc;
5178
5179 foreach(lc, op->d.grouping_func.clauses)
5180 {
5181 int attnum = lfirst_int(lc);
5182
5183 result <<= 1;
5184
5185 if (!bms_is_member(attnum, grouped_cols))
5186 result |= 1;
5187 }
5188
5189 *op->resvalue = Int32GetDatum(result);
5190 *op->resnull = false;
5191}
bool bms_is_member(int x, const Bitmapset *a)
Definition: bitmapset.c:510
#define castNode(_type_, nodeptr)
Definition: nodes.h:176
#define lfirst_int(lc)
Definition: pg_list.h:173
static Datum Int32GetDatum(int32 X)
Definition: postgres.h:217
Bitmapset * grouped_cols
Definition: execnodes.h:2533
struct ExprEvalStep::@55::@94 grouping_func
List * clauses
Definition: execExpr.h:668

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

4153{
4156 bool inclause = op->d.hashedscalararrayop.inclause;
4157 bool strictfunc = op->d.hashedscalararrayop.finfo->fn_strict;
4158 Datum scalar = fcinfo->args[0].value;
4159 bool scalar_isnull = fcinfo->args[0].isnull;
4160 Datum result;
4161 bool resultnull;
4162 bool hashfound;
4163
4164 /* We don't setup a hashed scalar array op if the array const is null. */
4165 Assert(!*op->resnull);
4166
4167 /*
4168 * If the scalar is NULL, and the function is strict, return NULL; no
4169 * point in executing the search.
4170 */
4171 if (fcinfo->args[0].isnull && strictfunc)
4172 {
4173 *op->resnull = true;
4174 return;
4175 }
4176
4177 /* Build the hash table on first evaluation */
4178 if (elements_tab == NULL)
4179 {
4180 ScalarArrayOpExpr *saop;
4181 int16 typlen;
4182 bool typbyval;
4183 char typalign;
4184 int nitems;
4185 bool has_nulls = false;
4186 char *s;
4187 bits8 *bitmap;
4188 int bitmask;
4189 MemoryContext oldcontext;
4190 ArrayType *arr;
4191
4192 saop = op->d.hashedscalararrayop.saop;
4193
4194 arr = DatumGetArrayTypeP(*op->resvalue);
4195 nitems = ArrayGetNItems(ARR_NDIM(arr), ARR_DIMS(arr));
4196
4198 &typlen,
4199 &typbyval,
4200 &typalign);
4201
4202 oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
4203
4204 elements_tab = (ScalarArrayOpExprHashTable *)
4205 palloc0(offsetof(ScalarArrayOpExprHashTable, hash_fcinfo_data) +
4207 op->d.hashedscalararrayop.elements_tab = elements_tab;
4208 elements_tab->op = op;
4209
4210 fmgr_info(saop->hashfuncid, &elements_tab->hash_finfo);
4211 fmgr_info_set_expr((Node *) saop, &elements_tab->hash_finfo);
4212
4214 &elements_tab->hash_finfo,
4215 1,
4216 saop->inputcollid,
4217 NULL,
4218 NULL);
4219
4220 /*
4221 * Create the hash table sizing it according to the number of elements
4222 * in the array. This does assume that the array has no duplicates.
4223 * If the array happens to contain many duplicate values then it'll
4224 * just mean that we sized the table a bit on the large side.
4225 */
4226 elements_tab->hashtab = saophash_create(CurrentMemoryContext, nitems,
4227 elements_tab);
4228
4229 MemoryContextSwitchTo(oldcontext);
4230
4231 s = (char *) ARR_DATA_PTR(arr);
4232 bitmap = ARR_NULLBITMAP(arr);
4233 bitmask = 1;
4234 for (int i = 0; i < nitems; i++)
4235 {
4236 /* Get array element, checking for NULL. */
4237 if (bitmap && (*bitmap & bitmask) == 0)
4238 {
4239 has_nulls = true;
4240 }
4241 else
4242 {
4243 Datum element;
4244
4245 element = fetch_att(s, typbyval, typlen);
4246 s = att_addlength_pointer(s, typlen, s);
4247 s = (char *) att_align_nominal(s, typalign);
4248
4249 saophash_insert(elements_tab->hashtab, element, &hashfound);
4250 }
4251
4252 /* Advance bitmap pointer if any. */
4253 if (bitmap)
4254 {
4255 bitmask <<= 1;
4256 if (bitmask == 0x100)
4257 {
4258 bitmap++;
4259 bitmask = 1;
4260 }
4261 }
4262 }
4263
4264 /*
4265 * Remember if we had any nulls so that we know if we need to execute
4266 * non-strict functions with a null lhs value if no match is found.
4267 */
4268 op->d.hashedscalararrayop.has_nulls = has_nulls;
4269 }
4270
4271 /* Check the hash to see if we have a match. */
4272 hashfound = NULL != saophash_lookup(elements_tab->hashtab, scalar);
4273
4274 /* the result depends on if the clause is an IN or NOT IN clause */
4275 if (inclause)
4276 result = BoolGetDatum(hashfound); /* IN */
4277 else
4278 result = BoolGetDatum(!hashfound); /* NOT IN */
4279
4280 resultnull = false;
4281
4282 /*
4283 * If we didn't find a match in the array, we still might need to handle
4284 * the possibility of null values. We didn't put any NULLs into the
4285 * hashtable, but instead marked if we found any when building the table
4286 * in has_nulls.
4287 */
4288 if (!hashfound && op->d.hashedscalararrayop.has_nulls)
4289 {
4290 if (strictfunc)
4291 {
4292
4293 /*
4294 * We have nulls in the array so a non-null lhs and no match must
4295 * yield NULL.
4296 */
4297 result = (Datum) 0;
4298 resultnull = true;
4299 }
4300 else
4301 {
4302 /*
4303 * Execute function will null rhs just once.
4304 *
4305 * The hash lookup path will have scribbled on the lhs argument so
4306 * we need to set it up also (even though we entered this function
4307 * with it already set).
4308 */
4309 fcinfo->args[0].value = scalar;
4310 fcinfo->args[0].isnull = scalar_isnull;
4311 fcinfo->args[1].value = (Datum) 0;
4312 fcinfo->args[1].isnull = true;
4313
4314 result = op->d.hashedscalararrayop.finfo->fn_addr(fcinfo);
4315 resultnull = fcinfo->isnull;
4316
4317 /*
4318 * Reverse the result for NOT IN clauses since the above function
4319 * is the equality function and we need not-equals.
4320 */
4321 if (!inclause)
4322 result = !result;
4323 }
4324 }
4325
4326 *op->resvalue = result;
4327 *op->resnull = resultnull;
4328}
int16_t int16
Definition: c.h:483
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:127
#define SizeForFunctionCallInfo(nargs)
Definition: fmgr.h:102
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#define fmgr_info_set_expr(expr, finfo)
Definition: fmgr.h:135
void get_typlenbyvalalign(Oid typid, int16 *typlen, bool *typbyval, char *typalign)
Definition: lsyscache.c:2271
char typalign
Definition: pg_type.h:176
static Datum BoolGetDatum(bool X)
Definition: postgres.h:107
static chr element(struct vars *v, const chr *startp, const chr *endp)
Definition: regc_locale.c:376
struct ExprEvalStep::@55::@90 hashedscalararrayop
bool has_nulls
Definition: execExpr.h:633
struct ScalarArrayOpExprHashTable * elements_tab
Definition: execExpr.h:635
bool inclause
Definition: execExpr.h:634
ScalarArrayOpExpr * saop
Definition: execExpr.h:638
FmgrInfo * finfo
Definition: execExpr.h:380
PGFunction fn_addr
Definition: fmgr.h:58
FunctionCallInfoBaseData hash_fcinfo_data
struct ExprEvalStep * op
#define att_align_nominal(cur_offset, attalign)
Definition: tupmacs.h:150
#define att_addlength_pointer(cur_offset, attlen, attptr)
Definition: tupmacs.h:185
static Datum fetch_att(const void *T, bool attbyval, int attlen)
Definition: tupmacs.h:53

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

Referenced by ExecInterpExpr().

◆ ExecEvalJsonCoercion()

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

Definition at line 5038 of file execExprInterp.c.

5040{
5042
5043 /*
5044 * Prepare to call json_populate_type() to coerce the boolean result of
5045 * JSON_EXISTS_OP to the target type. If the target type is integer or a
5046 * domain over integer, call the boolean-to-integer cast function instead,
5047 * because the integer's input function (which is what
5048 * json_populate_type() calls to coerce to scalar target types) doesn't
5049 * accept boolean literals as valid input. We only have a special case
5050 * for integer and domains thereof as it seems common to use those types
5051 * for EXISTS columns in JSON_TABLE().
5052 */
5054 {
5056 {
5057 /* Check domain constraints if any. */
5062 econtext->ecxt_per_query_memory,
5063 (Node *) escontext))
5064 {
5065 *op->resnull = true;
5066 *op->resvalue = (Datum) 0;
5067 }
5068 else
5070 return;
5071 }
5072
5074 DatumGetBool(*op->resvalue) ?
5075 CStringGetDatum("true") :
5076 CStringGetDatum("false"));
5077 }
5078
5079 *op->resvalue = json_populate_type(*op->resvalue, JSONBOID,
5083 econtext->ecxt_per_query_memory,
5084 op->resnull,
5086 (Node *) escontext);
5087}
bool domain_check_safe(Datum value, bool isnull, Oid domainType, void **extra, MemoryContext mcxt, Node *escontext)
Definition: domains.c:355
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:641
Datum bool_int4(PG_FUNCTION_ARGS)
Definition: int.c:372
Datum jsonb_in(PG_FUNCTION_ARGS)
Definition: jsonb.c:73
Datum json_populate_type(Datum json_val, Oid json_type, Oid typid, int32 typmod, void **cache, MemoryContext mcxt, bool *isnull, bool omit_quotes, Node *escontext)
Definition: jsonfuncs.c:3344
static Datum CStringGetDatum(const char *X)
Definition: postgres.h:355
void * json_coercion_cache
Definition: execExpr.h:760
bool exists_coerce
Definition: execExpr.h:757
bool exists_cast_to_int
Definition: execExpr.h:758
struct ExprEvalStep::@55::@104 jsonexpr_coercion
bool exists_check_domain
Definition: execExpr.h:759
int32 targettypmod
Definition: execExpr.h:754
Oid targettype
Definition: execExpr.h:753
bool omit_quotes
Definition: execExpr.h:755

References bool_int4(), CStringGetDatum(), DatumGetBool(), DirectFunctionCall1, domain_check_safe(), ExprContext::ecxt_per_query_memory, ExprEvalStep::escontext, json_populate_type(), jsonb_in(), and ExprEvalStep::op.

Referenced by ExecInterpExpr().

◆ ExecEvalJsonCoercionFinish()

void ExecEvalJsonCoercionFinish ( ExprState state,
ExprEvalStep op 
)

Definition at line 5118 of file execExprInterp.c.

5119{
5120 JsonExprState *jsestate = op->d.jsonexpr.jsestate;
5121
5122 if (SOFT_ERROR_OCCURRED(&jsestate->escontext))
5123 {
5124 /*
5125 * jsestate->error or jsestate->empty being set means that the error
5126 * occurred when coercing the JsonBehavior value. Throw the error in
5127 * that case with the actual coercion error message shown in the
5128 * DETAIL part.
5129 */
5130 if (DatumGetBool(jsestate->error.value))
5131 ereport(ERROR,
5132 (errcode(ERRCODE_DATATYPE_MISMATCH),
5133 /*- translator: first %s is a SQL/JSON clause (e.g. ON ERROR) */
5134 errmsg("could not coerce %s expression (%s) to the RETURNING type",
5135 "ON ERROR",
5137 errdetail("%s", jsestate->escontext.error_data->message)));
5138 else if (DatumGetBool(jsestate->empty.value))
5139 ereport(ERROR,
5140 (errcode(ERRCODE_DATATYPE_MISMATCH),
5141 /*- translator: first %s is a SQL/JSON clause (e.g. ON ERROR) */
5142 errmsg("could not coerce %s expression (%s) to the RETURNING type",
5143 "ON EMPTY",
5145 errdetail("%s", jsestate->escontext.error_data->message)));
5146
5147 *op->resvalue = (Datum) 0;
5148 *op->resnull = true;
5149
5150 jsestate->error.value = BoolGetDatum(true);
5151
5152 /*
5153 * Reset for next use such as for catching errors when coercing a
5154 * JsonBehavior expression.
5155 */
5156 jsestate->escontext.error_occurred = false;
5157 jsestate->escontext.error_occurred = false;
5158 jsestate->escontext.details_wanted = true;
5159 }
5160}
static char * GetJsonBehaviorValueString(JsonBehavior *behavior)
char * message
Definition: elog.h:440
bool details_wanted
Definition: miscnodes.h:48
ErrorData * error_data
Definition: miscnodes.h:49
bool error_occurred
Definition: miscnodes.h:47
struct JsonExprState * jsestate
Definition: execExpr.h:747
struct ExprEvalStep::@55::@103 jsonexpr
NullableDatum empty
Definition: execnodes.h:1069
JsonExpr * jsexpr
Definition: execnodes.h:1047
NullableDatum error
Definition: execnodes.h:1066
ErrorSaveContext escontext
Definition: execnodes.h:1106
JsonBehavior * on_empty
Definition: primnodes.h:1870
JsonBehavior * on_error
Definition: primnodes.h:1871

References BoolGetDatum(), DatumGetBool(), ErrorSaveContext::details_wanted, JsonExprState::empty, ereport, errcode(), errdetail(), errmsg(), JsonExprState::error, ERROR, ErrorSaveContext::error_data, ErrorSaveContext::error_occurred, JsonExprState::escontext, GetJsonBehaviorValueString(), ExprEvalStep::jsestate, JsonExprState::jsexpr, ErrorData::message, JsonExpr::on_empty, JsonExpr::on_error, ExprEvalStep::op, SOFT_ERROR_OCCURRED, and NullableDatum::value.

Referenced by ExecInterpExpr().

◆ ExecEvalJsonConstructor()

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

Definition at line 4583 of file execExprInterp.c.

4585{
4586 Datum res;
4588 JsonConstructorExpr *ctor = jcstate->constructor;
4589 bool is_jsonb = ctor->returning->format->format_type == JS_FORMAT_JSONB;
4590 bool isnull = false;
4591
4592 if (ctor->type == JSCTOR_JSON_ARRAY)
4593 res = (is_jsonb ?
4595 json_build_array_worker) (jcstate->nargs,
4596 jcstate->arg_values,
4597 jcstate->arg_nulls,
4598 jcstate->arg_types,
4599 jcstate->constructor->absent_on_null);
4600 else if (ctor->type == JSCTOR_JSON_OBJECT)
4601 res = (is_jsonb ?
4604 jcstate->arg_values,
4605 jcstate->arg_nulls,
4606 jcstate->arg_types,
4607 jcstate->constructor->absent_on_null,
4608 jcstate->constructor->unique);
4609 else if (ctor->type == JSCTOR_JSON_SCALAR)
4610 {
4611 if (jcstate->arg_nulls[0])
4612 {
4613 res = (Datum) 0;
4614 isnull = true;
4615 }
4616 else
4617 {
4618 Datum value = jcstate->arg_values[0];
4619 Oid outfuncid = jcstate->arg_type_cache[0].outfuncid;
4621 jcstate->arg_type_cache[0].category;
4622
4623 if (is_jsonb)
4624 res = datum_to_jsonb(value, category, outfuncid);
4625 else
4626 res = datum_to_json(value, category, outfuncid);
4627 }
4628 }
4629 else if (ctor->type == JSCTOR_JSON_PARSE)
4630 {
4631 if (jcstate->arg_nulls[0])
4632 {
4633 res = (Datum) 0;
4634 isnull = true;
4635 }
4636 else
4637 {
4638 Datum value = jcstate->arg_values[0];
4639 text *js = DatumGetTextP(value);
4640
4641 if (is_jsonb)
4642 res = jsonb_from_text(js, true);
4643 else
4644 {
4645 (void) json_validate(js, true, true);
4646 res = value;
4647 }
4648 }
4649 }
4650 else
4651 elog(ERROR, "invalid JsonConstructorExpr type %d", ctor->type);
4652
4653 *op->resvalue = res;
4654 *op->resnull = isnull;
4655}
#define DatumGetTextP(X)
Definition: fmgr.h:332
static struct @162 value
if(TABLE==NULL||TABLE_index==NULL)
Definition: isn.c:76
Datum json_build_array_worker(int nargs, const Datum *args, const bool *nulls, const Oid *types, bool absent_on_null)
Definition: json.c:1344
Datum json_build_object_worker(int nargs, const Datum *args, const bool *nulls, const Oid *types, bool absent_on_null, bool unique_keys)
Definition: json.c:1224
Datum datum_to_json(Datum val, JsonTypeCategory tcategory, Oid outfuncoid)
Definition: json.c:763
bool json_validate(text *json, bool check_unique_keys, bool throw_error)
Definition: json.c:1812
Datum jsonb_from_text(text *js, bool unique_keys)
Definition: jsonb.c:147
Datum jsonb_build_array_worker(int nargs, const Datum *args, const bool *nulls, const Oid *types, bool absent_on_null)
Definition: jsonb.c:1210
Datum jsonb_build_object_worker(int nargs, const Datum *args, const bool *nulls, const Oid *types, bool absent_on_null, bool unique_keys)
Definition: jsonb.c:1125
Datum datum_to_jsonb(Datum val, JsonTypeCategory tcategory, Oid outfuncoid)
Definition: jsonb.c:1112
JsonTypeCategory
Definition: jsonfuncs.h:69
@ JS_FORMAT_JSONB
Definition: primnodes.h:1671
@ JSCTOR_JSON_PARSE
Definition: primnodes.h:1725
@ JSCTOR_JSON_OBJECT
Definition: primnodes.h:1721
@ JSCTOR_JSON_SCALAR
Definition: primnodes.h:1726
@ JSCTOR_JSON_ARRAY
Definition: primnodes.h:1722
struct ExprEvalStep::@55::@92 json_constructor
struct JsonConstructorExprState * jcstate
Definition: execExpr.h:656
JsonConstructorExpr * constructor
Definition: execExpr.h:814
struct JsonConstructorExprState::@105 * arg_type_cache
JsonReturning * returning
Definition: primnodes.h:1741
JsonConstructorType type
Definition: primnodes.h:1737
JsonFormatType format_type
Definition: primnodes.h:1682
JsonFormat * format
Definition: primnodes.h:1694
Definition: c.h:644

References JsonConstructorExpr::absent_on_null, JsonConstructorExprState::arg_nulls, JsonConstructorExprState::arg_type_cache, JsonConstructorExprState::arg_types, JsonConstructorExprState::arg_values, JsonConstructorExprState::category, JsonConstructorExprState::constructor, datum_to_json(), datum_to_jsonb(), DatumGetTextP, elog, ERROR, JsonReturning::format, JsonFormat::format_type, if(), ExprEvalStep::isnull, ExprEvalStep::jcstate, 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(), JsonConstructorExprState::nargs, ExprEvalStep::op, JsonConstructorExprState::outfuncid, res, JsonConstructorExpr::returning, JsonConstructorExpr::type, JsonConstructorExpr::unique, and value.

Referenced by ExecInterpExpr().

◆ ExecEvalJsonExprPath()

int ExecEvalJsonExprPath ( ExprState state,
ExprEvalStep op,
ExprContext econtext 
)

Definition at line 4761 of file execExprInterp.c.

4763{
4764 JsonExprState *jsestate = op->d.jsonexpr.jsestate;
4765 JsonExpr *jsexpr = jsestate->jsexpr;
4766 Datum item;
4767 JsonPath *path;
4768 bool throw_error = jsexpr->on_error->btype == JSON_BEHAVIOR_ERROR;
4769 bool error = false,
4770 empty = false;
4771 int jump_eval_coercion = jsestate->jump_eval_coercion;
4772 char *val_string = NULL;
4773
4774 item = jsestate->formatted_expr.value;
4775 path = DatumGetJsonPathP(jsestate->pathspec.value);
4776
4777 /* Set error/empty to false. */
4778 memset(&jsestate->error, 0, sizeof(NullableDatum));
4779 memset(&jsestate->empty, 0, sizeof(NullableDatum));
4780
4781 /* Also reset ErrorSaveContext contents for the next row. */
4782 if (jsestate->escontext.details_wanted)
4783 {
4784 jsestate->escontext.error_data = NULL;
4785 jsestate->escontext.details_wanted = false;
4786 }
4787 jsestate->escontext.error_occurred = false;
4788
4789 switch (jsexpr->op)
4790 {
4791 case JSON_EXISTS_OP:
4792 {
4793 bool exists = JsonPathExists(item, path,
4794 !throw_error ? &error : NULL,
4795 jsestate->args);
4796
4797 if (!error)
4798 {
4799 *op->resnull = false;
4800 *op->resvalue = BoolGetDatum(exists);
4801 }
4802 }
4803 break;
4804
4805 case JSON_QUERY_OP:
4806 *op->resvalue = JsonPathQuery(item, path, jsexpr->wrapper, &empty,
4807 !throw_error ? &error : NULL,
4808 jsestate->args,
4809 jsexpr->column_name);
4810
4811 *op->resnull = (DatumGetPointer(*op->resvalue) == NULL);
4812 break;
4813
4814 case JSON_VALUE_OP:
4815 {
4816 JsonbValue *jbv = JsonPathValue(item, path, &empty,
4817 !throw_error ? &error : NULL,
4818 jsestate->args,
4819 jsexpr->column_name);
4820
4821 if (jbv == NULL)
4822 {
4823 /* Will be coerced with json_populate_type(), if needed. */
4824 *op->resvalue = (Datum) 0;
4825 *op->resnull = true;
4826 }
4827 else if (!error && !empty)
4828 {
4829 if (jsexpr->returning->typid == JSONOID ||
4830 jsexpr->returning->typid == JSONBOID)
4831 {
4834 }
4835 else if (jsexpr->use_json_coercion)
4836 {
4838 *op->resnull = false;
4839 }
4840 else
4841 {
4843
4844 /*
4845 * Simply convert to the default RETURNING type (text)
4846 * if no coercion needed.
4847 */
4848 if (!jsexpr->use_io_coercion)
4851 }
4852 }
4853 break;
4854 }
4855
4856 /* JSON_TABLE_OP can't happen here */
4857
4858 default:
4859 elog(ERROR, "unrecognized SQL/JSON expression op %d",
4860 (int) jsexpr->op);
4861 return false;
4862 }
4863
4864 /*
4865 * Coerce the result value to the RETURNING type by calling its input
4866 * function.
4867 */
4868 if (!*op->resnull && jsexpr->use_io_coercion)
4869 {
4870 FunctionCallInfo fcinfo;
4871
4872 Assert(jump_eval_coercion == -1);
4873 fcinfo = jsestate->input_fcinfo;
4874 Assert(fcinfo != NULL);
4875 Assert(val_string != NULL);
4876 fcinfo->args[0].value = PointerGetDatum(val_string);
4877 fcinfo->args[0].isnull = *op->resnull;
4878
4879 /*
4880 * Second and third arguments are already set up in
4881 * ExecInitJsonExpr().
4882 */
4883
4884 fcinfo->isnull = false;
4885 *op->resvalue = FunctionCallInvoke(fcinfo);
4886 if (SOFT_ERROR_OCCURRED(&jsestate->escontext))
4887 error = true;
4888 }
4889
4890 /*
4891 * When setting up the ErrorSaveContext (if needed) for capturing the
4892 * errors that occur when coercing the JsonBehavior expression, set
4893 * details_wanted to be able to show the actual error message as the
4894 * DETAIL of the error message that tells that it is the JsonBehavior
4895 * expression that caused the error; see ExecEvalJsonCoercionFinish().
4896 */
4897
4898 /* Handle ON EMPTY. */
4899 if (empty)
4900 {
4901 *op->resvalue = (Datum) 0;
4902 *op->resnull = true;
4903 if (jsexpr->on_empty)
4904 {
4905 if (jsexpr->on_empty->btype != JSON_BEHAVIOR_ERROR)
4906 {
4907 jsestate->empty.value = BoolGetDatum(true);
4908 /* Set up to catch coercion errors of the ON EMPTY value. */
4909 jsestate->escontext.error_occurred = false;
4910 jsestate->escontext.details_wanted = true;
4911 /* Jump to end if the ON EMPTY behavior is to return NULL */
4912 return jsestate->jump_empty >= 0 ? jsestate->jump_empty : jsestate->jump_end;
4913 }
4914 }
4915 else if (jsexpr->on_error->btype != JSON_BEHAVIOR_ERROR)
4916 {
4917 jsestate->error.value = BoolGetDatum(true);
4918 /* Set up to catch coercion errors of the ON ERROR value. */
4919 jsestate->escontext.error_occurred = false;
4920 jsestate->escontext.details_wanted = true;
4921 Assert(!throw_error);
4922 /* Jump to end if the ON ERROR behavior is to return NULL */
4923 return jsestate->jump_error >= 0 ? jsestate->jump_error : jsestate->jump_end;
4924 }
4925
4926 if (jsexpr->column_name)
4927 ereport(ERROR,
4928 errcode(ERRCODE_NO_SQL_JSON_ITEM),
4929 errmsg("no SQL/JSON item found for specified path of column \"%s\"",
4930 jsexpr->column_name));
4931 else
4932 ereport(ERROR,
4933 errcode(ERRCODE_NO_SQL_JSON_ITEM),
4934 errmsg("no SQL/JSON item found for specified path"));
4935 }
4936
4937 /*
4938 * ON ERROR. Wouldn't get here if the behavior is ERROR, because they
4939 * would have already been thrown.
4940 */
4941 if (error)
4942 {
4943 Assert(!throw_error);
4944 *op->resvalue = (Datum) 0;
4945 *op->resnull = true;
4946 jsestate->error.value = BoolGetDatum(true);
4947 /* Set up to catch coercion errors of the ON ERROR value. */
4948 jsestate->escontext.error_occurred = false;
4949 jsestate->escontext.details_wanted = true;
4950 /* Jump to end if the ON ERROR behavior is to return NULL */
4951 return jsestate->jump_error >= 0 ? jsestate->jump_error : jsestate->jump_end;
4952 }
4953
4954 return jump_eval_coercion >= 0 ? jump_eval_coercion : jsestate->jump_end;
4955}
static char * ExecGetJsonValueItemString(JsonbValue *item, bool *resnull)
char * val_string
Definition: informix.c:694
Datum jsonb_out(PG_FUNCTION_ARGS)
Definition: jsonb.c:108
static Datum JsonbPGetDatum(const Jsonb *p)
Definition: jsonb.h:386
Jsonb * JsonbValueToJsonb(JsonbValue *val)
Definition: jsonb_util.c:92
static JsonPath * DatumGetJsonPathP(Datum d)
Definition: jsonpath.h:35
bool JsonPathExists(Datum jb, JsonPath *jp, bool *error, List *vars)
Datum JsonPathQuery(Datum jb, JsonPath *jp, JsonWrapper wrapper, bool *empty, bool *error, List *vars, const char *column_name)
JsonbValue * JsonPathValue(Datum jb, JsonPath *jp, bool *empty, bool *error, List *vars, const char *column_name)
@ JSON_BEHAVIOR_ERROR
Definition: primnodes.h:1797
@ JSON_QUERY_OP
Definition: primnodes.h:1834
@ JSON_EXISTS_OP
Definition: primnodes.h:1833
@ JSON_VALUE_OP
Definition: primnodes.h:1835
static void error(void)
Definition: sql-dyntest.c:147
JsonBehaviorType btype
Definition: primnodes.h:1821
int jump_eval_coercion
Definition: execnodes.h:1083
FunctionCallInfo input_fcinfo
Definition: execnodes.h:1097
NullableDatum pathspec
Definition: execnodes.h:1053
NullableDatum formatted_expr
Definition: execnodes.h:1050
char * column_name
Definition: primnodes.h:1850
bool use_io_coercion
Definition: primnodes.h:1877
JsonReturning * returning
Definition: primnodes.h:1863
bool use_json_coercion
Definition: primnodes.h:1878
JsonWrapper wrapper
Definition: primnodes.h:1881
JsonExprOp op
Definition: primnodes.h:1848
Datum textin(PG_FUNCTION_ARGS)
Definition: varlena.c:579

References FunctionCallInfoBaseData::args, JsonExprState::args, Assert, BoolGetDatum(), JsonBehavior::btype, JsonExpr::column_name, CStringGetDatum(), DatumGetCString(), DatumGetJsonPathP(), DatumGetPointer(), ErrorSaveContext::details_wanted, DirectFunctionCall1, elog, JsonExprState::empty, ereport, errcode(), errmsg(), JsonExprState::error, ERROR, error(), ErrorSaveContext::error_data, ErrorSaveContext::error_occurred, JsonExprState::escontext, ExecGetJsonValueItemString(), JsonExprState::formatted_expr, FunctionCallInvoke, JsonExprState::input_fcinfo, FunctionCallInfoBaseData::isnull, NullableDatum::isnull, ExprEvalStep::jsestate, JsonExprState::jsexpr, JSON_BEHAVIOR_ERROR, JSON_EXISTS_OP, JSON_QUERY_OP, JSON_VALUE_OP, jsonb_out(), JsonbPGetDatum(), JsonbValueToJsonb(), JsonPathExists(), JsonPathQuery(), JsonPathValue(), JsonExprState::jump_empty, JsonExprState::jump_end, JsonExprState::jump_error, JsonExprState::jump_eval_coercion, JsonExpr::on_empty, JsonExpr::on_error, ExprEvalStep::op, JsonExpr::op, JsonExprState::pathspec, PointerGetDatum(), JsonExpr::returning, SOFT_ERROR_OCCURRED, textin(), JsonReturning::typid, JsonExpr::use_io_coercion, JsonExpr::use_json_coercion, val_string, NullableDatum::value, and JsonExpr::wrapper.

Referenced by ExecInterpExpr().

◆ ExecEvalJsonIsPredicate()

void ExecEvalJsonIsPredicate ( ExprState state,
ExprEvalStep op 
)

Definition at line 4661 of file execExprInterp.c.

4662{
4663 JsonIsPredicate *pred = op->d.is_json.pred;
4664 Datum js = *op->resvalue;
4665 Oid exprtype;
4666 bool res;
4667
4668 if (*op->resnull)
4669 {
4670 *op->resvalue = BoolGetDatum(false);
4671 return;
4672 }
4673
4674 exprtype = exprType(pred->expr);
4675
4676 if (exprtype == TEXTOID || exprtype == JSONOID)
4677 {
4678 text *json = DatumGetTextP(js);
4679
4680 if (pred->item_type == JS_TYPE_ANY)
4681 res = true;
4682 else
4683 {
4684 switch (json_get_first_token(json, false))
4685 {
4687 res = pred->item_type == JS_TYPE_OBJECT;
4688 break;
4690 res = pred->item_type == JS_TYPE_ARRAY;
4691 break;
4692 case JSON_TOKEN_STRING:
4693 case JSON_TOKEN_NUMBER:
4694 case JSON_TOKEN_TRUE:
4695 case JSON_TOKEN_FALSE:
4696 case JSON_TOKEN_NULL:
4697 res = pred->item_type == JS_TYPE_SCALAR;
4698 break;
4699 default:
4700 res = false;
4701 break;
4702 }
4703 }
4704
4705 /*
4706 * Do full parsing pass only for uniqueness check or for JSON text
4707 * validation.
4708 */
4709 if (res && (pred->unique_keys || exprtype == TEXTOID))
4710 res = json_validate(json, pred->unique_keys, false);
4711 }
4712 else if (exprtype == JSONBOID)
4713 {
4714 if (pred->item_type == JS_TYPE_ANY)
4715 res = true;
4716 else
4717 {
4718 Jsonb *jb = DatumGetJsonbP(js);
4719
4720 switch (pred->item_type)
4721 {
4722 case JS_TYPE_OBJECT:
4723 res = JB_ROOT_IS_OBJECT(jb);
4724 break;
4725 case JS_TYPE_ARRAY:
4727 break;
4728 case JS_TYPE_SCALAR:
4730 break;
4731 default:
4732 res = false;
4733 break;
4734 }
4735 }
4736
4737 /* Key uniqueness check is redundant for jsonb */
4738 }
4739 else
4740 res = false;
4741
4742 *op->resvalue = BoolGetDatum(res);
4743}
@ JSON_TOKEN_FALSE
Definition: jsonapi.h:29
@ JSON_TOKEN_TRUE
Definition: jsonapi.h:28
@ JSON_TOKEN_NULL
Definition: jsonapi.h:30
@ JSON_TOKEN_OBJECT_START
Definition: jsonapi.h:22
@ JSON_TOKEN_NUMBER
Definition: jsonapi.h:21
@ JSON_TOKEN_STRING
Definition: jsonapi.h:20
@ JSON_TOKEN_ARRAY_START
Definition: jsonapi.h:24
#define JB_ROOT_IS_OBJECT(jbp_)
Definition: jsonb.h:221
#define JB_ROOT_IS_ARRAY(jbp_)
Definition: jsonb.h:222
static Jsonb * DatumGetJsonbP(Datum d)
Definition: jsonb.h:374
#define JB_ROOT_IS_SCALAR(jbp_)
Definition: jsonb.h:220
JsonTokenType json_get_first_token(text *json, bool throw_error)
Definition: jsonfuncs.c:5949
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:42
@ JS_TYPE_ANY
Definition: primnodes.h:1753
@ JS_TYPE_ARRAY
Definition: primnodes.h:1755
@ JS_TYPE_OBJECT
Definition: primnodes.h:1754
@ JS_TYPE_SCALAR
Definition: primnodes.h:1756
JsonIsPredicate * pred
Definition: execExpr.h:741
struct ExprEvalStep::@55::@102 is_json
JsonValueType item_type
Definition: primnodes.h:1768
Definition: jsonb.h:213

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

◆ ExecEvalMergeSupportFunc()

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

Definition at line 5199 of file execExprInterp.c.

5201{
5202 ModifyTableState *mtstate = castNode(ModifyTableState, state->parent);
5203 MergeActionState *relaction = mtstate->mt_merge_action;
5204
5205 if (!relaction)
5206 elog(ERROR, "no merge action in progress");
5207
5208 /* Return the MERGE action ("INSERT", "UPDATE", or "DELETE") */
5209 switch (relaction->mas_action->commandType)
5210 {
5211 case CMD_INSERT:
5213 *op->resnull = false;
5214 break;
5215 case CMD_UPDATE:
5217 *op->resnull = false;
5218 break;
5219 case CMD_DELETE:
5221 *op->resnull = false;
5222 break;
5223 case CMD_NOTHING:
5224 elog(ERROR, "unexpected merge action: DO NOTHING");
5225 break;
5226 default:
5227 elog(ERROR, "unrecognized commandType: %d",
5228 (int) relaction->mas_action->commandType);
5229 }
5230}
@ CMD_INSERT
Definition: nodes.h:267
@ CMD_DELETE
Definition: nodes.h:268
@ CMD_UPDATE
Definition: nodes.h:266
@ CMD_NOTHING
Definition: nodes.h:272
MergeAction * mas_action
Definition: execnodes.h:443
CmdType commandType
Definition: primnodes.h:2038
MergeActionState * mt_merge_action
Definition: execnodes.h:1427
text * cstring_to_text_with_len(const char *s, int len)
Definition: varlena.c:196

References castNode, CMD_DELETE, CMD_INSERT, CMD_NOTHING, CMD_UPDATE, MergeAction::commandType, cstring_to_text_with_len(), elog, ERROR, MergeActionState::mas_action, ModifyTableState::mt_merge_action, ExprEvalStep::op, and PointerGetDatum().

Referenced by ExecInterpExpr().

◆ ExecEvalMinMax()

void ExecEvalMinMax ( ExprState state,
ExprEvalStep op 
)

Definition at line 3602 of file execExprInterp.c.

3603{
3604 Datum *values = op->d.minmax.values;
3605 bool *nulls = op->d.minmax.nulls;
3606 FunctionCallInfo fcinfo = op->d.minmax.fcinfo_data;
3607 MinMaxOp operator = op->d.minmax.op;
3608
3609 /* set at initialization */
3610 Assert(fcinfo->args[0].isnull == false);
3611 Assert(fcinfo->args[1].isnull == false);
3612
3613 /* default to null result */
3614 *op->resnull = true;
3615
3616 for (int off = 0; off < op->d.minmax.nelems; off++)
3617 {
3618 /* ignore NULL inputs */
3619 if (nulls[off])
3620 continue;
3621
3622 if (*op->resnull)
3623 {
3624 /* first nonnull input, adopt value */
3625 *op->resvalue = values[off];
3626 *op->resnull = false;
3627 }
3628 else
3629 {
3630 int cmpresult;
3631
3632 /* apply comparison function */
3633 fcinfo->args[0].value = *op->resvalue;
3634 fcinfo->args[1].value = values[off];
3635
3636 fcinfo->isnull = false;
3637 cmpresult = DatumGetInt32(FunctionCallInvoke(fcinfo));
3638 if (fcinfo->isnull) /* probably should not happen */
3639 continue;
3640
3641 if (cmpresult > 0 && operator == IS_LEAST)
3642 *op->resvalue = values[off];
3643 else if (cmpresult < 0 && operator == IS_GREATEST)
3644 *op->resvalue = values[off];
3645 }
3646 }
3647}
static Datum values[MAXATTR]
Definition: bootstrap.c:151
static int32 DatumGetInt32(Datum X)
Definition: postgres.h:207
MinMaxOp
Definition: primnodes.h:1532
@ IS_LEAST
Definition: primnodes.h:1534
@ IS_GREATEST
Definition: primnodes.h:1533
MinMaxOp op
Definition: execExpr.h:525
struct ExprEvalStep::@55::@80 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 3199 of file execExprInterp.c.

3200{
3202
3203 switch (op->d.nextvalueexpr.seqtypid)
3204 {
3205 case INT2OID:
3207 break;
3208 case INT4OID:
3210 break;
3211 case INT8OID:
3213 break;
3214 default:
3215 elog(ERROR, "unsupported sequence type %u",
3217 }
3218 *op->resnull = false;
3219}
int64_t int64
Definition: c.h:485
int64 nextval_internal(Oid relid, bool check_permissions)
Definition: sequence.c:623
Datum Int64GetDatum(int64 X)
Definition: fmgr.c:1807
#define newval
static Datum Int16GetDatum(int16 X)
Definition: postgres.h:177
Oid seqtypid
Definition: execExpr.h:465
struct ExprEvalStep::@55::@74 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 2974 of file execExprInterp.c.

2975{
2976 ParamExecData *prm;
2977
2978 prm = &(econtext->ecxt_param_exec_vals[op->d.param.paramid]);
2979 if (unlikely(prm->execPlan != NULL))
2980 {
2981 /* Parameter not evaluated yet, so go do it */
2982 ExecSetParamPlan(prm->execPlan, econtext);
2983 /* ExecSetParamPlan should have processed this param... */
2984 Assert(prm->execPlan == NULL);
2985 }
2986 *op->resvalue = prm->value;
2987 *op->resnull = prm->isnull;
2988}
void ExecSetParamPlan(SubPlanState *node, ExprContext *econtext)
Definition: nodeSubplan.c:1100
ParamExecData * ecxt_param_exec_vals
Definition: execnodes.h:278
struct ExprEvalStep::@55::@68 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 2996 of file execExprInterp.c.

2997{
2998 ParamListInfo paramInfo = econtext->ecxt_param_list_info;
2999 int paramId = op->d.param.paramid;
3000
3001 if (likely(paramInfo &&
3002 paramId > 0 && paramId <= paramInfo->numParams))
3003 {
3004 ParamExternData *prm;
3005 ParamExternData prmdata;
3006
3007 /* give hook a chance in case parameter is dynamic */
3008 if (paramInfo->paramFetch != NULL)
3009 prm = paramInfo->paramFetch(paramInfo, paramId, false, &prmdata);
3010 else
3011 prm = &paramInfo->params[paramId - 1];
3012
3013 if (likely(OidIsValid(prm->ptype)))
3014 {
3015 /* safety check in case hook did something unexpected */
3016 if (unlikely(prm->ptype != op->d.param.paramtype))
3017 ereport(ERROR,
3018 (errcode(ERRCODE_DATATYPE_MISMATCH),
3019 errmsg("type of parameter %d (%s) does not match that when preparing the plan (%s)",
3020 paramId,
3021 format_type_be(prm->ptype),
3023 *op->resvalue = prm->value;
3024 *op->resnull = prm->isnull;
3025 return;
3026 }
3027 }
3028
3029 ereport(ERROR,
3030 (errcode(ERRCODE_UNDEFINED_OBJECT),
3031 errmsg("no value found for parameter %d", paramId)));
3032}
#define likely(x)
Definition: c.h:332
#define OidIsValid(objectId)
Definition: c.h:732
ParamListInfo ecxt_param_list_info
Definition: execnodes.h:279
Oid paramtype
Definition: execExpr.h:418
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().

◆ ExecEvalParamSet()

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

Definition at line 3039 of file execExprInterp.c.

3040{
3041 ParamExecData *prm;
3042
3043 prm = &(econtext->ecxt_param_exec_vals[op->d.param.paramid]);
3044
3045 /* Shouldn't have a pending evaluation anymore */
3046 Assert(prm->execPlan == NULL);
3047
3048 prm->value = state->resvalue;
3049 prm->isnull = state->resnull;
3050}

References Assert, ExprContext::ecxt_param_exec_vals, ParamExecData::execPlan, ParamExecData::isnull, ExprEvalStep::op, and ParamExecData::value.

Referenced by ExecInterpExpr().

◆ ExecEvalPreOrderedDistinctMulti()

bool ExecEvalPreOrderedDistinctMulti ( AggState aggstate,
AggStatePerTrans  pertrans 
)

Definition at line 5688 of file execExprInterp.c.

5689{
5690 ExprContext *tmpcontext = aggstate->tmpcontext;
5691 bool isdistinct = false; /* for now */
5692 TupleTableSlot *save_outer;
5693 TupleTableSlot *save_inner;
5694
5695 for (int i = 0; i < pertrans->numTransInputs; i++)
5696 {
5697 pertrans->sortslot->tts_values[i] = pertrans->transfn_fcinfo->args[i + 1].value;
5698 pertrans->sortslot->tts_isnull[i] = pertrans->transfn_fcinfo->args[i + 1].isnull;
5699 }
5700
5701 ExecClearTuple(pertrans->sortslot);
5702 pertrans->sortslot->tts_nvalid = pertrans->numInputs;
5704
5705 /* save the previous slots before we overwrite them */
5706 save_outer = tmpcontext->ecxt_outertuple;
5707 save_inner = tmpcontext->ecxt_innertuple;
5708
5709 tmpcontext->ecxt_outertuple = pertrans->sortslot;
5710 tmpcontext->ecxt_innertuple = pertrans->uniqslot;
5711
5712 if (!pertrans->haslast ||
5713 !ExecQual(pertrans->equalfnMulti, tmpcontext))
5714 {
5715 if (pertrans->haslast)
5716 ExecClearTuple(pertrans->uniqslot);
5717
5718 pertrans->haslast = true;
5719 ExecCopySlot(pertrans->uniqslot, pertrans->sortslot);
5720
5721 isdistinct = true;
5722 }
5723
5724 /* restore the original slots */
5725 tmpcontext->ecxt_outertuple = save_outer;
5726 tmpcontext->ecxt_innertuple = save_inner;
5727
5728 return isdistinct;
5729}
static bool ExecQual(ExprState *state, ExprContext *econtext)
Definition: executor.h:426
ExprState * equalfnMulti
Definition: nodeAgg.h:116
TupleTableSlot * uniqslot
Definition: nodeAgg.h:142
ExprContext * tmpcontext
Definition: execnodes.h:2522
bool * tts_isnull
Definition: tuptable.h:127
Datum * tts_values
Definition: tuptable.h:125
static TupleTableSlot * ExecCopySlot(TupleTableSlot *dstslot, TupleTableSlot *srcslot)
Definition: tuptable.h:509

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

Referenced by ExecInterpExpr().

◆ ExecEvalPreOrderedDistinctSingle()

bool ExecEvalPreOrderedDistinctSingle ( AggState aggstate,
AggStatePerTrans  pertrans 
)

Definition at line 5645 of file execExprInterp.c.

5646{
5647 Datum value = pertrans->transfn_fcinfo->args[1].value;
5648 bool isnull = pertrans->transfn_fcinfo->args[1].isnull;
5649
5650 if (!pertrans->haslast ||
5651 pertrans->lastisnull != isnull ||
5652 (!isnull && !DatumGetBool(FunctionCall2Coll(&pertrans->equalfnOne,
5653 pertrans->aggCollation,
5654 pertrans->lastdatum, value))))
5655 {
5656 if (pertrans->haslast && !pertrans->inputtypeByVal &&
5657 !pertrans->lastisnull)
5658 pfree(DatumGetPointer(pertrans->lastdatum));
5659
5660 pertrans->haslast = true;
5661 if (!isnull)
5662 {
5663 MemoryContext oldContext;
5664
5666
5667 pertrans->lastdatum = datumCopy(value, pertrans->inputtypeByVal,
5668 pertrans->inputtypeLen);
5669
5670 MemoryContextSwitchTo(oldContext);
5671 }
5672 else
5673 pertrans->lastdatum = (Datum) 0;
5674 pertrans->lastisnull = isnull;
5675 return true;
5676 }
5677
5678 return false;
5679}
Datum FunctionCall2Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2)
Definition: fmgr.c:1149
FmgrInfo equalfnOne
Definition: nodeAgg.h:115

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

Referenced by ExecInterpExpr().

◆ ExecEvalRow()

void ExecEvalRow ( ExprState state,
ExprEvalStep op 
)

Definition at line 3582 of file execExprInterp.c.

3583{
3584 HeapTuple tuple;
3585
3586 /* build tuple from evaluated field values */
3587 tuple = heap_form_tuple(op->d.row.tupdesc,
3588 op->d.row.elemvalues,
3589 op->d.row.elemnulls);
3590
3591 *op->resvalue = HeapTupleGetDatum(tuple);
3592 *op->resnull = false;
3593}
TupleDesc tupdesc
Definition: execExpr.h:342
struct ExprEvalStep::@55::@77 row

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

Referenced by ExecInterpExpr().

◆ ExecEvalRowNotNull()

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

Definition at line 3234 of file execExprInterp.c.

3235{
3236 ExecEvalRowNullInt(state, op, econtext, false);
3237}
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 3225 of file execExprInterp.c.

3226{
3227 ExecEvalRowNullInt(state, op, econtext, true);
3228}

References ExecEvalRowNullInt(), and ExprEvalStep::op.

Referenced by ExecInterpExpr().

◆ ExecEvalScalarArrayOp()

void ExecEvalScalarArrayOp ( ExprState state,
ExprEvalStep op 
)

Definition at line 3949 of file execExprInterp.c.

3950{
3952 bool useOr = op->d.scalararrayop.useOr;
3953 bool strictfunc = op->d.scalararrayop.finfo->fn_strict;
3954 ArrayType *arr;
3955 int nitems;
3956 Datum result;
3957 bool resultnull;
3958 int16 typlen;
3959 bool typbyval;
3960 char typalign;
3961 char *s;
3962 bits8 *bitmap;
3963 int bitmask;
3964
3965 /*
3966 * If the array is NULL then we return NULL --- it's not very meaningful
3967 * to do anything else, even if the operator isn't strict.
3968 */
3969 if (*op->resnull)
3970 return;
3971
3972 /* Else okay to fetch and detoast the array */
3973 arr = DatumGetArrayTypeP(*op->resvalue);
3974
3975 /*
3976 * If the array is empty, we return either FALSE or TRUE per the useOr
3977 * flag. This is correct even if the scalar is NULL; since we would
3978 * evaluate the operator zero times, it matters not whether it would want
3979 * to return NULL.
3980 */
3981 nitems = ArrayGetNItems(ARR_NDIM(arr), ARR_DIMS(arr));
3982 if (nitems <= 0)
3983 {
3984 *op->resvalue = BoolGetDatum(!useOr);
3985 *op->resnull = false;
3986 return;
3987 }
3988
3989 /*
3990 * If the scalar is NULL, and the function is strict, return NULL; no
3991 * point in iterating the loop.
3992 */
3993 if (fcinfo->args[0].isnull && strictfunc)
3994 {
3995 *op->resnull = true;
3996 return;
3997 }
3998
3999 /*
4000 * We arrange to look up info about the element type only once per series
4001 * of calls, assuming the element type doesn't change underneath us.
4002 */
4003 if (op->d.scalararrayop.element_type != ARR_ELEMTYPE(arr))
4004 {
4006 &op->d.scalararrayop.typlen,
4008 &op->d.scalararrayop.typalign);
4010 }
4011
4012 typlen = op->d.scalararrayop.typlen;
4013 typbyval = op->d.scalararrayop.typbyval;
4015
4016 /* Initialize result appropriately depending on useOr */
4017 result = BoolGetDatum(!useOr);
4018 resultnull = false;
4019
4020 /* Loop over the array elements */
4021 s = (char *) ARR_DATA_PTR(arr);
4022 bitmap = ARR_NULLBITMAP(arr);
4023 bitmask = 1;
4024
4025 for (int i = 0; i < nitems; i++)
4026 {
4027 Datum elt;
4028 Datum thisresult;
4029
4030 /* Get array element, checking for NULL */
4031 if (bitmap && (*bitmap & bitmask) == 0)
4032 {
4033 fcinfo->args[1].value = (Datum) 0;
4034 fcinfo->args[1].isnull = true;
4035 }
4036 else
4037 {
4038 elt = fetch_att(s, typbyval, typlen);
4039 s = att_addlength_pointer(s, typlen, s);
4040 s = (char *) att_align_nominal(s, typalign);
4041 fcinfo->args[1].value = elt;
4042 fcinfo->args[1].isnull = false;
4043 }
4044
4045 /* Call comparison function */
4046 if (fcinfo->args[1].isnull && strictfunc)
4047 {
4048 fcinfo->isnull = true;
4049 thisresult = (Datum) 0;
4050 }
4051 else
4052 {
4053 fcinfo->isnull = false;
4054 thisresult = op->d.scalararrayop.fn_addr(fcinfo);
4055 }
4056
4057 /* Combine results per OR or AND semantics */
4058 if (fcinfo->isnull)
4059 resultnull = true;
4060 else if (useOr)
4061 {
4062 if (DatumGetBool(thisresult))
4063 {
4064 result = BoolGetDatum(true);
4065 resultnull = false;
4066 break; /* needn't look at any more elements */
4067 }
4068 }
4069 else
4070 {
4071 if (!DatumGetBool(thisresult))
4072 {
4073 result = BoolGetDatum(false);
4074 resultnull = false;
4075 break; /* needn't look at any more elements */
4076 }
4077 }
4078
4079 /* advance bitmap pointer if any */
4080 if (bitmap)
4081 {
4082 bitmask <<= 1;
4083 if (bitmask == 0x100)
4084 {
4085 bitmap++;
4086 bitmask = 1;
4087 }
4088 }
4089 }
4090
4091 *op->resvalue = result;
4092 *op->resnull = resultnull;
4093}
bool typbyval
Definition: execExpr.h:622
char typalign
Definition: execExpr.h:623
bool useOr
Definition: execExpr.h:620
struct ExprEvalStep::@55::@89 scalararrayop
int16 typlen
Definition: execExpr.h:621
Oid element_type
Definition: execExpr.h:619

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

Referenced by ExecInterpExpr().

◆ ExecEvalSQLValueFunction()

void ExecEvalSQLValueFunction ( ExprState state,
ExprEvalStep op 
)

Definition at line 3121 of file execExprInterp.c.

3122{
3123 LOCAL_FCINFO(fcinfo, 0);
3125
3126 *op->resnull = false;
3127
3128 /*
3129 * Note: current_schema() can return NULL. current_user() etc currently
3130 * cannot, but might as well code those cases the same way for safety.
3131 */
3132 switch (svf->op)
3133 {
3134 case SVFOP_CURRENT_DATE:
3136 break;
3137 case SVFOP_CURRENT_TIME:
3140 break;
3144 break;
3145 case SVFOP_LOCALTIME:
3146 case SVFOP_LOCALTIME_N:
3148 break;
3152 break;
3153 case SVFOP_CURRENT_ROLE:
3154 case SVFOP_CURRENT_USER:
3155 case SVFOP_USER:
3156 InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
3157 *op->resvalue = current_user(fcinfo);
3158 *op->resnull = fcinfo->isnull;
3159 break;
3160 case SVFOP_SESSION_USER:
3161 InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
3162 *op->resvalue = session_user(fcinfo);
3163 *op->resnull = fcinfo->isnull;
3164 break;
3166 InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
3167 *op->resvalue = current_database(fcinfo);
3168 *op->resnull = fcinfo->isnull;
3169 break;
3171 InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
3172 *op->resvalue = current_schema(fcinfo);
3173 *op->resnull = fcinfo->isnull;
3174 break;
3175 }
3176}
Datum current_database(PG_FUNCTION_ARGS)
Definition: misc.c:195
Timestamp GetSQLLocalTimestamp(int32 typmod)
Definition: timestamp.c:1676
TimestampTz GetSQLCurrentTimestamp(int32 typmod)
Definition: timestamp.c:1662
TimeADT GetSQLLocalTime(int32 typmod)
Definition: date.c:369
DateADT GetSQLCurrentDate(void)
Definition: date.c:316
TimeTzADT * GetSQLCurrentTime(int32 typmod)
Definition: date.c:349
static Datum DateADTGetDatum(DateADT X)
Definition: date.h:72
static Datum TimeTzADTPGetDatum(const TimeTzADT *X)
Definition: date.h:84
static Datum TimeADTGetDatum(TimeADT X)
Definition: date.h:78
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
Datum current_user(PG_FUNCTION_ARGS)
Definition: name.c:263
Datum session_user(PG_FUNCTION_ARGS)
Definition: name.c:269
Datum current_schema(PG_FUNCTION_ARGS)
Definition: name.c:279
@ SVFOP_CURRENT_CATALOG
Definition: primnodes.h:1580
@ SVFOP_LOCALTIME_N
Definition: primnodes.h:1573
@ SVFOP_CURRENT_TIMESTAMP
Definition: primnodes.h:1570
@ SVFOP_LOCALTIME
Definition: primnodes.h:1572
@ SVFOP_CURRENT_TIMESTAMP_N
Definition: primnodes.h:1571
@ SVFOP_CURRENT_ROLE
Definition: primnodes.h:1576
@ SVFOP_USER
Definition: primnodes.h:1578
@ SVFOP_CURRENT_SCHEMA
Definition: primnodes.h:1581
@ SVFOP_LOCALTIMESTAMP_N
Definition: primnodes.h:1575
@ SVFOP_CURRENT_DATE
Definition: primnodes.h:1567
@ SVFOP_CURRENT_TIME_N
Definition: primnodes.h:1569
@ SVFOP_CURRENT_TIME
Definition: primnodes.h:1568
@ SVFOP_LOCALTIMESTAMP
Definition: primnodes.h:1574
@ SVFOP_CURRENT_USER
Definition: primnodes.h:1577
@ SVFOP_SESSION_USER
Definition: primnodes.h:1579
struct ExprEvalStep::@55::@73 sqlvaluefunction
SQLValueFunction * svf
Definition: execExpr.h:458
SQLValueFunctionOp op
Definition: primnodes.h:1587
static Datum TimestampTzGetDatum(TimestampTz X)
Definition: timestamp.h:52
static Datum TimestampGetDatum(Timestamp X)
Definition: timestamp.h:46

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

Referenced by ExecInterpExpr().

◆ ExecEvalStepOp()

ExprEvalOp ExecEvalStepOp ( ExprState state,
ExprEvalStep op 
)

Definition at line 2886 of file execExprInterp.c.

2887{
2888#if defined(EEO_USE_COMPUTED_GOTO)
2889 if (state->flags & EEO_FLAG_DIRECT_THREADED)
2890 {
2891 ExprEvalOpLookup key;
2892 ExprEvalOpLookup *res;
2893
2894 key.opcode = (void *) op->opcode;
2895 res = bsearch(&key,
2896 reverse_dispatch_table,
2897 EEOP_LAST /* nmembers */ ,
2898 sizeof(ExprEvalOpLookup),
2899 dispatch_compare_ptr);
2900 Assert(res); /* unknown ops shouldn't get looked up */
2901 return res->op;
2902 }
2903#endif
2904 return (ExprEvalOp) op->opcode;
2905}
#define EEO_FLAG_DIRECT_THREADED
Definition: execExpr.h:31
intptr_t opcode
Definition: execExpr.h:299

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

5237{
5238 SubPlanState *sstate = op->d.subplan.sstate;
5239
5240 /* could potentially be nested, so make sure there's enough stack */
5242
5243 *op->resvalue = ExecSubPlan(sstate, econtext, op->resnull);
5244}
Datum ExecSubPlan(SubPlanState *node, ExprContext *econtext, bool *isNull)
Definition: nodeSubplan.c:62
void check_stack_depth(void)
Definition: stack_depth.c:95
SubPlanState * sstate
Definition: execExpr.h:682
struct ExprEvalStep::@55::@96 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 5512 of file execExprInterp.c.

5514{
5515 Datum d;
5516
5517 /* OLD/NEW system attribute is NULL if OLD/NEW row is NULL */
5519 state->flags & EEO_FLAG_OLD_IS_NULL) ||
5521 state->flags & EEO_FLAG_NEW_IS_NULL))
5522 {
5523 *op->resvalue = (Datum) 0;
5524 *op->resnull = true;
5525 return;
5526 }
5527
5528 /* slot_getsysattr has sufficient defenses against bad attnums */
5529 d = slot_getsysattr(slot,
5530 op->d.var.attnum,
5531 op->resnull);
5532 *op->resvalue = d;
5533 /* this ought to be unreachable, but it's cheap enough to check */
5534 if (unlikely(*op->resnull))
5535 elog(ERROR, "failed to fetch attribute from slot");
5536}
#define EEO_FLAG_NEW_IS_NULL
Definition: execnodes.h:84
#define EEO_FLAG_OLD_IS_NULL
Definition: execnodes.h:82
@ VAR_RETURNING_OLD
Definition: primnodes.h:256
@ VAR_RETURNING_NEW
Definition: primnodes.h:257
VarReturningType varreturningtype
Definition: execExpr.h:333
static Datum slot_getsysattr(TupleTableSlot *slot, int attnum, bool *isnull)
Definition: tuptable.h:416

References ExprEvalStep::d, EEO_FLAG_NEW_IS_NULL, EEO_FLAG_OLD_IS_NULL, elog, ERROR, ExprEvalStep::op, slot_getsysattr(), unlikely, VAR_RETURNING_NEW, and VAR_RETURNING_OLD.

Referenced by ExecInterpExpr().

◆ ExecEvalWholeRowVar()

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

Definition at line 5253 of file execExprInterp.c.

5254{
5255 Var *variable = op->d.wholerow.var;
5256 TupleTableSlot *slot = NULL;
5257 TupleDesc output_tupdesc;
5258 MemoryContext oldcontext;
5259 HeapTupleHeader dtuple;
5260 HeapTuple tuple;
5261
5262 /* This was checked by ExecInitExpr */
5263 Assert(variable->varattno == InvalidAttrNumber);
5264
5265 /* Get the input slot we want */
5266 switch (variable->varno)
5267 {
5268 case INNER_VAR:
5269 /* get the tuple from the inner node */
5270 slot = econtext->ecxt_innertuple;
5271 break;
5272
5273 case OUTER_VAR:
5274 /* get the tuple from the outer node */
5275 slot = econtext->ecxt_outertuple;
5276 break;
5277
5278 /* INDEX_VAR is handled by default case */
5279
5280 default:
5281
5282 /*
5283 * Get the tuple from the relation being scanned.
5284 *
5285 * By default, this uses the "scan" tuple slot, but a wholerow Var
5286 * in the RETURNING list may explicitly refer to OLD/NEW. If the
5287 * OLD/NEW row doesn't exist, we just return NULL.
5288 */
5289 switch (variable->varreturningtype)
5290 {
5292 slot = econtext->ecxt_scantuple;
5293 break;
5294
5295 case VAR_RETURNING_OLD:
5296 if (state->flags & EEO_FLAG_OLD_IS_NULL)
5297 {
5298 *op->resvalue = (Datum) 0;
5299 *op->resnull = true;
5300 return;
5301 }
5302 slot = econtext->ecxt_oldtuple;
5303 break;
5304
5305 case VAR_RETURNING_NEW:
5306 if (state->flags & EEO_FLAG_NEW_IS_NULL)
5307 {
5308 *op->resvalue = (Datum) 0;
5309 *op->resnull = true;
5310 return;
5311 }
5312 slot = econtext->ecxt_newtuple;
5313 break;
5314 }
5315 break;
5316 }
5317
5318 /* Apply the junkfilter if any */
5319 if (op->d.wholerow.junkFilter != NULL)
5320 slot = ExecFilterJunk(op->d.wholerow.junkFilter, slot);
5321
5322 /*
5323 * If first time through, obtain tuple descriptor and check compatibility.
5324 *
5325 * XXX: It'd be great if this could be moved to the expression
5326 * initialization phase, but due to using slots that's currently not
5327 * feasible.
5328 */
5329 if (op->d.wholerow.first)
5330 {
5331 /* optimistically assume we don't need slow path */
5332 op->d.wholerow.slow = false;
5333
5334 /*
5335 * If the Var identifies a named composite type, we must check that
5336 * the actual tuple type is compatible with it.
5337 */
5338 if (variable->vartype != RECORDOID)
5339 {
5340 TupleDesc var_tupdesc;
5341 TupleDesc slot_tupdesc;
5342
5343 /*
5344 * We really only care about numbers of attributes and data types.
5345 * Also, we can ignore type mismatch on columns that are dropped
5346 * in the destination type, so long as (1) the physical storage
5347 * matches or (2) the actual column value is NULL. Case (1) is
5348 * helpful in some cases involving out-of-date cached plans, while
5349 * case (2) is expected behavior in situations such as an INSERT
5350 * into a table with dropped columns (the planner typically
5351 * generates an INT4 NULL regardless of the dropped column type).
5352 * If we find a dropped column and cannot verify that case (1)
5353 * holds, we have to use the slow path to check (2) for each row.
5354 *
5355 * If vartype is a domain over composite, just look through that
5356 * to the base composite type.
5357 */
5358 var_tupdesc = lookup_rowtype_tupdesc_domain(variable->vartype,
5359 -1, false);
5360
5361 slot_tupdesc = slot->tts_tupleDescriptor;
5362
5363 if (var_tupdesc->natts != slot_tupdesc->natts)
5364 ereport(ERROR,
5365 (errcode(ERRCODE_DATATYPE_MISMATCH),
5366 errmsg("table row type and query-specified row type do not match"),
5367 errdetail_plural("Table row contains %d attribute, but query expects %d.",
5368 "Table row contains %d attributes, but query expects %d.",
5369 slot_tupdesc->natts,
5370 slot_tupdesc->natts,
5371 var_tupdesc->natts)));
5372
5373 for (int i = 0; i < var_tupdesc->natts; i++)
5374 {
5375 Form_pg_attribute vattr = TupleDescAttr(var_tupdesc, i);
5376 Form_pg_attribute sattr = TupleDescAttr(slot_tupdesc, i);
5377
5378 if (vattr->atttypid == sattr->atttypid)
5379 continue; /* no worries */
5380 if (!vattr->attisdropped)
5381 ereport(ERROR,
5382 (errcode(ERRCODE_DATATYPE_MISMATCH),
5383 errmsg("table row type and query-specified row type do not match"),
5384 errdetail("Table has type %s at ordinal position %d, but query expects %s.",
5385 format_type_be(sattr->atttypid),
5386 i + 1,
5387 format_type_be(vattr->atttypid))));
5388
5389 if (vattr->attlen != sattr->attlen ||
5390 vattr->attalign != sattr->attalign)
5391 op->d.wholerow.slow = true; /* need to check for nulls */
5392 }
5393
5394 /*
5395 * Use the variable's declared rowtype as the descriptor for the
5396 * output values. In particular, we *must* absorb any
5397 * attisdropped markings.
5398 */
5399 oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
5400 output_tupdesc = CreateTupleDescCopy(var_tupdesc);
5401 MemoryContextSwitchTo(oldcontext);
5402
5403 ReleaseTupleDesc(var_tupdesc);
5404 }
5405 else
5406 {
5407 /*
5408 * In the RECORD case, we use the input slot's rowtype as the
5409 * descriptor for the output values, modulo possibly assigning new
5410 * column names below.
5411 */
5412 oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
5413 output_tupdesc = CreateTupleDescCopy(slot->tts_tupleDescriptor);
5414 MemoryContextSwitchTo(oldcontext);
5415
5416 /*
5417 * It's possible that the input slot is a relation scan slot and
5418 * so is marked with that relation's rowtype. But we're supposed
5419 * to be returning RECORD, so reset to that.
5420 */
5421 output_tupdesc->tdtypeid = RECORDOID;
5422 output_tupdesc->tdtypmod = -1;
5423
5424 /*
5425 * We already got the correct physical datatype info above, but
5426 * now we should try to find the source RTE and adopt its column
5427 * aliases, since it's unlikely that the input slot has the
5428 * desired names.
5429 *
5430 * If we can't locate the RTE, assume the column names we've got
5431 * are OK. (As of this writing, the only cases where we can't
5432 * locate the RTE are in execution of trigger WHEN clauses, and
5433 * then the Var will have the trigger's relation's rowtype, so its
5434 * names are fine.) Also, if the creator of the RTE didn't bother
5435 * to fill in an eref field, assume our column names are OK. (This
5436 * happens in COPY, and perhaps other places.)
5437 */
5438 if (econtext->ecxt_estate &&
5439 variable->varno <= econtext->ecxt_estate->es_range_table_size)
5440 {
5441 RangeTblEntry *rte = exec_rt_fetch(variable->varno,
5442 econtext->ecxt_estate);
5443
5444 if (rte->eref)
5445 ExecTypeSetColNames(output_tupdesc, rte->eref->colnames);
5446 }
5447 }
5448
5449 /* Bless the tupdesc if needed, and save it in the execution state */
5450 op->d.wholerow.tupdesc = BlessTupleDesc(output_tupdesc);
5451
5452 op->d.wholerow.first = false;
5453 }
5454
5455 /*
5456 * Make sure all columns of the slot are accessible in the slot's
5457 * Datum/isnull arrays.
5458 */
5459 slot_getallattrs(slot);
5460
5461 if (op->d.wholerow.slow)
5462 {
5463 /* Check to see if any dropped attributes are non-null */
5464 TupleDesc tupleDesc = slot->tts_tupleDescriptor;
5465 TupleDesc var_tupdesc = op->d.wholerow.tupdesc;
5466
5467 Assert(var_tupdesc->natts == tupleDesc->natts);
5468
5469 for (int i = 0; i < var_tupdesc->natts; i++)
5470 {
5471 CompactAttribute *vattr = TupleDescCompactAttr(var_tupdesc, i);
5472 CompactAttribute *sattr = TupleDescCompactAttr(tupleDesc, i);
5473
5474 if (!vattr->attisdropped)
5475 continue; /* already checked non-dropped cols */
5476 if (slot->tts_isnull[i])
5477 continue; /* null is always okay */
5478 if (vattr->attlen != sattr->attlen ||
5479 vattr->attalignby != sattr->attalignby)
5480 ereport(ERROR,
5481 (errcode(ERRCODE_DATATYPE_MISMATCH),
5482 errmsg("table row type and query-specified row type do not match"),
5483 errdetail("Physical storage mismatch on dropped attribute at ordinal position %d.",
5484 i + 1)));
5485 }
5486 }
5487
5488 /*
5489 * Build a composite datum, making sure any toasted fields get detoasted.
5490 *
5491 * (Note: it is critical that we not change the slot's state here.)
5492 */
5494 slot->tts_values,
5495 slot->tts_isnull);
5496 dtuple = tuple->t_data;
5497
5498 /*
5499 * Label the datum with the composite type info we identified before.
5500 *
5501 * (Note: we could skip doing this by passing op->d.wholerow.tupdesc to
5502 * the tuple build step; but that seems a tad risky so let's not.)
5503 */
5506
5507 *op->resvalue = PointerGetDatum(dtuple);
5508 *op->resnull = false;
5509}
#define InvalidAttrNumber
Definition: attnum.h:23
int errdetail_plural(const char *fmt_singular, const char *fmt_plural, unsigned long n,...)
Definition: elog.c:1295
TupleTableSlot * ExecFilterJunk(JunkFilter *junkfilter, TupleTableSlot *slot)
Definition: execJunk.c:247
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:2258
void ExecTypeSetColNames(TupleDesc typeInfo, List *namesList)
Definition: execTuples.c:2217
static RangeTblEntry * exec_rt_fetch(Index rti, EState *estate)
Definition: executor.h:603
HeapTuple toast_build_flattened_tuple(TupleDesc tupleDesc, Datum *values, bool *isnull)
Definition: heaptoast.c:563
#define HeapTupleHeaderSetTypMod(tup, typmod)
Definition: htup_details.h:471
#define HeapTupleHeaderSetTypeId(tup, typeid)
Definition: htup_details.h:461
@ VAR_RETURNING_DEFAULT
Definition: primnodes.h:255
#define OUTER_VAR
Definition: primnodes.h:242
#define INNER_VAR
Definition: primnodes.h:241
uint8 attalignby
Definition: tupdesc.h:79
bool attisdropped
Definition: tupdesc.h:76
int16 attlen
Definition: tupdesc.h:70
Index es_range_table_size
Definition: execnodes.h:651
struct EState * ecxt_estate
Definition: execnodes.h:309
JunkFilter * junkFilter
Definition: execExpr.h:343
struct ExprEvalStep::@55::@58 wholerow
bool first
Definition: execExpr.h:340
int32 tdtypmod
Definition: tupdesc.h:132
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:123
Definition: primnodes.h:261
TupleDesc CreateTupleDescCopy(TupleDesc tupdesc)
Definition: tupdesc.c:234
#define ReleaseTupleDesc(tupdesc)
Definition: tupdesc.h:212
static CompactAttribute * TupleDescCompactAttr(TupleDesc tupdesc, int i)
Definition: tupdesc.h:168
static void slot_getallattrs(TupleTableSlot *slot)
Definition: tuptable.h:368
TupleDesc lookup_rowtype_tupdesc_domain(Oid type_id, int32 typmod, bool noError)
Definition: typcache.c:1976

References Assert, CompactAttribute::attalignby, CompactAttribute::attisdropped, CompactAttribute::attlen, BlessTupleDesc(), CreateTupleDescCopy(), ExprContext::ecxt_estate, ExprContext::ecxt_innertuple, ExprContext::ecxt_newtuple, ExprContext::ecxt_oldtuple, ExprContext::ecxt_outertuple, ExprContext::ecxt_per_query_memory, ExprContext::ecxt_scantuple, EEO_FLAG_NEW_IS_NULL, EEO_FLAG_OLD_IS_NULL, 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, TupleDescAttr(), TupleDescCompactAttr(), VAR_RETURNING_DEFAULT, VAR_RETURNING_NEW, and VAR_RETURNING_OLD.

Referenced by ExecInterpExpr().

◆ ExecEvalXmlExpr()

void ExecEvalXmlExpr ( ExprState state,
ExprEvalStep op 
)

Definition at line 4368 of file execExprInterp.c.

4369{
4370 XmlExpr *xexpr = op->d.xmlexpr.xexpr;
4371 Datum value;
4372
4373 *op->resnull = true; /* until we get a result */
4374 *op->resvalue = (Datum) 0;
4375
4376 switch (xexpr->op)
4377 {
4378 case IS_XMLCONCAT:
4379 {
4380 Datum *argvalue = op->d.xmlexpr.argvalue;
4381 bool *argnull = op->d.xmlexpr.argnull;
4382 List *values = NIL;
4383
4384 for (int i = 0; i < list_length(xexpr->args); i++)
4385 {
4386 if (!argnull[i])
4387 values = lappend(values, DatumGetPointer(argvalue[i]));
4388 }
4389
4390 if (values != NIL)
4391 {
4393 *op->resnull = false;
4394 }
4395 }
4396 break;
4397
4398 case IS_XMLFOREST:
4399 {
4400 Datum *argvalue = op->d.xmlexpr.named_argvalue;
4401 bool *argnull = op->d.xmlexpr.named_argnull;
4403 ListCell *lc;
4404 ListCell *lc2;
4405 int i;
4406
4408
4409 i = 0;
4410 forboth(lc, xexpr->named_args, lc2, xexpr->arg_names)
4411 {
4412 Expr *e = (Expr *) lfirst(lc);
4413 char *argname = strVal(lfirst(lc2));
4414
4415 if (!argnull[i])
4416 {
4417 value = argvalue[i];
4418 appendStringInfo(&buf, "<%s>%s</%s>",
4419 argname,
4421 exprType((Node *) e), true),
4422 argname);
4423 *op->resnull = false;
4424 }
4425 i++;
4426 }
4427
4428 if (!*op->resnull)
4429 {
4430 text *result;
4431
4432 result = cstring_to_text_with_len(buf.data, buf.len);
4433 *op->resvalue = PointerGetDatum(result);
4434 }
4435
4436 pfree(buf.data);
4437 }
4438 break;
4439
4440 case IS_XMLELEMENT:
4441 *op->resvalue = PointerGetDatum(xmlelement(xexpr,
4444 op->d.xmlexpr.argvalue,
4445 op->d.xmlexpr.argnull));
4446 *op->resnull = false;
4447 break;
4448
4449 case IS_XMLPARSE:
4450 {
4451 Datum *argvalue = op->d.xmlexpr.argvalue;
4452 bool *argnull = op->d.xmlexpr.argnull;
4453 text *data;
4454 bool preserve_whitespace;
4455
4456 /* arguments are known to be text, bool */
4457 Assert(list_length(xexpr->args) == 2);
4458
4459 if (argnull[0])
4460 return;
4461 value = argvalue[0];
4463
4464 if (argnull[1]) /* probably can't happen */
4465 return;
4466 value = argvalue[1];
4467 preserve_whitespace = DatumGetBool(value);
4468
4470 xexpr->xmloption,
4471 preserve_whitespace));
4472 *op->resnull = false;
4473 }
4474 break;
4475
4476 case IS_XMLPI:
4477 {
4478 text *arg;
4479 bool isnull;
4480
4481 /* optional argument is known to be text */
4482 Assert(list_length(xexpr->args) <= 1);
4483
4484 if (xexpr->args)
4485 {
4486 isnull = op->d.xmlexpr.argnull[0];
4487 if (isnull)
4488 arg = NULL;
4489 else
4491 }
4492 else
4493 {
4494 arg = NULL;
4495 isnull = false;
4496 }
4497
4498 *op->resvalue = PointerGetDatum(xmlpi(xexpr->name,
4499 arg,
4500 isnull,
4501 op->resnull));
4502 }
4503 break;
4504
4505 case IS_XMLROOT:
4506 {
4507 Datum *argvalue = op->d.xmlexpr.argvalue;
4508 bool *argnull = op->d.xmlexpr.argnull;
4509 xmltype *data;
4510 text *version;
4511 int standalone;
4512
4513 /* arguments are known to be xml, text, int */
4514 Assert(list_length(xexpr->args) == 3);
4515
4516 if (argnull[0])
4517 return;
4518 data = DatumGetXmlP(argvalue[0]);
4519
4520 if (argnull[1])
4521 version = NULL;
4522 else
4523 version = DatumGetTextPP(argvalue[1]);
4524
4525 Assert(!argnull[2]); /* always present */
4526 standalone = DatumGetInt32(argvalue[2]);
4527
4529 version,
4530 standalone));
4531 *op->resnull = false;
4532 }
4533 break;
4534
4535 case IS_XMLSERIALIZE:
4536 {
4537 Datum *argvalue = op->d.xmlexpr.argvalue;
4538 bool *argnull = op->d.xmlexpr.argnull;
4539
4540 /* argument type is known to be xml */
4541 Assert(list_length(xexpr->args) == 1);
4542
4543 if (argnull[0])
4544 return;
4545 value = argvalue[0];
4546
4547 *op->resvalue =
4549 xexpr->xmloption,
4550 xexpr->indent));
4551 *op->resnull = false;
4552 }
4553 break;
4554
4555 case IS_DOCUMENT:
4556 {
4557 Datum *argvalue = op->d.xmlexpr.argvalue;
4558 bool *argnull = op->d.xmlexpr.argnull;
4559
4560 /* optional argument is known to be xml */
4561 Assert(list_length(xexpr->args) == 1);
4562
4563 if (argnull[0])
4564 return;
4565 value = argvalue[0];
4566
4567 *op->resvalue =
4569 *op->resnull = false;
4570 }
4571 break;
4572
4573 default:
4574 elog(ERROR, "unrecognized XML operation");
4575 break;
4576 }
4577}
#define DatumGetTextPP(X)
Definition: fmgr.h:292
List * lappend(List *list, void *datum)
Definition: list.c:339
void * arg
const void * data
#define lfirst(lc)
Definition: pg_list.h:172
static int list_length(const List *l)
Definition: pg_list.h:152
#define NIL
Definition: pg_list.h:68
#define forboth(cell1, list1, cell2, list2)
Definition: pg_list.h:518
static char * buf
Definition: pg_test_fsync.c:72
e
Definition: preproc-init.c:82
@ IS_DOCUMENT
Definition: primnodes.h:1618
@ IS_XMLFOREST
Definition: primnodes.h:1613
@ IS_XMLCONCAT
Definition: primnodes.h:1611
@ IS_XMLPI
Definition: primnodes.h:1615
@ IS_XMLPARSE
Definition: primnodes.h:1614
@ IS_XMLSERIALIZE
Definition: primnodes.h:1617
@ IS_XMLROOT
Definition: primnodes.h:1616
@ IS_XMLELEMENT
Definition: primnodes.h:1612
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:145
void initStringInfo(StringInfo str)
Definition: stringinfo.c:97
XmlExpr * xexpr
Definition: execExpr.h:644
bool * named_argnull
Definition: execExpr.h:647
bool * argnull
Definition: execExpr.h:650
struct ExprEvalStep::@55::@91 xmlexpr
Datum * named_argvalue
Definition: execExpr.h:646
Datum * argvalue
Definition: execExpr.h:649
Definition: pg_list.h:54
List * args
Definition: primnodes.h:1639
bool indent
Definition: primnodes.h:1643
List * named_args
Definition: primnodes.h:1635
XmlExprOp op
Definition: primnodes.h:1631
#define strVal(v)
Definition: value.h:82
xmltype * xmlroot(xmltype *data, text *version, int standalone)
Definition: xml.c:1051
text * xmltotext_with_options(xmltype *data, XmlOptionType xmloption_arg, bool indent)
Definition: xml.c:656
char * map_sql_value_to_xml_value(Datum value, Oid type, bool xml_escape_strings)
Definition: xml.c:2476
xmltype * xmlconcat(List *args)
Definition: xml.c:553
bool xml_is_document(xmltype *arg)
Definition: xml.c:1117
xmltype * xmlparse(text *data, XmlOptionType xmloption_arg, bool preserve_whitespace)
Definition: xml.c:981
xmltype * xmlelement(XmlExpr *xexpr, Datum *named_argvalue, bool *named_argnull, Datum *argvalue, bool *argnull)
Definition: xml.c:857
xmltype * xmlpi(const char *target, text *arg, bool arg_is_null, bool *result_is_null)
Definition: xml.c:999
static xmltype * DatumGetXmlP(Datum X)
Definition: xml.h:51

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

Referenced by ExecInterpExpr().

◆ ExecInterpExprStillValid()

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

Definition at line 2217 of file execExprInterp.c.

2218{
2219 /*
2220 * First time through, check whether attribute matches Var. Might not be
2221 * ok anymore, due to schema changes.
2222 */
2223 CheckExprStillValid(state, econtext);
2224
2225 /* skip the check during further executions */
2226 state->evalfunc = (ExprStateEvalFunc) state->evalfunc_private;
2227
2228 /* and actually execute */
2229 return state->evalfunc(state, econtext, isNull);
2230}
void CheckExprStillValid(ExprState *state, ExprContext *econtext)
Datum(* ExprStateEvalFunc)(struct ExprState *expression, struct ExprContext *econtext, bool *isNull)
Definition: execnodes.h:70

References CheckExprStillValid().

Referenced by ExecReadyInterpretedExpr().

◆ ExecReadyInterpretedExpr()

void ExecReadyInterpretedExpr ( ExprState state)

Definition at line 242 of file execExprInterp.c.

243{
244 /* Ensure one-time interpreter setup has been done */
246
247 /* Simple validity checks on expression */
248 Assert(state->steps_len >= 1);
249 Assert(state->steps[state->steps_len - 1].opcode == EEOP_DONE);
250
251 /*
252 * Don't perform redundant initialization. This is unreachable in current
253 * cases, but might be hit if there's additional expression evaluation
254 * methods that rely on interpreted execution to work.
255 */
257 return;
258
259 /*
260 * First time through, check whether attribute matches Var. Might not be
261 * ok anymore, due to schema changes. We do that by setting up a callback
262 * that does checking on the first call, which then sets the evalfunc
263 * callback to the actual method of execution.
264 */
266
267 /* DIRECT_THREADED should not already be set */
268 Assert((state->flags & EEO_FLAG_DIRECT_THREADED) == 0);
269
270 /*
271 * There shouldn't be any errors before the expression is fully
272 * initialized, and even if so, it'd lead to the expression being
273 * abandoned. So we can set the flag now and save some code.
274 */
276
277 /*
278 * Select fast-path evalfuncs for very simple expressions. "Starting up"
279 * the full interpreter is a measurable overhead for these, and these
280 * patterns occur often enough to be worth optimizing.
281 */
282 if (state->steps_len == 5)
283 {
284 ExprEvalOp step0 = state->steps[0].opcode;
285 ExprEvalOp step1 = state->steps[1].opcode;
286 ExprEvalOp step2 = state->steps[2].opcode;
287 ExprEvalOp step3 = state->steps[3].opcode;
288
289 if (step0 == EEOP_INNER_FETCHSOME &&
291 step2 == EEOP_INNER_VAR &&
292 step3 == EEOP_HASHDATUM_NEXT32)
293 {
294 state->evalfunc_private = (void *) ExecJustHashInnerVarWithIV;
295 return;
296 }
297 }
298 else if (state->steps_len == 4)
299 {
300 ExprEvalOp step0 = state->steps[0].opcode;
301 ExprEvalOp step1 = state->steps[1].opcode;
302 ExprEvalOp step2 = state->steps[2].opcode;
303
304 if (step0 == EEOP_OUTER_FETCHSOME &&
305 step1 == EEOP_OUTER_VAR &&
306 step2 == EEOP_HASHDATUM_FIRST)
307 {
308 state->evalfunc_private = (void *) ExecJustHashOuterVar;
309 return;
310 }
311 else if (step0 == EEOP_INNER_FETCHSOME &&
312 step1 == EEOP_INNER_VAR &&
313 step2 == EEOP_HASHDATUM_FIRST)
314 {
315 state->evalfunc_private = (void *) ExecJustHashInnerVar;
316 return;
317 }
318 else if (step0 == EEOP_OUTER_FETCHSOME &&
319 step1 == EEOP_OUTER_VAR &&
321 {
322 state->evalfunc_private = (void *) ExecJustHashOuterVarStrict;
323 return;
324 }
325 }
326 else if (state->steps_len == 3)
327 {
328 ExprEvalOp step0 = state->steps[0].opcode;
329 ExprEvalOp step1 = state->steps[1].opcode;
330
331 if (step0 == EEOP_INNER_FETCHSOME &&
332 step1 == EEOP_INNER_VAR)
333 {
334 state->evalfunc_private = ExecJustInnerVar;
335 return;
336 }
337 else if (step0 == EEOP_OUTER_FETCHSOME &&
338 step1 == EEOP_OUTER_VAR)
339 {
340 state->evalfunc_private = ExecJustOuterVar;
341 return;
342 }
343 else if (step0 == EEOP_SCAN_FETCHSOME &&
344 step1 == EEOP_SCAN_VAR)
345 {
346 state->evalfunc_private = ExecJustScanVar;
347 return;
348 }
349 else if (step0 == EEOP_INNER_FETCHSOME &&
350 step1 == EEOP_ASSIGN_INNER_VAR)
351 {
352 state->evalfunc_private = ExecJustAssignInnerVar;
353 return;
354 }
355 else if (step0 == EEOP_OUTER_FETCHSOME &&
356 step1 == EEOP_ASSIGN_OUTER_VAR)
357 {
358 state->evalfunc_private = ExecJustAssignOuterVar;
359 return;
360 }
361 else if (step0 == EEOP_SCAN_FETCHSOME &&
362 step1 == EEOP_ASSIGN_SCAN_VAR)
363 {
364 state->evalfunc_private = ExecJustAssignScanVar;
365 return;
366 }
367 else if (step0 == EEOP_CASE_TESTVAL &&
368 step1 == EEOP_FUNCEXPR_STRICT &&
369 state->steps[0].d.casetest.value)
370 {
371 state->evalfunc_private = ExecJustApplyFuncToCase;
372 return;
373 }
374 else if (step0 == EEOP_INNER_VAR &&
375 step1 == EEOP_HASHDATUM_FIRST)
376 {
377 state->evalfunc_private = (void *) ExecJustHashInnerVarVirt;
378 return;
379 }
380 else if (step0 == EEOP_OUTER_VAR &&
381 step1 == EEOP_HASHDATUM_FIRST)
382 {
383 state->evalfunc_private = (void *) ExecJustHashOuterVarVirt;
384 return;
385 }
386 }
387 else if (state->steps_len == 2)
388 {
389 ExprEvalOp step0 = state->steps[0].opcode;
390
391 if (step0 == EEOP_CONST)
392 {
393 state->evalfunc_private = ExecJustConst;
394 return;
395 }
396 else if (step0 == EEOP_INNER_VAR)
397 {
398 state->evalfunc_private = ExecJustInnerVarVirt;
399 return;
400 }
401 else if (step0 == EEOP_OUTER_VAR)
402 {
403 state->evalfunc_private = ExecJustOuterVarVirt;
404 return;
405 }
406 else if (step0 == EEOP_SCAN_VAR)
407 {
408 state->evalfunc_private = ExecJustScanVarVirt;
409 return;
410 }
411 else if (step0 == EEOP_ASSIGN_INNER_VAR)
412 {
413 state->evalfunc_private = ExecJustAssignInnerVarVirt;
414 return;
415 }
416 else if (step0 == EEOP_ASSIGN_OUTER_VAR)
417 {
418 state->evalfunc_private = ExecJustAssignOuterVarVirt;
419 return;
420 }
421 else if (step0 == EEOP_ASSIGN_SCAN_VAR)
422 {
423 state->evalfunc_private = ExecJustAssignScanVarVirt;
424 return;
425 }
426 }
427
428#if defined(EEO_USE_COMPUTED_GOTO)
429
430 /*
431 * In the direct-threaded implementation, replace each opcode with the
432 * address to jump to. (Use ExecEvalStepOp() to get back the opcode.)
433 */
434 for (int off = 0; off < state->steps_len; off++)
435 {
436 ExprEvalStep *op = &state->steps[off];
437
438 op->opcode = EEO_OPCODE(op->opcode);
439 }
440
442#endif /* EEO_USE_COMPUTED_GOTO */
443
444 state->evalfunc_private = ExecInterpExpr;
445}
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 ExecJustHashInnerVarVirt(ExprState *state, ExprContext *econtext, bool *isnull)
static Datum ExecJustInnerVarVirt(ExprState *state, ExprContext *econtext, bool *isnull)
static Datum ExecJustHashInnerVarWithIV(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 ExecJustHashOuterVarVirt(ExprState *state, ExprContext *econtext, bool *isnull)
static Datum ExecJustAssignScanVarVirt(ExprState *state, ExprContext *econtext, bool *isnull)
static Datum ExecJustHashOuterVarStrict(ExprState *state, ExprContext *econtext, bool *isnull)
static Datum ExecJustAssignOuterVar(ExprState *state, ExprContext *econtext, bool *isnull)
static Datum ExecJustHashOuterVar(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)
static Datum ExecJustHashInnerVar(ExprState *state, ExprContext *econtext, bool *isnull)
#define EEO_FLAG_INTERPRETER_INITIALIZED
Definition: execExpr.h:29

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_HASHDATUM_FIRST, EEOP_HASHDATUM_FIRST_STRICT, EEOP_HASHDATUM_NEXT32, EEOP_HASHDATUM_SET_INITVAL, 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(), ExecJustHashInnerVar(), ExecJustHashInnerVarVirt(), ExecJustHashInnerVarWithIV(), ExecJustHashOuterVar(), ExecJustHashOuterVarStrict(), ExecJustHashOuterVarVirt(), ExecJustInnerVar(), ExecJustInnerVarVirt(), ExecJustOuterVar(), ExecJustOuterVarVirt(), ExecJustScanVar(), ExecJustScanVarVirt(), and ExprEvalStep::op.

Referenced by ExecReadyExpr().

◆ ExprEvalPushStep()

void ExprEvalPushStep ( ExprState es,
const ExprEvalStep s 
)

◆ StaticAssertDecl()

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