PostgreSQL Source Code  git master
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 << 1)
 
#define EEO_FLAG_DIRECT_THREADED   (1 << 2)
 

Typedefs

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

Enumerations

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

Functions

 StaticAssertDecl (sizeof(ExprEvalStep)<=64, "size of ExprEvalStep exceeds 64 bytes")
 
void ExprEvalPushStep (ExprState *es, const ExprEvalStep *s)
 
void ExecReadyInterpretedExpr (ExprState *state)
 
ExprEvalOp ExecEvalStepOp (ExprState *state, ExprEvalStep *op)
 
Datum ExecInterpExprStillValid (ExprState *state, ExprContext *econtext, bool *isNull)
 
void CheckExprStillValid (ExprState *state, ExprContext *econtext)
 
void ExecEvalFuncExprFusage (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalFuncExprStrictFusage (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalParamExec (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void 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)
 
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 << 2)

Definition at line 31 of file execExpr.h.

◆ EEO_FLAG_INTERPRETER_INITIALIZED

#define EEO_FLAG_INTERPRETER_INITIALIZED   (1 << 1)

Definition at line 29 of file execExpr.h.

Typedef Documentation

◆ ExecEvalBoolSubroutine

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

Definition at line 39 of file execExpr.h.

◆ ExecEvalSubroutine

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

Definition at line 34 of file execExpr.h.

◆ ExprEvalOp

typedef enum ExprEvalOp ExprEvalOp

◆ ExprEvalRowtypeCache

◆ ExprEvalStep

typedef struct ExprEvalStep ExprEvalStep

◆ JsonConstructorExprState

◆ SubscriptExecSteps

◆ SubscriptingRefState

Enumeration Type Documentation

◆ ExprEvalOp

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

Definition at line 66 of file execExpr.h.

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

Function Documentation

◆ CheckExprStillValid()

void CheckExprStillValid ( ExprState state,
ExprContext econtext 
)

Definition at line 1897 of file execExprInterp.c.

1898 {
1899  TupleTableSlot *innerslot;
1900  TupleTableSlot *outerslot;
1901  TupleTableSlot *scanslot;
1902 
1903  innerslot = econtext->ecxt_innertuple;
1904  outerslot = econtext->ecxt_outertuple;
1905  scanslot = econtext->ecxt_scantuple;
1906 
1907  for (int i = 0; i < state->steps_len; i++)
1908  {
1909  ExprEvalStep *op = &state->steps[i];
1910 
1911  switch (ExecEvalStepOp(state, op))
1912  {
1913  case EEOP_INNER_VAR:
1914  {
1915  int attnum = op->d.var.attnum;
1916 
1917  CheckVarSlotCompatibility(innerslot, attnum + 1, op->d.var.vartype);
1918  break;
1919  }
1920 
1921  case EEOP_OUTER_VAR:
1922  {
1923  int attnum = op->d.var.attnum;
1924 
1925  CheckVarSlotCompatibility(outerslot, attnum + 1, op->d.var.vartype);
1926  break;
1927  }
1928 
1929  case EEOP_SCAN_VAR:
1930  {
1931  int attnum = op->d.var.attnum;
1932 
1933  CheckVarSlotCompatibility(scanslot, attnum + 1, op->d.var.vartype);
1934  break;
1935  }
1936  default:
1937  break;
1938  }
1939  }
1940 }
static void CheckVarSlotCompatibility(TupleTableSlot *slot, int attnum, Oid vartype)
ExprEvalOp ExecEvalStepOp(ExprState *state, ExprEvalStep *op)
int i
Definition: isn.c:73
int16 attnum
Definition: pg_attribute.h:74
TupleTableSlot * ecxt_innertuple
Definition: execnodes.h:257
TupleTableSlot * ecxt_scantuple
Definition: execnodes.h:255
TupleTableSlot * ecxt_outertuple
Definition: execnodes.h:259
union ExprEvalStep::@51 d
struct ExprEvalStep::@51::@53 var
Definition: regguts.h:323

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

Referenced by ExecInterpExprStillValid(), and ExecRunCompiledExpr().

◆ ExecAggCopyTransValue()

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

Definition at line 4617 of file execExprInterp.c.

4620 {
4621  Assert(newValue != oldValue);
4622 
4623  if (!newValueIsNull)
4624  {
4626  if (DatumIsReadWriteExpandedObject(newValue,
4627  false,
4628  pertrans->transtypeLen) &&
4629  MemoryContextGetParent(DatumGetEOHP(newValue)->eoh_context) == CurrentMemoryContext)
4630  /* do nothing */ ;
4631  else
4632  newValue = datumCopy(newValue,
4633  pertrans->transtypeByVal,
4634  pertrans->transtypeLen);
4635  }
4636  else
4637  {
4638  /*
4639  * Ensure that AggStatePerGroup->transValue ends up being 0, so
4640  * callers can safely compare newValue/oldValue without having to
4641  * check their respective nullness.
4642  */
4643  newValue = (Datum) 0;
4644  }
4645 
4646  if (!oldValueIsNull)
4647  {
4648  if (DatumIsReadWriteExpandedObject(oldValue,
4649  false,
4650  pertrans->transtypeLen))
4651  DeleteExpandedObject(oldValue);
4652  else
4653  pfree(DatumGetPointer(oldValue));
4654  }
4655 
4656  return newValue;
4657 }
Datum datumCopy(Datum value, bool typByVal, int typLen)
Definition: datum.c:132
ExpandedObjectHeader * DatumGetEOHP(Datum d)
Definition: expandeddatum.c:29
void DeleteExpandedObject(Datum d)
#define DatumIsReadWriteExpandedObject(d, isnull, typlen)
Assert(fmt[strlen(fmt) - 1] !='\n')
void pfree(void *pointer)
Definition: mcxt.c:1508
MemoryContext CurrentMemoryContext
Definition: mcxt.c:131
MemoryContext MemoryContextGetParent(MemoryContext context)
Definition: mcxt.c:719
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:124
uintptr_t Datum
Definition: postgres.h:64
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:312
ExprContext * curaggcontext
Definition: execnodes.h:2399
MemoryContext ecxt_per_tuple_memory
Definition: execnodes.h:263

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

4566 {
4567  FunctionCallInfo fcinfo = pertrans->transfn_fcinfo;
4568  MemoryContext oldContext;
4569 
4570  /*
4571  * We must copy the datum into aggcontext if it is pass-by-ref. We do not
4572  * need to pfree the old transValue, since it's NULL. (We already checked
4573  * that the agg's input type is binary-compatible with its transtype, so
4574  * straight copy here is OK.)
4575  */
4576  oldContext = MemoryContextSwitchTo(aggcontext->ecxt_per_tuple_memory);
4577  pergroup->transValue = datumCopy(fcinfo->args[1].value,
4578  pertrans->transtypeByVal,
4579  pertrans->transtypeLen);
4580  pergroup->transValueIsNull = false;
4581  pergroup->noTransValue = false;
4582  MemoryContextSwitchTo(oldContext);
4583 }
FunctionCallInfo transfn_fcinfo
Definition: nodeAgg.h:170
NullableDatum args[FLEXIBLE_ARRAY_MEMBER]
Definition: fmgr.h:95
Datum value
Definition: postgres.h:75

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

Referenced by ExecInterpExpr().

◆ ExecEvalAggOrderedTransDatum()

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

Definition at line 4756 of file execExprInterp.c.

4758 {
4759  AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
4760  int setno = op->d.agg_trans.setno;
4761 
4762  tuplesort_putdatum(pertrans->sortstates[setno],
4763  *op->resvalue, *op->resnull);
4764 }
Tuplesortstate ** sortstates
Definition: nodeAgg.h:162
Datum * resvalue
Definition: execExpr.h:281
struct ExprEvalStep::@51::@94 agg_trans
bool * resnull
Definition: execExpr.h:282
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 4770 of file execExprInterp.c.

4772 {
4773  AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
4774  int setno = op->d.agg_trans.setno;
4775 
4776  ExecClearTuple(pertrans->sortslot);
4777  pertrans->sortslot->tts_nvalid = pertrans->numInputs;
4778  ExecStoreVirtualTuple(pertrans->sortslot);
4779  tuplesort_puttupleslot(pertrans->sortstates[setno], pertrans->sortslot);
4780 }
TupleTableSlot * ExecStoreVirtualTuple(TupleTableSlot *slot)
Definition: execTuples.c:1551
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:433

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

Referenced by ExecInterpExpr().

◆ ExecEvalArrayCoerce()

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

Definition at line 3021 of file execExprInterp.c.

3022 {
3023  Datum arraydatum;
3024 
3025  /* NULL array -> NULL result */
3026  if (*op->resnull)
3027  return;
3028 
3029  arraydatum = *op->resvalue;
3030 
3031  /*
3032  * If it's binary-compatible, modify the element type in the array header,
3033  * but otherwise leave the array as we received it.
3034  */
3035  if (op->d.arraycoerce.elemexprstate == NULL)
3036  {
3037  /* Detoast input array if necessary, and copy in any case */
3038  ArrayType *array = DatumGetArrayTypePCopy(arraydatum);
3039 
3040  ARR_ELEMTYPE(array) = op->d.arraycoerce.resultelemtype;
3041  *op->resvalue = PointerGetDatum(array);
3042  return;
3043  }
3044 
3045  /*
3046  * Use array_map to apply the sub-expression to each array element.
3047  */
3048  *op->resvalue = array_map(arraydatum,
3049  op->d.arraycoerce.elemexprstate,
3050  econtext,
3051  op->d.arraycoerce.resultelemtype,
3052  op->d.arraycoerce.amstate);
3053 }
#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:3194
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:322
struct ExprEvalStep::@51::@71 arraycoerce

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

Referenced by ExecInterpExpr().

◆ ExecEvalArrayExpr()

void ExecEvalArrayExpr ( ExprState state,
ExprEvalStep op 
)

Definition at line 2807 of file execExprInterp.c.

2808 {
2809  ArrayType *result;
2810  Oid element_type = op->d.arrayexpr.elemtype;
2811  int nelems = op->d.arrayexpr.nelems;
2812  int ndims = 0;
2813  int dims[MAXDIM];
2814  int lbs[MAXDIM];
2815 
2816  /* Set non-null as default */
2817  *op->resnull = false;
2818 
2819  if (!op->d.arrayexpr.multidims)
2820  {
2821  /* Elements are presumably of scalar type */
2822  Datum *dvalues = op->d.arrayexpr.elemvalues;
2823  bool *dnulls = op->d.arrayexpr.elemnulls;
2824 
2825  /* setup for 1-D array of the given length */
2826  ndims = 1;
2827  dims[0] = nelems;
2828  lbs[0] = 1;
2829 
2830  result = construct_md_array(dvalues, dnulls, ndims, dims, lbs,
2831  element_type,
2832  op->d.arrayexpr.elemlength,
2833  op->d.arrayexpr.elembyval,
2834  op->d.arrayexpr.elemalign);
2835  }
2836  else
2837  {
2838  /* Must be nested array expressions */
2839  int nbytes = 0;
2840  int nitems;
2841  int outer_nelems = 0;
2842  int elem_ndims = 0;
2843  int *elem_dims = NULL;
2844  int *elem_lbs = NULL;
2845  bool firstone = true;
2846  bool havenulls = false;
2847  bool haveempty = false;
2848  char **subdata;
2849  bits8 **subbitmaps;
2850  int *subbytes;
2851  int *subnitems;
2852  int32 dataoffset;
2853  char *dat;
2854  int iitem;
2855 
2856  subdata = (char **) palloc(nelems * sizeof(char *));
2857  subbitmaps = (bits8 **) palloc(nelems * sizeof(bits8 *));
2858  subbytes = (int *) palloc(nelems * sizeof(int));
2859  subnitems = (int *) palloc(nelems * sizeof(int));
2860 
2861  /* loop through and get data area from each element */
2862  for (int elemoff = 0; elemoff < nelems; elemoff++)
2863  {
2864  Datum arraydatum;
2865  bool eisnull;
2866  ArrayType *array;
2867  int this_ndims;
2868 
2869  arraydatum = op->d.arrayexpr.elemvalues[elemoff];
2870  eisnull = op->d.arrayexpr.elemnulls[elemoff];
2871 
2872  /* temporarily ignore null subarrays */
2873  if (eisnull)
2874  {
2875  haveempty = true;
2876  continue;
2877  }
2878 
2879  array = DatumGetArrayTypeP(arraydatum);
2880 
2881  /* run-time double-check on element type */
2882  if (element_type != ARR_ELEMTYPE(array))
2883  ereport(ERROR,
2884  (errcode(ERRCODE_DATATYPE_MISMATCH),
2885  errmsg("cannot merge incompatible arrays"),
2886  errdetail("Array with element type %s cannot be "
2887  "included in ARRAY construct with element type %s.",
2888  format_type_be(ARR_ELEMTYPE(array)),
2889  format_type_be(element_type))));
2890 
2891  this_ndims = ARR_NDIM(array);
2892  /* temporarily ignore zero-dimensional subarrays */
2893  if (this_ndims <= 0)
2894  {
2895  haveempty = true;
2896  continue;
2897  }
2898 
2899  if (firstone)
2900  {
2901  /* Get sub-array details from first member */
2902  elem_ndims = this_ndims;
2903  ndims = elem_ndims + 1;
2904  if (ndims <= 0 || ndims > MAXDIM)
2905  ereport(ERROR,
2906  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
2907  errmsg("number of array dimensions (%d) exceeds the maximum allowed (%d)",
2908  ndims, MAXDIM)));
2909 
2910  elem_dims = (int *) palloc(elem_ndims * sizeof(int));
2911  memcpy(elem_dims, ARR_DIMS(array), elem_ndims * sizeof(int));
2912  elem_lbs = (int *) palloc(elem_ndims * sizeof(int));
2913  memcpy(elem_lbs, ARR_LBOUND(array), elem_ndims * sizeof(int));
2914 
2915  firstone = false;
2916  }
2917  else
2918  {
2919  /* Check other sub-arrays are compatible */
2920  if (elem_ndims != this_ndims ||
2921  memcmp(elem_dims, ARR_DIMS(array),
2922  elem_ndims * sizeof(int)) != 0 ||
2923  memcmp(elem_lbs, ARR_LBOUND(array),
2924  elem_ndims * sizeof(int)) != 0)
2925  ereport(ERROR,
2926  (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
2927  errmsg("multidimensional arrays must have array "
2928  "expressions with matching dimensions")));
2929  }
2930 
2931  subdata[outer_nelems] = ARR_DATA_PTR(array);
2932  subbitmaps[outer_nelems] = ARR_NULLBITMAP(array);
2933  subbytes[outer_nelems] = ARR_SIZE(array) - ARR_DATA_OFFSET(array);
2934  nbytes += subbytes[outer_nelems];
2935  /* check for overflow of total request */
2936  if (!AllocSizeIsValid(nbytes))
2937  ereport(ERROR,
2938  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
2939  errmsg("array size exceeds the maximum allowed (%d)",
2940  (int) MaxAllocSize)));
2941  subnitems[outer_nelems] = ArrayGetNItems(this_ndims,
2942  ARR_DIMS(array));
2943  havenulls |= ARR_HASNULL(array);
2944  outer_nelems++;
2945  }
2946 
2947  /*
2948  * If all items were null or empty arrays, return an empty array;
2949  * otherwise, if some were and some weren't, raise error. (Note: we
2950  * must special-case this somehow to avoid trying to generate a 1-D
2951  * array formed from empty arrays. It's not ideal...)
2952  */
2953  if (haveempty)
2954  {
2955  if (ndims == 0) /* didn't find any nonempty array */
2956  {
2957  *op->resvalue = PointerGetDatum(construct_empty_array(element_type));
2958  return;
2959  }
2960  ereport(ERROR,
2961  (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
2962  errmsg("multidimensional arrays must have array "
2963  "expressions with matching dimensions")));
2964  }
2965 
2966  /* setup for multi-D array */
2967  dims[0] = outer_nelems;
2968  lbs[0] = 1;
2969  for (int i = 1; i < ndims; i++)
2970  {
2971  dims[i] = elem_dims[i - 1];
2972  lbs[i] = elem_lbs[i - 1];
2973  }
2974 
2975  /* check for subscript overflow */
2976  nitems = ArrayGetNItems(ndims, dims);
2977  ArrayCheckBounds(ndims, dims, lbs);
2978 
2979  if (havenulls)
2980  {
2981  dataoffset = ARR_OVERHEAD_WITHNULLS(ndims, nitems);
2982  nbytes += dataoffset;
2983  }
2984  else
2985  {
2986  dataoffset = 0; /* marker for no null bitmap */
2987  nbytes += ARR_OVERHEAD_NONULLS(ndims);
2988  }
2989 
2990  result = (ArrayType *) palloc0(nbytes);
2991  SET_VARSIZE(result, nbytes);
2992  result->ndim = ndims;
2993  result->dataoffset = dataoffset;
2994  result->elemtype = element_type;
2995  memcpy(ARR_DIMS(result), dims, ndims * sizeof(int));
2996  memcpy(ARR_LBOUND(result), lbs, ndims * sizeof(int));
2997 
2998  dat = ARR_DATA_PTR(result);
2999  iitem = 0;
3000  for (int i = 0; i < outer_nelems; i++)
3001  {
3002  memcpy(dat, subdata[i], subbytes[i]);
3003  dat += subbytes[i];
3004  if (havenulls)
3005  array_bitmap_copy(ARR_NULLBITMAP(result), iitem,
3006  subbitmaps[i], 0,
3007  subnitems[i]);
3008  iitem += subnitems[i];
3009  }
3010  }
3011 
3012  *op->resvalue = PointerGetDatum(result);
3013 }
#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:3561
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:3475
void array_bitmap_copy(bits8 *destbitmap, int destoffset, const bits8 *srcbitmap, int srcoffset, int nitems)
Definition: arrayfuncs.c:4947
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
signed int int32
Definition: c.h:481
uint8 bits8
Definition: c.h:500
int errdetail(const char *fmt,...)
Definition: elog.c:1205
int errcode(int sqlerrcode)
Definition: elog.c:859
int errmsg(const char *fmt,...)
Definition: elog.c:1072
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
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:1334
void * palloc(Size size)
Definition: mcxt.c:1304
#define AllocSizeIsValid(size)
Definition: memutils.h:42
#define MaxAllocSize
Definition: memutils.h:40
unsigned int Oid
Definition: postgres_ext.h:31
Oid elemtype
Definition: array.h:97
int ndim
Definition: array.h:95
int32 dataoffset
Definition: array.h:96
struct ExprEvalStep::@51::@70 arrayexpr
#define SET_VARSIZE(PTR, len)
Definition: varatt.h:305

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

Referenced by ExecInterpExpr().

◆ ExecEvalCoerceViaIOSafe()

void ExecEvalCoerceViaIOSafe ( ExprState state,
ExprEvalStep op 
)

Definition at line 2541 of file execExprInterp.c.

2542 {
2543  char *str;
2544 
2545  /* call output function (similar to OutputFunctionCall) */
2546  if (*op->resnull)
2547  {
2548  /* output functions are not called on nulls */
2549  str = NULL;
2550  }
2551  else
2552  {
2553  FunctionCallInfo fcinfo_out;
2554 
2555  fcinfo_out = op->d.iocoerce.fcinfo_data_out;
2556  fcinfo_out->args[0].value = *op->resvalue;
2557  fcinfo_out->args[0].isnull = false;
2558 
2559  fcinfo_out->isnull = false;
2560  str = DatumGetCString(FunctionCallInvoke(fcinfo_out));
2561 
2562  /* OutputFunctionCall assumes result isn't null */
2563  Assert(!fcinfo_out->isnull);
2564  }
2565 
2566  /* call input function (similar to InputFunctionCallSafe) */
2567  if (!op->d.iocoerce.finfo_in->fn_strict || str != NULL)
2568  {
2569  FunctionCallInfo fcinfo_in;
2570 
2571  fcinfo_in = op->d.iocoerce.fcinfo_data_in;
2572  fcinfo_in->args[0].value = PointerGetDatum(str);
2573  fcinfo_in->args[0].isnull = *op->resnull;
2574  /* second and third arguments are already set up */
2575 
2576  /* ErrorSaveContext must be present. */
2577  Assert(IsA(fcinfo_in->context, ErrorSaveContext));
2578 
2579  fcinfo_in->isnull = false;
2580  *op->resvalue = FunctionCallInvoke(fcinfo_in);
2581 
2582  if (SOFT_ERROR_OCCURRED(fcinfo_in->context))
2583  {
2584  *op->resnull = true;
2585  *op->resvalue = (Datum) 0;
2586  return;
2587  }
2588 
2589  /* Should get null result if and only if str is NULL */
2590  if (str == NULL)
2591  Assert(*op->resnull);
2592  else
2593  Assert(!*op->resnull);
2594  }
2595 }
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:172
#define SOFT_ERROR_OCCURRED(escontext)
Definition: miscnodes.h:52
#define IsA(nodeptr, _type_)
Definition: nodes.h:158
static char * DatumGetCString(Datum X)
Definition: postgres.h:335
struct ExprEvalStep::@51::@67 iocoerce
fmNodePtr context
Definition: fmgr.h:88
bool isnull
Definition: postgres.h:77

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

Referenced by ExecInterpExpr().

◆ ExecEvalConstraintCheck()

void ExecEvalConstraintCheck ( ExprState state,
ExprEvalStep op 
)

Definition at line 3828 of file execExprInterp.c.

3829 {
3830  if (!*op->d.domaincheck.checknull &&
3831  !DatumGetBool(*op->d.domaincheck.checkvalue))
3832  errsave((Node *) op->d.domaincheck.escontext,
3833  (errcode(ERRCODE_CHECK_VIOLATION),
3834  errmsg("value for domain %s violates check constraint \"%s\"",
3835  format_type_be(op->d.domaincheck.resulttype),
3836  op->d.domaincheck.constraintname),
3837  errdomainconstraint(op->d.domaincheck.resulttype,
3838  op->d.domaincheck.constraintname)));
3839 }
int errdomainconstraint(Oid datatypeOid, const char *conname)
Definition: domains.c:431
#define errsave(context,...)
Definition: elog.h:260
static bool DatumGetBool(Datum X)
Definition: postgres.h:90
struct ExprEvalStep::@51::@80 domaincheck
Definition: nodes.h:129

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

Referenced by ExecInterpExpr().

◆ ExecEvalConstraintNotNull()

void ExecEvalConstraintNotNull ( ExprState state,
ExprEvalStep op 
)

Definition at line 3814 of file execExprInterp.c.

3815 {
3816  if (*op->resnull)
3817  errsave((Node *) op->d.domaincheck.escontext,
3818  (errcode(ERRCODE_NOT_NULL_VIOLATION),
3819  errmsg("domain %s does not allow null values",
3820  format_type_be(op->d.domaincheck.resulttype)),
3821  errdatatype(op->d.domaincheck.resulttype)));
3822 }
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 3334 of file execExprInterp.c.

3335 {
3336  HeapTuple result;
3337  Datum tupDatum;
3338  HeapTupleHeader tuple;
3339  HeapTupleData tmptup;
3340  TupleDesc indesc,
3341  outdesc;
3342  bool changed = false;
3343 
3344  /* NULL in -> NULL out */
3345  if (*op->resnull)
3346  return;
3347 
3348  tupDatum = *op->resvalue;
3349  tuple = DatumGetHeapTupleHeader(tupDatum);
3350 
3351  /*
3352  * Lookup tupdescs if first time through or if type changes. We'd better
3353  * pin them since type conversion functions could do catalog lookups and
3354  * hence cause cache invalidation.
3355  */
3356  indesc = get_cached_rowtype(op->d.convert_rowtype.inputtype, -1,
3357  op->d.convert_rowtype.incache,
3358  &changed);
3359  IncrTupleDescRefCount(indesc);
3360  outdesc = get_cached_rowtype(op->d.convert_rowtype.outputtype, -1,
3361  op->d.convert_rowtype.outcache,
3362  &changed);
3363  IncrTupleDescRefCount(outdesc);
3364 
3365  /*
3366  * We used to be able to assert that incoming tuples are marked with
3367  * exactly the rowtype of indesc. However, now that ExecEvalWholeRowVar
3368  * might change the tuples' marking to plain RECORD due to inserting
3369  * aliases, we can only make this weak test:
3370  */
3371  Assert(HeapTupleHeaderGetTypeId(tuple) == indesc->tdtypeid ||
3372  HeapTupleHeaderGetTypeId(tuple) == RECORDOID);
3373 
3374  /* if first time through, or after change, initialize conversion map */
3375  if (changed)
3376  {
3377  MemoryContext old_cxt;
3378 
3379  /* allocate map in long-lived memory context */
3380  old_cxt = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
3381 
3382  /* prepare map from old to new attribute numbers */
3383  op->d.convert_rowtype.map = convert_tuples_by_name(indesc, outdesc);
3384 
3385  MemoryContextSwitchTo(old_cxt);
3386  }
3387 
3388  /* Following steps need a HeapTuple not a bare HeapTupleHeader */
3389  tmptup.t_len = HeapTupleHeaderGetDatumLength(tuple);
3390  tmptup.t_data = tuple;
3391 
3392  if (op->d.convert_rowtype.map != NULL)
3393  {
3394  /* Full conversion with attribute rearrangement needed */
3395  result = execute_attr_map_tuple(&tmptup, op->d.convert_rowtype.map);
3396  /* Result already has appropriate composite-datum header fields */
3397  *op->resvalue = HeapTupleGetDatum(result);
3398  }
3399  else
3400  {
3401  /*
3402  * The tuple is physically compatible as-is, but we need to insert the
3403  * destination rowtype OID in its composite-datum header field, so we
3404  * have to copy it anyway. heap_copy_tuple_as_datum() is convenient
3405  * for this since it will both make the physical copy and insert the
3406  * correct composite header fields. Note that we aren't expecting to
3407  * have to flatten any toasted fields: the input was a composite
3408  * datum, so it shouldn't contain any. So heap_copy_tuple_as_datum()
3409  * is overkill here, but its check for external fields is cheap.
3410  */
3411  *op->resvalue = heap_copy_tuple_as_datum(&tmptup, outdesc);
3412  }
3413 
3414  DecrTupleDescRefCount(indesc);
3415  DecrTupleDescRefCount(outdesc);
3416 }
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:1080
#define HeapTupleHeaderGetTypeId(tup)
Definition: htup_details.h:456
#define HeapTupleHeaderGetDatumLength(tup)
Definition: htup_details.h:450
MemoryContext ecxt_per_query_memory
Definition: execnodes.h:262
struct ExprEvalStep::@51::@81 convert_rowtype
uint32 t_len
Definition: htup.h:64
HeapTupleHeader t_data
Definition: htup.h:68
Oid tdtypeid
Definition: tupdesc.h:82
TupleConversionMap * convert_tuples_by_name(TupleDesc indesc, TupleDesc outdesc)
Definition: tupconvert.c:102
HeapTuple execute_attr_map_tuple(HeapTuple tuple, TupleConversionMap *map)
Definition: tupconvert.c:154
void DecrTupleDescRefCount(TupleDesc tupdesc)
Definition: tupdesc.c:406
void IncrTupleDescRefCount(TupleDesc tupdesc)
Definition: tupdesc.c:388

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

2669 {
2670  ereport(ERROR,
2671  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2672  errmsg("WHERE CURRENT OF is not supported for this table type")));
2673 }

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

Referenced by ExecInterpExpr().

◆ ExecEvalFieldSelect()

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

Definition at line 3135 of file execExprInterp.c.

3136 {
3137  AttrNumber fieldnum = op->d.fieldselect.fieldnum;
3138  Datum tupDatum;
3139  HeapTupleHeader tuple;
3140  Oid tupType;
3141  int32 tupTypmod;
3142  TupleDesc tupDesc;
3143  Form_pg_attribute attr;
3144  HeapTupleData tmptup;
3145 
3146  /* NULL record -> NULL result */
3147  if (*op->resnull)
3148  return;
3149 
3150  tupDatum = *op->resvalue;
3151 
3152  /* We can special-case expanded records for speed */
3154  {
3156 
3157  Assert(erh->er_magic == ER_MAGIC);
3158 
3159  /* Extract record's TupleDesc */
3160  tupDesc = expanded_record_get_tupdesc(erh);
3161 
3162  /*
3163  * Find field's attr record. Note we don't support system columns
3164  * here: a datum tuple doesn't have valid values for most of the
3165  * interesting system columns anyway.
3166  */
3167  if (fieldnum <= 0) /* should never happen */
3168  elog(ERROR, "unsupported reference to system column %d in FieldSelect",
3169  fieldnum);
3170  if (fieldnum > tupDesc->natts) /* should never happen */
3171  elog(ERROR, "attribute number %d exceeds number of columns %d",
3172  fieldnum, tupDesc->natts);
3173  attr = TupleDescAttr(tupDesc, fieldnum - 1);
3174 
3175  /* Check for dropped column, and force a NULL result if so */
3176  if (attr->attisdropped)
3177  {
3178  *op->resnull = true;
3179  return;
3180  }
3181 
3182  /* Check for type mismatch --- possible after ALTER COLUMN TYPE? */
3183  /* As in CheckVarSlotCompatibility, we should but can't check typmod */
3184  if (op->d.fieldselect.resulttype != attr->atttypid)
3185  ereport(ERROR,
3186  (errcode(ERRCODE_DATATYPE_MISMATCH),
3187  errmsg("attribute %d has wrong type", fieldnum),
3188  errdetail("Table has type %s, but query expects %s.",
3189  format_type_be(attr->atttypid),
3190  format_type_be(op->d.fieldselect.resulttype))));
3191 
3192  /* extract the field */
3193  *op->resvalue = expanded_record_get_field(erh, fieldnum,
3194  op->resnull);
3195  }
3196  else
3197  {
3198  /* Get the composite datum and extract its type fields */
3199  tuple = DatumGetHeapTupleHeader(tupDatum);
3200 
3201  tupType = HeapTupleHeaderGetTypeId(tuple);
3202  tupTypmod = HeapTupleHeaderGetTypMod(tuple);
3203 
3204  /* Lookup tupdesc if first time through or if type changes */
3205  tupDesc = get_cached_rowtype(tupType, tupTypmod,
3206  &op->d.fieldselect.rowcache, NULL);
3207 
3208  /*
3209  * Find field's attr record. Note we don't support system columns
3210  * here: a datum tuple doesn't have valid values for most of the
3211  * interesting system columns anyway.
3212  */
3213  if (fieldnum <= 0) /* should never happen */
3214  elog(ERROR, "unsupported reference to system column %d in FieldSelect",
3215  fieldnum);
3216  if (fieldnum > tupDesc->natts) /* should never happen */
3217  elog(ERROR, "attribute number %d exceeds number of columns %d",
3218  fieldnum, tupDesc->natts);
3219  attr = TupleDescAttr(tupDesc, fieldnum - 1);
3220 
3221  /* Check for dropped column, and force a NULL result if so */
3222  if (attr->attisdropped)
3223  {
3224  *op->resnull = true;
3225  return;
3226  }
3227 
3228  /* Check for type mismatch --- possible after ALTER COLUMN TYPE? */
3229  /* As in CheckVarSlotCompatibility, we should but can't check typmod */
3230  if (op->d.fieldselect.resulttype != attr->atttypid)
3231  ereport(ERROR,
3232  (errcode(ERRCODE_DATATYPE_MISMATCH),
3233  errmsg("attribute %d has wrong type", fieldnum),
3234  errdetail("Table has type %s, but query expects %s.",
3235  format_type_be(attr->atttypid),
3236  format_type_be(op->d.fieldselect.resulttype))));
3237 
3238  /* heap_getattr needs a HeapTuple not a bare HeapTupleHeader */
3239  tmptup.t_len = HeapTupleHeaderGetDatumLength(tuple);
3240  tmptup.t_data = tuple;
3241 
3242  /* extract the field */
3243  *op->resvalue = heap_getattr(&tmptup,
3244  fieldnum,
3245  tupDesc,
3246  op->resnull);
3247  }
3248 }
int16 AttrNumber
Definition: attnum.h:21
#define elog(elevel,...)
Definition: elog.h:224
static Datum expanded_record_get_field(ExpandedRecordHeader *erh, int fnumber, bool *isnull)
#define ER_MAGIC
static TupleDesc expanded_record_get_tupdesc(ExpandedRecordHeader *erh)
static Datum heap_getattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
Definition: htup_details.h:792
#define HeapTupleHeaderGetTypMod(tup)
Definition: htup_details.h:466
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:209
struct ExprEvalStep::@51::@76 fieldselect
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
#define VARATT_IS_EXTERNAL_EXPANDED(PTR)
Definition: varatt.h:298

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

Referenced by ExecInterpExpr().

◆ ExecEvalFieldStoreDeForm()

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

Definition at line 3260 of file execExprInterp.c.

3261 {
3262  if (*op->resnull)
3263  {
3264  /* Convert null input tuple into an all-nulls row */
3265  memset(op->d.fieldstore.nulls, true,
3266  op->d.fieldstore.ncolumns * sizeof(bool));
3267  }
3268  else
3269  {
3270  /*
3271  * heap_deform_tuple needs a HeapTuple not a bare HeapTupleHeader. We
3272  * set all the fields in the struct just in case.
3273  */
3274  Datum tupDatum = *op->resvalue;
3275  HeapTupleHeader tuphdr;
3276  HeapTupleData tmptup;
3277  TupleDesc tupDesc;
3278 
3279  tuphdr = DatumGetHeapTupleHeader(tupDatum);
3280  tmptup.t_len = HeapTupleHeaderGetDatumLength(tuphdr);
3281  ItemPointerSetInvalid(&(tmptup.t_self));
3282  tmptup.t_tableOid = InvalidOid;
3283  tmptup.t_data = tuphdr;
3284 
3285  /*
3286  * Lookup tupdesc if first time through or if type changes. Because
3287  * we don't pin the tupdesc, we must not do this lookup until after
3288  * doing DatumGetHeapTupleHeader: that could do database access while
3289  * detoasting the datum.
3290  */
3291  tupDesc = get_cached_rowtype(op->d.fieldstore.fstore->resulttype, -1,
3292  op->d.fieldstore.rowcache, NULL);
3293 
3294  /* Check that current tupdesc doesn't have more fields than allocated */
3295  if (unlikely(tupDesc->natts > op->d.fieldstore.ncolumns))
3296  elog(ERROR, "too many columns in composite type %u",
3297  op->d.fieldstore.fstore->resulttype);
3298 
3299  heap_deform_tuple(&tmptup, tupDesc,
3300  op->d.fieldstore.values,
3301  op->d.fieldstore.nulls);
3302  }
3303 }
#define unlikely(x)
Definition: c.h:298
void heap_deform_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *values, bool *isnull)
Definition: heaptuple.c:1345
static void ItemPointerSetInvalid(ItemPointerData *pointer)
Definition: itemptr.h:184
#define InvalidOid
Definition: postgres_ext.h:36
struct ExprEvalStep::@51::@77 fieldstore
ItemPointerData t_self
Definition: htup.h:65
Oid t_tableOid
Definition: htup.h:66

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

Referenced by ExecInterpExpr().

◆ ExecEvalFieldStoreForm()

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

Definition at line 3310 of file execExprInterp.c.

3311 {
3312  TupleDesc tupDesc;
3313  HeapTuple tuple;
3314 
3315  /* Lookup tupdesc (should be valid already) */
3316  tupDesc = get_cached_rowtype(op->d.fieldstore.fstore->resulttype, -1,
3317  op->d.fieldstore.rowcache, NULL);
3318 
3319  tuple = heap_form_tuple(tupDesc,
3320  op->d.fieldstore.values,
3321  op->d.fieldstore.nulls);
3322 
3323  *op->resvalue = HeapTupleGetDatum(tuple);
3324  *op->resnull = false;
3325 }
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
Definition: heaptuple.c:1116

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

2416 {
2417  FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
2418  PgStat_FunctionCallUsage fcusage;
2419  Datum d;
2420 
2421  pgstat_init_function_usage(fcinfo, &fcusage);
2422 
2423  fcinfo->isnull = false;
2424  d = op->d.func.fn_addr(fcinfo);
2425  *op->resvalue = d;
2426  *op->resnull = fcinfo->isnull;
2427 
2428  pgstat_end_function_usage(&fcusage, true);
2429 }
void pgstat_init_function_usage(FunctionCallInfo fcinfo, PgStat_FunctionCallUsage *fcu)
void pgstat_end_function_usage(PgStat_FunctionCallUsage *fcu, bool finalize)
struct ExprEvalStep::@51::@58 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 2435 of file execExprInterp.c.

2437 {
2438 
2439  FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
2440  PgStat_FunctionCallUsage fcusage;
2441  NullableDatum *args = fcinfo->args;
2442  int nargs = op->d.func.nargs;
2443  Datum d;
2444 
2445  /* strict function, so check for NULL args */
2446  for (int argno = 0; argno < nargs; argno++)
2447  {
2448  if (args[argno].isnull)
2449  {
2450  *op->resnull = true;
2451  return;
2452  }
2453  }
2454 
2455  pgstat_init_function_usage(fcinfo, &fcusage);
2456 
2457  fcinfo->isnull = false;
2458  d = op->d.func.fn_addr(fcinfo);
2459  *op->resvalue = d;
2460  *op->resnull = fcinfo->isnull;
2461 
2462  pgstat_end_function_usage(&fcusage, true);
2463 }

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

4237 {
4238  AggState *aggstate = castNode(AggState, state->parent);
4239  int result = 0;
4240  Bitmapset *grouped_cols = aggstate->grouped_cols;
4241  ListCell *lc;
4242 
4243  foreach(lc, op->d.grouping_func.clauses)
4244  {
4245  int attnum = lfirst_int(lc);
4246 
4247  result <<= 1;
4248 
4249  if (!bms_is_member(attnum, grouped_cols))
4250  result |= 1;
4251  }
4252 
4253  *op->resvalue = Int32GetDatum(result);
4254  *op->resnull = false;
4255 }
bool bms_is_member(int x, const Bitmapset *a)
Definition: bitmapset.c:510
#define castNode(_type_, nodeptr)
Definition: nodes.h:176
#define lfirst_int(lc)
Definition: pg_list.h:173
static Datum Int32GetDatum(int32 X)
Definition: postgres.h:212
Bitmapset * grouped_cols
Definition: execnodes.h:2408
struct ExprEvalStep::@51::@87 grouping_func

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

Referenced by ExecInterpExpr().

◆ ExecEvalHashedScalarArrayOp()

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

Definition at line 3632 of file execExprInterp.c.

3633 {
3634  ScalarArrayOpExprHashTable *elements_tab = op->d.hashedscalararrayop.elements_tab;
3635  FunctionCallInfo fcinfo = op->d.hashedscalararrayop.fcinfo_data;
3636  bool inclause = op->d.hashedscalararrayop.inclause;
3637  bool strictfunc = op->d.hashedscalararrayop.finfo->fn_strict;
3638  Datum scalar = fcinfo->args[0].value;
3639  bool scalar_isnull = fcinfo->args[0].isnull;
3640  Datum result;
3641  bool resultnull;
3642  bool hashfound;
3643 
3644  /* We don't setup a hashed scalar array op if the array const is null. */
3645  Assert(!*op->resnull);
3646 
3647  /*
3648  * If the scalar is NULL, and the function is strict, return NULL; no
3649  * point in executing the search.
3650  */
3651  if (fcinfo->args[0].isnull && strictfunc)
3652  {
3653  *op->resnull = true;
3654  return;
3655  }
3656 
3657  /* Build the hash table on first evaluation */
3658  if (elements_tab == NULL)
3659  {
3660  ScalarArrayOpExpr *saop;
3661  int16 typlen;
3662  bool typbyval;
3663  char typalign;
3664  int nitems;
3665  bool has_nulls = false;
3666  char *s;
3667  bits8 *bitmap;
3668  int bitmask;
3669  MemoryContext oldcontext;
3670  ArrayType *arr;
3671 
3672  saop = op->d.hashedscalararrayop.saop;
3673 
3674  arr = DatumGetArrayTypeP(*op->resvalue);
3675  nitems = ArrayGetNItems(ARR_NDIM(arr), ARR_DIMS(arr));
3676 
3678  &typlen,
3679  &typbyval,
3680  &typalign);
3681 
3682  oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
3683 
3684  elements_tab = (ScalarArrayOpExprHashTable *)
3685  palloc0(offsetof(ScalarArrayOpExprHashTable, hash_fcinfo_data) +
3687  op->d.hashedscalararrayop.elements_tab = elements_tab;
3688  elements_tab->op = op;
3689 
3690  fmgr_info(saop->hashfuncid, &elements_tab->hash_finfo);
3691  fmgr_info_set_expr((Node *) saop, &elements_tab->hash_finfo);
3692 
3694  &elements_tab->hash_finfo,
3695  1,
3696  saop->inputcollid,
3697  NULL,
3698  NULL);
3699 
3700  /*
3701  * Create the hash table sizing it according to the number of elements
3702  * in the array. This does assume that the array has no duplicates.
3703  * If the array happens to contain many duplicate values then it'll
3704  * just mean that we sized the table a bit on the large side.
3705  */
3706  elements_tab->hashtab = saophash_create(CurrentMemoryContext, nitems,
3707  elements_tab);
3708 
3709  MemoryContextSwitchTo(oldcontext);
3710 
3711  s = (char *) ARR_DATA_PTR(arr);
3712  bitmap = ARR_NULLBITMAP(arr);
3713  bitmask = 1;
3714  for (int i = 0; i < nitems; i++)
3715  {
3716  /* Get array element, checking for NULL. */
3717  if (bitmap && (*bitmap & bitmask) == 0)
3718  {
3719  has_nulls = true;
3720  }
3721  else
3722  {
3723  Datum element;
3724 
3725  element = fetch_att(s, typbyval, typlen);
3726  s = att_addlength_pointer(s, typlen, s);
3727  s = (char *) att_align_nominal(s, typalign);
3728 
3729  saophash_insert(elements_tab->hashtab, element, &hashfound);
3730  }
3731 
3732  /* Advance bitmap pointer if any. */
3733  if (bitmap)
3734  {
3735  bitmask <<= 1;
3736  if (bitmask == 0x100)
3737  {
3738  bitmap++;
3739  bitmask = 1;
3740  }
3741  }
3742  }
3743 
3744  /*
3745  * Remember if we had any nulls so that we know if we need to execute
3746  * non-strict functions with a null lhs value if no match is found.
3747  */
3748  op->d.hashedscalararrayop.has_nulls = has_nulls;
3749  }
3750 
3751  /* Check the hash to see if we have a match. */
3752  hashfound = NULL != saophash_lookup(elements_tab->hashtab, scalar);
3753 
3754  /* the result depends on if the clause is an IN or NOT IN clause */
3755  if (inclause)
3756  result = BoolGetDatum(hashfound); /* IN */
3757  else
3758  result = BoolGetDatum(!hashfound); /* NOT IN */
3759 
3760  resultnull = false;
3761 
3762  /*
3763  * If we didn't find a match in the array, we still might need to handle
3764  * the possibility of null values. We didn't put any NULLs into the
3765  * hashtable, but instead marked if we found any when building the table
3766  * in has_nulls.
3767  */
3768  if (!hashfound && op->d.hashedscalararrayop.has_nulls)
3769  {
3770  if (strictfunc)
3771  {
3772 
3773  /*
3774  * We have nulls in the array so a non-null lhs and no match must
3775  * yield NULL.
3776  */
3777  result = (Datum) 0;
3778  resultnull = true;
3779  }
3780  else
3781  {
3782  /*
3783  * Execute function will null rhs just once.
3784  *
3785  * The hash lookup path will have scribbled on the lhs argument so
3786  * we need to set it up also (even though we entered this function
3787  * with it already set).
3788  */
3789  fcinfo->args[0].value = scalar;
3790  fcinfo->args[0].isnull = scalar_isnull;
3791  fcinfo->args[1].value = (Datum) 0;
3792  fcinfo->args[1].isnull = true;
3793 
3794  result = op->d.hashedscalararrayop.finfo->fn_addr(fcinfo);
3795  resultnull = fcinfo->isnull;
3796 
3797  /*
3798  * Reverse the result for NOT IN clauses since the above function
3799  * is the equality function and we need not-equals.
3800  */
3801  if (!inclause)
3802  result = !result;
3803  }
3804  }
3805 
3806  *op->resvalue = result;
3807  *op->resnull = resultnull;
3808 }
signed short int16
Definition: c.h:480
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:2227
char typalign
Definition: pg_type.h:176
static Datum BoolGetDatum(bool X)
Definition: postgres.h:102
static chr element(struct vars *v, const chr *startp, const chr *endp)
Definition: regc_locale.c:376
struct ExprEvalStep::@51::@83 hashedscalararrayop
FunctionCallInfoBaseData hash_fcinfo_data
struct ExprEvalStep * op
#define att_align_nominal(cur_offset, attalign)
Definition: tupmacs.h:129
#define att_addlength_pointer(cur_offset, attlen, attptr)
Definition: tupmacs.h:157
static Datum fetch_att(const void *T, bool attbyval, int attlen)
Definition: tupmacs.h:52

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

Referenced by ExecInterpExpr().

◆ ExecEvalJsonConstructor()

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

Definition at line 4063 of file execExprInterp.c.

4065 {
4066  Datum res;
4067  JsonConstructorExprState *jcstate = op->d.json_constructor.jcstate;
4068  JsonConstructorExpr *ctor = jcstate->constructor;
4069  bool is_jsonb = ctor->returning->format->format_type == JS_FORMAT_JSONB;
4070  bool isnull = false;
4071 
4072  if (ctor->type == JSCTOR_JSON_ARRAY)
4073  res = (is_jsonb ?
4075  json_build_array_worker) (jcstate->nargs,
4076  jcstate->arg_values,
4077  jcstate->arg_nulls,
4078  jcstate->arg_types,
4079  jcstate->constructor->absent_on_null);
4080  else if (ctor->type == JSCTOR_JSON_OBJECT)
4081  res = (is_jsonb ?
4083  json_build_object_worker) (jcstate->nargs,
4084  jcstate->arg_values,
4085  jcstate->arg_nulls,
4086  jcstate->arg_types,
4087  jcstate->constructor->absent_on_null,
4088  jcstate->constructor->unique);
4089  else if (ctor->type == JSCTOR_JSON_SCALAR)
4090  {
4091  if (jcstate->arg_nulls[0])
4092  {
4093  res = (Datum) 0;
4094  isnull = true;
4095  }
4096  else
4097  {
4098  Datum value = jcstate->arg_values[0];
4099  Oid outfuncid = jcstate->arg_type_cache[0].outfuncid;
4100  JsonTypeCategory category = (JsonTypeCategory)
4101  jcstate->arg_type_cache[0].category;
4102 
4103  if (is_jsonb)
4104  res = datum_to_jsonb(value, category, outfuncid);
4105  else
4106  res = datum_to_json(value, category, outfuncid);
4107  }
4108  }
4109  else if (ctor->type == JSCTOR_JSON_PARSE)
4110  {
4111  if (jcstate->arg_nulls[0])
4112  {
4113  res = (Datum) 0;
4114  isnull = true;
4115  }
4116  else
4117  {
4118  Datum value = jcstate->arg_values[0];
4119  text *js = DatumGetTextP(value);
4120 
4121  if (is_jsonb)
4122  res = jsonb_from_text(js, true);
4123  else
4124  {
4125  (void) json_validate(js, true, true);
4126  res = value;
4127  }
4128  }
4129  }
4130  else
4131  elog(ERROR, "invalid JsonConstructorExpr type %d", ctor->type);
4132 
4133  *op->resvalue = res;
4134  *op->resnull = isnull;
4135 }
#define DatumGetTextP(X)
Definition: fmgr.h:332
static struct @150 value
if(TABLE==NULL||TABLE_index==NULL)
Definition: isn.c:77
Datum json_build_array_worker(int nargs, const Datum *args, const bool *nulls, const Oid *types, bool absent_on_null)
Definition: json.c:1321
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:1208
Datum datum_to_json(Datum val, JsonTypeCategory tcategory, Oid outfuncoid)
Definition: json.c:754
bool json_validate(text *json, bool check_unique_keys, bool throw_error)
Definition: json.c:1650
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:68
@ JS_FORMAT_JSONB
Definition: primnodes.h:1596
@ JSCTOR_JSON_PARSE
Definition: primnodes.h:1646
@ JSCTOR_JSON_OBJECT
Definition: primnodes.h:1642
@ JSCTOR_JSON_SCALAR
Definition: primnodes.h:1647
@ JSCTOR_JSON_ARRAY
Definition: primnodes.h:1643
struct ExprEvalStep::@51::@85 json_constructor
JsonConstructorExpr * constructor
Definition: execExpr.h:747
struct JsonConstructorExprState::@96 * arg_type_cache
JsonReturning * returning
Definition: primnodes.h:1662
JsonConstructorType type
Definition: primnodes.h:1658
JsonFormatType format_type
Definition: primnodes.h:1607
JsonFormat * format
Definition: primnodes.h:1619
Definition: c.h:674

References JsonConstructorExpr::absent_on_null, JsonConstructorExprState::arg_nulls, JsonConstructorExprState::arg_type_cache, JsonConstructorExprState::arg_types, JsonConstructorExprState::arg_values, JsonConstructorExprState::category, JsonConstructorExprState::constructor, datum_to_json(), datum_to_jsonb(), DatumGetTextP, elog, ERROR, JsonReturning::format, JsonFormat::format_type, if(), ExprEvalStep::isnull, ExprEvalStep::jcstate, JS_FORMAT_JSONB, JSCTOR_JSON_ARRAY, JSCTOR_JSON_OBJECT, JSCTOR_JSON_PARSE, JSCTOR_JSON_SCALAR, json_build_array_worker(), json_build_object_worker(), json_validate(), jsonb_build_array_worker(), jsonb_build_object_worker(), jsonb_from_text(), JsonConstructorExprState::nargs, ExprEvalStep::op, JsonConstructorExprState::outfuncid, res, JsonConstructorExpr::returning, JsonConstructorExpr::type, JsonConstructorExpr::unique, and value.

Referenced by ExecInterpExpr().

◆ ExecEvalJsonIsPredicate()

void ExecEvalJsonIsPredicate ( ExprState state,
ExprEvalStep op 
)

Definition at line 4141 of file execExprInterp.c.

4142 {
4143  JsonIsPredicate *pred = op->d.is_json.pred;
4144  Datum js = *op->resvalue;
4145  Oid exprtype;
4146  bool res;
4147 
4148  if (*op->resnull)
4149  {
4150  *op->resvalue = BoolGetDatum(false);
4151  return;
4152  }
4153 
4154  exprtype = exprType(pred->expr);
4155 
4156  if (exprtype == TEXTOID || exprtype == JSONOID)
4157  {
4158  text *json = DatumGetTextP(js);
4159 
4160  if (pred->item_type == JS_TYPE_ANY)
4161  res = true;
4162  else
4163  {
4164  switch (json_get_first_token(json, false))
4165  {
4167  res = pred->item_type == JS_TYPE_OBJECT;
4168  break;
4170  res = pred->item_type == JS_TYPE_ARRAY;
4171  break;
4172  case JSON_TOKEN_STRING:
4173  case JSON_TOKEN_NUMBER:
4174  case JSON_TOKEN_TRUE:
4175  case JSON_TOKEN_FALSE:
4176  case JSON_TOKEN_NULL:
4177  res = pred->item_type == JS_TYPE_SCALAR;
4178  break;
4179  default:
4180  res = false;
4181  break;
4182  }
4183  }
4184 
4185  /*
4186  * Do full parsing pass only for uniqueness check or for JSON text
4187  * validation.
4188  */
4189  if (res && (pred->unique_keys || exprtype == TEXTOID))
4190  res = json_validate(json, pred->unique_keys, false);
4191  }
4192  else if (exprtype == JSONBOID)
4193  {
4194  if (pred->item_type == JS_TYPE_ANY)
4195  res = true;
4196  else
4197  {
4198  Jsonb *jb = DatumGetJsonbP(js);
4199 
4200  switch (pred->item_type)
4201  {
4202  case JS_TYPE_OBJECT:
4203  res = JB_ROOT_IS_OBJECT(jb);
4204  break;
4205  case JS_TYPE_ARRAY:
4206  res = JB_ROOT_IS_ARRAY(jb) && !JB_ROOT_IS_SCALAR(jb);
4207  break;
4208  case JS_TYPE_SCALAR:
4209  res = JB_ROOT_IS_ARRAY(jb) && JB_ROOT_IS_SCALAR(jb);
4210  break;
4211  default:
4212  res = false;
4213  break;
4214  }
4215  }
4216 
4217  /* Key uniqueness check is redundant for jsonb */
4218  }
4219  else
4220  res = false;
4221 
4222  *op->resvalue = BoolGetDatum(res);
4223 }
@ JSON_TOKEN_FALSE
Definition: jsonapi.h:31
@ JSON_TOKEN_TRUE
Definition: jsonapi.h:30
@ JSON_TOKEN_NULL
Definition: jsonapi.h:32
@ JSON_TOKEN_OBJECT_START
Definition: jsonapi.h:24
@ JSON_TOKEN_NUMBER
Definition: jsonapi.h:23
@ JSON_TOKEN_STRING
Definition: jsonapi.h:22
@ JSON_TOKEN_ARRAY_START
Definition: jsonapi.h:26
static Jsonb * DatumGetJsonbP(Datum d)
Definition: jsonb.h:374
#define JB_ROOT_IS_OBJECT(jbp_)
Definition: jsonb.h:221
#define JB_ROOT_IS_ARRAY(jbp_)
Definition: jsonb.h:222
#define JB_ROOT_IS_SCALAR(jbp_)
Definition: jsonb.h:220
JsonTokenType json_get_first_token(text *json, bool throw_error)
Definition: jsonfuncs.c:5870
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:42
@ JS_TYPE_ANY
Definition: primnodes.h:1674
@ JS_TYPE_ARRAY
Definition: primnodes.h:1676
@ JS_TYPE_OBJECT
Definition: primnodes.h:1675
@ JS_TYPE_SCALAR
Definition: primnodes.h:1677
struct ExprEvalStep::@51::@95 is_json
JsonValueType item_type
Definition: primnodes.h:1689
Definition: jsonb.h:213

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

Referenced by ExecInterpExpr().

◆ ExecEvalMergeSupportFunc()

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

Definition at line 4263 of file execExprInterp.c.

4265 {
4266  ModifyTableState *mtstate = castNode(ModifyTableState, state->parent);
4267  MergeActionState *relaction = mtstate->mt_merge_action;
4268 
4269  if (!relaction)
4270  elog(ERROR, "no merge action in progress");
4271 
4272  /* Return the MERGE action ("INSERT", "UPDATE", or "DELETE") */
4273  switch (relaction->mas_action->commandType)
4274  {
4275  case CMD_INSERT:
4276  *op->resvalue = PointerGetDatum(cstring_to_text_with_len("INSERT", 6));
4277  *op->resnull = false;
4278  break;
4279  case CMD_UPDATE:
4280  *op->resvalue = PointerGetDatum(cstring_to_text_with_len("UPDATE", 6));
4281  *op->resnull = false;
4282  break;
4283  case CMD_DELETE:
4284  *op->resvalue = PointerGetDatum(cstring_to_text_with_len("DELETE", 6));
4285  *op->resnull = false;
4286  break;
4287  case CMD_NOTHING:
4288  elog(ERROR, "unexpected merge action: DO NOTHING");
4289  break;
4290  default:
4291  elog(ERROR, "unrecognized commandType: %d",
4292  (int) relaction->mas_action->commandType);
4293  }
4294 }
@ CMD_INSERT
Definition: nodes.h:257
@ CMD_DELETE
Definition: nodes.h:258
@ CMD_UPDATE
Definition: nodes.h:256
@ CMD_NOTHING
Definition: nodes.h:262
MergeAction * mas_action
Definition: execnodes.h:425
CmdType commandType
Definition: primnodes.h:1760
MergeActionState * mt_merge_action
Definition: execnodes.h:1329
text * cstring_to_text_with_len(const char *s, int len)
Definition: varlena.c:196

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

Referenced by ExecInterpExpr().

◆ ExecEvalMinMax()

void ExecEvalMinMax ( ExprState state,
ExprEvalStep op 
)

Definition at line 3082 of file execExprInterp.c.

3083 {
3084  Datum *values = op->d.minmax.values;
3085  bool *nulls = op->d.minmax.nulls;
3086  FunctionCallInfo fcinfo = op->d.minmax.fcinfo_data;
3087  MinMaxOp operator = op->d.minmax.op;
3088 
3089  /* set at initialization */
3090  Assert(fcinfo->args[0].isnull == false);
3091  Assert(fcinfo->args[1].isnull == false);
3092 
3093  /* default to null result */
3094  *op->resnull = true;
3095 
3096  for (int off = 0; off < op->d.minmax.nelems; off++)
3097  {
3098  /* ignore NULL inputs */
3099  if (nulls[off])
3100  continue;
3101 
3102  if (*op->resnull)
3103  {
3104  /* first nonnull input, adopt value */
3105  *op->resvalue = values[off];
3106  *op->resnull = false;
3107  }
3108  else
3109  {
3110  int cmpresult;
3111 
3112  /* apply comparison function */
3113  fcinfo->args[0].value = *op->resvalue;
3114  fcinfo->args[1].value = values[off];
3115 
3116  fcinfo->isnull = false;
3117  cmpresult = DatumGetInt32(FunctionCallInvoke(fcinfo));
3118  if (fcinfo->isnull) /* probably should not happen */
3119  continue;
3120 
3121  if (cmpresult > 0 && operator == IS_LEAST)
3122  *op->resvalue = values[off];
3123  else if (cmpresult < 0 && operator == IS_GREATEST)
3124  *op->resvalue = values[off];
3125  }
3126  }
3127 }
static Datum values[MAXATTR]
Definition: bootstrap.c:152
static int32 DatumGetInt32(Datum X)
Definition: postgres.h:202
MinMaxOp
Definition: primnodes.h:1457
@ IS_LEAST
Definition: primnodes.h:1459
@ IS_GREATEST
Definition: primnodes.h:1458
struct ExprEvalStep::@51::@75 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 2679 of file execExprInterp.c.

2680 {
2681  int64 newval = nextval_internal(op->d.nextvalueexpr.seqid, false);
2682 
2683  switch (op->d.nextvalueexpr.seqtypid)
2684  {
2685  case INT2OID:
2686  *op->resvalue = Int16GetDatum((int16) newval);
2687  break;
2688  case INT4OID:
2689  *op->resvalue = Int32GetDatum((int32) newval);
2690  break;
2691  case INT8OID:
2692  *op->resvalue = Int64GetDatum((int64) newval);
2693  break;
2694  default:
2695  elog(ERROR, "unsupported sequence type %u",
2696  op->d.nextvalueexpr.seqtypid);
2697  }
2698  *op->resnull = false;
2699 }
int64 nextval_internal(Oid relid, bool check_permissions)
Definition: sequence.c:616
Datum Int64GetDatum(int64 X)
Definition: fmgr.c:1807
#define newval
static Datum Int16GetDatum(int16 X)
Definition: postgres.h:172
struct ExprEvalStep::@51::@69 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 2472 of file execExprInterp.c.

2473 {
2474  ParamExecData *prm;
2475 
2476  prm = &(econtext->ecxt_param_exec_vals[op->d.param.paramid]);
2477  if (unlikely(prm->execPlan != NULL))
2478  {
2479  /* Parameter not evaluated yet, so go do it */
2480  ExecSetParamPlan(prm->execPlan, econtext);
2481  /* ExecSetParamPlan should have processed this param... */
2482  Assert(prm->execPlan == NULL);
2483  }
2484  *op->resvalue = prm->value;
2485  *op->resnull = prm->isnull;
2486 }
void ExecSetParamPlan(SubPlanState *node, ExprContext *econtext)
Definition: nodeSubplan.c:1092
ParamExecData * ecxt_param_exec_vals
Definition: execnodes.h:266
struct ExprEvalStep::@51::@63 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 2494 of file execExprInterp.c.

2495 {
2496  ParamListInfo paramInfo = econtext->ecxt_param_list_info;
2497  int paramId = op->d.param.paramid;
2498 
2499  if (likely(paramInfo &&
2500  paramId > 0 && paramId <= paramInfo->numParams))
2501  {
2502  ParamExternData *prm;
2503  ParamExternData prmdata;
2504 
2505  /* give hook a chance in case parameter is dynamic */
2506  if (paramInfo->paramFetch != NULL)
2507  prm = paramInfo->paramFetch(paramInfo, paramId, false, &prmdata);
2508  else
2509  prm = &paramInfo->params[paramId - 1];
2510 
2511  if (likely(OidIsValid(prm->ptype)))
2512  {
2513  /* safety check in case hook did something unexpected */
2514  if (unlikely(prm->ptype != op->d.param.paramtype))
2515  ereport(ERROR,
2516  (errcode(ERRCODE_DATATYPE_MISMATCH),
2517  errmsg("type of parameter %d (%s) does not match that when preparing the plan (%s)",
2518  paramId,
2519  format_type_be(prm->ptype),
2520  format_type_be(op->d.param.paramtype))));
2521  *op->resvalue = prm->value;
2522  *op->resnull = prm->isnull;
2523  return;
2524  }
2525  }
2526 
2527  ereport(ERROR,
2528  (errcode(ERRCODE_UNDEFINED_OBJECT),
2529  errmsg("no value found for parameter %d", paramId)));
2530 }
#define likely(x)
Definition: c.h:297
#define OidIsValid(objectId)
Definition: c.h:762
ParamListInfo ecxt_param_list_info
Definition: execnodes.h:267
bool isnull
Definition: params.h:93
Datum value
Definition: params.h:92
ParamExternData params[FLEXIBLE_ARRAY_MEMBER]
Definition: params.h:125
ParamFetchHook paramFetch
Definition: params.h:112

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

Referenced by ExecInterpExpr().

◆ ExecEvalPreOrderedDistinctMulti()

bool ExecEvalPreOrderedDistinctMulti ( AggState aggstate,
AggStatePerTrans  pertrans 
)

Definition at line 4709 of file execExprInterp.c.

4710 {
4711  ExprContext *tmpcontext = aggstate->tmpcontext;
4712  bool isdistinct = false; /* for now */
4713  TupleTableSlot *save_outer;
4714  TupleTableSlot *save_inner;
4715 
4716  for (int i = 0; i < pertrans->numTransInputs; i++)
4717  {
4718  pertrans->sortslot->tts_values[i] = pertrans->transfn_fcinfo->args[i + 1].value;
4719  pertrans->sortslot->tts_isnull[i] = pertrans->transfn_fcinfo->args[i + 1].isnull;
4720  }
4721 
4722  ExecClearTuple(pertrans->sortslot);
4723  pertrans->sortslot->tts_nvalid = pertrans->numInputs;
4724  ExecStoreVirtualTuple(pertrans->sortslot);
4725 
4726  /* save the previous slots before we overwrite them */
4727  save_outer = tmpcontext->ecxt_outertuple;
4728  save_inner = tmpcontext->ecxt_innertuple;
4729 
4730  tmpcontext->ecxt_outertuple = pertrans->sortslot;
4731  tmpcontext->ecxt_innertuple = pertrans->uniqslot;
4732 
4733  if (!pertrans->haslast ||
4734  !ExecQual(pertrans->equalfnMulti, tmpcontext))
4735  {
4736  if (pertrans->haslast)
4737  ExecClearTuple(pertrans->uniqslot);
4738 
4739  pertrans->haslast = true;
4740  ExecCopySlot(pertrans->uniqslot, pertrans->sortslot);
4741 
4742  isdistinct = true;
4743  }
4744 
4745  /* restore the original slots */
4746  tmpcontext->ecxt_outertuple = save_outer;
4747  tmpcontext->ecxt_innertuple = save_inner;
4748 
4749  return isdistinct;
4750 }
static bool ExecQual(ExprState *state, ExprContext *econtext)
Definition: executor.h:413
ExprState * equalfnMulti
Definition: nodeAgg.h:116
TupleTableSlot * uniqslot
Definition: nodeAgg.h:142
ExprContext * tmpcontext
Definition: execnodes.h:2397
bool * tts_isnull
Definition: tuptable.h:127
Datum * tts_values
Definition: tuptable.h:125
static TupleTableSlot * ExecCopySlot(TupleTableSlot *dstslot, TupleTableSlot *srcslot)
Definition: tuptable.h:488

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

4667 {
4668  Datum value = pertrans->transfn_fcinfo->args[1].value;
4669  bool isnull = pertrans->transfn_fcinfo->args[1].isnull;
4670 
4671  if (!pertrans->haslast ||
4672  pertrans->lastisnull != isnull ||
4673  (!isnull && !DatumGetBool(FunctionCall2Coll(&pertrans->equalfnOne,
4674  pertrans->aggCollation,
4675  pertrans->lastdatum, value))))
4676  {
4677  if (pertrans->haslast && !pertrans->inputtypeByVal &&
4678  !pertrans->lastisnull)
4679  pfree(DatumGetPointer(pertrans->lastdatum));
4680 
4681  pertrans->haslast = true;
4682  if (!isnull)
4683  {
4684  MemoryContext oldContext;
4685 
4687 
4688  pertrans->lastdatum = datumCopy(value, pertrans->inputtypeByVal,
4689  pertrans->inputtypeLen);
4690 
4691  MemoryContextSwitchTo(oldContext);
4692  }
4693  else
4694  pertrans->lastdatum = (Datum) 0;
4695  pertrans->lastisnull = isnull;
4696  return true;
4697  }
4698 
4699  return false;
4700 }
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 3062 of file execExprInterp.c.

3063 {
3064  HeapTuple tuple;
3065 
3066  /* build tuple from evaluated field values */
3067  tuple = heap_form_tuple(op->d.row.tupdesc,
3068  op->d.row.elemvalues,
3069  op->d.row.elemnulls);
3070 
3071  *op->resvalue = HeapTupleGetDatum(tuple);
3072  *op->resnull = false;
3073 }
struct ExprEvalStep::@51::@72 row

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

Referenced by ExecInterpExpr().

◆ ExecEvalRowNotNull()

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

Definition at line 2714 of file execExprInterp.c.

2715 {
2716  ExecEvalRowNullInt(state, op, econtext, false);
2717 }
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 2705 of file execExprInterp.c.

2706 {
2707  ExecEvalRowNullInt(state, op, econtext, true);
2708 }

References ExecEvalRowNullInt(), and ExprEvalStep::op.

Referenced by ExecInterpExpr().

◆ ExecEvalScalarArrayOp()

void ExecEvalScalarArrayOp ( ExprState state,
ExprEvalStep op 
)

Definition at line 3429 of file execExprInterp.c.

3430 {
3431  FunctionCallInfo fcinfo = op->d.scalararrayop.fcinfo_data;
3432  bool useOr = op->d.scalararrayop.useOr;
3433  bool strictfunc = op->d.scalararrayop.finfo->fn_strict;
3434  ArrayType *arr;
3435  int nitems;
3436  Datum result;
3437  bool resultnull;
3438  int16 typlen;
3439  bool typbyval;
3440  char typalign;
3441  char *s;
3442  bits8 *bitmap;
3443  int bitmask;
3444 
3445  /*
3446  * If the array is NULL then we return NULL --- it's not very meaningful
3447  * to do anything else, even if the operator isn't strict.
3448  */
3449  if (*op->resnull)
3450  return;
3451 
3452  /* Else okay to fetch and detoast the array */
3453  arr = DatumGetArrayTypeP(*op->resvalue);
3454 
3455  /*
3456  * If the array is empty, we return either FALSE or TRUE per the useOr
3457  * flag. This is correct even if the scalar is NULL; since we would
3458  * evaluate the operator zero times, it matters not whether it would want
3459  * to return NULL.
3460  */
3461  nitems = ArrayGetNItems(ARR_NDIM(arr), ARR_DIMS(arr));
3462  if (nitems <= 0)
3463  {
3464  *op->resvalue = BoolGetDatum(!useOr);
3465  *op->resnull = false;
3466  return;
3467  }
3468 
3469  /*
3470  * If the scalar is NULL, and the function is strict, return NULL; no
3471  * point in iterating the loop.
3472  */
3473  if (fcinfo->args[0].isnull && strictfunc)
3474  {
3475  *op->resnull = true;
3476  return;
3477  }
3478 
3479  /*
3480  * We arrange to look up info about the element type only once per series
3481  * of calls, assuming the element type doesn't change underneath us.
3482  */
3483  if (op->d.scalararrayop.element_type != ARR_ELEMTYPE(arr))
3484  {
3486  &op->d.scalararrayop.typlen,
3487  &op->d.scalararrayop.typbyval,
3488  &op->d.scalararrayop.typalign);
3489  op->d.scalararrayop.element_type = ARR_ELEMTYPE(arr);
3490  }
3491 
3492  typlen = op->d.scalararrayop.typlen;
3493  typbyval = op->d.scalararrayop.typbyval;
3494  typalign = op->d.scalararrayop.typalign;
3495 
3496  /* Initialize result appropriately depending on useOr */
3497  result = BoolGetDatum(!useOr);
3498  resultnull = false;
3499 
3500  /* Loop over the array elements */
3501  s = (char *) ARR_DATA_PTR(arr);
3502  bitmap = ARR_NULLBITMAP(arr);
3503  bitmask = 1;
3504 
3505  for (int i = 0; i < nitems; i++)
3506  {
3507  Datum elt;
3508  Datum thisresult;
3509 
3510  /* Get array element, checking for NULL */
3511  if (bitmap && (*bitmap & bitmask) == 0)
3512  {
3513  fcinfo->args[1].value = (Datum) 0;
3514  fcinfo->args[1].isnull = true;
3515  }
3516  else
3517  {
3518  elt = fetch_att(s, typbyval, typlen);
3519  s = att_addlength_pointer(s, typlen, s);
3520  s = (char *) att_align_nominal(s, typalign);
3521  fcinfo->args[1].value = elt;
3522  fcinfo->args[1].isnull = false;
3523  }
3524 
3525  /* Call comparison function */
3526  if (fcinfo->args[1].isnull && strictfunc)
3527  {
3528  fcinfo->isnull = true;
3529  thisresult = (Datum) 0;
3530  }
3531  else
3532  {
3533  fcinfo->isnull = false;
3534  thisresult = op->d.scalararrayop.fn_addr(fcinfo);
3535  }
3536 
3537  /* Combine results per OR or AND semantics */
3538  if (fcinfo->isnull)
3539  resultnull = true;
3540  else if (useOr)
3541  {
3542  if (DatumGetBool(thisresult))
3543  {
3544  result = BoolGetDatum(true);
3545  resultnull = false;
3546  break; /* needn't look at any more elements */
3547  }
3548  }
3549  else
3550  {
3551  if (!DatumGetBool(thisresult))
3552  {
3553  result = BoolGetDatum(false);
3554  resultnull = false;
3555  break; /* needn't look at any more elements */
3556  }
3557  }
3558 
3559  /* advance bitmap pointer if any */
3560  if (bitmap)
3561  {
3562  bitmask <<= 1;
3563  if (bitmask == 0x100)
3564  {
3565  bitmap++;
3566  bitmask = 1;
3567  }
3568  }
3569  }
3570 
3571  *op->resvalue = result;
3572  *op->resnull = resultnull;
3573 }
struct ExprEvalStep::@51::@82 scalararrayop

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

Referenced by ExecInterpExpr().

◆ ExecEvalSQLValueFunction()

void ExecEvalSQLValueFunction ( ExprState state,
ExprEvalStep op 
)

Definition at line 2601 of file execExprInterp.c.

2602 {
2603  LOCAL_FCINFO(fcinfo, 0);
2604  SQLValueFunction *svf = op->d.sqlvaluefunction.svf;
2605 
2606  *op->resnull = false;
2607 
2608  /*
2609  * Note: current_schema() can return NULL. current_user() etc currently
2610  * cannot, but might as well code those cases the same way for safety.
2611  */
2612  switch (svf->op)
2613  {
2614  case SVFOP_CURRENT_DATE:
2616  break;
2617  case SVFOP_CURRENT_TIME:
2618  case SVFOP_CURRENT_TIME_N:
2620  break;
2624  break;
2625  case SVFOP_LOCALTIME:
2626  case SVFOP_LOCALTIME_N:
2628  break;
2629  case SVFOP_LOCALTIMESTAMP:
2632  break;
2633  case SVFOP_CURRENT_ROLE:
2634  case SVFOP_CURRENT_USER:
2635  case SVFOP_USER:
2636  InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
2637  *op->resvalue = current_user(fcinfo);
2638  *op->resnull = fcinfo->isnull;
2639  break;
2640  case SVFOP_SESSION_USER:
2641  InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
2642  *op->resvalue = session_user(fcinfo);
2643  *op->resnull = fcinfo->isnull;
2644  break;
2645  case SVFOP_CURRENT_CATALOG:
2646  InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
2647  *op->resvalue = current_database(fcinfo);
2648  *op->resnull = fcinfo->isnull;
2649  break;
2650  case SVFOP_CURRENT_SCHEMA:
2651  InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
2652  *op->resvalue = current_schema(fcinfo);
2653  *op->resnull = fcinfo->isnull;
2654  break;
2655  }
2656 }
Datum current_database(PG_FUNCTION_ARGS)
Definition: misc.c:194
Timestamp GetSQLLocalTimestamp(int32 typmod)
Definition: timestamp.c:1686
TimestampTz GetSQLCurrentTimestamp(int32 typmod)
Definition: timestamp.c:1672
TimeTzADT * GetSQLCurrentTime(int32 typmod)
Definition: date.c:342
TimeADT GetSQLLocalTime(int32 typmod)
Definition: date.c:362
DateADT GetSQLCurrentDate(void)
Definition: date.c:309
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:1505
@ SVFOP_LOCALTIME_N
Definition: primnodes.h:1498
@ SVFOP_CURRENT_TIMESTAMP
Definition: primnodes.h:1495
@ SVFOP_LOCALTIME
Definition: primnodes.h:1497
@ SVFOP_CURRENT_TIMESTAMP_N
Definition: primnodes.h:1496
@ SVFOP_CURRENT_ROLE
Definition: primnodes.h:1501
@ SVFOP_USER
Definition: primnodes.h:1503
@ SVFOP_CURRENT_SCHEMA
Definition: primnodes.h:1506
@ SVFOP_LOCALTIMESTAMP_N
Definition: primnodes.h:1500
@ SVFOP_CURRENT_DATE
Definition: primnodes.h:1492
@ SVFOP_CURRENT_TIME_N
Definition: primnodes.h:1494
@ SVFOP_CURRENT_TIME
Definition: primnodes.h:1493
@ SVFOP_LOCALTIMESTAMP
Definition: primnodes.h:1499
@ SVFOP_CURRENT_USER
Definition: primnodes.h:1502
@ SVFOP_SESSION_USER
Definition: primnodes.h:1504
struct ExprEvalStep::@51::@68 sqlvaluefunction
SQLValueFunctionOp op
Definition: primnodes.h:1512
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 2384 of file execExprInterp.c.

2385 {
2386 #if defined(EEO_USE_COMPUTED_GOTO)
2387  if (state->flags & EEO_FLAG_DIRECT_THREADED)
2388  {
2389  ExprEvalOpLookup key;
2390  ExprEvalOpLookup *res;
2391 
2392  key.opcode = (void *) op->opcode;
2393  res = bsearch(&key,
2394  reverse_dispatch_table,
2395  EEOP_LAST /* nmembers */ ,
2396  sizeof(ExprEvalOpLookup),
2397  dispatch_compare_ptr);
2398  Assert(res); /* unknown ops shouldn't get looked up */
2399  return res->op;
2400  }
2401 #endif
2402  return (ExprEvalOp) op->opcode;
2403 }
#define EEO_FLAG_DIRECT_THREADED
Definition: execExpr.h:31
intptr_t opcode
Definition: execExpr.h:278

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

Referenced by CheckExprStillValid().

◆ ExecEvalSubPlan()

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

Definition at line 4300 of file execExprInterp.c.

4301 {
4302  SubPlanState *sstate = op->d.subplan.sstate;
4303 
4304  /* could potentially be nested, so make sure there's enough stack */
4306 
4307  *op->resvalue = ExecSubPlan(sstate, econtext, op->resnull);
4308 }
Datum ExecSubPlan(SubPlanState *node, ExprContext *econtext, bool *isNull)
Definition: nodeSubplan.c:62
void check_stack_depth(void)
Definition: postgres.c:3531
struct ExprEvalStep::@51::@89 subplan

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

Referenced by ExecInterpExpr().

◆ ExecEvalSysVar()

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

Definition at line 4544 of file execExprInterp.c.

4546 {
4547  Datum d;
4548 
4549  /* slot_getsysattr has sufficient defenses against bad attnums */
4550  d = slot_getsysattr(slot,
4551  op->d.var.attnum,
4552  op->resnull);
4553  *op->resvalue = d;
4554  /* this ought to be unreachable, but it's cheap enough to check */
4555  if (unlikely(*op->resnull))
4556  elog(ERROR, "failed to fetch attribute from slot");
4557 }
static Datum slot_getsysattr(TupleTableSlot *slot, int attnum, bool *isnull)
Definition: tuptable.h:410

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

Referenced by ExecInterpExpr().

◆ ExecEvalWholeRowVar()

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

Definition at line 4317 of file execExprInterp.c.

4318 {
4319  Var *variable = op->d.wholerow.var;
4320  TupleTableSlot *slot;
4321  TupleDesc output_tupdesc;
4322  MemoryContext oldcontext;
4323  HeapTupleHeader dtuple;
4324  HeapTuple tuple;
4325 
4326  /* This was checked by ExecInitExpr */
4327  Assert(variable->varattno == InvalidAttrNumber);
4328 
4329  /* Get the input slot we want */
4330  switch (variable->varno)
4331  {
4332  case INNER_VAR:
4333  /* get the tuple from the inner node */
4334  slot = econtext->ecxt_innertuple;
4335  break;
4336 
4337  case OUTER_VAR:
4338  /* get the tuple from the outer node */
4339  slot = econtext->ecxt_outertuple;
4340  break;
4341 
4342  /* INDEX_VAR is handled by default case */
4343 
4344  default:
4345  /* get the tuple from the relation being scanned */
4346  slot = econtext->ecxt_scantuple;
4347  break;
4348  }
4349 
4350  /* Apply the junkfilter if any */
4351  if (op->d.wholerow.junkFilter != NULL)
4352  slot = ExecFilterJunk(op->d.wholerow.junkFilter, slot);
4353 
4354  /*
4355  * If first time through, obtain tuple descriptor and check compatibility.
4356  *
4357  * XXX: It'd be great if this could be moved to the expression
4358  * initialization phase, but due to using slots that's currently not
4359  * feasible.
4360  */
4361  if (op->d.wholerow.first)
4362  {
4363  /* optimistically assume we don't need slow path */
4364  op->d.wholerow.slow = false;
4365 
4366  /*
4367  * If the Var identifies a named composite type, we must check that
4368  * the actual tuple type is compatible with it.
4369  */
4370  if (variable->vartype != RECORDOID)
4371  {
4372  TupleDesc var_tupdesc;
4373  TupleDesc slot_tupdesc;
4374 
4375  /*
4376  * We really only care about numbers of attributes and data types.
4377  * Also, we can ignore type mismatch on columns that are dropped
4378  * in the destination type, so long as (1) the physical storage
4379  * matches or (2) the actual column value is NULL. Case (1) is
4380  * helpful in some cases involving out-of-date cached plans, while
4381  * case (2) is expected behavior in situations such as an INSERT
4382  * into a table with dropped columns (the planner typically
4383  * generates an INT4 NULL regardless of the dropped column type).
4384  * If we find a dropped column and cannot verify that case (1)
4385  * holds, we have to use the slow path to check (2) for each row.
4386  *
4387  * If vartype is a domain over composite, just look through that
4388  * to the base composite type.
4389  */
4390  var_tupdesc = lookup_rowtype_tupdesc_domain(variable->vartype,
4391  -1, false);
4392 
4393  slot_tupdesc = slot->tts_tupleDescriptor;
4394 
4395  if (var_tupdesc->natts != slot_tupdesc->natts)
4396  ereport(ERROR,
4397  (errcode(ERRCODE_DATATYPE_MISMATCH),
4398  errmsg("table row type and query-specified row type do not match"),
4399  errdetail_plural("Table row contains %d attribute, but query expects %d.",
4400  "Table row contains %d attributes, but query expects %d.",
4401  slot_tupdesc->natts,
4402  slot_tupdesc->natts,
4403  var_tupdesc->natts)));
4404 
4405  for (int i = 0; i < var_tupdesc->natts; i++)
4406  {
4407  Form_pg_attribute vattr = TupleDescAttr(var_tupdesc, i);
4408  Form_pg_attribute sattr = TupleDescAttr(slot_tupdesc, i);
4409 
4410  if (vattr->atttypid == sattr->atttypid)
4411  continue; /* no worries */
4412  if (!vattr->attisdropped)
4413  ereport(ERROR,
4414  (errcode(ERRCODE_DATATYPE_MISMATCH),
4415  errmsg("table row type and query-specified row type do not match"),
4416  errdetail("Table has type %s at ordinal position %d, but query expects %s.",
4417  format_type_be(sattr->atttypid),
4418  i + 1,
4419  format_type_be(vattr->atttypid))));
4420 
4421  if (vattr->attlen != sattr->attlen ||
4422  vattr->attalign != sattr->attalign)
4423  op->d.wholerow.slow = true; /* need to check for nulls */
4424  }
4425 
4426  /*
4427  * Use the variable's declared rowtype as the descriptor for the
4428  * output values. In particular, we *must* absorb any
4429  * attisdropped markings.
4430  */
4431  oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
4432  output_tupdesc = CreateTupleDescCopy(var_tupdesc);
4433  MemoryContextSwitchTo(oldcontext);
4434 
4435  ReleaseTupleDesc(var_tupdesc);
4436  }
4437  else
4438  {
4439  /*
4440  * In the RECORD case, we use the input slot's rowtype as the
4441  * descriptor for the output values, modulo possibly assigning new
4442  * column names below.
4443  */
4444  oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
4445  output_tupdesc = CreateTupleDescCopy(slot->tts_tupleDescriptor);
4446  MemoryContextSwitchTo(oldcontext);
4447 
4448  /*
4449  * It's possible that the input slot is a relation scan slot and
4450  * so is marked with that relation's rowtype. But we're supposed
4451  * to be returning RECORD, so reset to that.
4452  */
4453  output_tupdesc->tdtypeid = RECORDOID;
4454  output_tupdesc->tdtypmod = -1;
4455 
4456  /*
4457  * We already got the correct physical datatype info above, but
4458  * now we should try to find the source RTE and adopt its column
4459  * aliases, since it's unlikely that the input slot has the
4460  * desired names.
4461  *
4462  * If we can't locate the RTE, assume the column names we've got
4463  * are OK. (As of this writing, the only cases where we can't
4464  * locate the RTE are in execution of trigger WHEN clauses, and
4465  * then the Var will have the trigger's relation's rowtype, so its
4466  * names are fine.) Also, if the creator of the RTE didn't bother
4467  * to fill in an eref field, assume our column names are OK. (This
4468  * happens in COPY, and perhaps other places.)
4469  */
4470  if (econtext->ecxt_estate &&
4471  variable->varno <= econtext->ecxt_estate->es_range_table_size)
4472  {
4473  RangeTblEntry *rte = exec_rt_fetch(variable->varno,
4474  econtext->ecxt_estate);
4475 
4476  if (rte->eref)
4477  ExecTypeSetColNames(output_tupdesc, rte->eref->colnames);
4478  }
4479  }
4480 
4481  /* Bless the tupdesc if needed, and save it in the execution state */
4482  op->d.wholerow.tupdesc = BlessTupleDesc(output_tupdesc);
4483 
4484  op->d.wholerow.first = false;
4485  }
4486 
4487  /*
4488  * Make sure all columns of the slot are accessible in the slot's
4489  * Datum/isnull arrays.
4490  */
4491  slot_getallattrs(slot);
4492 
4493  if (op->d.wholerow.slow)
4494  {
4495  /* Check to see if any dropped attributes are non-null */
4496  TupleDesc tupleDesc = slot->tts_tupleDescriptor;
4497  TupleDesc var_tupdesc = op->d.wholerow.tupdesc;
4498 
4499  Assert(var_tupdesc->natts == tupleDesc->natts);
4500 
4501  for (int i = 0; i < var_tupdesc->natts; i++)
4502  {
4503  Form_pg_attribute vattr = TupleDescAttr(var_tupdesc, i);
4504  Form_pg_attribute sattr = TupleDescAttr(tupleDesc, i);
4505 
4506  if (!vattr->attisdropped)
4507  continue; /* already checked non-dropped cols */
4508  if (slot->tts_isnull[i])
4509  continue; /* null is always okay */
4510  if (vattr->attlen != sattr->attlen ||
4511  vattr->attalign != sattr->attalign)
4512  ereport(ERROR,
4513  (errcode(ERRCODE_DATATYPE_MISMATCH),
4514  errmsg("table row type and query-specified row type do not match"),
4515  errdetail("Physical storage mismatch on dropped attribute at ordinal position %d.",
4516  i + 1)));
4517  }
4518  }
4519 
4520  /*
4521  * Build a composite datum, making sure any toasted fields get detoasted.
4522  *
4523  * (Note: it is critical that we not change the slot's state here.)
4524  */
4526  slot->tts_values,
4527  slot->tts_isnull);
4528  dtuple = tuple->t_data;
4529 
4530  /*
4531  * Label the datum with the composite type info we identified before.
4532  *
4533  * (Note: we could skip doing this by passing op->d.wholerow.tupdesc to
4534  * the tuple build step; but that seems a tad risky so let's not.)
4535  */
4536  HeapTupleHeaderSetTypeId(dtuple, op->d.wholerow.tupdesc->tdtypeid);
4537  HeapTupleHeaderSetTypMod(dtuple, op->d.wholerow.tupdesc->tdtypmod);
4538 
4539  *op->resvalue = PointerGetDatum(dtuple);
4540  *op->resnull = false;
4541 }
#define InvalidAttrNumber
Definition: attnum.h:23
int errdetail_plural(const char *fmt_singular, const char *fmt_plural, unsigned long n,...)
Definition: elog.c:1297
TupleTableSlot * ExecFilterJunk(JunkFilter *junkfilter, TupleTableSlot *slot)
Definition: execJunk.c:247
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:2070
void ExecTypeSetColNames(TupleDesc typeInfo, List *namesList)
Definition: execTuples.c:2029
static RangeTblEntry * exec_rt_fetch(Index rti, EState *estate)
Definition: executor.h:587
HeapTuple toast_build_flattened_tuple(TupleDesc tupleDesc, Datum *values, bool *isnull)
Definition: heaptoast.c:563
#define HeapTupleHeaderSetTypMod(tup, typmod)
Definition: htup_details.h:471
#define HeapTupleHeaderSetTypeId(tup, typeid)
Definition: htup_details.h:461
#define OUTER_VAR
Definition: primnodes.h:223
#define INNER_VAR
Definition: primnodes.h:222
List * colnames
Definition: primnodes.h:51
Index es_range_table_size
Definition: execnodes.h:625
struct EState * ecxt_estate
Definition: execnodes.h:291
struct ExprEvalStep::@51::@54 wholerow
Alias * eref
Definition: parsenodes.h:1205
int32 tdtypmod
Definition: tupdesc.h:83
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:123
Definition: primnodes.h:234
TupleDesc CreateTupleDescCopy(TupleDesc tupdesc)
Definition: tupdesc.c:133
#define ReleaseTupleDesc(tupdesc)
Definition: tupdesc.h:122
static void slot_getallattrs(TupleTableSlot *slot)
Definition: tuptable.h:362
TupleDesc lookup_rowtype_tupdesc_domain(Oid type_id, int32 typmod, bool noError)
Definition: typcache.c:1889

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

Referenced by ExecInterpExpr().

◆ ExecEvalXmlExpr()

void ExecEvalXmlExpr ( ExprState state,
ExprEvalStep op 
)

Definition at line 3848 of file execExprInterp.c.

3849 {
3850  XmlExpr *xexpr = op->d.xmlexpr.xexpr;
3851  Datum value;
3852 
3853  *op->resnull = true; /* until we get a result */
3854  *op->resvalue = (Datum) 0;
3855 
3856  switch (xexpr->op)
3857  {
3858  case IS_XMLCONCAT:
3859  {
3860  Datum *argvalue = op->d.xmlexpr.argvalue;
3861  bool *argnull = op->d.xmlexpr.argnull;
3862  List *values = NIL;
3863 
3864  for (int i = 0; i < list_length(xexpr->args); i++)
3865  {
3866  if (!argnull[i])
3867  values = lappend(values, DatumGetPointer(argvalue[i]));
3868  }
3869 
3870  if (values != NIL)
3871  {
3873  *op->resnull = false;
3874  }
3875  }
3876  break;
3877 
3878  case IS_XMLFOREST:
3879  {
3880  Datum *argvalue = op->d.xmlexpr.named_argvalue;
3881  bool *argnull = op->d.xmlexpr.named_argnull;
3883  ListCell *lc;
3884  ListCell *lc2;
3885  int i;
3886 
3887  initStringInfo(&buf);
3888 
3889  i = 0;
3890  forboth(lc, xexpr->named_args, lc2, xexpr->arg_names)
3891  {
3892  Expr *e = (Expr *) lfirst(lc);
3893  char *argname = strVal(lfirst(lc2));
3894 
3895  if (!argnull[i])
3896  {
3897  value = argvalue[i];
3898  appendStringInfo(&buf, "<%s>%s</%s>",
3899  argname,
3901  exprType((Node *) e), true),
3902  argname);
3903  *op->resnull = false;
3904  }
3905  i++;
3906  }
3907 
3908  if (!*op->resnull)
3909  {
3910  text *result;
3911 
3912  result = cstring_to_text_with_len(buf.data, buf.len);
3913  *op->resvalue = PointerGetDatum(result);
3914  }
3915 
3916  pfree(buf.data);
3917  }
3918  break;
3919 
3920  case IS_XMLELEMENT:
3921  *op->resvalue = PointerGetDatum(xmlelement(xexpr,
3922  op->d.xmlexpr.named_argvalue,
3923  op->d.xmlexpr.named_argnull,
3924  op->d.xmlexpr.argvalue,
3925  op->d.xmlexpr.argnull));
3926  *op->resnull = false;
3927  break;
3928 
3929  case IS_XMLPARSE:
3930  {
3931  Datum *argvalue = op->d.xmlexpr.argvalue;
3932  bool *argnull = op->d.xmlexpr.argnull;
3933  text *data;
3934  bool preserve_whitespace;
3935 
3936  /* arguments are known to be text, bool */
3937  Assert(list_length(xexpr->args) == 2);
3938 
3939  if (argnull[0])
3940  return;
3941  value = argvalue[0];
3943 
3944  if (argnull[1]) /* probably can't happen */
3945  return;
3946  value = argvalue[1];
3947  preserve_whitespace = DatumGetBool(value);
3948 
3950  xexpr->xmloption,
3951  preserve_whitespace));
3952  *op->resnull = false;
3953  }
3954  break;
3955 
3956  case IS_XMLPI:
3957  {
3958  text *arg;
3959  bool isnull;
3960 
3961  /* optional argument is known to be text */
3962  Assert(list_length(xexpr->args) <= 1);
3963 
3964  if (xexpr->args)
3965  {
3966  isnull = op->d.xmlexpr.argnull[0];
3967  if (isnull)
3968  arg = NULL;
3969  else
3970  arg = DatumGetTextPP(op->d.xmlexpr.argvalue[0]);
3971  }
3972  else
3973  {
3974  arg = NULL;
3975  isnull = false;
3976  }
3977 
3978  *op->resvalue = PointerGetDatum(xmlpi(xexpr->name,
3979  arg,
3980  isnull,
3981  op->resnull));
3982  }
3983  break;
3984 
3985  case IS_XMLROOT:
3986  {
3987  Datum *argvalue = op->d.xmlexpr.argvalue;
3988  bool *argnull = op->d.xmlexpr.argnull;
3989  xmltype *data;
3990  text *version;
3991  int standalone;
3992 
3993  /* arguments are known to be xml, text, int */
3994  Assert(list_length(xexpr->args) == 3);
3995 
3996  if (argnull[0])
3997  return;
3998  data = DatumGetXmlP(argvalue[0]);
3999 
4000  if (argnull[1])
4001  version = NULL;
4002  else
4003  version = DatumGetTextPP(argvalue[1]);
4004 
4005  Assert(!argnull[2]); /* always present */
4006  standalone = DatumGetInt32(argvalue[2]);
4007 
4009  version,
4010  standalone));
4011  *op->resnull = false;
4012  }
4013  break;
4014 
4015  case IS_XMLSERIALIZE:
4016  {
4017  Datum *argvalue = op->d.xmlexpr.argvalue;
4018  bool *argnull = op->d.xmlexpr.argnull;
4019 
4020  /* argument type is known to be xml */
4021  Assert(list_length(xexpr->args) == 1);
4022 
4023  if (argnull[0])
4024  return;
4025  value = argvalue[0];
4026 
4027  *op->resvalue =
4029  xexpr->xmloption,
4030  xexpr->indent));
4031  *op->resnull = false;
4032  }
4033  break;
4034 
4035  case IS_DOCUMENT:
4036  {
4037  Datum *argvalue = op->d.xmlexpr.argvalue;
4038  bool *argnull = op->d.xmlexpr.argnull;
4039 
4040  /* optional argument is known to be xml */
4041  Assert(list_length(xexpr->args) == 1);
4042 
4043  if (argnull[0])
4044  return;
4045  value = argvalue[0];
4046 
4047  *op->resvalue =
4049  *op->resnull = false;
4050  }
4051  break;
4052 
4053  default:
4054  elog(ERROR, "unrecognized XML operation");
4055  break;
4056  }
4057 }
#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:73
e
Definition: preproc-init.c:82
@ IS_DOCUMENT
Definition: primnodes.h:1543
@ IS_XMLFOREST
Definition: primnodes.h:1538
@ IS_XMLCONCAT
Definition: primnodes.h:1536
@ IS_XMLPI
Definition: primnodes.h:1540
@ IS_XMLPARSE
Definition: primnodes.h:1539
@ IS_XMLSERIALIZE
Definition: primnodes.h:1542
@ IS_XMLROOT
Definition: primnodes.h:1541
@ IS_XMLELEMENT
Definition: primnodes.h:1537
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:97
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
struct ExprEvalStep::@51::@84 xmlexpr
Definition: pg_list.h:54
List * args
Definition: primnodes.h:1564
bool indent
Definition: primnodes.h:1568
List * named_args
Definition: primnodes.h:1560
XmlExprOp op
Definition: primnodes.h:1556
#define strVal(v)
Definition: value.h:82
xmltype * xmlconcat(List *args)
Definition: xml.c:553
text * xmltotext_with_options(xmltype *data, XmlOptionType xmloption_arg, bool indent)
Definition: xml.c:656
xmltype * xmlparse(text *data, XmlOptionType xmloption_arg, bool preserve_whitespace)
Definition: xml.c:960
bool xml_is_document(xmltype *arg)
Definition: xml.c:1096
xmltype * xmlpi(const char *target, text *arg, bool arg_is_null, bool *result_is_null)
Definition: xml.c:978
char * map_sql_value_to_xml_value(Datum value, Oid type, bool xml_escape_strings)
Definition: xml.c:2413
xmltype * xmlelement(XmlExpr *xexpr, Datum *named_argvalue, bool *named_argnull, Datum *argvalue, bool *argnull)
Definition: xml.c:836
xmltype * xmlroot(xmltype *data, text *version, int standalone)
Definition: xml.c:1030
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 1877 of file execExprInterp.c.

1878 {
1879  /*
1880  * First time through, check whether attribute matches Var. Might not be
1881  * ok anymore, due to schema changes.
1882  */
1883  CheckExprStillValid(state, econtext);
1884 
1885  /* skip the check during further executions */
1886  state->evalfunc = (ExprStateEvalFunc) state->evalfunc_private;
1887 
1888  /* and actually execute */
1889  return state->evalfunc(state, econtext, isNull);
1890 }
void CheckExprStillValid(ExprState *state, ExprContext *econtext)
Datum(* ExprStateEvalFunc)(struct ExprState *expression, struct ExprContext *econtext, bool *isNull)
Definition: execnodes.h:70

References CheckExprStillValid().

Referenced by ExecReadyInterpretedExpr().

◆ ExecReadyInterpretedExpr()

void ExecReadyInterpretedExpr ( ExprState state)

Definition at line 235 of file execExprInterp.c.

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

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

Referenced by ExecReadyExpr().

◆ ExprEvalPushStep()

void ExprEvalPushStep ( ExprState es,
const ExprEvalStep s 
)

Definition at line 2567 of file execExpr.c.

2568 {
2569  if (es->steps_alloc == 0)
2570  {
2571  es->steps_alloc = 16;
2572  es->steps = palloc(sizeof(ExprEvalStep) * es->steps_alloc);
2573  }
2574  else if (es->steps_alloc == es->steps_len)
2575  {
2576  es->steps_alloc *= 2;
2577  es->steps = repalloc(es->steps,
2578  sizeof(ExprEvalStep) * es->steps_alloc);
2579  }
2580 
2581  memcpy(&es->steps[es->steps_len++], s, sizeof(ExprEvalStep));
2582 }
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:1528
struct ExprEvalStep * steps
Definition: execnodes.h:102
int steps_alloc
Definition: execnodes.h:122
int steps_len
Definition: execnodes.h:121

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

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

◆ StaticAssertDecl()

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