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

Function Documentation

◆ CheckExprStillValid()

void CheckExprStillValid ( ExprState state,
ExprContext econtext 
)

Definition at line 2307 of file execExprInterp.c.

2308{
2309 TupleTableSlot *innerslot;
2310 TupleTableSlot *outerslot;
2311 TupleTableSlot *scanslot;
2312 TupleTableSlot *oldslot;
2313 TupleTableSlot *newslot;
2314
2315 innerslot = econtext->ecxt_innertuple;
2316 outerslot = econtext->ecxt_outertuple;
2317 scanslot = econtext->ecxt_scantuple;
2318 oldslot = econtext->ecxt_oldtuple;
2319 newslot = econtext->ecxt_newtuple;
2320
2321 for (int i = 0; i < state->steps_len; i++)
2322 {
2323 ExprEvalStep *op = &state->steps[i];
2324
2325 switch (ExecEvalStepOp(state, op))
2326 {
2327 case EEOP_INNER_VAR:
2328 {
2329 int attnum = op->d.var.attnum;
2330
2331 CheckVarSlotCompatibility(innerslot, attnum + 1, op->d.var.vartype);
2332 break;
2333 }
2334
2335 case EEOP_OUTER_VAR:
2336 {
2337 int attnum = op->d.var.attnum;
2338
2339 CheckVarSlotCompatibility(outerslot, attnum + 1, op->d.var.vartype);
2340 break;
2341 }
2342
2343 case EEOP_SCAN_VAR:
2344 {
2345 int attnum = op->d.var.attnum;
2346
2347 CheckVarSlotCompatibility(scanslot, attnum + 1, op->d.var.vartype);
2348 break;
2349 }
2350
2351 case EEOP_OLD_VAR:
2352 {
2353 int attnum = op->d.var.attnum;
2354
2355 CheckVarSlotCompatibility(oldslot, attnum + 1, op->d.var.vartype);
2356 break;
2357 }
2358
2359 case EEOP_NEW_VAR:
2360 {
2361 int attnum = op->d.var.attnum;
2362
2363 CheckVarSlotCompatibility(newslot, attnum + 1, op->d.var.vartype);
2364 break;
2365 }
2366 default:
2367 break;
2368 }
2369 }
2370}
static void CheckVarSlotCompatibility(TupleTableSlot *slot, int attnum, Oid vartype)
ExprEvalOp ExecEvalStepOp(ExprState *state, ExprEvalStep *op)
int i
Definition: isn.c:77
int16 attnum
Definition: pg_attribute.h:74
TupleTableSlot * ecxt_innertuple
Definition: execnodes.h:270
TupleTableSlot * ecxt_newtuple
Definition: execnodes.h:307
TupleTableSlot * ecxt_scantuple
Definition: execnodes.h:268
TupleTableSlot * ecxt_oldtuple
Definition: execnodes.h:305
TupleTableSlot * ecxt_outertuple
Definition: execnodes.h:272
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 5670 of file execExprInterp.c.

5673{
5674 Assert(newValue != oldValue);
5675
5676 if (!newValueIsNull)
5677 {
5679 if (DatumIsReadWriteExpandedObject(newValue,
5680 false,
5681 pertrans->transtypeLen) &&
5682 MemoryContextGetParent(DatumGetEOHP(newValue)->eoh_context) == CurrentMemoryContext)
5683 /* do nothing */ ;
5684 else
5685 newValue = datumCopy(newValue,
5686 pertrans->transtypeByVal,
5687 pertrans->transtypeLen);
5688 }
5689 else
5690 {
5691 /*
5692 * Ensure that AggStatePerGroup->transValue ends up being 0, so
5693 * callers can safely compare newValue/oldValue without having to
5694 * check their respective nullness.
5695 */
5696 newValue = (Datum) 0;
5697 }
5698
5699 if (!oldValueIsNull)
5700 {
5701 if (DatumIsReadWriteExpandedObject(oldValue,
5702 false,
5703 pertrans->transtypeLen))
5704 DeleteExpandedObject(oldValue);
5705 else
5706 pfree(DatumGetPointer(oldValue));
5707 }
5708
5709 return newValue;
5710}
Datum datumCopy(Datum value, bool typByVal, int typLen)
Definition: datum.c:132
ExpandedObjectHeader * DatumGetEOHP(Datum d)
Definition: expandeddatum.c:29
void DeleteExpandedObject(Datum d)
#define DatumIsReadWriteExpandedObject(d, isnull, typlen)
Assert(PointerIsAligned(start, uint64))
void pfree(void *pointer)
Definition: mcxt.c:1524
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:2542
MemoryContext ecxt_per_tuple_memory
Definition: execnodes.h:276

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

5619{
5620 FunctionCallInfo fcinfo = pertrans->transfn_fcinfo;
5621 MemoryContext oldContext;
5622
5623 /*
5624 * We must copy the datum into aggcontext if it is pass-by-ref. We do not
5625 * need to pfree the old transValue, since it's NULL. (We already checked
5626 * that the agg's input type is binary-compatible with its transtype, so
5627 * straight copy here is OK.)
5628 */
5629 oldContext = MemoryContextSwitchTo(aggcontext->ecxt_per_tuple_memory);
5630 pergroup->transValue = datumCopy(fcinfo->args[1].value,
5631 pertrans->transtypeByVal,
5632 pertrans->transtypeLen);
5633 pergroup->transValueIsNull = false;
5634 pergroup->noTransValue = false;
5635 MemoryContextSwitchTo(oldContext);
5636}
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 5809 of file execExprInterp.c.

5811{
5812 AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
5813 int setno = op->d.agg_trans.setno;
5814
5815 tuplesort_putdatum(pertrans->sortstates[setno],
5816 *op->resvalue, *op->resnull);
5817}
Tuplesortstate ** sortstates
Definition: nodeAgg.h:162
AggStatePerTrans pertrans
Definition: execExpr.h:731
Datum * resvalue
Definition: execExpr.h:310
bool * resnull
Definition: execExpr.h:311
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 5823 of file execExprInterp.c.

5825{
5826 AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
5827 int setno = op->d.agg_trans.setno;
5828
5829 ExecClearTuple(pertrans->sortslot);
5830 pertrans->sortslot->tts_nvalid = pertrans->numInputs;
5832 tuplesort_puttupleslot(pertrans->sortstates[setno], pertrans->sortslot);
5833}
TupleTableSlot * ExecStoreVirtualTuple(TupleTableSlot *slot)
Definition: execTuples.c:1741
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:458

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

3616{
3617 Datum arraydatum;
3618
3619 /* NULL array -> NULL result */
3620 if (*op->resnull)
3621 return;
3622
3623 arraydatum = *op->resvalue;
3624
3625 /*
3626 * If it's binary-compatible, modify the element type in the array header,
3627 * but otherwise leave the array as we received it.
3628 */
3629 if (op->d.arraycoerce.elemexprstate == NULL)
3630 {
3631 /* Detoast input array if necessary, and copy in any case */
3632 ArrayType *array = DatumGetArrayTypePCopy(arraydatum);
3633
3635 *op->resvalue = PointerGetDatum(array);
3636 return;
3637 }
3638
3639 /*
3640 * Use array_map to apply the sub-expression to each array element.
3641 */
3642 *op->resvalue = array_map(arraydatum,
3644 econtext,
3646 op->d.arraycoerce.amstate);
3647}
#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:493
Oid resultelemtype
Definition: execExpr.h:494
struct ArrayMapState * amstate
Definition: execExpr.h:495
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 3401 of file execExprInterp.c.

3402{
3403 ArrayType *result;
3404 Oid element_type = op->d.arrayexpr.elemtype;
3405 int nelems = op->d.arrayexpr.nelems;
3406 int ndims = 0;
3407 int dims[MAXDIM];
3408 int lbs[MAXDIM];
3409
3410 /* Set non-null as default */
3411 *op->resnull = false;
3412
3413 if (!op->d.arrayexpr.multidims)
3414 {
3415 /* Elements are presumably of scalar type */
3416 Datum *dvalues = op->d.arrayexpr.elemvalues;
3417 bool *dnulls = op->d.arrayexpr.elemnulls;
3418
3419 /* setup for 1-D array of the given length */
3420 ndims = 1;
3421 dims[0] = nelems;
3422 lbs[0] = 1;
3423
3424 result = construct_md_array(dvalues, dnulls, ndims, dims, lbs,
3425 element_type,
3427 op->d.arrayexpr.elembyval,
3428 op->d.arrayexpr.elemalign);
3429 }
3430 else
3431 {
3432 /* Must be nested array expressions */
3433 int nbytes = 0;
3434 int nitems;
3435 int outer_nelems = 0;
3436 int elem_ndims = 0;
3437 int *elem_dims = NULL;
3438 int *elem_lbs = NULL;
3439 bool firstone = true;
3440 bool havenulls = false;
3441 bool haveempty = false;
3442 char **subdata;
3443 bits8 **subbitmaps;
3444 int *subbytes;
3445 int *subnitems;
3446 int32 dataoffset;
3447 char *dat;
3448 int iitem;
3449
3450 subdata = (char **) palloc(nelems * sizeof(char *));
3451 subbitmaps = (bits8 **) palloc(nelems * sizeof(bits8 *));
3452 subbytes = (int *) palloc(nelems * sizeof(int));
3453 subnitems = (int *) palloc(nelems * sizeof(int));
3454
3455 /* loop through and get data area from each element */
3456 for (int elemoff = 0; elemoff < nelems; elemoff++)
3457 {
3458 Datum arraydatum;
3459 bool eisnull;
3460 ArrayType *array;
3461 int this_ndims;
3462
3463 arraydatum = op->d.arrayexpr.elemvalues[elemoff];
3464 eisnull = op->d.arrayexpr.elemnulls[elemoff];
3465
3466 /* temporarily ignore null subarrays */
3467 if (eisnull)
3468 {
3469 haveempty = true;
3470 continue;
3471 }
3472
3473 array = DatumGetArrayTypeP(arraydatum);
3474
3475 /* run-time double-check on element type */
3476 if (element_type != ARR_ELEMTYPE(array))
3477 ereport(ERROR,
3478 (errcode(ERRCODE_DATATYPE_MISMATCH),
3479 errmsg("cannot merge incompatible arrays"),
3480 errdetail("Array with element type %s cannot be "
3481 "included in ARRAY construct with element type %s.",
3483 format_type_be(element_type))));
3484
3485 this_ndims = ARR_NDIM(array);
3486 /* temporarily ignore zero-dimensional subarrays */
3487 if (this_ndims <= 0)
3488 {
3489 haveempty = true;
3490 continue;
3491 }
3492
3493 if (firstone)
3494 {
3495 /* Get sub-array details from first member */
3496 elem_ndims = this_ndims;
3497 ndims = elem_ndims + 1;
3498 if (ndims <= 0 || ndims > MAXDIM)
3499 ereport(ERROR,
3500 (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
3501 errmsg("number of array dimensions (%d) exceeds the maximum allowed (%d)",
3502 ndims, MAXDIM)));
3503
3504 elem_dims = (int *) palloc(elem_ndims * sizeof(int));
3505 memcpy(elem_dims, ARR_DIMS(array), elem_ndims * sizeof(int));
3506 elem_lbs = (int *) palloc(elem_ndims * sizeof(int));
3507 memcpy(elem_lbs, ARR_LBOUND(array), elem_ndims * sizeof(int));
3508
3509 firstone = false;
3510 }
3511 else
3512 {
3513 /* Check other sub-arrays are compatible */
3514 if (elem_ndims != this_ndims ||
3515 memcmp(elem_dims, ARR_DIMS(array),
3516 elem_ndims * sizeof(int)) != 0 ||
3517 memcmp(elem_lbs, ARR_LBOUND(array),
3518 elem_ndims * sizeof(int)) != 0)
3519 ereport(ERROR,
3520 (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
3521 errmsg("multidimensional arrays must have array "
3522 "expressions with matching dimensions")));
3523 }
3524
3525 subdata[outer_nelems] = ARR_DATA_PTR(array);
3526 subbitmaps[outer_nelems] = ARR_NULLBITMAP(array);
3527 subbytes[outer_nelems] = ARR_SIZE(array) - ARR_DATA_OFFSET(array);
3528 nbytes += subbytes[outer_nelems];
3529 /* check for overflow of total request */
3530 if (!AllocSizeIsValid(nbytes))
3531 ereport(ERROR,
3532 (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
3533 errmsg("array size exceeds the maximum allowed (%d)",
3534 (int) MaxAllocSize)));
3535 subnitems[outer_nelems] = ArrayGetNItems(this_ndims,
3536 ARR_DIMS(array));
3537 havenulls |= ARR_HASNULL(array);
3538 outer_nelems++;
3539 }
3540
3541 /*
3542 * If all items were null or empty arrays, return an empty array;
3543 * otherwise, if some were and some weren't, raise error. (Note: we
3544 * must special-case this somehow to avoid trying to generate a 1-D
3545 * array formed from empty arrays. It's not ideal...)
3546 */
3547 if (haveempty)
3548 {
3549 if (ndims == 0) /* didn't find any nonempty array */
3550 {
3551 *op->resvalue = PointerGetDatum(construct_empty_array(element_type));
3552 return;
3553 }
3554 ereport(ERROR,
3555 (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
3556 errmsg("multidimensional arrays must have array "
3557 "expressions with matching dimensions")));
3558 }
3559
3560 /* setup for multi-D array */
3561 dims[0] = outer_nelems;
3562 lbs[0] = 1;
3563 for (int i = 1; i < ndims; i++)
3564 {
3565 dims[i] = elem_dims[i - 1];
3566 lbs[i] = elem_lbs[i - 1];
3567 }
3568
3569 /* check for subscript overflow */
3570 nitems = ArrayGetNItems(ndims, dims);
3571 ArrayCheckBounds(ndims, dims, lbs);
3572
3573 if (havenulls)
3574 {
3575 dataoffset = ARR_OVERHEAD_WITHNULLS(ndims, nitems);
3576 nbytes += dataoffset;
3577 }
3578 else
3579 {
3580 dataoffset = 0; /* marker for no null bitmap */
3581 nbytes += ARR_OVERHEAD_NONULLS(ndims);
3582 }
3583
3584 result = (ArrayType *) palloc0(nbytes);
3585 SET_VARSIZE(result, nbytes);
3586 result->ndim = ndims;
3587 result->dataoffset = dataoffset;
3588 result->elemtype = element_type;
3589 memcpy(ARR_DIMS(result), dims, ndims * sizeof(int));
3590 memcpy(ARR_LBOUND(result), lbs, ndims * sizeof(int));
3591
3592 dat = ARR_DATA_PTR(result);
3593 iitem = 0;
3594 for (int i = 0; i < outer_nelems; i++)
3595 {
3596 memcpy(dat, subdata[i], subbytes[i]);
3597 dat += subbytes[i];
3598 if (havenulls)
3599 array_bitmap_copy(ARR_NULLBITMAP(result), iitem,
3600 subbitmaps[i], 0,
3601 subnitems[i]);
3602 iitem += subnitems[i];
3603 }
3604 }
3605
3606 *op->resvalue = PointerGetDatum(result);
3607}
#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:509
int32_t int32
Definition: c.h:498
int errdetail(const char *fmt,...)
Definition: elog.c:1204
int errcode(int sqlerrcode)
Definition: elog.c:854
int errmsg(const char *fmt,...)
Definition: elog.c:1071
#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:30
Oid elemtype
Definition: array.h:97
int ndim
Definition: array.h:95
int32 dataoffset
Definition: array.h:96
char elemalign
Definition: execExpr.h:486
bool * elemnulls
Definition: execExpr.h:481
bool multidims
Definition: execExpr.h:487
int16 elemlength
Definition: execExpr.h:484
bool elembyval
Definition: execExpr.h:485
Datum * elemvalues
Definition: execExpr.h:480
struct ExprEvalStep::@55::@75 arrayexpr
Oid elemtype
Definition: execExpr.h:483
#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 3135 of file execExprInterp.c.

3136{
3137 char *str;
3138
3139 /* call output function (similar to OutputFunctionCall) */
3140 if (*op->resnull)
3141 {
3142 /* output functions are not called on nulls */
3143 str = NULL;
3144 }
3145 else
3146 {
3147 FunctionCallInfo fcinfo_out;
3148
3149 fcinfo_out = op->d.iocoerce.fcinfo_data_out;
3150 fcinfo_out->args[0].value = *op->resvalue;
3151 fcinfo_out->args[0].isnull = false;
3152
3153 fcinfo_out->isnull = false;
3154 str = DatumGetCString(FunctionCallInvoke(fcinfo_out));
3155
3156 /* OutputFunctionCall assumes result isn't null */
3157 Assert(!fcinfo_out->isnull);
3158 }
3159
3160 /* call input function (similar to InputFunctionCallSafe) */
3161 if (!op->d.iocoerce.finfo_in->fn_strict || str != NULL)
3162 {
3163 FunctionCallInfo fcinfo_in;
3164
3165 fcinfo_in = op->d.iocoerce.fcinfo_data_in;
3166 fcinfo_in->args[0].value = PointerGetDatum(str);
3167 fcinfo_in->args[0].isnull = *op->resnull;
3168 /* second and third arguments are already set up */
3169
3170 /* ErrorSaveContext must be present. */
3171 Assert(IsA(fcinfo_in->context, ErrorSaveContext));
3172
3173 fcinfo_in->isnull = false;
3174 *op->resvalue = FunctionCallInvoke(fcinfo_in);
3175
3176 if (SOFT_ERROR_OCCURRED(fcinfo_in->context))
3177 {
3178 *op->resnull = true;
3179 *op->resvalue = (Datum) 0;
3180 return;
3181 }
3182
3183 /* Should get null result if and only if str is NULL */
3184 if (str == NULL)
3185 Assert(*op->resnull);
3186 else
3187 Assert(!*op->resnull);
3188 }
3189}
#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:164
static char * DatumGetCString(Datum X)
Definition: postgres.h:340
FunctionCallInfo fcinfo_data_in
Definition: execExpr.h:461
FmgrInfo * finfo_in
Definition: execExpr.h:460
struct ExprEvalStep::@55::@72 iocoerce
FunctionCallInfo fcinfo_data_out
Definition: execExpr.h:458
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 4422 of file execExprInterp.c.

4423{
4424 if (!*op->d.domaincheck.checknull &&
4427 (errcode(ERRCODE_CHECK_VIOLATION),
4428 errmsg("value for domain %s violates check constraint \"%s\"",
4433}
int errdomainconstraint(Oid datatypeOid, const char *conname)
Definition: domains.c:431
#define errsave(context,...)
Definition: elog.h:262
static bool DatumGetBool(Datum X)
Definition: postgres.h:95
bool * checknull
Definition: execExpr.h:589
struct ExprEvalStep::@55::@85 domaincheck
Oid resulttype
Definition: execExpr.h:544
Datum * checkvalue
Definition: execExpr.h:588
ErrorSaveContext * escontext
Definition: execExpr.h:592
char * constraintname
Definition: execExpr.h:586
Definition: nodes.h:135

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

4409{
4410 if (*op->resnull)
4412 (errcode(ERRCODE_NOT_NULL_VIOLATION),
4413 errmsg("domain %s does not allow null values",
4416}
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 3928 of file execExprInterp.c.

3929{
3930 HeapTuple result;
3931 Datum tupDatum;
3932 HeapTupleHeader tuple;
3933 HeapTupleData tmptup;
3934 TupleDesc indesc,
3935 outdesc;
3936 bool changed = false;
3937
3938 /* NULL in -> NULL out */
3939 if (*op->resnull)
3940 return;
3941
3942 tupDatum = *op->resvalue;
3943 tuple = DatumGetHeapTupleHeader(tupDatum);
3944
3945 /*
3946 * Lookup tupdescs if first time through or if type changes. We'd better
3947 * pin them since type conversion functions could do catalog lookups and
3948 * hence cause cache invalidation.
3949 */
3952 &changed);
3953 IncrTupleDescRefCount(indesc);
3956 &changed);
3957 IncrTupleDescRefCount(outdesc);
3958
3959 /*
3960 * We used to be able to assert that incoming tuples are marked with
3961 * exactly the rowtype of indesc. However, now that ExecEvalWholeRowVar
3962 * might change the tuples' marking to plain RECORD due to inserting
3963 * aliases, we can only make this weak test:
3964 */
3965 Assert(HeapTupleHeaderGetTypeId(tuple) == indesc->tdtypeid ||
3966 HeapTupleHeaderGetTypeId(tuple) == RECORDOID);
3967
3968 /* if first time through, or after change, initialize conversion map */
3969 if (changed)
3970 {
3971 MemoryContext old_cxt;
3972
3973 /* allocate map in long-lived memory context */
3974 old_cxt = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
3975
3976 /* prepare map from old to new attribute numbers */
3977 op->d.convert_rowtype.map = convert_tuples_by_name(indesc, outdesc);
3978
3979 MemoryContextSwitchTo(old_cxt);
3980 }
3981
3982 /* Following steps need a HeapTuple not a bare HeapTupleHeader */
3983 tmptup.t_len = HeapTupleHeaderGetDatumLength(tuple);
3984 tmptup.t_data = tuple;
3985
3986 if (op->d.convert_rowtype.map != NULL)
3987 {
3988 /* Full conversion with attribute rearrangement needed */
3989 result = execute_attr_map_tuple(&tmptup, op->d.convert_rowtype.map);
3990 /* Result already has appropriate composite-datum header fields */
3991 *op->resvalue = HeapTupleGetDatum(result);
3992 }
3993 else
3994 {
3995 /*
3996 * The tuple is physically compatible as-is, but we need to insert the
3997 * destination rowtype OID in its composite-datum header field, so we
3998 * have to copy it anyway. heap_copy_tuple_as_datum() is convenient
3999 * for this since it will both make the physical copy and insert the
4000 * correct composite header fields. Note that we aren't expecting to
4001 * have to flatten any toasted fields: the input was a composite
4002 * datum, so it shouldn't contain any. So heap_copy_tuple_as_datum()
4003 * is overkill here, but its check for external fields is cheap.
4004 */
4005 *op->resvalue = heap_copy_tuple_as_datum(&tmptup, outdesc);
4006 }
4007
4008 DecrTupleDescRefCount(indesc);
4009 DecrTupleDescRefCount(outdesc);
4010}
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
static uint32 HeapTupleHeaderGetDatumLength(const HeapTupleHeaderData *tup)
Definition: htup_details.h:492
static Oid HeapTupleHeaderGetTypeId(const HeapTupleHeaderData *tup)
Definition: htup_details.h:504
MemoryContext ecxt_per_query_memory
Definition: execnodes.h:275
Oid outputtype
Definition: execExpr.h:617
TupleConversionMap * map
Definition: execExpr.h:621
Oid inputtype
Definition: execExpr.h:616
ExprEvalRowtypeCache * incache
Definition: execExpr.h:619
struct ExprEvalStep::@55::@88 convert_rowtype
ExprEvalRowtypeCache * outcache
Definition: execExpr.h:620
uint32 t_len
Definition: htup.h:64
HeapTupleHeader t_data
Definition: htup.h:68
Oid tdtypeid
Definition: tupdesc.h:138
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:570
void IncrTupleDescRefCount(TupleDesc tupdesc)
Definition: tupdesc.c:552

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

3263{
3264 ereport(ERROR,
3265 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3266 errmsg("WHERE CURRENT OF is not supported for this table type")));
3267}

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

Referenced by ExecInterpExpr().

◆ ExecEvalFieldSelect()

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

Definition at line 3729 of file execExprInterp.c.

3730{
3731 AttrNumber fieldnum = op->d.fieldselect.fieldnum;
3732 Datum tupDatum;
3733 HeapTupleHeader tuple;
3734 Oid tupType;
3735 int32 tupTypmod;
3736 TupleDesc tupDesc;
3737 Form_pg_attribute attr;
3738 HeapTupleData tmptup;
3739
3740 /* NULL record -> NULL result */
3741 if (*op->resnull)
3742 return;
3743
3744 tupDatum = *op->resvalue;
3745
3746 /* We can special-case expanded records for speed */
3748 {
3750
3751 Assert(erh->er_magic == ER_MAGIC);
3752
3753 /* Extract record's TupleDesc */
3754 tupDesc = expanded_record_get_tupdesc(erh);
3755
3756 /*
3757 * Find field's attr record. Note we don't support system columns
3758 * here: a datum tuple doesn't have valid values for most of the
3759 * interesting system columns anyway.
3760 */
3761 if (fieldnum <= 0) /* should never happen */
3762 elog(ERROR, "unsupported reference to system column %d in FieldSelect",
3763 fieldnum);
3764 if (fieldnum > tupDesc->natts) /* should never happen */
3765 elog(ERROR, "attribute number %d exceeds number of columns %d",
3766 fieldnum, tupDesc->natts);
3767 attr = TupleDescAttr(tupDesc, fieldnum - 1);
3768
3769 /* Check for dropped column, and force a NULL result if so */
3770 if (attr->attisdropped)
3771 {
3772 *op->resnull = true;
3773 return;
3774 }
3775
3776 /* Check for type mismatch --- possible after ALTER COLUMN TYPE? */
3777 /* As in CheckVarSlotCompatibility, we should but can't check typmod */
3778 if (op->d.fieldselect.resulttype != attr->atttypid)
3779 ereport(ERROR,
3780 (errcode(ERRCODE_DATATYPE_MISMATCH),
3781 errmsg("attribute %d has wrong type", fieldnum),
3782 errdetail("Table has type %s, but query expects %s.",
3783 format_type_be(attr->atttypid),
3785
3786 /* extract the field */
3787 *op->resvalue = expanded_record_get_field(erh, fieldnum,
3788 op->resnull);
3789 }
3790 else
3791 {
3792 /* Get the composite datum and extract its type fields */
3793 tuple = DatumGetHeapTupleHeader(tupDatum);
3794
3795 tupType = HeapTupleHeaderGetTypeId(tuple);
3796 tupTypmod = HeapTupleHeaderGetTypMod(tuple);
3797
3798 /* Lookup tupdesc if first time through or if type changes */
3799 tupDesc = get_cached_rowtype(tupType, tupTypmod,
3800 &op->d.fieldselect.rowcache, NULL);
3801
3802 /*
3803 * Find field's attr record. Note we don't support system columns
3804 * here: a datum tuple doesn't have valid values for most of the
3805 * interesting system columns anyway.
3806 */
3807 if (fieldnum <= 0) /* should never happen */
3808 elog(ERROR, "unsupported reference to system column %d in FieldSelect",
3809 fieldnum);
3810 if (fieldnum > tupDesc->natts) /* should never happen */
3811 elog(ERROR, "attribute number %d exceeds number of columns %d",
3812 fieldnum, tupDesc->natts);
3813 attr = TupleDescAttr(tupDesc, fieldnum - 1);
3814
3815 /* Check for dropped column, and force a NULL result if so */
3816 if (attr->attisdropped)
3817 {
3818 *op->resnull = true;
3819 return;
3820 }
3821
3822 /* Check for type mismatch --- possible after ALTER COLUMN TYPE? */
3823 /* As in CheckVarSlotCompatibility, we should but can't check typmod */
3824 if (op->d.fieldselect.resulttype != attr->atttypid)
3825 ereport(ERROR,
3826 (errcode(ERRCODE_DATATYPE_MISMATCH),
3827 errmsg("attribute %d has wrong type", fieldnum),
3828 errdetail("Table has type %s, but query expects %s.",
3829 format_type_be(attr->atttypid),
3831
3832 /* heap_getattr needs a HeapTuple not a bare HeapTupleHeader */
3833 tmptup.t_len = HeapTupleHeaderGetDatumLength(tuple);
3834 tmptup.t_data = tuple;
3835
3836 /* extract the field */
3837 *op->resvalue = heap_getattr(&tmptup,
3838 fieldnum,
3839 tupDesc,
3840 op->resnull);
3841 }
3842}
int16 AttrNumber
Definition: attnum.h:21
#define elog(elevel,...)
Definition: elog.h:226
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:904
static int32 HeapTupleHeaderGetTypMod(const HeapTupleHeaderData *tup)
Definition: htup_details.h:516
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:202
struct ExprEvalStep::@55::@81 fieldselect
AttrNumber fieldnum
Definition: execExpr.h:543
ExprEvalRowtypeCache rowcache
Definition: execExpr.h:419
static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)
Definition: tupdesc.h:160
#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 3854 of file execExprInterp.c.

3855{
3856 if (*op->resnull)
3857 {
3858 /* Convert null input tuple into an all-nulls row */
3859 memset(op->d.fieldstore.nulls, true,
3860 op->d.fieldstore.ncolumns * sizeof(bool));
3861 }
3862 else
3863 {
3864 /*
3865 * heap_deform_tuple needs a HeapTuple not a bare HeapTupleHeader. We
3866 * set all the fields in the struct just in case.
3867 */
3868 Datum tupDatum = *op->resvalue;
3869 HeapTupleHeader tuphdr;
3870 HeapTupleData tmptup;
3871 TupleDesc tupDesc;
3872
3873 tuphdr = DatumGetHeapTupleHeader(tupDatum);
3874 tmptup.t_len = HeapTupleHeaderGetDatumLength(tuphdr);
3875 ItemPointerSetInvalid(&(tmptup.t_self));
3876 tmptup.t_tableOid = InvalidOid;
3877 tmptup.t_data = tuphdr;
3878
3879 /*
3880 * Lookup tupdesc if first time through or if type changes. Because
3881 * we don't pin the tupdesc, we must not do this lookup until after
3882 * doing DatumGetHeapTupleHeader: that could do database access while
3883 * detoasting the datum.
3884 */
3885 tupDesc = get_cached_rowtype(op->d.fieldstore.fstore->resulttype, -1,
3886 op->d.fieldstore.rowcache, NULL);
3887
3888 /* Check that current tupdesc doesn't have more fields than allocated */
3889 if (unlikely(tupDesc->natts > op->d.fieldstore.ncolumns))
3890 elog(ERROR, "too many columns in composite type %u",
3891 op->d.fieldstore.fstore->resulttype);
3892
3893 heap_deform_tuple(&tmptup, tupDesc,
3894 op->d.fieldstore.values,
3895 op->d.fieldstore.nulls);
3896 }
3897}
#define unlikely(x)
Definition: c.h:347
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:35
Datum * values
Definition: execExpr.h:530
int ncolumns
Definition: execExpr.h:562
struct ExprEvalStep::@55::@82 fieldstore
bool * nulls
Definition: execExpr.h:531
FieldStore * fstore
Definition: execExpr.h:553
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 3904 of file execExprInterp.c.

3905{
3906 TupleDesc tupDesc;
3907 HeapTuple tuple;
3908
3909 /* Lookup tupdesc (should be valid already) */
3910 tupDesc = get_cached_rowtype(op->d.fieldstore.fstore->resulttype, -1,
3911 op->d.fieldstore.rowcache, NULL);
3912
3913 tuple = heap_form_tuple(tupDesc,
3914 op->d.fieldstore.values,
3915 op->d.fieldstore.nulls);
3916
3917 *op->resvalue = HeapTupleGetDatum(tuple);
3918 *op->resnull = false;
3919}
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 2990 of file execExprInterp.c.

2992{
2993 FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
2995 Datum d;
2996
2997 pgstat_init_function_usage(fcinfo, &fcusage);
2998
2999 fcinfo->isnull = false;
3000 d = op->d.func.fn_addr(fcinfo);
3001 *op->resvalue = d;
3002 *op->resnull = fcinfo->isnull;
3003
3004 pgstat_end_function_usage(&fcusage, true);
3005}
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:391
FunctionCallInfo fcinfo_data
Definition: execExpr.h:389
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 3011 of file execExprInterp.c.

3013{
3014
3015 FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
3017 NullableDatum *args = fcinfo->args;
3018 int nargs = op->d.func.nargs;
3019 Datum d;
3020
3021 /* strict function, so check for NULL args */
3022 for (int argno = 0; argno < nargs; argno++)
3023 {
3024 if (args[argno].isnull)
3025 {
3026 *op->resnull = true;
3027 return;
3028 }
3029 }
3030
3031 pgstat_init_function_usage(fcinfo, &fcusage);
3032
3033 fcinfo->isnull = false;
3034 d = op->d.func.fn_addr(fcinfo);
3035 *op->resvalue = d;
3036 *op->resnull = fcinfo->isnull;
3037
3038 pgstat_end_function_usage(&fcusage, true);
3039}

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

5247{
5248 AggState *aggstate = castNode(AggState, state->parent);
5249 int result = 0;
5250 Bitmapset *grouped_cols = aggstate->grouped_cols;
5251 ListCell *lc;
5252
5253 foreach(lc, op->d.grouping_func.clauses)
5254 {
5255 int attnum = lfirst_int(lc);
5256
5257 result <<= 1;
5258
5259 if (!bms_is_member(attnum, grouped_cols))
5260 result |= 1;
5261 }
5262
5263 *op->resvalue = Int32GetDatum(result);
5264 *op->resnull = false;
5265}
bool bms_is_member(int x, const Bitmapset *a)
Definition: bitmapset.c:510
#define castNode(_type_, nodeptr)
Definition: nodes.h:182
#define lfirst_int(lc)
Definition: pg_list.h:173
static Datum Int32GetDatum(int32 X)
Definition: postgres.h:217
Bitmapset * grouped_cols
Definition: execnodes.h:2551
struct ExprEvalStep::@55::@94 grouping_func
List * clauses
Definition: execExpr.h:677

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

4227{
4230 bool inclause = op->d.hashedscalararrayop.inclause;
4231 bool strictfunc = op->d.hashedscalararrayop.finfo->fn_strict;
4232 Datum scalar = fcinfo->args[0].value;
4233 bool scalar_isnull = fcinfo->args[0].isnull;
4234 Datum result;
4235 bool resultnull;
4236 bool hashfound;
4237
4238 /* We don't setup a hashed scalar array op if the array const is null. */
4239 Assert(!*op->resnull);
4240
4241 /*
4242 * If the scalar is NULL, and the function is strict, return NULL; no
4243 * point in executing the search.
4244 */
4245 if (fcinfo->args[0].isnull && strictfunc)
4246 {
4247 *op->resnull = true;
4248 return;
4249 }
4250
4251 /* Build the hash table on first evaluation */
4252 if (elements_tab == NULL)
4253 {
4254 ScalarArrayOpExpr *saop;
4255 int16 typlen;
4256 bool typbyval;
4257 char typalign;
4258 int nitems;
4259 bool has_nulls = false;
4260 char *s;
4261 bits8 *bitmap;
4262 int bitmask;
4263 MemoryContext oldcontext;
4264 ArrayType *arr;
4265
4266 saop = op->d.hashedscalararrayop.saop;
4267
4268 arr = DatumGetArrayTypeP(*op->resvalue);
4269 nitems = ArrayGetNItems(ARR_NDIM(arr), ARR_DIMS(arr));
4270
4272 &typlen,
4273 &typbyval,
4274 &typalign);
4275
4276 oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
4277
4278 elements_tab = (ScalarArrayOpExprHashTable *)
4279 palloc0(offsetof(ScalarArrayOpExprHashTable, hash_fcinfo_data) +
4281 op->d.hashedscalararrayop.elements_tab = elements_tab;
4282 elements_tab->op = op;
4283
4284 fmgr_info(saop->hashfuncid, &elements_tab->hash_finfo);
4285 fmgr_info_set_expr((Node *) saop, &elements_tab->hash_finfo);
4286
4288 &elements_tab->hash_finfo,
4289 1,
4290 saop->inputcollid,
4291 NULL,
4292 NULL);
4293
4294 /*
4295 * Create the hash table sizing it according to the number of elements
4296 * in the array. This does assume that the array has no duplicates.
4297 * If the array happens to contain many duplicate values then it'll
4298 * just mean that we sized the table a bit on the large side.
4299 */
4300 elements_tab->hashtab = saophash_create(CurrentMemoryContext, nitems,
4301 elements_tab);
4302
4303 MemoryContextSwitchTo(oldcontext);
4304
4305 s = (char *) ARR_DATA_PTR(arr);
4306 bitmap = ARR_NULLBITMAP(arr);
4307 bitmask = 1;
4308 for (int i = 0; i < nitems; i++)
4309 {
4310 /* Get array element, checking for NULL. */
4311 if (bitmap && (*bitmap & bitmask) == 0)
4312 {
4313 has_nulls = true;
4314 }
4315 else
4316 {
4317 Datum element;
4318
4319 element = fetch_att(s, typbyval, typlen);
4320 s = att_addlength_pointer(s, typlen, s);
4321 s = (char *) att_align_nominal(s, typalign);
4322
4323 saophash_insert(elements_tab->hashtab, element, &hashfound);
4324 }
4325
4326 /* Advance bitmap pointer if any. */
4327 if (bitmap)
4328 {
4329 bitmask <<= 1;
4330 if (bitmask == 0x100)
4331 {
4332 bitmap++;
4333 bitmask = 1;
4334 }
4335 }
4336 }
4337
4338 /*
4339 * Remember if we had any nulls so that we know if we need to execute
4340 * non-strict functions with a null lhs value if no match is found.
4341 */
4342 op->d.hashedscalararrayop.has_nulls = has_nulls;
4343 }
4344
4345 /* Check the hash to see if we have a match. */
4346 hashfound = NULL != saophash_lookup(elements_tab->hashtab, scalar);
4347
4348 /* the result depends on if the clause is an IN or NOT IN clause */
4349 if (inclause)
4350 result = BoolGetDatum(hashfound); /* IN */
4351 else
4352 result = BoolGetDatum(!hashfound); /* NOT IN */
4353
4354 resultnull = false;
4355
4356 /*
4357 * If we didn't find a match in the array, we still might need to handle
4358 * the possibility of null values. We didn't put any NULLs into the
4359 * hashtable, but instead marked if we found any when building the table
4360 * in has_nulls.
4361 */
4362 if (!hashfound && op->d.hashedscalararrayop.has_nulls)
4363 {
4364 if (strictfunc)
4365 {
4366
4367 /*
4368 * We have nulls in the array so a non-null lhs and no match must
4369 * yield NULL.
4370 */
4371 result = (Datum) 0;
4372 resultnull = true;
4373 }
4374 else
4375 {
4376 /*
4377 * Execute function will null rhs just once.
4378 *
4379 * The hash lookup path will have scribbled on the lhs argument so
4380 * we need to set it up also (even though we entered this function
4381 * with it already set).
4382 */
4383 fcinfo->args[0].value = scalar;
4384 fcinfo->args[0].isnull = scalar_isnull;
4385 fcinfo->args[1].value = (Datum) 0;
4386 fcinfo->args[1].isnull = true;
4387
4388 result = op->d.hashedscalararrayop.finfo->fn_addr(fcinfo);
4389 resultnull = fcinfo->isnull;
4390
4391 /*
4392 * Reverse the result for NOT IN clauses since the above function
4393 * is the equality function and we need not-equals.
4394 */
4395 if (!inclause)
4396 result = !result;
4397 }
4398 }
4399
4400 *op->resvalue = result;
4401 *op->resnull = resultnull;
4402}
int16_t int16
Definition: c.h:497
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:2411
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:642
struct ScalarArrayOpExprHashTable * elements_tab
Definition: execExpr.h:644
bool inclause
Definition: execExpr.h:643
ScalarArrayOpExpr * saop
Definition: execExpr.h:647
FmgrInfo * finfo
Definition: execExpr.h:388
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 5112 of file execExprInterp.c.

5114{
5116
5117 /*
5118 * Prepare to call json_populate_type() to coerce the boolean result of
5119 * JSON_EXISTS_OP to the target type. If the target type is integer or a
5120 * domain over integer, call the boolean-to-integer cast function instead,
5121 * because the integer's input function (which is what
5122 * json_populate_type() calls to coerce to scalar target types) doesn't
5123 * accept boolean literals as valid input. We only have a special case
5124 * for integer and domains thereof as it seems common to use those types
5125 * for EXISTS columns in JSON_TABLE().
5126 */
5128 {
5130 {
5131 /* Check domain constraints if any. */
5136 econtext->ecxt_per_query_memory,
5137 (Node *) escontext))
5138 {
5139 *op->resnull = true;
5140 *op->resvalue = (Datum) 0;
5141 }
5142 else
5144 return;
5145 }
5146
5148 DatumGetBool(*op->resvalue) ?
5149 CStringGetDatum("true") :
5150 CStringGetDatum("false"));
5151 }
5152
5153 *op->resvalue = json_populate_type(*op->resvalue, JSONBOID,
5157 econtext->ecxt_per_query_memory,
5158 op->resnull,
5160 (Node *) escontext);
5161}
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:682
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:3345
static Datum CStringGetDatum(const char *X)
Definition: postgres.h:355
void * json_coercion_cache
Definition: execExpr.h:769
bool exists_coerce
Definition: execExpr.h:766
bool exists_cast_to_int
Definition: execExpr.h:767
struct ExprEvalStep::@55::@104 jsonexpr_coercion
bool exists_check_domain
Definition: execExpr.h:768
int32 targettypmod
Definition: execExpr.h:763
Oid targettype
Definition: execExpr.h:762
bool omit_quotes
Definition: execExpr.h:764

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

5193{
5194 JsonExprState *jsestate = op->d.jsonexpr.jsestate;
5195
5196 if (SOFT_ERROR_OCCURRED(&jsestate->escontext))
5197 {
5198 /*
5199 * jsestate->error or jsestate->empty being set means that the error
5200 * occurred when coercing the JsonBehavior value. Throw the error in
5201 * that case with the actual coercion error message shown in the
5202 * DETAIL part.
5203 */
5204 if (DatumGetBool(jsestate->error.value))
5205 ereport(ERROR,
5206 (errcode(ERRCODE_DATATYPE_MISMATCH),
5207 /*- translator: first %s is a SQL/JSON clause (e.g. ON ERROR) */
5208 errmsg("could not coerce %s expression (%s) to the RETURNING type",
5209 "ON ERROR",
5211 errdetail("%s", jsestate->escontext.error_data->message)));
5212 else if (DatumGetBool(jsestate->empty.value))
5213 ereport(ERROR,
5214 (errcode(ERRCODE_DATATYPE_MISMATCH),
5215 /*- translator: first %s is a SQL/JSON clause (e.g. ON ERROR) */
5216 errmsg("could not coerce %s expression (%s) to the RETURNING type",
5217 "ON EMPTY",
5219 errdetail("%s", jsestate->escontext.error_data->message)));
5220
5221 *op->resvalue = (Datum) 0;
5222 *op->resnull = true;
5223
5224 jsestate->error.value = BoolGetDatum(true);
5225
5226 /*
5227 * Reset for next use such as for catching errors when coercing a
5228 * JsonBehavior expression.
5229 */
5230 jsestate->escontext.error_occurred = false;
5231 jsestate->escontext.error_occurred = false;
5232 jsestate->escontext.details_wanted = true;
5233 }
5234}
static char * GetJsonBehaviorValueString(JsonBehavior *behavior)
char * message
Definition: elog.h:432
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:756
struct ExprEvalStep::@55::@103 jsonexpr
NullableDatum empty
Definition: execnodes.h:1087
JsonExpr * jsexpr
Definition: execnodes.h:1065
NullableDatum error
Definition: execnodes.h:1084
ErrorSaveContext escontext
Definition: execnodes.h:1124
JsonBehavior * on_empty
Definition: primnodes.h:1844
JsonBehavior * on_error
Definition: primnodes.h:1845

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

4659{
4660 Datum res;
4662 JsonConstructorExpr *ctor = jcstate->constructor;
4663 bool is_jsonb = ctor->returning->format->format_type == JS_FORMAT_JSONB;
4664 bool isnull = false;
4665
4666 if (ctor->type == JSCTOR_JSON_ARRAY)
4667 res = (is_jsonb ?
4669 json_build_array_worker) (jcstate->nargs,
4670 jcstate->arg_values,
4671 jcstate->arg_nulls,
4672 jcstate->arg_types,
4673 jcstate->constructor->absent_on_null);
4674 else if (ctor->type == JSCTOR_JSON_OBJECT)
4675 res = (is_jsonb ?
4678 jcstate->arg_values,
4679 jcstate->arg_nulls,
4680 jcstate->arg_types,
4681 jcstate->constructor->absent_on_null,
4682 jcstate->constructor->unique);
4683 else if (ctor->type == JSCTOR_JSON_SCALAR)
4684 {
4685 if (jcstate->arg_nulls[0])
4686 {
4687 res = (Datum) 0;
4688 isnull = true;
4689 }
4690 else
4691 {
4692 Datum value = jcstate->arg_values[0];
4693 Oid outfuncid = jcstate->arg_type_cache[0].outfuncid;
4695 jcstate->arg_type_cache[0].category;
4696
4697 if (is_jsonb)
4698 res = datum_to_jsonb(value, category, outfuncid);
4699 else
4700 res = datum_to_json(value, category, outfuncid);
4701 }
4702 }
4703 else if (ctor->type == JSCTOR_JSON_PARSE)
4704 {
4705 if (jcstate->arg_nulls[0])
4706 {
4707 res = (Datum) 0;
4708 isnull = true;
4709 }
4710 else
4711 {
4712 Datum value = jcstate->arg_values[0];
4713 text *js = DatumGetTextP(value);
4714
4715 if (is_jsonb)
4716 res = jsonb_from_text(js, true);
4717 else
4718 {
4719 (void) json_validate(js, true, true);
4720 res = value;
4721 }
4722 }
4723 }
4724 else
4725 elog(ERROR, "invalid JsonConstructorExpr type %d", ctor->type);
4726
4727 *op->resvalue = res;
4728 *op->resnull = isnull;
4729}
#define DatumGetTextP(X)
Definition: fmgr.h:332
static struct @165 value
if(TABLE==NULL||TABLE_index==NULL)
Definition: isn.c:81
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:1645
@ JSCTOR_JSON_PARSE
Definition: primnodes.h:1699
@ JSCTOR_JSON_OBJECT
Definition: primnodes.h:1695
@ JSCTOR_JSON_SCALAR
Definition: primnodes.h:1700
@ JSCTOR_JSON_ARRAY
Definition: primnodes.h:1696
struct ExprEvalStep::@55::@92 json_constructor
struct JsonConstructorExprState * jcstate
Definition: execExpr.h:665
JsonConstructorExpr * constructor
Definition: execExpr.h:823
struct JsonConstructorExprState::@105 * arg_type_cache
JsonReturning * returning
Definition: primnodes.h:1715
JsonConstructorType type
Definition: primnodes.h:1711
JsonFormatType format_type
Definition: primnodes.h:1656
JsonFormat * format
Definition: primnodes.h:1668
Definition: c.h:658

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, JsonConstructorExpr::returning, JsonConstructorExpr::type, JsonConstructorExpr::unique, and value.

Referenced by ExecInterpExpr().

◆ ExecEvalJsonExprPath()

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

Definition at line 4835 of file execExprInterp.c.

4837{
4838 JsonExprState *jsestate = op->d.jsonexpr.jsestate;
4839 JsonExpr *jsexpr = jsestate->jsexpr;
4840 Datum item;
4841 JsonPath *path;
4842 bool throw_error = jsexpr->on_error->btype == JSON_BEHAVIOR_ERROR;
4843 bool error = false,
4844 empty = false;
4845 int jump_eval_coercion = jsestate->jump_eval_coercion;
4846 char *val_string = NULL;
4847
4848 item = jsestate->formatted_expr.value;
4849 path = DatumGetJsonPathP(jsestate->pathspec.value);
4850
4851 /* Set error/empty to false. */
4852 memset(&jsestate->error, 0, sizeof(NullableDatum));
4853 memset(&jsestate->empty, 0, sizeof(NullableDatum));
4854
4855 /* Also reset ErrorSaveContext contents for the next row. */
4856 if (jsestate->escontext.details_wanted)
4857 {
4858 jsestate->escontext.error_data = NULL;
4859 jsestate->escontext.details_wanted = false;
4860 }
4861 jsestate->escontext.error_occurred = false;
4862
4863 switch (jsexpr->op)
4864 {
4865 case JSON_EXISTS_OP:
4866 {
4867 bool exists = JsonPathExists(item, path,
4868 !throw_error ? &error : NULL,
4869 jsestate->args);
4870
4871 if (!error)
4872 {
4873 *op->resnull = false;
4874 *op->resvalue = BoolGetDatum(exists);
4875 }
4876 }
4877 break;
4878
4879 case JSON_QUERY_OP:
4880 *op->resvalue = JsonPathQuery(item, path, jsexpr->wrapper, &empty,
4881 !throw_error ? &error : NULL,
4882 jsestate->args,
4883 jsexpr->column_name);
4884
4885 *op->resnull = (DatumGetPointer(*op->resvalue) == NULL);
4886 break;
4887
4888 case JSON_VALUE_OP:
4889 {
4890 JsonbValue *jbv = JsonPathValue(item, path, &empty,
4891 !throw_error ? &error : NULL,
4892 jsestate->args,
4893 jsexpr->column_name);
4894
4895 if (jbv == NULL)
4896 {
4897 /* Will be coerced with json_populate_type(), if needed. */
4898 *op->resvalue = (Datum) 0;
4899 *op->resnull = true;
4900 }
4901 else if (!error && !empty)
4902 {
4903 if (jsexpr->returning->typid == JSONOID ||
4904 jsexpr->returning->typid == JSONBOID)
4905 {
4908 }
4909 else if (jsexpr->use_json_coercion)
4910 {
4912 *op->resnull = false;
4913 }
4914 else
4915 {
4917
4918 /*
4919 * Simply convert to the default RETURNING type (text)
4920 * if no coercion needed.
4921 */
4922 if (!jsexpr->use_io_coercion)
4925 }
4926 }
4927 break;
4928 }
4929
4930 /* JSON_TABLE_OP can't happen here */
4931
4932 default:
4933 elog(ERROR, "unrecognized SQL/JSON expression op %d",
4934 (int) jsexpr->op);
4935 return false;
4936 }
4937
4938 /*
4939 * Coerce the result value to the RETURNING type by calling its input
4940 * function.
4941 */
4942 if (!*op->resnull && jsexpr->use_io_coercion)
4943 {
4944 FunctionCallInfo fcinfo;
4945
4946 Assert(jump_eval_coercion == -1);
4947 fcinfo = jsestate->input_fcinfo;
4948 Assert(fcinfo != NULL);
4949 Assert(val_string != NULL);
4950 fcinfo->args[0].value = PointerGetDatum(val_string);
4951 fcinfo->args[0].isnull = *op->resnull;
4952
4953 /*
4954 * Second and third arguments are already set up in
4955 * ExecInitJsonExpr().
4956 */
4957
4958 fcinfo->isnull = false;
4959 *op->resvalue = FunctionCallInvoke(fcinfo);
4960 if (SOFT_ERROR_OCCURRED(&jsestate->escontext))
4961 error = true;
4962 }
4963
4964 /*
4965 * When setting up the ErrorSaveContext (if needed) for capturing the
4966 * errors that occur when coercing the JsonBehavior expression, set
4967 * details_wanted to be able to show the actual error message as the
4968 * DETAIL of the error message that tells that it is the JsonBehavior
4969 * expression that caused the error; see ExecEvalJsonCoercionFinish().
4970 */
4971
4972 /* Handle ON EMPTY. */
4973 if (empty)
4974 {
4975 *op->resvalue = (Datum) 0;
4976 *op->resnull = true;
4977 if (jsexpr->on_empty)
4978 {
4979 if (jsexpr->on_empty->btype != JSON_BEHAVIOR_ERROR)
4980 {
4981 jsestate->empty.value = BoolGetDatum(true);
4982 /* Set up to catch coercion errors of the ON EMPTY value. */
4983 jsestate->escontext.error_occurred = false;
4984 jsestate->escontext.details_wanted = true;
4985 /* Jump to end if the ON EMPTY behavior is to return NULL */
4986 return jsestate->jump_empty >= 0 ? jsestate->jump_empty : jsestate->jump_end;
4987 }
4988 }
4989 else if (jsexpr->on_error->btype != JSON_BEHAVIOR_ERROR)
4990 {
4991 jsestate->error.value = BoolGetDatum(true);
4992 /* Set up to catch coercion errors of the ON ERROR value. */
4993 jsestate->escontext.error_occurred = false;
4994 jsestate->escontext.details_wanted = true;
4995 Assert(!throw_error);
4996 /* Jump to end if the ON ERROR behavior is to return NULL */
4997 return jsestate->jump_error >= 0 ? jsestate->jump_error : jsestate->jump_end;
4998 }
4999
5000 if (jsexpr->column_name)
5001 ereport(ERROR,
5002 errcode(ERRCODE_NO_SQL_JSON_ITEM),
5003 errmsg("no SQL/JSON item found for specified path of column \"%s\"",
5004 jsexpr->column_name));
5005 else
5006 ereport(ERROR,
5007 errcode(ERRCODE_NO_SQL_JSON_ITEM),
5008 errmsg("no SQL/JSON item found for specified path"));
5009 }
5010
5011 /*
5012 * ON ERROR. Wouldn't get here if the behavior is ERROR, because they
5013 * would have already been thrown.
5014 */
5015 if (error)
5016 {
5017 Assert(!throw_error);
5018 *op->resvalue = (Datum) 0;
5019 *op->resnull = true;
5020 jsestate->error.value = BoolGetDatum(true);
5021 /* Set up to catch coercion errors of the ON ERROR value. */
5022 jsestate->escontext.error_occurred = false;
5023 jsestate->escontext.details_wanted = true;
5024 /* Jump to end if the ON ERROR behavior is to return NULL */
5025 return jsestate->jump_error >= 0 ? jsestate->jump_error : jsestate->jump_end;
5026 }
5027
5028 return jump_eval_coercion >= 0 ? jump_eval_coercion : jsestate->jump_end;
5029}
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:1771
@ JSON_QUERY_OP
Definition: primnodes.h:1808
@ JSON_EXISTS_OP
Definition: primnodes.h:1807
@ JSON_VALUE_OP
Definition: primnodes.h:1809
static void error(void)
Definition: sql-dyntest.c:147
JsonBehaviorType btype
Definition: primnodes.h:1795
int jump_eval_coercion
Definition: execnodes.h:1101
FunctionCallInfo input_fcinfo
Definition: execnodes.h:1115
NullableDatum pathspec
Definition: execnodes.h:1071
NullableDatum formatted_expr
Definition: execnodes.h:1068
char * column_name
Definition: primnodes.h:1824
bool use_io_coercion
Definition: primnodes.h:1851
JsonReturning * returning
Definition: primnodes.h:1837
bool use_json_coercion
Definition: primnodes.h:1852
JsonWrapper wrapper
Definition: primnodes.h:1855
JsonExprOp op
Definition: primnodes.h:1822
Datum textin(PG_FUNCTION_ARGS)
Definition: varlena.c:587

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

4736{
4737 JsonIsPredicate *pred = op->d.is_json.pred;
4738 Datum js = *op->resvalue;
4739 Oid exprtype;
4740 bool res;
4741
4742 if (*op->resnull)
4743 {
4744 *op->resvalue = BoolGetDatum(false);
4745 return;
4746 }
4747
4748 exprtype = exprType(pred->expr);
4749
4750 if (exprtype == TEXTOID || exprtype == JSONOID)
4751 {
4752 text *json = DatumGetTextP(js);
4753
4754 if (pred->item_type == JS_TYPE_ANY)
4755 res = true;
4756 else
4757 {
4758 switch (json_get_first_token(json, false))
4759 {
4761 res = pred->item_type == JS_TYPE_OBJECT;
4762 break;
4764 res = pred->item_type == JS_TYPE_ARRAY;
4765 break;
4766 case JSON_TOKEN_STRING:
4767 case JSON_TOKEN_NUMBER:
4768 case JSON_TOKEN_TRUE:
4769 case JSON_TOKEN_FALSE:
4770 case JSON_TOKEN_NULL:
4771 res = pred->item_type == JS_TYPE_SCALAR;
4772 break;
4773 default:
4774 res = false;
4775 break;
4776 }
4777 }
4778
4779 /*
4780 * Do full parsing pass only for uniqueness check or for JSON text
4781 * validation.
4782 */
4783 if (res && (pred->unique_keys || exprtype == TEXTOID))
4784 res = json_validate(json, pred->unique_keys, false);
4785 }
4786 else if (exprtype == JSONBOID)
4787 {
4788 if (pred->item_type == JS_TYPE_ANY)
4789 res = true;
4790 else
4791 {
4792 Jsonb *jb = DatumGetJsonbP(js);
4793
4794 switch (pred->item_type)
4795 {
4796 case JS_TYPE_OBJECT:
4797 res = JB_ROOT_IS_OBJECT(jb);
4798 break;
4799 case JS_TYPE_ARRAY:
4800 res = JB_ROOT_IS_ARRAY(jb) && !JB_ROOT_IS_SCALAR(jb);
4801 break;
4802 case JS_TYPE_SCALAR:
4803 res = JB_ROOT_IS_ARRAY(jb) && JB_ROOT_IS_SCALAR(jb);
4804 break;
4805 default:
4806 res = false;
4807 break;
4808 }
4809 }
4810
4811 /* Key uniqueness check is redundant for jsonb */
4812 }
4813 else
4814 res = false;
4815
4816 *op->resvalue = BoolGetDatum(res);
4817}
@ 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:5972
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:42
@ JS_TYPE_ANY
Definition: primnodes.h:1727
@ JS_TYPE_ARRAY
Definition: primnodes.h:1729
@ JS_TYPE_OBJECT
Definition: primnodes.h:1728
@ JS_TYPE_SCALAR
Definition: primnodes.h:1730
JsonIsPredicate * pred
Definition: execExpr.h:750
struct ExprEvalStep::@55::@102 is_json
JsonValueType item_type
Definition: primnodes.h:1742
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, and JsonIsPredicate::unique_keys.

Referenced by ExecInterpExpr().

◆ ExecEvalMergeSupportFunc()

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

Definition at line 5273 of file execExprInterp.c.

5275{
5276 ModifyTableState *mtstate = castNode(ModifyTableState, state->parent);
5277 MergeActionState *relaction = mtstate->mt_merge_action;
5278
5279 if (!relaction)
5280 elog(ERROR, "no merge action in progress");
5281
5282 /* Return the MERGE action ("INSERT", "UPDATE", or "DELETE") */
5283 switch (relaction->mas_action->commandType)
5284 {
5285 case CMD_INSERT:
5287 *op->resnull = false;
5288 break;
5289 case CMD_UPDATE:
5291 *op->resnull = false;
5292 break;
5293 case CMD_DELETE:
5295 *op->resnull = false;
5296 break;
5297 case CMD_NOTHING:
5298 elog(ERROR, "unexpected merge action: DO NOTHING");
5299 break;
5300 default:
5301 elog(ERROR, "unrecognized commandType: %d",
5302 (int) relaction->mas_action->commandType);
5303 }
5304}
@ CMD_INSERT
Definition: nodes.h:273
@ CMD_DELETE
Definition: nodes.h:274
@ CMD_UPDATE
Definition: nodes.h:272
@ CMD_NOTHING
Definition: nodes.h:278
MergeAction * mas_action
Definition: execnodes.h:444
CmdType commandType
Definition: primnodes.h:2012
MergeActionState * mt_merge_action
Definition: execnodes.h:1445
text * cstring_to_text_with_len(const char *s, int len)
Definition: varlena.c:204

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

3677{
3678 Datum *values = op->d.minmax.values;
3679 bool *nulls = op->d.minmax.nulls;
3680 FunctionCallInfo fcinfo = op->d.minmax.fcinfo_data;
3681 MinMaxOp operator = op->d.minmax.op;
3682
3683 /* set at initialization */
3684 Assert(fcinfo->args[0].isnull == false);
3685 Assert(fcinfo->args[1].isnull == false);
3686
3687 /* default to null result */
3688 *op->resnull = true;
3689
3690 for (int off = 0; off < op->d.minmax.nelems; off++)
3691 {
3692 /* ignore NULL inputs */
3693 if (nulls[off])
3694 continue;
3695
3696 if (*op->resnull)
3697 {
3698 /* first nonnull input, adopt value */
3699 *op->resvalue = values[off];
3700 *op->resnull = false;
3701 }
3702 else
3703 {
3704 int cmpresult;
3705
3706 /* apply comparison function */
3707 fcinfo->args[0].value = *op->resvalue;
3708 fcinfo->args[1].value = values[off];
3709
3710 fcinfo->isnull = false;
3711 cmpresult = DatumGetInt32(FunctionCallInvoke(fcinfo));
3712 if (fcinfo->isnull) /* probably should not happen */
3713 continue;
3714
3715 if (cmpresult > 0 && operator == IS_LEAST)
3716 *op->resvalue = values[off];
3717 else if (cmpresult < 0 && operator == IS_GREATEST)
3718 *op->resvalue = values[off];
3719 }
3720 }
3721}
static Datum values[MAXATTR]
Definition: bootstrap.c:151
static int32 DatumGetInt32(Datum X)
Definition: postgres.h:207
MinMaxOp
Definition: primnodes.h:1506
@ IS_LEAST
Definition: primnodes.h:1508
@ IS_GREATEST
Definition: primnodes.h:1507
MinMaxOp op
Definition: execExpr.h:534
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 3273 of file execExprInterp.c.

3274{
3276
3277 switch (op->d.nextvalueexpr.seqtypid)
3278 {
3279 case INT2OID:
3281 break;
3282 case INT4OID:
3284 break;
3285 case INT8OID:
3287 break;
3288 default:
3289 elog(ERROR, "unsupported sequence type %u",
3291 }
3292 *op->resnull = false;
3293}
int64_t int64
Definition: c.h:499
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:474
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 3048 of file execExprInterp.c.

3049{
3050 ParamExecData *prm;
3051
3052 prm = &(econtext->ecxt_param_exec_vals[op->d.param.paramid]);
3053 if (unlikely(prm->execPlan != NULL))
3054 {
3055 /* Parameter not evaluated yet, so go do it */
3056 ExecSetParamPlan(prm->execPlan, econtext);
3057 /* ExecSetParamPlan should have processed this param... */
3058 Assert(prm->execPlan == NULL);
3059 }
3060 *op->resvalue = prm->value;
3061 *op->resnull = prm->isnull;
3062}
void ExecSetParamPlan(SubPlanState *node, ExprContext *econtext)
Definition: nodeSubplan.c:1100
ParamExecData * ecxt_param_exec_vals
Definition: execnodes.h:279
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 3070 of file execExprInterp.c.

3071{
3072 ParamListInfo paramInfo = econtext->ecxt_param_list_info;
3073 int paramId = op->d.param.paramid;
3074
3075 if (likely(paramInfo &&
3076 paramId > 0 && paramId <= paramInfo->numParams))
3077 {
3078 ParamExternData *prm;
3079 ParamExternData prmdata;
3080
3081 /* give hook a chance in case parameter is dynamic */
3082 if (paramInfo->paramFetch != NULL)
3083 prm = paramInfo->paramFetch(paramInfo, paramId, false, &prmdata);
3084 else
3085 prm = &paramInfo->params[paramId - 1];
3086
3087 if (likely(OidIsValid(prm->ptype)))
3088 {
3089 /* safety check in case hook did something unexpected */
3090 if (unlikely(prm->ptype != op->d.param.paramtype))
3091 ereport(ERROR,
3092 (errcode(ERRCODE_DATATYPE_MISMATCH),
3093 errmsg("type of parameter %d (%s) does not match that when preparing the plan (%s)",
3094 paramId,
3095 format_type_be(prm->ptype),
3097 *op->resvalue = prm->value;
3098 *op->resnull = prm->isnull;
3099 return;
3100 }
3101 }
3102
3103 ereport(ERROR,
3104 (errcode(ERRCODE_UNDEFINED_OBJECT),
3105 errmsg("no value found for parameter %d", paramId)));
3106}
#define likely(x)
Definition: c.h:346
#define OidIsValid(objectId)
Definition: c.h:746
ParamListInfo ecxt_param_list_info
Definition: execnodes.h:280
Oid paramtype
Definition: execExpr.h:426
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 3113 of file execExprInterp.c.

3114{
3115 ParamExecData *prm;
3116
3117 prm = &(econtext->ecxt_param_exec_vals[op->d.param.paramid]);
3118
3119 /* Shouldn't have a pending evaluation anymore */
3120 Assert(prm->execPlan == NULL);
3121
3122 prm->value = state->resvalue;
3123 prm->isnull = state->resnull;
3124}

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

5763{
5764 ExprContext *tmpcontext = aggstate->tmpcontext;
5765 bool isdistinct = false; /* for now */
5766 TupleTableSlot *save_outer;
5767 TupleTableSlot *save_inner;
5768
5769 for (int i = 0; i < pertrans->numTransInputs; i++)
5770 {
5771 pertrans->sortslot->tts_values[i] = pertrans->transfn_fcinfo->args[i + 1].value;
5772 pertrans->sortslot->tts_isnull[i] = pertrans->transfn_fcinfo->args[i + 1].isnull;
5773 }
5774
5775 ExecClearTuple(pertrans->sortslot);
5776 pertrans->sortslot->tts_nvalid = pertrans->numInputs;
5778
5779 /* save the previous slots before we overwrite them */
5780 save_outer = tmpcontext->ecxt_outertuple;
5781 save_inner = tmpcontext->ecxt_innertuple;
5782
5783 tmpcontext->ecxt_outertuple = pertrans->sortslot;
5784 tmpcontext->ecxt_innertuple = pertrans->uniqslot;
5785
5786 if (!pertrans->haslast ||
5787 !ExecQual(pertrans->equalfnMulti, tmpcontext))
5788 {
5789 if (pertrans->haslast)
5790 ExecClearTuple(pertrans->uniqslot);
5791
5792 pertrans->haslast = true;
5793 ExecCopySlot(pertrans->uniqslot, pertrans->sortslot);
5794
5795 isdistinct = true;
5796 }
5797
5798 /* restore the original slots */
5799 tmpcontext->ecxt_outertuple = save_outer;
5800 tmpcontext->ecxt_innertuple = save_inner;
5801
5802 return isdistinct;
5803}
static bool ExecQual(ExprState *state, ExprContext *econtext)
Definition: executor.h:541
ExprState * equalfnMulti
Definition: nodeAgg.h:116
TupleTableSlot * uniqslot
Definition: nodeAgg.h:142
ExprContext * tmpcontext
Definition: execnodes.h:2540
bool * tts_isnull
Definition: tuptable.h:127
Datum * tts_values
Definition: tuptable.h:125
static TupleTableSlot * ExecCopySlot(TupleTableSlot *dstslot, TupleTableSlot *srcslot)
Definition: tuptable.h:525

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

5720{
5721 Datum value = pertrans->transfn_fcinfo->args[1].value;
5722 bool isnull = pertrans->transfn_fcinfo->args[1].isnull;
5723
5724 if (!pertrans->haslast ||
5725 pertrans->lastisnull != isnull ||
5726 (!isnull && !DatumGetBool(FunctionCall2Coll(&pertrans->equalfnOne,
5727 pertrans->aggCollation,
5728 pertrans->lastdatum, value))))
5729 {
5730 if (pertrans->haslast && !pertrans->inputtypeByVal &&
5731 !pertrans->lastisnull)
5732 pfree(DatumGetPointer(pertrans->lastdatum));
5733
5734 pertrans->haslast = true;
5735 if (!isnull)
5736 {
5737 MemoryContext oldContext;
5738
5740
5741 pertrans->lastdatum = datumCopy(value, pertrans->inputtypeByVal,
5742 pertrans->inputtypeLen);
5743
5744 MemoryContextSwitchTo(oldContext);
5745 }
5746 else
5747 pertrans->lastdatum = (Datum) 0;
5748 pertrans->lastisnull = isnull;
5749 return true;
5750 }
5751
5752 return false;
5753}
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 3656 of file execExprInterp.c.

3657{
3658 HeapTuple tuple;
3659
3660 /* build tuple from evaluated field values */
3661 tuple = heap_form_tuple(op->d.row.tupdesc,
3662 op->d.row.elemvalues,
3663 op->d.row.elemnulls);
3664
3665 *op->resvalue = HeapTupleGetDatum(tuple);
3666 *op->resnull = false;
3667}
TupleDesc tupdesc
Definition: execExpr.h:350
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 3308 of file execExprInterp.c.

3309{
3310 ExecEvalRowNullInt(state, op, econtext, false);
3311}
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 3299 of file execExprInterp.c.

3300{
3301 ExecEvalRowNullInt(state, op, econtext, true);
3302}

References ExecEvalRowNullInt(), and ExprEvalStep::op.

Referenced by ExecInterpExpr().

◆ ExecEvalScalarArrayOp()

void ExecEvalScalarArrayOp ( ExprState state,
ExprEvalStep op 
)

Definition at line 4023 of file execExprInterp.c.

4024{
4026 bool useOr = op->d.scalararrayop.useOr;
4027 bool strictfunc = op->d.scalararrayop.finfo->fn_strict;
4028 ArrayType *arr;
4029 int nitems;
4030 Datum result;
4031 bool resultnull;
4032 int16 typlen;
4033 bool typbyval;
4034 char typalign;
4035 char *s;
4036 bits8 *bitmap;
4037 int bitmask;
4038
4039 /*
4040 * If the array is NULL then we return NULL --- it's not very meaningful
4041 * to do anything else, even if the operator isn't strict.
4042 */
4043 if (*op->resnull)
4044 return;
4045
4046 /* Else okay to fetch and detoast the array */
4047 arr = DatumGetArrayTypeP(*op->resvalue);
4048
4049 /*
4050 * If the array is empty, we return either FALSE or TRUE per the useOr
4051 * flag. This is correct even if the scalar is NULL; since we would
4052 * evaluate the operator zero times, it matters not whether it would want
4053 * to return NULL.
4054 */
4055 nitems = ArrayGetNItems(ARR_NDIM(arr), ARR_DIMS(arr));
4056 if (nitems <= 0)
4057 {
4058 *op->resvalue = BoolGetDatum(!useOr);
4059 *op->resnull = false;
4060 return;
4061 }
4062
4063 /*
4064 * If the scalar is NULL, and the function is strict, return NULL; no
4065 * point in iterating the loop.
4066 */
4067 if (fcinfo->args[0].isnull && strictfunc)
4068 {
4069 *op->resnull = true;
4070 return;
4071 }
4072
4073 /*
4074 * We arrange to look up info about the element type only once per series
4075 * of calls, assuming the element type doesn't change underneath us.
4076 */
4077 if (op->d.scalararrayop.element_type != ARR_ELEMTYPE(arr))
4078 {
4080 &op->d.scalararrayop.typlen,
4082 &op->d.scalararrayop.typalign);
4084 }
4085
4086 typlen = op->d.scalararrayop.typlen;
4087 typbyval = op->d.scalararrayop.typbyval;
4089
4090 /* Initialize result appropriately depending on useOr */
4091 result = BoolGetDatum(!useOr);
4092 resultnull = false;
4093
4094 /* Loop over the array elements */
4095 s = (char *) ARR_DATA_PTR(arr);
4096 bitmap = ARR_NULLBITMAP(arr);
4097 bitmask = 1;
4098
4099 for (int i = 0; i < nitems; i++)
4100 {
4101 Datum elt;
4102 Datum thisresult;
4103
4104 /* Get array element, checking for NULL */
4105 if (bitmap && (*bitmap & bitmask) == 0)
4106 {
4107 fcinfo->args[1].value = (Datum) 0;
4108 fcinfo->args[1].isnull = true;
4109 }
4110 else
4111 {
4112 elt = fetch_att(s, typbyval, typlen);
4113 s = att_addlength_pointer(s, typlen, s);
4114 s = (char *) att_align_nominal(s, typalign);
4115 fcinfo->args[1].value = elt;
4116 fcinfo->args[1].isnull = false;
4117 }
4118
4119 /* Call comparison function */
4120 if (fcinfo->args[1].isnull && strictfunc)
4121 {
4122 fcinfo->isnull = true;
4123 thisresult = (Datum) 0;
4124 }
4125 else
4126 {
4127 fcinfo->isnull = false;
4128 thisresult = op->d.scalararrayop.fn_addr(fcinfo);
4129 }
4130
4131 /* Combine results per OR or AND semantics */
4132 if (fcinfo->isnull)
4133 resultnull = true;
4134 else if (useOr)
4135 {
4136 if (DatumGetBool(thisresult))
4137 {
4138 result = BoolGetDatum(true);
4139 resultnull = false;
4140 break; /* needn't look at any more elements */
4141 }
4142 }
4143 else
4144 {
4145 if (!DatumGetBool(thisresult))
4146 {
4147 result = BoolGetDatum(false);
4148 resultnull = false;
4149 break; /* needn't look at any more elements */
4150 }
4151 }
4152
4153 /* advance bitmap pointer if any */
4154 if (bitmap)
4155 {
4156 bitmask <<= 1;
4157 if (bitmask == 0x100)
4158 {
4159 bitmap++;
4160 bitmask = 1;
4161 }
4162 }
4163 }
4164
4165 *op->resvalue = result;
4166 *op->resnull = resultnull;
4167}
bool typbyval
Definition: execExpr.h:631
char typalign
Definition: execExpr.h:632
bool useOr
Definition: execExpr.h:629
struct ExprEvalStep::@55::@89 scalararrayop
int16 typlen
Definition: execExpr.h:630
Oid element_type
Definition: execExpr.h:628

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

3196{
3197 LOCAL_FCINFO(fcinfo, 0);
3199
3200 *op->resnull = false;
3201
3202 /*
3203 * Note: current_schema() can return NULL. current_user() etc currently
3204 * cannot, but might as well code those cases the same way for safety.
3205 */
3206 switch (svf->op)
3207 {
3208 case SVFOP_CURRENT_DATE:
3210 break;
3211 case SVFOP_CURRENT_TIME:
3214 break;
3218 break;
3219 case SVFOP_LOCALTIME:
3220 case SVFOP_LOCALTIME_N:
3222 break;
3226 break;
3227 case SVFOP_CURRENT_ROLE:
3228 case SVFOP_CURRENT_USER:
3229 case SVFOP_USER:
3230 InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
3231 *op->resvalue = current_user(fcinfo);
3232 *op->resnull = fcinfo->isnull;
3233 break;
3234 case SVFOP_SESSION_USER:
3235 InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
3236 *op->resvalue = session_user(fcinfo);
3237 *op->resnull = fcinfo->isnull;
3238 break;
3240 InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
3241 *op->resvalue = current_database(fcinfo);
3242 *op->resnull = fcinfo->isnull;
3243 break;
3245 InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
3246 *op->resvalue = current_schema(fcinfo);
3247 *op->resnull = fcinfo->isnull;
3248 break;
3249 }
3250}
Datum current_database(PG_FUNCTION_ARGS)
Definition: misc.c:195
Timestamp GetSQLLocalTimestamp(int32 typmod)
Definition: timestamp.c:1677
TimestampTz GetSQLCurrentTimestamp(int32 typmod)
Definition: timestamp.c:1663
TimeADT GetSQLLocalTime(int32 typmod)
Definition: date.c:370
DateADT GetSQLCurrentDate(void)
Definition: date.c:317
TimeTzADT * GetSQLCurrentTime(int32 typmod)
Definition: date.c:350
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:1554
@ SVFOP_LOCALTIME_N
Definition: primnodes.h:1547
@ SVFOP_CURRENT_TIMESTAMP
Definition: primnodes.h:1544
@ SVFOP_LOCALTIME
Definition: primnodes.h:1546
@ SVFOP_CURRENT_TIMESTAMP_N
Definition: primnodes.h:1545
@ SVFOP_CURRENT_ROLE
Definition: primnodes.h:1550
@ SVFOP_USER
Definition: primnodes.h:1552
@ SVFOP_CURRENT_SCHEMA
Definition: primnodes.h:1555
@ SVFOP_LOCALTIMESTAMP_N
Definition: primnodes.h:1549
@ SVFOP_CURRENT_DATE
Definition: primnodes.h:1541
@ SVFOP_CURRENT_TIME_N
Definition: primnodes.h:1543
@ SVFOP_CURRENT_TIME
Definition: primnodes.h:1542
@ SVFOP_LOCALTIMESTAMP
Definition: primnodes.h:1548
@ SVFOP_CURRENT_USER
Definition: primnodes.h:1551
@ SVFOP_SESSION_USER
Definition: primnodes.h:1553
struct ExprEvalStep::@55::@73 sqlvaluefunction
SQLValueFunction * svf
Definition: execExpr.h:467
SQLValueFunctionOp op
Definition: primnodes.h:1561
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 2960 of file execExprInterp.c.

2961{
2962#if defined(EEO_USE_COMPUTED_GOTO)
2963 if (state->flags & EEO_FLAG_DIRECT_THREADED)
2964 {
2965 ExprEvalOpLookup key;
2966 ExprEvalOpLookup *res;
2967
2968 key.opcode = (void *) op->opcode;
2969 res = bsearch(&key,
2970 reverse_dispatch_table,
2971 EEOP_LAST /* nmembers */ ,
2972 sizeof(ExprEvalOpLookup),
2973 dispatch_compare_ptr);
2974 Assert(res); /* unknown ops shouldn't get looked up */
2975 return res->op;
2976 }
2977#endif
2978 return (ExprEvalOp) op->opcode;
2979}
#define EEO_FLAG_DIRECT_THREADED
Definition: execExpr.h:31
intptr_t opcode
Definition: execExpr.h:307

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

Referenced by CheckExprStillValid().

◆ ExecEvalSubPlan()

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

Definition at line 5310 of file execExprInterp.c.

5311{
5312 SubPlanState *sstate = op->d.subplan.sstate;
5313
5314 /* could potentially be nested, so make sure there's enough stack */
5316
5317 *op->resvalue = ExecSubPlan(sstate, econtext, op->resnull);
5318}
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:691
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 5586 of file execExprInterp.c.

5588{
5589 Datum d;
5590
5591 /* OLD/NEW system attribute is NULL if OLD/NEW row is NULL */
5593 state->flags & EEO_FLAG_OLD_IS_NULL) ||
5595 state->flags & EEO_FLAG_NEW_IS_NULL))
5596 {
5597 *op->resvalue = (Datum) 0;
5598 *op->resnull = true;
5599 return;
5600 }
5601
5602 /* slot_getsysattr has sufficient defenses against bad attnums */
5603 d = slot_getsysattr(slot,
5604 op->d.var.attnum,
5605 op->resnull);
5606 *op->resvalue = d;
5607 /* this ought to be unreachable, but it's cheap enough to check */
5608 if (unlikely(*op->resnull))
5609 elog(ERROR, "failed to fetch attribute from slot");
5610}
#define EEO_FLAG_NEW_IS_NULL
Definition: execnodes.h:85
#define EEO_FLAG_OLD_IS_NULL
Definition: execnodes.h:83
@ VAR_RETURNING_OLD
Definition: primnodes.h:257
@ VAR_RETURNING_NEW
Definition: primnodes.h:258
VarReturningType varreturningtype
Definition: execExpr.h:341
static Datum slot_getsysattr(TupleTableSlot *slot, int attnum, bool *isnull)
Definition: tuptable.h:420

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

5328{
5329 Var *variable = op->d.wholerow.var;
5330 TupleTableSlot *slot = NULL;
5331 TupleDesc output_tupdesc;
5332 MemoryContext oldcontext;
5333 HeapTupleHeader dtuple;
5334 HeapTuple tuple;
5335
5336 /* This was checked by ExecInitExpr */
5337 Assert(variable->varattno == InvalidAttrNumber);
5338
5339 /* Get the input slot we want */
5340 switch (variable->varno)
5341 {
5342 case INNER_VAR:
5343 /* get the tuple from the inner node */
5344 slot = econtext->ecxt_innertuple;
5345 break;
5346
5347 case OUTER_VAR:
5348 /* get the tuple from the outer node */
5349 slot = econtext->ecxt_outertuple;
5350 break;
5351
5352 /* INDEX_VAR is handled by default case */
5353
5354 default:
5355
5356 /*
5357 * Get the tuple from the relation being scanned.
5358 *
5359 * By default, this uses the "scan" tuple slot, but a wholerow Var
5360 * in the RETURNING list may explicitly refer to OLD/NEW. If the
5361 * OLD/NEW row doesn't exist, we just return NULL.
5362 */
5363 switch (variable->varreturningtype)
5364 {
5366 slot = econtext->ecxt_scantuple;
5367 break;
5368
5369 case VAR_RETURNING_OLD:
5370 if (state->flags & EEO_FLAG_OLD_IS_NULL)
5371 {
5372 *op->resvalue = (Datum) 0;
5373 *op->resnull = true;
5374 return;
5375 }
5376 slot = econtext->ecxt_oldtuple;
5377 break;
5378
5379 case VAR_RETURNING_NEW:
5380 if (state->flags & EEO_FLAG_NEW_IS_NULL)
5381 {
5382 *op->resvalue = (Datum) 0;
5383 *op->resnull = true;
5384 return;
5385 }
5386 slot = econtext->ecxt_newtuple;
5387 break;
5388 }
5389 break;
5390 }
5391
5392 /* Apply the junkfilter if any */
5393 if (op->d.wholerow.junkFilter != NULL)
5394 slot = ExecFilterJunk(op->d.wholerow.junkFilter, slot);
5395
5396 /*
5397 * If first time through, obtain tuple descriptor and check compatibility.
5398 *
5399 * XXX: It'd be great if this could be moved to the expression
5400 * initialization phase, but due to using slots that's currently not
5401 * feasible.
5402 */
5403 if (op->d.wholerow.first)
5404 {
5405 /* optimistically assume we don't need slow path */
5406 op->d.wholerow.slow = false;
5407
5408 /*
5409 * If the Var identifies a named composite type, we must check that
5410 * the actual tuple type is compatible with it.
5411 */
5412 if (variable->vartype != RECORDOID)
5413 {
5414 TupleDesc var_tupdesc;
5415 TupleDesc slot_tupdesc;
5416
5417 /*
5418 * We really only care about numbers of attributes and data types.
5419 * Also, we can ignore type mismatch on columns that are dropped
5420 * in the destination type, so long as (1) the physical storage
5421 * matches or (2) the actual column value is NULL. Case (1) is
5422 * helpful in some cases involving out-of-date cached plans, while
5423 * case (2) is expected behavior in situations such as an INSERT
5424 * into a table with dropped columns (the planner typically
5425 * generates an INT4 NULL regardless of the dropped column type).
5426 * If we find a dropped column and cannot verify that case (1)
5427 * holds, we have to use the slow path to check (2) for each row.
5428 *
5429 * If vartype is a domain over composite, just look through that
5430 * to the base composite type.
5431 */
5432 var_tupdesc = lookup_rowtype_tupdesc_domain(variable->vartype,
5433 -1, false);
5434
5435 slot_tupdesc = slot->tts_tupleDescriptor;
5436
5437 if (var_tupdesc->natts != slot_tupdesc->natts)
5438 ereport(ERROR,
5439 (errcode(ERRCODE_DATATYPE_MISMATCH),
5440 errmsg("table row type and query-specified row type do not match"),
5441 errdetail_plural("Table row contains %d attribute, but query expects %d.",
5442 "Table row contains %d attributes, but query expects %d.",
5443 slot_tupdesc->natts,
5444 slot_tupdesc->natts,
5445 var_tupdesc->natts)));
5446
5447 for (int i = 0; i < var_tupdesc->natts; i++)
5448 {
5449 Form_pg_attribute vattr = TupleDescAttr(var_tupdesc, i);
5450 Form_pg_attribute sattr = TupleDescAttr(slot_tupdesc, i);
5451
5452 if (vattr->atttypid == sattr->atttypid)
5453 continue; /* no worries */
5454 if (!vattr->attisdropped)
5455 ereport(ERROR,
5456 (errcode(ERRCODE_DATATYPE_MISMATCH),
5457 errmsg("table row type and query-specified row type do not match"),
5458 errdetail("Table has type %s at ordinal position %d, but query expects %s.",
5459 format_type_be(sattr->atttypid),
5460 i + 1,
5461 format_type_be(vattr->atttypid))));
5462
5463 if (vattr->attlen != sattr->attlen ||
5464 vattr->attalign != sattr->attalign)
5465 op->d.wholerow.slow = true; /* need to check for nulls */
5466 }
5467
5468 /*
5469 * Use the variable's declared rowtype as the descriptor for the
5470 * output values. In particular, we *must* absorb any
5471 * attisdropped markings.
5472 */
5473 oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
5474 output_tupdesc = CreateTupleDescCopy(var_tupdesc);
5475 MemoryContextSwitchTo(oldcontext);
5476
5477 ReleaseTupleDesc(var_tupdesc);
5478 }
5479 else
5480 {
5481 /*
5482 * In the RECORD case, we use the input slot's rowtype as the
5483 * descriptor for the output values, modulo possibly assigning new
5484 * column names below.
5485 */
5486 oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
5487 output_tupdesc = CreateTupleDescCopy(slot->tts_tupleDescriptor);
5488 MemoryContextSwitchTo(oldcontext);
5489
5490 /*
5491 * It's possible that the input slot is a relation scan slot and
5492 * so is marked with that relation's rowtype. But we're supposed
5493 * to be returning RECORD, so reset to that.
5494 */
5495 output_tupdesc->tdtypeid = RECORDOID;
5496 output_tupdesc->tdtypmod = -1;
5497
5498 /*
5499 * We already got the correct physical datatype info above, but
5500 * now we should try to find the source RTE and adopt its column
5501 * aliases, since it's unlikely that the input slot has the
5502 * desired names.
5503 *
5504 * If we can't locate the RTE, assume the column names we've got
5505 * are OK. (As of this writing, the only cases where we can't
5506 * locate the RTE are in execution of trigger WHEN clauses, and
5507 * then the Var will have the trigger's relation's rowtype, so its
5508 * names are fine.) Also, if the creator of the RTE didn't bother
5509 * to fill in an eref field, assume our column names are OK. (This
5510 * happens in COPY, and perhaps other places.)
5511 */
5512 if (econtext->ecxt_estate &&
5513 variable->varno <= econtext->ecxt_estate->es_range_table_size)
5514 {
5515 RangeTblEntry *rte = exec_rt_fetch(variable->varno,
5516 econtext->ecxt_estate);
5517
5518 if (rte->eref)
5519 ExecTypeSetColNames(output_tupdesc, rte->eref->colnames);
5520 }
5521 }
5522
5523 /* Bless the tupdesc if needed, and save it in the execution state */
5524 op->d.wholerow.tupdesc = BlessTupleDesc(output_tupdesc);
5525
5526 op->d.wholerow.first = false;
5527 }
5528
5529 /*
5530 * Make sure all columns of the slot are accessible in the slot's
5531 * Datum/isnull arrays.
5532 */
5533 slot_getallattrs(slot);
5534
5535 if (op->d.wholerow.slow)
5536 {
5537 /* Check to see if any dropped attributes are non-null */
5538 TupleDesc tupleDesc = slot->tts_tupleDescriptor;
5539 TupleDesc var_tupdesc = op->d.wholerow.tupdesc;
5540
5541 Assert(var_tupdesc->natts == tupleDesc->natts);
5542
5543 for (int i = 0; i < var_tupdesc->natts; i++)
5544 {
5545 CompactAttribute *vattr = TupleDescCompactAttr(var_tupdesc, i);
5546 CompactAttribute *sattr = TupleDescCompactAttr(tupleDesc, i);
5547
5548 if (!vattr->attisdropped)
5549 continue; /* already checked non-dropped cols */
5550 if (slot->tts_isnull[i])
5551 continue; /* null is always okay */
5552 if (vattr->attlen != sattr->attlen ||
5553 vattr->attalignby != sattr->attalignby)
5554 ereport(ERROR,
5555 (errcode(ERRCODE_DATATYPE_MISMATCH),
5556 errmsg("table row type and query-specified row type do not match"),
5557 errdetail("Physical storage mismatch on dropped attribute at ordinal position %d.",
5558 i + 1)));
5559 }
5560 }
5561
5562 /*
5563 * Build a composite datum, making sure any toasted fields get detoasted.
5564 *
5565 * (Note: it is critical that we not change the slot's state here.)
5566 */
5568 slot->tts_values,
5569 slot->tts_isnull);
5570 dtuple = tuple->t_data;
5571
5572 /*
5573 * Label the datum with the composite type info we identified before.
5574 *
5575 * (Note: we could skip doing this by passing op->d.wholerow.tupdesc to
5576 * the tuple build step; but that seems a tad risky so let's not.)
5577 */
5580
5581 *op->resvalue = PointerGetDatum(dtuple);
5582 *op->resnull = false;
5583}
#define InvalidAttrNumber
Definition: attnum.h:23
int errdetail_plural(const char *fmt_singular, const char *fmt_plural, unsigned long n,...)
Definition: elog.c:1296
TupleTableSlot * ExecFilterJunk(JunkFilter *junkfilter, TupleTableSlot *slot)
Definition: execJunk.c:247
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:2260
void ExecTypeSetColNames(TupleDesc typeInfo, List *namesList)
Definition: execTuples.c:2219
static RangeTblEntry * exec_rt_fetch(Index rti, EState *estate)
Definition: executor.h:719
HeapTuple toast_build_flattened_tuple(TupleDesc tupleDesc, Datum *values, bool *isnull)
Definition: heaptoast.c:563
static void HeapTupleHeaderSetTypMod(HeapTupleHeaderData *tup, int32 typmod)
Definition: htup_details.h:522
static void HeapTupleHeaderSetTypeId(HeapTupleHeaderData *tup, Oid datum_typeid)
Definition: htup_details.h:510
@ VAR_RETURNING_DEFAULT
Definition: primnodes.h:256
#define OUTER_VAR
Definition: primnodes.h:243
#define INNER_VAR
Definition: primnodes.h:242
uint8 attalignby
Definition: tupdesc.h:80
bool attisdropped
Definition: tupdesc.h:77
int16 attlen
Definition: tupdesc.h:71
Index es_range_table_size
Definition: execnodes.h:660
struct EState * ecxt_estate
Definition: execnodes.h:310
JunkFilter * junkFilter
Definition: execExpr.h:351
struct ExprEvalStep::@55::@58 wholerow
bool first
Definition: execExpr.h:348
int32 tdtypmod
Definition: tupdesc.h:139
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:123
Definition: primnodes.h:262
TupleDesc CreateTupleDescCopy(TupleDesc tupdesc)
Definition: tupdesc.c:245
#define ReleaseTupleDesc(tupdesc)
Definition: tupdesc.h:219
static CompactAttribute * TupleDescCompactAttr(TupleDesc tupdesc, int i)
Definition: tupdesc.h:175
static void slot_getallattrs(TupleTableSlot *slot)
Definition: tuptable.h:372
TupleDesc lookup_rowtype_tupdesc_domain(Oid type_id, int32 typmod, bool noError)
Definition: typcache.c:1978

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

4443{
4444 XmlExpr *xexpr = op->d.xmlexpr.xexpr;
4445 Datum value;
4446
4447 *op->resnull = true; /* until we get a result */
4448 *op->resvalue = (Datum) 0;
4449
4450 switch (xexpr->op)
4451 {
4452 case IS_XMLCONCAT:
4453 {
4454 Datum *argvalue = op->d.xmlexpr.argvalue;
4455 bool *argnull = op->d.xmlexpr.argnull;
4456 List *values = NIL;
4457
4458 for (int i = 0; i < list_length(xexpr->args); i++)
4459 {
4460 if (!argnull[i])
4461 values = lappend(values, DatumGetPointer(argvalue[i]));
4462 }
4463
4464 if (values != NIL)
4465 {
4467 *op->resnull = false;
4468 }
4469 }
4470 break;
4471
4472 case IS_XMLFOREST:
4473 {
4474 Datum *argvalue = op->d.xmlexpr.named_argvalue;
4475 bool *argnull = op->d.xmlexpr.named_argnull;
4477 ListCell *lc;
4478 ListCell *lc2;
4479 int i;
4480
4482
4483 i = 0;
4484 forboth(lc, xexpr->named_args, lc2, xexpr->arg_names)
4485 {
4486 Expr *e = (Expr *) lfirst(lc);
4487 char *argname = strVal(lfirst(lc2));
4488
4489 if (!argnull[i])
4490 {
4491 value = argvalue[i];
4492 appendStringInfo(&buf, "<%s>%s</%s>",
4493 argname,
4495 exprType((Node *) e), true),
4496 argname);
4497 *op->resnull = false;
4498 }
4499 i++;
4500 }
4501
4502 if (!*op->resnull)
4503 {
4504 text *result;
4505
4506 result = cstring_to_text_with_len(buf.data, buf.len);
4507 *op->resvalue = PointerGetDatum(result);
4508 }
4509
4510 pfree(buf.data);
4511 }
4512 break;
4513
4514 case IS_XMLELEMENT:
4515 *op->resvalue = PointerGetDatum(xmlelement(xexpr,
4518 op->d.xmlexpr.argvalue,
4519 op->d.xmlexpr.argnull));
4520 *op->resnull = false;
4521 break;
4522
4523 case IS_XMLPARSE:
4524 {
4525 Datum *argvalue = op->d.xmlexpr.argvalue;
4526 bool *argnull = op->d.xmlexpr.argnull;
4527 text *data;
4528 bool preserve_whitespace;
4529
4530 /* arguments are known to be text, bool */
4531 Assert(list_length(xexpr->args) == 2);
4532
4533 if (argnull[0])
4534 return;
4535 value = argvalue[0];
4537
4538 if (argnull[1]) /* probably can't happen */
4539 return;
4540 value = argvalue[1];
4541 preserve_whitespace = DatumGetBool(value);
4542
4544 xexpr->xmloption,
4545 preserve_whitespace));
4546 *op->resnull = false;
4547 }
4548 break;
4549
4550 case IS_XMLPI:
4551 {
4552 text *arg;
4553 bool isnull;
4554
4555 /* optional argument is known to be text */
4556 Assert(list_length(xexpr->args) <= 1);
4557
4558 if (xexpr->args)
4559 {
4560 isnull = op->d.xmlexpr.argnull[0];
4561 if (isnull)
4562 arg = NULL;
4563 else
4565 }
4566 else
4567 {
4568 arg = NULL;
4569 isnull = false;
4570 }
4571
4572 *op->resvalue = PointerGetDatum(xmlpi(xexpr->name,
4573 arg,
4574 isnull,
4575 op->resnull));
4576 }
4577 break;
4578
4579 case IS_XMLROOT:
4580 {
4581 Datum *argvalue = op->d.xmlexpr.argvalue;
4582 bool *argnull = op->d.xmlexpr.argnull;
4583 xmltype *data;
4584 text *version;
4585 int standalone;
4586
4587 /* arguments are known to be xml, text, int */
4588 Assert(list_length(xexpr->args) == 3);
4589
4590 if (argnull[0])
4591 return;
4592 data = DatumGetXmlP(argvalue[0]);
4593
4594 if (argnull[1])
4595 version = NULL;
4596 else
4597 version = DatumGetTextPP(argvalue[1]);
4598
4599 Assert(!argnull[2]); /* always present */
4600 standalone = DatumGetInt32(argvalue[2]);
4601
4603 version,
4604 standalone));
4605 *op->resnull = false;
4606 }
4607 break;
4608
4609 case IS_XMLSERIALIZE:
4610 {
4611 Datum *argvalue = op->d.xmlexpr.argvalue;
4612 bool *argnull = op->d.xmlexpr.argnull;
4613
4614 /* argument type is known to be xml */
4615 Assert(list_length(xexpr->args) == 1);
4616
4617 if (argnull[0])
4618 return;
4619 value = argvalue[0];
4620
4621 *op->resvalue =
4623 xexpr->xmloption,
4624 xexpr->indent));
4625 *op->resnull = false;
4626 }
4627 break;
4628
4629 case IS_DOCUMENT:
4630 {
4631 Datum *argvalue = op->d.xmlexpr.argvalue;
4632 bool *argnull = op->d.xmlexpr.argnull;
4633
4634 /* optional argument is known to be xml */
4635 Assert(list_length(xexpr->args) == 1);
4636
4637 if (argnull[0])
4638 return;
4639 value = argvalue[0];
4640
4641 *op->resvalue =
4643 *op->resnull = false;
4644 }
4645 break;
4646
4647 default:
4648 elog(ERROR, "unrecognized XML operation");
4649 break;
4650 }
4651}
#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:1592
@ IS_XMLFOREST
Definition: primnodes.h:1587
@ IS_XMLCONCAT
Definition: primnodes.h:1585
@ IS_XMLPI
Definition: primnodes.h:1589
@ IS_XMLPARSE
Definition: primnodes.h:1588
@ IS_XMLSERIALIZE
Definition: primnodes.h:1591
@ IS_XMLROOT
Definition: primnodes.h:1590
@ IS_XMLELEMENT
Definition: primnodes.h:1586
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:145
void initStringInfo(StringInfo str)
Definition: stringinfo.c:97
XmlExpr * xexpr
Definition: execExpr.h:653
bool * named_argnull
Definition: execExpr.h:656
bool * argnull
Definition: execExpr.h:659
struct ExprEvalStep::@55::@91 xmlexpr
Datum * named_argvalue
Definition: execExpr.h:655
Datum * argvalue
Definition: execExpr.h:658
Definition: pg_list.h:54
List * args
Definition: primnodes.h:1613
bool indent
Definition: primnodes.h:1617
List * named_args
Definition: primnodes.h:1609
XmlExprOp op
Definition: primnodes.h:1605
#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 2287 of file execExprInterp.c.

2288{
2289 /*
2290 * First time through, check whether attribute matches Var. Might not be
2291 * ok anymore, due to schema changes.
2292 */
2293 CheckExprStillValid(state, econtext);
2294
2295 /* skip the check during further executions */
2296 state->evalfunc = (ExprStateEvalFunc) state->evalfunc_private;
2297
2298 /* and actually execute */
2299 return state->evalfunc(state, econtext, isNull);
2300}
void CheckExprStillValid(ExprState *state, ExprContext *econtext)
Datum(* ExprStateEvalFunc)(struct ExprState *expression, struct ExprContext *econtext, bool *isNull)
Definition: execnodes.h:71

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