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

Go to the source code of this file.

Data Structures

struct  ExprEvalRowtypeCache
 
struct  ExprEvalStep
 
struct  SubscriptingRefState
 
struct  SubscriptExecSteps
 

Macros

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

Typedefs

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

Enumerations

enum  ExprEvalOp {
  EEOP_DONE , EEOP_INNER_FETCHSOME , EEOP_OUTER_FETCHSOME , EEOP_SCAN_FETCHSOME ,
  EEOP_INNER_VAR , EEOP_OUTER_VAR , EEOP_SCAN_VAR , EEOP_INNER_SYSVAR ,
  EEOP_OUTER_SYSVAR , EEOP_SCAN_SYSVAR , EEOP_WHOLEROW , EEOP_ASSIGN_INNER_VAR ,
  EEOP_ASSIGN_OUTER_VAR , EEOP_ASSIGN_SCAN_VAR , EEOP_ASSIGN_TMP , EEOP_ASSIGN_TMP_MAKE_RO ,
  EEOP_CONST , EEOP_FUNCEXPR , EEOP_FUNCEXPR_STRICT , EEOP_FUNCEXPR_FUSAGE ,
  EEOP_FUNCEXPR_STRICT_FUSAGE , EEOP_BOOL_AND_STEP_FIRST , EEOP_BOOL_AND_STEP , EEOP_BOOL_AND_STEP_LAST ,
  EEOP_BOOL_OR_STEP_FIRST , EEOP_BOOL_OR_STEP , EEOP_BOOL_OR_STEP_LAST , EEOP_BOOL_NOT_STEP ,
  EEOP_QUAL , EEOP_JUMP , EEOP_JUMP_IF_NULL , EEOP_JUMP_IF_NOT_NULL ,
  EEOP_JUMP_IF_NOT_TRUE , EEOP_NULLTEST_ISNULL , EEOP_NULLTEST_ISNOTNULL , EEOP_NULLTEST_ROWISNULL ,
  EEOP_NULLTEST_ROWISNOTNULL , EEOP_BOOLTEST_IS_TRUE , EEOP_BOOLTEST_IS_NOT_TRUE , EEOP_BOOLTEST_IS_FALSE ,
  EEOP_BOOLTEST_IS_NOT_FALSE , EEOP_PARAM_EXEC , EEOP_PARAM_EXTERN , EEOP_PARAM_CALLBACK ,
  EEOP_CASE_TESTVAL , EEOP_MAKE_READONLY , EEOP_IOCOERCE , EEOP_DISTINCT ,
  EEOP_NOT_DISTINCT , EEOP_NULLIF , EEOP_CURRENTOFEXPR , EEOP_NEXTVALUEEXPR ,
  EEOP_ARRAYEXPR , EEOP_ARRAYCOERCE , EEOP_ROW , EEOP_ROWCOMPARE_STEP ,
  EEOP_ROWCOMPARE_FINAL , EEOP_MINMAX , EEOP_FIELDSELECT , EEOP_FIELDSTORE_DEFORM ,
  EEOP_FIELDSTORE_FORM , EEOP_SBSREF_SUBSCRIPTS , EEOP_SBSREF_OLD , EEOP_SBSREF_ASSIGN ,
  EEOP_SBSREF_FETCH , EEOP_DOMAIN_TESTVAL , EEOP_DOMAIN_NOTNULL , EEOP_DOMAIN_CHECK ,
  EEOP_CONVERT_ROWTYPE , EEOP_SCALARARRAYOP , EEOP_HASHED_SCALARARRAYOP , EEOP_XMLEXPR ,
  EEOP_AGGREF , EEOP_GROUPING_FUNC , EEOP_WINDOW_FUNC , EEOP_SUBPLAN ,
  EEOP_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

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 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 ExecEvalGroupingFunc (ExprState *state, ExprEvalStep *op)
 
void ExecEvalSubPlan (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalWholeRowVar (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalSysVar (ExprState *state, ExprEvalStep *op, ExprContext *econtext, TupleTableSlot *slot)
 
void ExecAggInitGroup (AggState *aggstate, AggStatePerTrans pertrans, AggStatePerGroup pergroup, ExprContext *aggcontext)
 
Datum ExecAggTransReparent (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 29 of file execExpr.h.

◆ EEO_FLAG_INTERPRETER_INITIALIZED

#define EEO_FLAG_INTERPRETER_INITIALIZED   (1 << 1)

Definition at line 27 of file execExpr.h.

Typedef Documentation

◆ ExecEvalBoolSubroutine

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

Definition at line 37 of file execExpr.h.

◆ ExecEvalSubroutine

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

Definition at line 32 of file execExpr.h.

◆ ExprEvalOp

typedef enum ExprEvalOp ExprEvalOp

◆ ExprEvalRowtypeCache

◆ ExprEvalStep

typedef struct ExprEvalStep ExprEvalStep

◆ SubscriptExecSteps

◆ SubscriptingRefState

Enumeration Type Documentation

◆ ExprEvalOp

enum ExprEvalOp
Enumerator
EEOP_DONE 
EEOP_INNER_FETCHSOME 
EEOP_OUTER_FETCHSOME 
EEOP_SCAN_FETCHSOME 
EEOP_INNER_VAR 
EEOP_OUTER_VAR 
EEOP_SCAN_VAR 
EEOP_INNER_SYSVAR 
EEOP_OUTER_SYSVAR 
EEOP_SCAN_SYSVAR 
EEOP_WHOLEROW 
EEOP_ASSIGN_INNER_VAR 
EEOP_ASSIGN_OUTER_VAR 
EEOP_ASSIGN_SCAN_VAR 
EEOP_ASSIGN_TMP 
EEOP_ASSIGN_TMP_MAKE_RO 
EEOP_CONST 
EEOP_FUNCEXPR 
EEOP_FUNCEXPR_STRICT 
EEOP_FUNCEXPR_FUSAGE 
EEOP_FUNCEXPR_STRICT_FUSAGE 
EEOP_BOOL_AND_STEP_FIRST 
EEOP_BOOL_AND_STEP 
EEOP_BOOL_AND_STEP_LAST 
EEOP_BOOL_OR_STEP_FIRST 
EEOP_BOOL_OR_STEP 
EEOP_BOOL_OR_STEP_LAST 
EEOP_BOOL_NOT_STEP 
EEOP_QUAL 
EEOP_JUMP 
EEOP_JUMP_IF_NULL 
EEOP_JUMP_IF_NOT_NULL 
EEOP_JUMP_IF_NOT_TRUE 
EEOP_NULLTEST_ISNULL 
EEOP_NULLTEST_ISNOTNULL 
EEOP_NULLTEST_ROWISNULL 
EEOP_NULLTEST_ROWISNOTNULL 
EEOP_BOOLTEST_IS_TRUE 
EEOP_BOOLTEST_IS_NOT_TRUE 
EEOP_BOOLTEST_IS_FALSE 
EEOP_BOOLTEST_IS_NOT_FALSE 
EEOP_PARAM_EXEC 
EEOP_PARAM_EXTERN 
EEOP_PARAM_CALLBACK 
EEOP_CASE_TESTVAL 
EEOP_MAKE_READONLY 
EEOP_IOCOERCE 
EEOP_DISTINCT 
EEOP_NOT_DISTINCT 
EEOP_NULLIF 
EEOP_CURRENTOFEXPR 
EEOP_NEXTVALUEEXPR 
EEOP_ARRAYEXPR 
EEOP_ARRAYCOERCE 
EEOP_ROW 
EEOP_ROWCOMPARE_STEP 
EEOP_ROWCOMPARE_FINAL 
EEOP_MINMAX 
EEOP_FIELDSELECT 
EEOP_FIELDSTORE_DEFORM 
EEOP_FIELDSTORE_FORM 
EEOP_SBSREF_SUBSCRIPTS 
EEOP_SBSREF_OLD 
EEOP_SBSREF_ASSIGN 
EEOP_SBSREF_FETCH 
EEOP_DOMAIN_TESTVAL 
EEOP_DOMAIN_NOTNULL 
EEOP_DOMAIN_CHECK 
EEOP_CONVERT_ROWTYPE 
EEOP_SCALARARRAYOP 
EEOP_HASHED_SCALARARRAYOP 
EEOP_XMLEXPR 
EEOP_AGGREF 
EEOP_GROUPING_FUNC 
EEOP_WINDOW_FUNC 
EEOP_SUBPLAN 
EEOP_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 64 of file execExpr.h.

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

Function Documentation

◆ CheckExprStillValid()

void CheckExprStillValid ( ExprState state,
ExprContext econtext 
)

Definition at line 1846 of file execExprInterp.c.

1847 {
1848  TupleTableSlot *innerslot;
1849  TupleTableSlot *outerslot;
1850  TupleTableSlot *scanslot;
1851 
1852  innerslot = econtext->ecxt_innertuple;
1853  outerslot = econtext->ecxt_outertuple;
1854  scanslot = econtext->ecxt_scantuple;
1855 
1856  for (int i = 0; i < state->steps_len; i++)
1857  {
1858  ExprEvalStep *op = &state->steps[i];
1859 
1860  switch (ExecEvalStepOp(state, op))
1861  {
1862  case EEOP_INNER_VAR:
1863  {
1864  int attnum = op->d.var.attnum;
1865 
1866  CheckVarSlotCompatibility(innerslot, attnum + 1, op->d.var.vartype);
1867  break;
1868  }
1869 
1870  case EEOP_OUTER_VAR:
1871  {
1872  int attnum = op->d.var.attnum;
1873 
1874  CheckVarSlotCompatibility(outerslot, attnum + 1, op->d.var.vartype);
1875  break;
1876  }
1877 
1878  case EEOP_SCAN_VAR:
1879  {
1880  int attnum = op->d.var.attnum;
1881 
1882  CheckVarSlotCompatibility(scanslot, attnum + 1, op->d.var.vartype);
1883  break;
1884  }
1885  default:
1886  break;
1887  }
1888  }
1889 }
static void CheckVarSlotCompatibility(TupleTableSlot *slot, int attnum, Oid vartype)
ExprEvalOp ExecEvalStepOp(ExprState *state, ExprEvalStep *op)
int i
Definition: isn.c:73
int16 attnum
Definition: pg_attribute.h:83
TupleTableSlot * ecxt_innertuple
Definition: execnodes.h:249
TupleTableSlot * ecxt_scantuple
Definition: execnodes.h:247
TupleTableSlot * ecxt_outertuple
Definition: execnodes.h:251
struct ExprEvalStep::@50::@52 var
union ExprEvalStep::@50 d
Definition: regguts.h:318

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

Referenced by ExecInterpExprStillValid(), and ExecRunCompiledExpr().

◆ ExecAggInitGroup()

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

Definition at line 4169 of file execExprInterp.c.

4171 {
4172  FunctionCallInfo fcinfo = pertrans->transfn_fcinfo;
4173  MemoryContext oldContext;
4174 
4175  /*
4176  * We must copy the datum into aggcontext if it is pass-by-ref. We do not
4177  * need to pfree the old transValue, since it's NULL. (We already checked
4178  * that the agg's input type is binary-compatible with its transtype, so
4179  * straight copy here is OK.)
4180  */
4181  oldContext = MemoryContextSwitchTo(aggcontext->ecxt_per_tuple_memory);
4182  pergroup->transValue = datumCopy(fcinfo->args[1].value,
4183  pertrans->transtypeByVal,
4184  pertrans->transtypeLen);
4185  pergroup->transValueIsNull = false;
4186  pergroup->noTransValue = false;
4187  MemoryContextSwitchTo(oldContext);
4188 }
Datum datumCopy(Datum value, bool typByVal, int typLen)
Definition: datum.c:132
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:135
FunctionCallInfo transfn_fcinfo
Definition: nodeAgg.h:170
MemoryContext ecxt_per_tuple_memory
Definition: execnodes.h:255
NullableDatum args[FLEXIBLE_ARRAY_MEMBER]
Definition: fmgr.h:95
Datum value
Definition: postgres.h:423

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

Referenced by ExecInterpExpr().

◆ ExecAggTransReparent()

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

Definition at line 4197 of file execExprInterp.c.

4200 {
4201  Assert(newValue != oldValue);
4202 
4203  if (!newValueIsNull)
4204  {
4206  if (DatumIsReadWriteExpandedObject(newValue,
4207  false,
4208  pertrans->transtypeLen) &&
4209  MemoryContextGetParent(DatumGetEOHP(newValue)->eoh_context) == CurrentMemoryContext)
4210  /* do nothing */ ;
4211  else
4212  newValue = datumCopy(newValue,
4213  pertrans->transtypeByVal,
4214  pertrans->transtypeLen);
4215  }
4216  else
4217  {
4218  /*
4219  * Ensure that AggStatePerGroup->transValue ends up being 0, so
4220  * callers can safely compare newValue/oldValue without having to
4221  * check their respective nullness.
4222  */
4223  newValue = (Datum) 0;
4224  }
4225 
4226  if (!oldValueIsNull)
4227  {
4228  if (DatumIsReadWriteExpandedObject(oldValue,
4229  false,
4230  pertrans->transtypeLen))
4231  DeleteExpandedObject(oldValue);
4232  else
4233  pfree(DatumGetPointer(oldValue));
4234  }
4235 
4236  return newValue;
4237 }
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:1306
MemoryContext CurrentMemoryContext
Definition: mcxt.c:124
MemoryContext MemoryContextGetParent(MemoryContext context)
Definition: mcxt.c:613
uintptr_t Datum
Definition: postgres.h:412
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:660
ExprContext * curaggcontext
Definition: execnodes.h:2373

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

Referenced by advance_transition_function(), and ExecAggPlainTransByRef().

◆ ExecEvalAggOrderedTransDatum()

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

Definition at line 4321 of file execExprInterp.c.

4323 {
4324  AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
4325  int setno = op->d.agg_trans.setno;
4326 
4327  tuplesort_putdatum(pertrans->sortstates[setno],
4328  *op->resvalue, *op->resnull);
4329 }
Tuplesortstate ** sortstates
Definition: nodeAgg.h:162
Datum * resvalue
Definition: execExpr.h:274
struct ExprEvalStep::@50::@91 agg_trans
bool * resnull
Definition: execExpr.h:275
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 4335 of file execExprInterp.c.

4337 {
4338  AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
4339  int setno = op->d.agg_trans.setno;
4340 
4341  ExecClearTuple(pertrans->sortslot);
4342  pertrans->sortslot->tts_nvalid = pertrans->numInputs;
4343  ExecStoreVirtualTuple(pertrans->sortslot);
4344  tuplesort_puttupleslot(pertrans->sortstates[setno], pertrans->sortslot);
4345 }
TupleTableSlot * ExecStoreVirtualTuple(TupleTableSlot *slot)
Definition: execTuples.c:1552
TupleTableSlot * sortslot
Definition: nodeAgg.h:141
AttrNumber tts_nvalid
Definition: tuptable.h:121
void tuplesort_puttupleslot(Tuplesortstate *state, TupleTableSlot *slot)
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:433

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

Referenced by ExecInterpExpr().

◆ ExecEvalArrayCoerce()

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

Definition at line 2838 of file execExprInterp.c.

2839 {
2840  Datum arraydatum;
2841 
2842  /* NULL array -> NULL result */
2843  if (*op->resnull)
2844  return;
2845 
2846  arraydatum = *op->resvalue;
2847 
2848  /*
2849  * If it's binary-compatible, modify the element type in the array header,
2850  * but otherwise leave the array as we received it.
2851  */
2852  if (op->d.arraycoerce.elemexprstate == NULL)
2853  {
2854  /* Detoast input array if necessary, and copy in any case */
2855  ArrayType *array = DatumGetArrayTypePCopy(arraydatum);
2856 
2857  ARR_ELEMTYPE(array) = op->d.arraycoerce.resultelemtype;
2858  *op->resvalue = PointerGetDatum(array);
2859  return;
2860  }
2861 
2862  /*
2863  * Use array_map to apply the sub-expression to each array element.
2864  */
2865  *op->resvalue = array_map(arraydatum,
2866  op->d.arraycoerce.elemexprstate,
2867  econtext,
2868  op->d.arraycoerce.resultelemtype,
2869  op->d.arraycoerce.amstate);
2870 }
#define DatumGetArrayTypePCopy(X)
Definition: array.h:255
#define ARR_ELEMTYPE(a)
Definition: array.h:285
Datum array_map(Datum arrayd, ExprState *exprstate, ExprContext *econtext, Oid retType, ArrayMapState *amstate)
Definition: arrayfuncs.c:3158
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:670
struct ExprEvalStep::@50::@69 arraycoerce

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

Referenced by ExecInterpExpr().

◆ ExecEvalArrayExpr()

void ExecEvalArrayExpr ( ExprState state,
ExprEvalStep op 
)

Definition at line 2629 of file execExprInterp.c.

2630 {
2631  ArrayType *result;
2632  Oid element_type = op->d.arrayexpr.elemtype;
2633  int nelems = op->d.arrayexpr.nelems;
2634  int ndims = 0;
2635  int dims[MAXDIM];
2636  int lbs[MAXDIM];
2637 
2638  /* Set non-null as default */
2639  *op->resnull = false;
2640 
2641  if (!op->d.arrayexpr.multidims)
2642  {
2643  /* Elements are presumably of scalar type */
2644  Datum *dvalues = op->d.arrayexpr.elemvalues;
2645  bool *dnulls = op->d.arrayexpr.elemnulls;
2646 
2647  /* setup for 1-D array of the given length */
2648  ndims = 1;
2649  dims[0] = nelems;
2650  lbs[0] = 1;
2651 
2652  result = construct_md_array(dvalues, dnulls, ndims, dims, lbs,
2653  element_type,
2654  op->d.arrayexpr.elemlength,
2655  op->d.arrayexpr.elembyval,
2656  op->d.arrayexpr.elemalign);
2657  }
2658  else
2659  {
2660  /* Must be nested array expressions */
2661  int nbytes = 0;
2662  int nitems = 0;
2663  int outer_nelems = 0;
2664  int elem_ndims = 0;
2665  int *elem_dims = NULL;
2666  int *elem_lbs = NULL;
2667  bool firstone = true;
2668  bool havenulls = false;
2669  bool haveempty = false;
2670  char **subdata;
2671  bits8 **subbitmaps;
2672  int *subbytes;
2673  int *subnitems;
2674  int32 dataoffset;
2675  char *dat;
2676  int iitem;
2677 
2678  subdata = (char **) palloc(nelems * sizeof(char *));
2679  subbitmaps = (bits8 **) palloc(nelems * sizeof(bits8 *));
2680  subbytes = (int *) palloc(nelems * sizeof(int));
2681  subnitems = (int *) palloc(nelems * sizeof(int));
2682 
2683  /* loop through and get data area from each element */
2684  for (int elemoff = 0; elemoff < nelems; elemoff++)
2685  {
2686  Datum arraydatum;
2687  bool eisnull;
2688  ArrayType *array;
2689  int this_ndims;
2690 
2691  arraydatum = op->d.arrayexpr.elemvalues[elemoff];
2692  eisnull = op->d.arrayexpr.elemnulls[elemoff];
2693 
2694  /* temporarily ignore null subarrays */
2695  if (eisnull)
2696  {
2697  haveempty = true;
2698  continue;
2699  }
2700 
2701  array = DatumGetArrayTypeP(arraydatum);
2702 
2703  /* run-time double-check on element type */
2704  if (element_type != ARR_ELEMTYPE(array))
2705  ereport(ERROR,
2706  (errcode(ERRCODE_DATATYPE_MISMATCH),
2707  errmsg("cannot merge incompatible arrays"),
2708  errdetail("Array with element type %s cannot be "
2709  "included in ARRAY construct with element type %s.",
2710  format_type_be(ARR_ELEMTYPE(array)),
2711  format_type_be(element_type))));
2712 
2713  this_ndims = ARR_NDIM(array);
2714  /* temporarily ignore zero-dimensional subarrays */
2715  if (this_ndims <= 0)
2716  {
2717  haveempty = true;
2718  continue;
2719  }
2720 
2721  if (firstone)
2722  {
2723  /* Get sub-array details from first member */
2724  elem_ndims = this_ndims;
2725  ndims = elem_ndims + 1;
2726  if (ndims <= 0 || ndims > MAXDIM)
2727  ereport(ERROR,
2728  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
2729  errmsg("number of array dimensions (%d) exceeds the maximum allowed (%d)",
2730  ndims, MAXDIM)));
2731 
2732  elem_dims = (int *) palloc(elem_ndims * sizeof(int));
2733  memcpy(elem_dims, ARR_DIMS(array), elem_ndims * sizeof(int));
2734  elem_lbs = (int *) palloc(elem_ndims * sizeof(int));
2735  memcpy(elem_lbs, ARR_LBOUND(array), elem_ndims * sizeof(int));
2736 
2737  firstone = false;
2738  }
2739  else
2740  {
2741  /* Check other sub-arrays are compatible */
2742  if (elem_ndims != this_ndims ||
2743  memcmp(elem_dims, ARR_DIMS(array),
2744  elem_ndims * sizeof(int)) != 0 ||
2745  memcmp(elem_lbs, ARR_LBOUND(array),
2746  elem_ndims * sizeof(int)) != 0)
2747  ereport(ERROR,
2748  (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
2749  errmsg("multidimensional arrays must have array "
2750  "expressions with matching dimensions")));
2751  }
2752 
2753  subdata[outer_nelems] = ARR_DATA_PTR(array);
2754  subbitmaps[outer_nelems] = ARR_NULLBITMAP(array);
2755  subbytes[outer_nelems] = ARR_SIZE(array) - ARR_DATA_OFFSET(array);
2756  nbytes += subbytes[outer_nelems];
2757  subnitems[outer_nelems] = ArrayGetNItems(this_ndims,
2758  ARR_DIMS(array));
2759  nitems += subnitems[outer_nelems];
2760  havenulls |= ARR_HASNULL(array);
2761  outer_nelems++;
2762  }
2763 
2764  /*
2765  * If all items were null or empty arrays, return an empty array;
2766  * otherwise, if some were and some weren't, raise error. (Note: we
2767  * must special-case this somehow to avoid trying to generate a 1-D
2768  * array formed from empty arrays. It's not ideal...)
2769  */
2770  if (haveempty)
2771  {
2772  if (ndims == 0) /* didn't find any nonempty array */
2773  {
2774  *op->resvalue = PointerGetDatum(construct_empty_array(element_type));
2775  return;
2776  }
2777  ereport(ERROR,
2778  (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
2779  errmsg("multidimensional arrays must have array "
2780  "expressions with matching dimensions")));
2781  }
2782 
2783  /* setup for multi-D array */
2784  dims[0] = outer_nelems;
2785  lbs[0] = 1;
2786  for (int i = 1; i < ndims; i++)
2787  {
2788  dims[i] = elem_dims[i - 1];
2789  lbs[i] = elem_lbs[i - 1];
2790  }
2791 
2792  /* check for subscript overflow */
2793  (void) ArrayGetNItems(ndims, dims);
2794  ArrayCheckBounds(ndims, dims, lbs);
2795 
2796  if (havenulls)
2797  {
2798  dataoffset = ARR_OVERHEAD_WITHNULLS(ndims, nitems);
2799  nbytes += dataoffset;
2800  }
2801  else
2802  {
2803  dataoffset = 0; /* marker for no null bitmap */
2804  nbytes += ARR_OVERHEAD_NONULLS(ndims);
2805  }
2806 
2807  result = (ArrayType *) palloc(nbytes);
2808  SET_VARSIZE(result, nbytes);
2809  result->ndim = ndims;
2810  result->dataoffset = dataoffset;
2811  result->elemtype = element_type;
2812  memcpy(ARR_DIMS(result), dims, ndims * sizeof(int));
2813  memcpy(ARR_LBOUND(result), lbs, ndims * sizeof(int));
2814 
2815  dat = ARR_DATA_PTR(result);
2816  iitem = 0;
2817  for (int i = 0; i < outer_nelems; i++)
2818  {
2819  memcpy(dat, subdata[i], subbytes[i]);
2820  dat += subbytes[i];
2821  if (havenulls)
2822  array_bitmap_copy(ARR_NULLBITMAP(result), iitem,
2823  subbitmaps[i], 0,
2824  subnitems[i]);
2825  iitem += subnitems[i];
2826  }
2827  }
2828 
2829  *op->resvalue = PointerGetDatum(result);
2830 }
#define ARR_NDIM(a)
Definition: array.h:283
#define ARR_DATA_PTR(a)
Definition: array.h:315
#define MAXDIM
Definition: array.h:75
#define ARR_NULLBITMAP(a)
Definition: array.h:293
#define ARR_OVERHEAD_WITHNULLS(ndims, nitems)
Definition: array.h:305
#define DatumGetArrayTypeP(X)
Definition: array.h:254
#define ARR_SIZE(a)
Definition: array.h:282
#define ARR_OVERHEAD_NONULLS(ndims)
Definition: array.h:303
#define ARR_DATA_OFFSET(a)
Definition: array.h:309
#define ARR_DIMS(a)
Definition: array.h:287
#define ARR_HASNULL(a)
Definition: array.h:284
#define ARR_LBOUND(a)
Definition: array.h:289
ArrayType * construct_empty_array(Oid elmtype)
Definition: arrayfuncs.c:3525
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:3439
void array_bitmap_copy(bits8 *destbitmap, int destoffset, const bits8 *srcbitmap, int srcoffset, int nitems)
Definition: arrayfuncs.c:4911
int ArrayGetNItems(int ndim, const int *dims)
Definition: arrayutils.c:76
void ArrayCheckBounds(int ndim, const int *dims, const int *lb)
Definition: arrayutils.c:128
signed int int32
Definition: c.h:430
uint8 bits8
Definition: c.h:449
int errdetail(const char *fmt,...)
Definition: elog.c:1039
int errcode(int sqlerrcode)
Definition: elog.c:695
int errmsg(const char *fmt,...)
Definition: elog.c:906
#define ERROR
Definition: elog.h:35
#define ereport(elevel,...)
Definition: elog.h:145
char * format_type_be(Oid type_oid)
Definition: format_type.c:339
void * palloc(Size size)
Definition: mcxt.c:1199
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:343
unsigned int Oid
Definition: postgres_ext.h:31
Oid elemtype
Definition: array.h:90
int ndim
Definition: array.h:88
int32 dataoffset
Definition: array.h:89
struct ExprEvalStep::@50::@68 arrayexpr

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

Referenced by ExecInterpExpr().

◆ ExecEvalConstraintCheck()

void ExecEvalConstraintCheck ( ExprState state,
ExprEvalStep op 
)

Definition at line 3641 of file execExprInterp.c.

3642 {
3643  if (!*op->d.domaincheck.checknull &&
3644  !DatumGetBool(*op->d.domaincheck.checkvalue))
3645  ereport(ERROR,
3646  (errcode(ERRCODE_CHECK_VIOLATION),
3647  errmsg("value for domain %s violates check constraint \"%s\"",
3648  format_type_be(op->d.domaincheck.resulttype),
3649  op->d.domaincheck.constraintname),
3650  errdomainconstraint(op->d.domaincheck.resulttype,
3651  op->d.domaincheck.constraintname)));
3652 }
int errdomainconstraint(Oid datatypeOid, const char *conname)
Definition: domains.c:384
static bool DatumGetBool(Datum X)
Definition: postgres.h:438
struct ExprEvalStep::@50::@78 domaincheck

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

Referenced by ExecInterpExpr().

◆ ExecEvalConstraintNotNull()

void ExecEvalConstraintNotNull ( ExprState state,
ExprEvalStep op 
)

Definition at line 3627 of file execExprInterp.c.

3628 {
3629  if (*op->resnull)
3630  ereport(ERROR,
3631  (errcode(ERRCODE_NOT_NULL_VIOLATION),
3632  errmsg("domain %s does not allow null values",
3633  format_type_be(op->d.domaincheck.resulttype)),
3634  errdatatype(op->d.domaincheck.resulttype)));
3635 }
int errdatatype(Oid datatypeOid)
Definition: domains.c:360

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

Referenced by ExecInterpExpr().

◆ ExecEvalConvertRowtype()

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

Definition at line 3147 of file execExprInterp.c.

3148 {
3149  HeapTuple result;
3150  Datum tupDatum;
3151  HeapTupleHeader tuple;
3152  HeapTupleData tmptup;
3153  TupleDesc indesc,
3154  outdesc;
3155  bool changed = false;
3156 
3157  /* NULL in -> NULL out */
3158  if (*op->resnull)
3159  return;
3160 
3161  tupDatum = *op->resvalue;
3162  tuple = DatumGetHeapTupleHeader(tupDatum);
3163 
3164  /*
3165  * Lookup tupdescs if first time through or if type changes. We'd better
3166  * pin them since type conversion functions could do catalog lookups and
3167  * hence cause cache invalidation.
3168  */
3169  indesc = get_cached_rowtype(op->d.convert_rowtype.inputtype, -1,
3170  op->d.convert_rowtype.incache,
3171  &changed);
3172  IncrTupleDescRefCount(indesc);
3173  outdesc = get_cached_rowtype(op->d.convert_rowtype.outputtype, -1,
3174  op->d.convert_rowtype.outcache,
3175  &changed);
3176  IncrTupleDescRefCount(outdesc);
3177 
3178  /*
3179  * We used to be able to assert that incoming tuples are marked with
3180  * exactly the rowtype of indesc. However, now that ExecEvalWholeRowVar
3181  * might change the tuples' marking to plain RECORD due to inserting
3182  * aliases, we can only make this weak test:
3183  */
3184  Assert(HeapTupleHeaderGetTypeId(tuple) == indesc->tdtypeid ||
3185  HeapTupleHeaderGetTypeId(tuple) == RECORDOID);
3186 
3187  /* if first time through, or after change, initialize conversion map */
3188  if (changed)
3189  {
3190  MemoryContext old_cxt;
3191 
3192  /* allocate map in long-lived memory context */
3193  old_cxt = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
3194 
3195  /* prepare map from old to new attribute numbers */
3196  op->d.convert_rowtype.map = convert_tuples_by_name(indesc, outdesc);
3197 
3198  MemoryContextSwitchTo(old_cxt);
3199  }
3200 
3201  /* Following steps need a HeapTuple not a bare HeapTupleHeader */
3202  tmptup.t_len = HeapTupleHeaderGetDatumLength(tuple);
3203  tmptup.t_data = tuple;
3204 
3205  if (op->d.convert_rowtype.map != NULL)
3206  {
3207  /* Full conversion with attribute rearrangement needed */
3208  result = execute_attr_map_tuple(&tmptup, op->d.convert_rowtype.map);
3209  /* Result already has appropriate composite-datum header fields */
3210  *op->resvalue = HeapTupleGetDatum(result);
3211  }
3212  else
3213  {
3214  /*
3215  * The tuple is physically compatible as-is, but we need to insert the
3216  * destination rowtype OID in its composite-datum header field, so we
3217  * have to copy it anyway. heap_copy_tuple_as_datum() is convenient
3218  * for this since it will both make the physical copy and insert the
3219  * correct composite header fields. Note that we aren't expecting to
3220  * have to flatten any toasted fields: the input was a composite
3221  * datum, so it shouldn't contain any. So heap_copy_tuple_as_datum()
3222  * is overkill here, but its check for external fields is cheap.
3223  */
3224  *op->resvalue = heap_copy_tuple_as_datum(&tmptup, outdesc);
3225  }
3226 
3227  DecrTupleDescRefCount(indesc);
3228  DecrTupleDescRefCount(outdesc);
3229 }
static TupleDesc get_cached_rowtype(Oid type_id, int32 typmod, ExprEvalRowtypeCache *rowcache, bool *changed)
#define DatumGetHeapTupleHeader(X)
Definition: fmgr.h:295
static Datum HeapTupleGetDatum(const HeapTupleData *tuple)
Definition: funcapi.h:230
Datum heap_copy_tuple_as_datum(HeapTuple tuple, TupleDesc tupleDesc)
Definition: heaptuple.c:984
#define HeapTupleHeaderGetTypeId(tup)
Definition: htup_details.h:452
#define HeapTupleHeaderGetDatumLength(tup)
Definition: htup_details.h:446
MemoryContext ecxt_per_query_memory
Definition: execnodes.h:254
struct ExprEvalStep::@50::@79 convert_rowtype
uint32 t_len
Definition: htup.h:64
HeapTupleHeader t_data
Definition: htup.h:68
Oid tdtypeid
Definition: tupdesc.h:82
TupleConversionMap * convert_tuples_by_name(TupleDesc indesc, TupleDesc outdesc)
Definition: tupconvert.c:102
HeapTuple execute_attr_map_tuple(HeapTuple tuple, TupleConversionMap *map)
Definition: tupconvert.c:154
void DecrTupleDescRefCount(TupleDesc tupdesc)
Definition: tupdesc.c:384
void IncrTupleDescRefCount(TupleDesc tupdesc)
Definition: tupdesc.c:366

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

Referenced by ExecInterpExpr().

◆ ExecEvalCurrentOfExpr()

void ExecEvalCurrentOfExpr ( ExprState state,
ExprEvalStep op 
)

Definition at line 2490 of file execExprInterp.c.

2491 {
2492  ereport(ERROR,
2493  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2494  errmsg("WHERE CURRENT OF is not supported for this table type")));
2495 }

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

Referenced by ExecInterpExpr().

◆ ExecEvalFieldSelect()

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

Definition at line 2952 of file execExprInterp.c.

2953 {
2954  AttrNumber fieldnum = op->d.fieldselect.fieldnum;
2955  Datum tupDatum;
2956  HeapTupleHeader tuple;
2957  Oid tupType;
2958  int32 tupTypmod;
2959  TupleDesc tupDesc;
2960  Form_pg_attribute attr;
2961  HeapTupleData tmptup;
2962 
2963  /* NULL record -> NULL result */
2964  if (*op->resnull)
2965  return;
2966 
2967  tupDatum = *op->resvalue;
2968 
2969  /* We can special-case expanded records for speed */
2971  {
2973 
2974  Assert(erh->er_magic == ER_MAGIC);
2975 
2976  /* Extract record's TupleDesc */
2977  tupDesc = expanded_record_get_tupdesc(erh);
2978 
2979  /*
2980  * Find field's attr record. Note we don't support system columns
2981  * here: a datum tuple doesn't have valid values for most of the
2982  * interesting system columns anyway.
2983  */
2984  if (fieldnum <= 0) /* should never happen */
2985  elog(ERROR, "unsupported reference to system column %d in FieldSelect",
2986  fieldnum);
2987  if (fieldnum > tupDesc->natts) /* should never happen */
2988  elog(ERROR, "attribute number %d exceeds number of columns %d",
2989  fieldnum, tupDesc->natts);
2990  attr = TupleDescAttr(tupDesc, fieldnum - 1);
2991 
2992  /* Check for dropped column, and force a NULL result if so */
2993  if (attr->attisdropped)
2994  {
2995  *op->resnull = true;
2996  return;
2997  }
2998 
2999  /* Check for type mismatch --- possible after ALTER COLUMN TYPE? */
3000  /* As in CheckVarSlotCompatibility, we should but can't check typmod */
3001  if (op->d.fieldselect.resulttype != attr->atttypid)
3002  ereport(ERROR,
3003  (errcode(ERRCODE_DATATYPE_MISMATCH),
3004  errmsg("attribute %d has wrong type", fieldnum),
3005  errdetail("Table has type %s, but query expects %s.",
3006  format_type_be(attr->atttypid),
3007  format_type_be(op->d.fieldselect.resulttype))));
3008 
3009  /* extract the field */
3010  *op->resvalue = expanded_record_get_field(erh, fieldnum,
3011  op->resnull);
3012  }
3013  else
3014  {
3015  /* Get the composite datum and extract its type fields */
3016  tuple = DatumGetHeapTupleHeader(tupDatum);
3017 
3018  tupType = HeapTupleHeaderGetTypeId(tuple);
3019  tupTypmod = HeapTupleHeaderGetTypMod(tuple);
3020 
3021  /* Lookup tupdesc if first time through or if type changes */
3022  tupDesc = get_cached_rowtype(tupType, tupTypmod,
3023  &op->d.fieldselect.rowcache, NULL);
3024 
3025  /*
3026  * Find field's attr record. Note we don't support system columns
3027  * here: a datum tuple doesn't have valid values for most of the
3028  * interesting system columns anyway.
3029  */
3030  if (fieldnum <= 0) /* should never happen */
3031  elog(ERROR, "unsupported reference to system column %d in FieldSelect",
3032  fieldnum);
3033  if (fieldnum > tupDesc->natts) /* should never happen */
3034  elog(ERROR, "attribute number %d exceeds number of columns %d",
3035  fieldnum, tupDesc->natts);
3036  attr = TupleDescAttr(tupDesc, fieldnum - 1);
3037 
3038  /* Check for dropped column, and force a NULL result if so */
3039  if (attr->attisdropped)
3040  {
3041  *op->resnull = true;
3042  return;
3043  }
3044 
3045  /* Check for type mismatch --- possible after ALTER COLUMN TYPE? */
3046  /* As in CheckVarSlotCompatibility, we should but can't check typmod */
3047  if (op->d.fieldselect.resulttype != attr->atttypid)
3048  ereport(ERROR,
3049  (errcode(ERRCODE_DATATYPE_MISMATCH),
3050  errmsg("attribute %d has wrong type", fieldnum),
3051  errdetail("Table has type %s, but query expects %s.",
3052  format_type_be(attr->atttypid),
3053  format_type_be(op->d.fieldselect.resulttype))));
3054 
3055  /* heap_getattr needs a HeapTuple not a bare HeapTupleHeader */
3056  tmptup.t_len = HeapTupleHeaderGetDatumLength(tuple);
3057  tmptup.t_data = tuple;
3058 
3059  /* extract the field */
3060  *op->resvalue = heap_getattr(&tmptup,
3061  fieldnum,
3062  tupDesc,
3063  op->resnull);
3064  }
3065 }
int16 AttrNumber
Definition: attnum.h:21
static Datum expanded_record_get_field(ExpandedRecordHeader *erh, int fnumber, bool *isnull)
#define ER_MAGIC
static TupleDesc expanded_record_get_tupdesc(ExpandedRecordHeader *erh)
static Datum heap_getattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
Definition: htup_details.h:788
#define HeapTupleHeaderGetTypMod(tup)
Definition: htup_details.h:462
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:207
#define VARATT_IS_EXTERNAL_EXPANDED(PTR)
Definition: postgres.h:336
struct ExprEvalStep::@50::@74 fieldselect
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92

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

Referenced by ExecInterpExpr().

◆ ExecEvalFieldStoreDeForm()

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

Definition at line 3077 of file execExprInterp.c.

3078 {
3079  TupleDesc tupDesc;
3080 
3081  /* Lookup tupdesc if first time through or if type changes */
3082  tupDesc = get_cached_rowtype(op->d.fieldstore.fstore->resulttype, -1,
3083  op->d.fieldstore.rowcache, NULL);
3084 
3085  /* Check that current tupdesc doesn't have more fields than we allocated */
3086  if (unlikely(tupDesc->natts > op->d.fieldstore.ncolumns))
3087  elog(ERROR, "too many columns in composite type %u",
3088  op->d.fieldstore.fstore->resulttype);
3089 
3090  if (*op->resnull)
3091  {
3092  /* Convert null input tuple into an all-nulls row */
3093  memset(op->d.fieldstore.nulls, true,
3094  op->d.fieldstore.ncolumns * sizeof(bool));
3095  }
3096  else
3097  {
3098  /*
3099  * heap_deform_tuple needs a HeapTuple not a bare HeapTupleHeader. We
3100  * set all the fields in the struct just in case.
3101  */
3102  Datum tupDatum = *op->resvalue;
3103  HeapTupleHeader tuphdr;
3104  HeapTupleData tmptup;
3105 
3106  tuphdr = DatumGetHeapTupleHeader(tupDatum);
3107  tmptup.t_len = HeapTupleHeaderGetDatumLength(tuphdr);
3108  ItemPointerSetInvalid(&(tmptup.t_self));
3109  tmptup.t_tableOid = InvalidOid;
3110  tmptup.t_data = tuphdr;
3111 
3112  heap_deform_tuple(&tmptup, tupDesc,
3113  op->d.fieldstore.values,
3114  op->d.fieldstore.nulls);
3115  }
3116 }
#define unlikely(x)
Definition: c.h:295
void heap_deform_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *values, bool *isnull)
Definition: heaptuple.c:1249
static void ItemPointerSetInvalid(ItemPointerData *pointer)
Definition: itemptr.h:184
#define InvalidOid
Definition: postgres_ext.h:36
struct ExprEvalStep::@50::@75 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 3123 of file execExprInterp.c.

3124 {
3125  TupleDesc tupDesc;
3126  HeapTuple tuple;
3127 
3128  /* Lookup tupdesc (should be valid already) */
3129  tupDesc = get_cached_rowtype(op->d.fieldstore.fstore->resulttype, -1,
3130  op->d.fieldstore.rowcache, NULL);
3131 
3132  tuple = heap_form_tuple(tupDesc,
3133  op->d.fieldstore.values,
3134  op->d.fieldstore.nulls);
3135 
3136  *op->resvalue = HeapTupleGetDatum(tuple);
3137  *op->resnull = false;
3138 }
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1020

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

Referenced by ExecInterpExpr().

◆ ExecEvalFuncExprFusage()

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

Definition at line 2362 of file execExprInterp.c.

2364 {
2365  FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
2366  PgStat_FunctionCallUsage fcusage;
2367  Datum d;
2368 
2369  pgstat_init_function_usage(fcinfo, &fcusage);
2370 
2371  fcinfo->isnull = false;
2372  d = op->d.func.fn_addr(fcinfo);
2373  *op->resvalue = d;
2374  *op->resnull = fcinfo->isnull;
2375 
2376  pgstat_end_function_usage(&fcusage, true);
2377 }
void pgstat_init_function_usage(FunctionCallInfo fcinfo, PgStat_FunctionCallUsage *fcu)
void pgstat_end_function_usage(PgStat_FunctionCallUsage *fcu, bool finalize)
struct ExprEvalStep::@50::@57 func

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

Referenced by ExecInterpExpr().

◆ ExecEvalFuncExprStrictFusage()

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

Definition at line 2383 of file execExprInterp.c.

2385 {
2386 
2387  FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
2388  PgStat_FunctionCallUsage fcusage;
2389  NullableDatum *args = fcinfo->args;
2390  int nargs = op->d.func.nargs;
2391  Datum d;
2392 
2393  /* strict function, so check for NULL args */
2394  for (int argno = 0; argno < nargs; argno++)
2395  {
2396  if (args[argno].isnull)
2397  {
2398  *op->resnull = true;
2399  return;
2400  }
2401  }
2402 
2403  pgstat_init_function_usage(fcinfo, &fcusage);
2404 
2405  fcinfo->isnull = false;
2406  d = op->d.func.fn_addr(fcinfo);
2407  *op->resvalue = d;
2408  *op->resnull = fcinfo->isnull;
2409 
2410  pgstat_end_function_usage(&fcusage, true);
2411 }

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

3881 {
3882  AggState *aggstate = castNode(AggState, state->parent);
3883  int result = 0;
3884  Bitmapset *grouped_cols = aggstate->grouped_cols;
3885  ListCell *lc;
3886 
3887  foreach(lc, op->d.grouping_func.clauses)
3888  {
3889  int attnum = lfirst_int(lc);
3890 
3891  result <<= 1;
3892 
3893  if (!bms_is_member(attnum, grouped_cols))
3894  result |= 1;
3895  }
3896 
3897  *op->resvalue = Int32GetDatum(result);
3898  *op->resnull = false;
3899 }
bool bms_is_member(int x, const Bitmapset *a)
Definition: bitmapset.c:428
#define castNode(_type_, nodeptr)
Definition: nodes.h:186
#define lfirst_int(lc)
Definition: pg_list.h:171
static Datum Int32GetDatum(int32 X)
Definition: postgres.h:560
Bitmapset * grouped_cols
Definition: execnodes.h:2382
struct ExprEvalStep::@50::@84 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 3445 of file execExprInterp.c.

3446 {
3447  ScalarArrayOpExprHashTable *elements_tab = op->d.hashedscalararrayop.elements_tab;
3448  FunctionCallInfo fcinfo = op->d.hashedscalararrayop.fcinfo_data;
3449  bool inclause = op->d.hashedscalararrayop.inclause;
3450  bool strictfunc = op->d.hashedscalararrayop.finfo->fn_strict;
3451  Datum scalar = fcinfo->args[0].value;
3452  bool scalar_isnull = fcinfo->args[0].isnull;
3453  Datum result;
3454  bool resultnull;
3455  bool hashfound;
3456 
3457  /* We don't setup a hashed scalar array op if the array const is null. */
3458  Assert(!*op->resnull);
3459 
3460  /*
3461  * If the scalar is NULL, and the function is strict, return NULL; no
3462  * point in executing the search.
3463  */
3464  if (fcinfo->args[0].isnull && strictfunc)
3465  {
3466  *op->resnull = true;
3467  return;
3468  }
3469 
3470  /* Build the hash table on first evaluation */
3471  if (elements_tab == NULL)
3472  {
3473  ScalarArrayOpExpr *saop;
3474  int16 typlen;
3475  bool typbyval;
3476  char typalign;
3477  int nitems;
3478  bool has_nulls = false;
3479  char *s;
3480  bits8 *bitmap;
3481  int bitmask;
3482  MemoryContext oldcontext;
3483  ArrayType *arr;
3484 
3485  saop = op->d.hashedscalararrayop.saop;
3486 
3487  arr = DatumGetArrayTypeP(*op->resvalue);
3488  nitems = ArrayGetNItems(ARR_NDIM(arr), ARR_DIMS(arr));
3489 
3491  &typlen,
3492  &typbyval,
3493  &typalign);
3494 
3495  oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
3496 
3497  elements_tab = (ScalarArrayOpExprHashTable *)
3498  palloc0(offsetof(ScalarArrayOpExprHashTable, hash_fcinfo_data) +
3500  op->d.hashedscalararrayop.elements_tab = elements_tab;
3501  elements_tab->op = op;
3502 
3503  fmgr_info(saop->hashfuncid, &elements_tab->hash_finfo);
3504  fmgr_info_set_expr((Node *) saop, &elements_tab->hash_finfo);
3505 
3507  &elements_tab->hash_finfo,
3508  1,
3509  saop->inputcollid,
3510  NULL,
3511  NULL);
3512 
3513  /*
3514  * Create the hash table sizing it according to the number of elements
3515  * in the array. This does assume that the array has no duplicates.
3516  * If the array happens to contain many duplicate values then it'll
3517  * just mean that we sized the table a bit on the large side.
3518  */
3519  elements_tab->hashtab = saophash_create(CurrentMemoryContext, nitems,
3520  elements_tab);
3521 
3522  MemoryContextSwitchTo(oldcontext);
3523 
3524  s = (char *) ARR_DATA_PTR(arr);
3525  bitmap = ARR_NULLBITMAP(arr);
3526  bitmask = 1;
3527  for (int i = 0; i < nitems; i++)
3528  {
3529  /* Get array element, checking for NULL. */
3530  if (bitmap && (*bitmap & bitmask) == 0)
3531  {
3532  has_nulls = true;
3533  }
3534  else
3535  {
3536  Datum element;
3537 
3538  element = fetch_att(s, typbyval, typlen);
3539  s = att_addlength_pointer(s, typlen, s);
3540  s = (char *) att_align_nominal(s, typalign);
3541 
3542  saophash_insert(elements_tab->hashtab, element, &hashfound);
3543  }
3544 
3545  /* Advance bitmap pointer if any. */
3546  if (bitmap)
3547  {
3548  bitmask <<= 1;
3549  if (bitmask == 0x100)
3550  {
3551  bitmap++;
3552  bitmask = 1;
3553  }
3554  }
3555  }
3556 
3557  /*
3558  * Remember if we had any nulls so that we know if we need to execute
3559  * non-strict functions with a null lhs value if no match is found.
3560  */
3561  op->d.hashedscalararrayop.has_nulls = has_nulls;
3562  }
3563 
3564  /* Check the hash to see if we have a match. */
3565  hashfound = NULL != saophash_lookup(elements_tab->hashtab, scalar);
3566 
3567  /* the result depends on if the clause is an IN or NOT IN clause */
3568  if (inclause)
3569  result = BoolGetDatum(hashfound); /* IN */
3570  else
3571  result = BoolGetDatum(!hashfound); /* NOT IN */
3572 
3573  resultnull = false;
3574 
3575  /*
3576  * If we didn't find a match in the array, we still might need to handle
3577  * the possibility of null values. We didn't put any NULLs into the
3578  * hashtable, but instead marked if we found any when building the table
3579  * in has_nulls.
3580  */
3581  if (!hashfound && op->d.hashedscalararrayop.has_nulls)
3582  {
3583  if (strictfunc)
3584  {
3585 
3586  /*
3587  * We have nulls in the array so a non-null lhs and no match must
3588  * yield NULL.
3589  */
3590  result = (Datum) 0;
3591  resultnull = true;
3592  }
3593  else
3594  {
3595  /*
3596  * Execute function will null rhs just once.
3597  *
3598  * The hash lookup path will have scribbled on the lhs argument so
3599  * we need to set it up also (even though we entered this function
3600  * with it already set).
3601  */
3602  fcinfo->args[0].value = scalar;
3603  fcinfo->args[0].isnull = scalar_isnull;
3604  fcinfo->args[1].value = (Datum) 0;
3605  fcinfo->args[1].isnull = true;
3606 
3607  result = op->d.hashedscalararrayop.finfo->fn_addr(fcinfo);
3608  resultnull = fcinfo->isnull;
3609 
3610  /*
3611  * Reverse the result for NOT IN clauses since the above function
3612  * is the equality function and we need not-equals.
3613  */
3614  if (!inclause)
3615  result = !result;
3616  }
3617  }
3618 
3619  *op->resvalue = result;
3620  *op->resnull = resultnull;
3621 }
signed short int16
Definition: c.h:429
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:126
#define SizeForFunctionCallInfo(nargs)
Definition: fmgr.h:102
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#define fmgr_info_set_expr(expr, finfo)
Definition: fmgr.h:135
void get_typlenbyvalalign(Oid typid, int16 *typlen, bool *typbyval, char *typalign)
Definition: lsyscache.c:2229
void * palloc0(Size size)
Definition: mcxt.c:1230
char typalign
Definition: pg_type.h:176
static Datum BoolGetDatum(bool X)
Definition: postgres.h:450
static chr element(struct vars *v, const chr *startp, const chr *endp)
Definition: regc_locale.c:376
struct ExprEvalStep::@50::@81 hashedscalararrayop
Definition: nodes.h:118
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, ScalarArrayOpExpr::inputcollid, FunctionCallInfoBaseData::isnull, NullableDatum::isnull, MemoryContextSwitchTo(), ScalarArrayOpExprHashTable::op, ExprEvalStep::op, palloc0(), ExprEvalStep::saop, SizeForFunctionCallInfo, typalign, ExprEvalStep::typbyval, ExprEvalStep::typlen, and NullableDatum::value.

Referenced by ExecInterpExpr().

◆ ExecEvalMinMax()

void ExecEvalMinMax ( ExprState state,
ExprEvalStep op 
)

Definition at line 2899 of file execExprInterp.c.

2900 {
2901  Datum *values = op->d.minmax.values;
2902  bool *nulls = op->d.minmax.nulls;
2903  FunctionCallInfo fcinfo = op->d.minmax.fcinfo_data;
2904  MinMaxOp operator = op->d.minmax.op;
2905 
2906  /* set at initialization */
2907  Assert(fcinfo->args[0].isnull == false);
2908  Assert(fcinfo->args[1].isnull == false);
2909 
2910  /* default to null result */
2911  *op->resnull = true;
2912 
2913  for (int off = 0; off < op->d.minmax.nelems; off++)
2914  {
2915  /* ignore NULL inputs */
2916  if (nulls[off])
2917  continue;
2918 
2919  if (*op->resnull)
2920  {
2921  /* first nonnull input, adopt value */
2922  *op->resvalue = values[off];
2923  *op->resnull = false;
2924  }
2925  else
2926  {
2927  int cmpresult;
2928 
2929  /* apply comparison function */
2930  fcinfo->args[0].value = *op->resvalue;
2931  fcinfo->args[1].value = values[off];
2932 
2933  fcinfo->isnull = false;
2934  cmpresult = DatumGetInt32(FunctionCallInvoke(fcinfo));
2935  if (fcinfo->isnull) /* probably should not happen */
2936  continue;
2937 
2938  if (cmpresult > 0 && operator == IS_LEAST)
2939  *op->resvalue = values[off];
2940  else if (cmpresult < 0 && operator == IS_GREATEST)
2941  *op->resvalue = values[off];
2942  }
2943  }
2944 }
static Datum values[MAXATTR]
Definition: bootstrap.c:156
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:172
static int32 DatumGetInt32(Datum X)
Definition: postgres.h:550
MinMaxOp
Definition: primnodes.h:1279
@ IS_LEAST
Definition: primnodes.h:1281
@ IS_GREATEST
Definition: primnodes.h:1280
struct ExprEvalStep::@50::@73 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 2501 of file execExprInterp.c.

2502 {
2503  int64 newval = nextval_internal(op->d.nextvalueexpr.seqid, false);
2504 
2505  switch (op->d.nextvalueexpr.seqtypid)
2506  {
2507  case INT2OID:
2508  *op->resvalue = Int16GetDatum((int16) newval);
2509  break;
2510  case INT4OID:
2511  *op->resvalue = Int32GetDatum((int32) newval);
2512  break;
2513  case INT8OID:
2514  *op->resvalue = Int64GetDatum((int64) newval);
2515  break;
2516  default:
2517  elog(ERROR, "unsupported sequence type %u",
2518  op->d.nextvalueexpr.seqtypid);
2519  }
2520  *op->resnull = false;
2521 }
Datum Int64GetDatum(int64 X)
Definition: fmgr.c:1683
#define newval
static Datum Int16GetDatum(int16 X)
Definition: postgres.h:520
int64 nextval_internal(Oid relid, bool check_permissions)
Definition: sequence.c:629
struct ExprEvalStep::@50::@67 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 2420 of file execExprInterp.c.

2421 {
2422  ParamExecData *prm;
2423 
2424  prm = &(econtext->ecxt_param_exec_vals[op->d.param.paramid]);
2425  if (unlikely(prm->execPlan != NULL))
2426  {
2427  /* Parameter not evaluated yet, so go do it */
2428  ExecSetParamPlan(prm->execPlan, econtext);
2429  /* ExecSetParamPlan should have processed this param... */
2430  Assert(prm->execPlan == NULL);
2431  }
2432  *op->resvalue = prm->value;
2433  *op->resnull = prm->isnull;
2434 }
void ExecSetParamPlan(SubPlanState *node, ExprContext *econtext)
Definition: nodeSubplan.c:1073
ParamExecData * ecxt_param_exec_vals
Definition: execnodes.h:258
struct ExprEvalStep::@50::@62 param
bool isnull
Definition: params.h:150
Datum value
Definition: params.h:149
void * execPlan
Definition: params.h:148

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

Referenced by ExecInterpExpr().

◆ ExecEvalParamExtern()

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

Definition at line 2442 of file execExprInterp.c.

2443 {
2444  ParamListInfo paramInfo = econtext->ecxt_param_list_info;
2445  int paramId = op->d.param.paramid;
2446 
2447  if (likely(paramInfo &&
2448  paramId > 0 && paramId <= paramInfo->numParams))
2449  {
2450  ParamExternData *prm;
2451  ParamExternData prmdata;
2452 
2453  /* give hook a chance in case parameter is dynamic */
2454  if (paramInfo->paramFetch != NULL)
2455  prm = paramInfo->paramFetch(paramInfo, paramId, false, &prmdata);
2456  else
2457  prm = &paramInfo->params[paramId - 1];
2458 
2459  if (likely(OidIsValid(prm->ptype)))
2460  {
2461  /* safety check in case hook did something unexpected */
2462  if (unlikely(prm->ptype != op->d.param.paramtype))
2463  ereport(ERROR,
2464  (errcode(ERRCODE_DATATYPE_MISMATCH),
2465  errmsg("type of parameter %d (%s) does not match that when preparing the plan (%s)",
2466  paramId,
2467  format_type_be(prm->ptype),
2468  format_type_be(op->d.param.paramtype))));
2469  *op->resvalue = prm->value;
2470  *op->resnull = prm->isnull;
2471  return;
2472  }
2473  }
2474 
2475  ereport(ERROR,
2476  (errcode(ERRCODE_UNDEFINED_OBJECT),
2477  errmsg("no value found for parameter %d", paramId)));
2478 }
#define likely(x)
Definition: c.h:294
#define OidIsValid(objectId)
Definition: c.h:711
ParamListInfo ecxt_param_list_info
Definition: execnodes.h:259
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 4287 of file execExprInterp.c.

4288 {
4289  ExprContext *tmpcontext = aggstate->tmpcontext;
4290 
4291  for (int i = 0; i < pertrans->numTransInputs; i++)
4292  {
4293  pertrans->sortslot->tts_values[i] = pertrans->transfn_fcinfo->args[i + 1].value;
4294  pertrans->sortslot->tts_isnull[i] = pertrans->transfn_fcinfo->args[i + 1].isnull;
4295  }
4296 
4297  ExecClearTuple(pertrans->sortslot);
4298  pertrans->sortslot->tts_nvalid = pertrans->numInputs;
4299  ExecStoreVirtualTuple(pertrans->sortslot);
4300 
4301  tmpcontext->ecxt_outertuple = pertrans->sortslot;
4302  tmpcontext->ecxt_innertuple = pertrans->uniqslot;
4303 
4304  if (!pertrans->haslast ||
4305  !ExecQual(pertrans->equalfnMulti, tmpcontext))
4306  {
4307  if (pertrans->haslast)
4308  ExecClearTuple(pertrans->uniqslot);
4309 
4310  pertrans->haslast = true;
4311  ExecCopySlot(pertrans->uniqslot, pertrans->sortslot);
4312  return true;
4313  }
4314  return false;
4315 }
static bool ExecQual(ExprState *state, ExprContext *econtext)
Definition: executor.h:398
ExprState * equalfnMulti
Definition: nodeAgg.h:116
TupleTableSlot * uniqslot
Definition: nodeAgg.h:142
ExprContext * tmpcontext
Definition: execnodes.h:2371
bool * tts_isnull
Definition: tuptable.h:128
Datum * tts_values
Definition: tuptable.h:126
static TupleTableSlot * ExecCopySlot(TupleTableSlot *dstslot, TupleTableSlot *srcslot)
Definition: tuptable.h:483

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

Referenced by ExecInterpExpr().

◆ ExecEvalPreOrderedDistinctSingle()

bool ExecEvalPreOrderedDistinctSingle ( AggState aggstate,
AggStatePerTrans  pertrans 
)

Definition at line 4246 of file execExprInterp.c.

4247 {
4248  Datum value = pertrans->transfn_fcinfo->args[1].value;
4249  bool isnull = pertrans->transfn_fcinfo->args[1].isnull;
4250 
4251  if (!pertrans->haslast ||
4252  pertrans->lastisnull != isnull ||
4254  pertrans->aggCollation,
4255  pertrans->lastdatum, value)))
4256  {
4257  if (pertrans->haslast && !pertrans->inputtypeByVal)
4258  pfree(DatumGetPointer(pertrans->lastdatum));
4259 
4260  pertrans->haslast = true;
4261  if (!isnull)
4262  {
4263  MemoryContext oldContext;
4264 
4266 
4267  pertrans->lastdatum = datumCopy(value, pertrans->inputtypeByVal,
4268  pertrans->inputtypeLen);
4269 
4270  MemoryContextSwitchTo(oldContext);
4271  }
4272  else
4273  pertrans->lastdatum = (Datum) 0;
4274  pertrans->lastisnull = isnull;
4275  return true;
4276  }
4277 
4278  return false;
4279 }
Datum FunctionCall2Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2)
Definition: fmgr.c:1134
static struct @143 value
FmgrInfo equalfnOne
Definition: nodeAgg.h:115

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

Referenced by ExecInterpExpr().

◆ ExecEvalRow()

void ExecEvalRow ( ExprState state,
ExprEvalStep op 
)

Definition at line 2879 of file execExprInterp.c.

2880 {
2881  HeapTuple tuple;
2882 
2883  /* build tuple from evaluated field values */
2884  tuple = heap_form_tuple(op->d.row.tupdesc,
2885  op->d.row.elemvalues,
2886  op->d.row.elemnulls);
2887 
2888  *op->resvalue = HeapTupleGetDatum(tuple);
2889  *op->resnull = false;
2890 }
struct ExprEvalStep::@50::@70 row

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

Referenced by ExecInterpExpr().

◆ ExecEvalRowNotNull()

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

Definition at line 2536 of file execExprInterp.c.

2537 {
2538  ExecEvalRowNullInt(state, op, econtext, false);
2539 }
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 2527 of file execExprInterp.c.

2528 {
2529  ExecEvalRowNullInt(state, op, econtext, true);
2530 }

References ExecEvalRowNullInt(), and ExprEvalStep::op.

Referenced by ExecInterpExpr().

◆ ExecEvalScalarArrayOp()

void ExecEvalScalarArrayOp ( ExprState state,
ExprEvalStep op 
)

Definition at line 3242 of file execExprInterp.c.

3243 {
3244  FunctionCallInfo fcinfo = op->d.scalararrayop.fcinfo_data;
3245  bool useOr = op->d.scalararrayop.useOr;
3246  bool strictfunc = op->d.scalararrayop.finfo->fn_strict;
3247  ArrayType *arr;
3248  int nitems;
3249  Datum result;
3250  bool resultnull;
3251  int16 typlen;
3252  bool typbyval;
3253  char typalign;
3254  char *s;
3255  bits8 *bitmap;
3256  int bitmask;
3257 
3258  /*
3259  * If the array is NULL then we return NULL --- it's not very meaningful
3260  * to do anything else, even if the operator isn't strict.
3261  */
3262  if (*op->resnull)
3263  return;
3264 
3265  /* Else okay to fetch and detoast the array */
3266  arr = DatumGetArrayTypeP(*op->resvalue);
3267 
3268  /*
3269  * If the array is empty, we return either FALSE or TRUE per the useOr
3270  * flag. This is correct even if the scalar is NULL; since we would
3271  * evaluate the operator zero times, it matters not whether it would want
3272  * to return NULL.
3273  */
3274  nitems = ArrayGetNItems(ARR_NDIM(arr), ARR_DIMS(arr));
3275  if (nitems <= 0)
3276  {
3277  *op->resvalue = BoolGetDatum(!useOr);
3278  *op->resnull = false;
3279  return;
3280  }
3281 
3282  /*
3283  * If the scalar is NULL, and the function is strict, return NULL; no
3284  * point in iterating the loop.
3285  */
3286  if (fcinfo->args[0].isnull && strictfunc)
3287  {
3288  *op->resnull = true;
3289  return;
3290  }
3291 
3292  /*
3293  * We arrange to look up info about the element type only once per series
3294  * of calls, assuming the element type doesn't change underneath us.
3295  */
3296  if (op->d.scalararrayop.element_type != ARR_ELEMTYPE(arr))
3297  {
3299  &op->d.scalararrayop.typlen,
3300  &op->d.scalararrayop.typbyval,
3301  &op->d.scalararrayop.typalign);
3302  op->d.scalararrayop.element_type = ARR_ELEMTYPE(arr);
3303  }
3304 
3305  typlen = op->d.scalararrayop.typlen;
3306  typbyval = op->d.scalararrayop.typbyval;
3307  typalign = op->d.scalararrayop.typalign;
3308 
3309  /* Initialize result appropriately depending on useOr */
3310  result = BoolGetDatum(!useOr);
3311  resultnull = false;
3312 
3313  /* Loop over the array elements */
3314  s = (char *) ARR_DATA_PTR(arr);
3315  bitmap = ARR_NULLBITMAP(arr);
3316  bitmask = 1;
3317 
3318  for (int i = 0; i < nitems; i++)
3319  {
3320  Datum elt;
3321  Datum thisresult;
3322 
3323  /* Get array element, checking for NULL */
3324  if (bitmap && (*bitmap & bitmask) == 0)
3325  {
3326  fcinfo->args[1].value = (Datum) 0;
3327  fcinfo->args[1].isnull = true;
3328  }
3329  else
3330  {
3331  elt = fetch_att(s, typbyval, typlen);
3332  s = att_addlength_pointer(s, typlen, s);
3333  s = (char *) att_align_nominal(s, typalign);
3334  fcinfo->args[1].value = elt;
3335  fcinfo->args[1].isnull = false;
3336  }
3337 
3338  /* Call comparison function */
3339  if (fcinfo->args[1].isnull && strictfunc)
3340  {
3341  fcinfo->isnull = true;
3342  thisresult = (Datum) 0;
3343  }
3344  else
3345  {
3346  fcinfo->isnull = false;
3347  thisresult = op->d.scalararrayop.fn_addr(fcinfo);
3348  }
3349 
3350  /* Combine results per OR or AND semantics */
3351  if (fcinfo->isnull)
3352  resultnull = true;
3353  else if (useOr)
3354  {
3355  if (DatumGetBool(thisresult))
3356  {
3357  result = BoolGetDatum(true);
3358  resultnull = false;
3359  break; /* needn't look at any more elements */
3360  }
3361  }
3362  else
3363  {
3364  if (!DatumGetBool(thisresult))
3365  {
3366  result = BoolGetDatum(false);
3367  resultnull = false;
3368  break; /* needn't look at any more elements */
3369  }
3370  }
3371 
3372  /* advance bitmap pointer if any */
3373  if (bitmap)
3374  {
3375  bitmask <<= 1;
3376  if (bitmask == 0x100)
3377  {
3378  bitmap++;
3379  bitmask = 1;
3380  }
3381  }
3382  }
3383 
3384  *op->resvalue = result;
3385  *op->resnull = resultnull;
3386 }
struct ExprEvalStep::@50::@80 scalararrayop

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

Referenced by ExecInterpExpr().

◆ ExecEvalStepOp()

ExprEvalOp ExecEvalStepOp ( ExprState state,
ExprEvalStep op 
)

Definition at line 2332 of file execExprInterp.c.

2333 {
2334 #if defined(EEO_USE_COMPUTED_GOTO)
2335  if (state->flags & EEO_FLAG_DIRECT_THREADED)
2336  {
2337  ExprEvalOpLookup key;
2338  ExprEvalOpLookup *res;
2339 
2340  key.opcode = (void *) op->opcode;
2341  res = bsearch(&key,
2342  reverse_dispatch_table,
2343  EEOP_LAST /* nmembers */ ,
2344  sizeof(ExprEvalOpLookup),
2345  dispatch_compare_ptr);
2346  Assert(res); /* unknown ops shouldn't get looked up */
2347  return res->op;
2348  }
2349 #endif
2350  return (ExprEvalOp) op->opcode;
2351 }
#define EEO_FLAG_DIRECT_THREADED
Definition: execExpr.h:29
intptr_t opcode
Definition: execExpr.h:271

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

3906 {
3907  SubPlanState *sstate = op->d.subplan.sstate;
3908 
3909  /* could potentially be nested, so make sure there's enough stack */
3911 
3912  *op->resvalue = ExecSubPlan(sstate, econtext, op->resnull);
3913 }
Datum ExecSubPlan(SubPlanState *node, ExprContext *econtext, bool *isNull)
Definition: nodeSubplan.c:62
void check_stack_depth(void)
Definition: postgres.c:3440
struct ExprEvalStep::@50::@86 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 4149 of file execExprInterp.c.

4151 {
4152  Datum d;
4153 
4154  /* slot_getsysattr has sufficient defenses against bad attnums */
4155  d = slot_getsysattr(slot,
4156  op->d.var.attnum,
4157  op->resnull);
4158  *op->resvalue = d;
4159  /* this ought to be unreachable, but it's cheap enough to check */
4160  if (unlikely(*op->resnull))
4161  elog(ERROR, "failed to fetch attribute from slot");
4162 }
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 3922 of file execExprInterp.c.

3923 {
3924  Var *variable = op->d.wholerow.var;
3925  TupleTableSlot *slot;
3926  TupleDesc output_tupdesc;
3927  MemoryContext oldcontext;
3928  HeapTupleHeader dtuple;
3929  HeapTuple tuple;
3930 
3931  /* This was checked by ExecInitExpr */
3932  Assert(variable->varattno == InvalidAttrNumber);
3933 
3934  /* Get the input slot we want */
3935  switch (variable->varno)
3936  {
3937  case INNER_VAR:
3938  /* get the tuple from the inner node */
3939  slot = econtext->ecxt_innertuple;
3940  break;
3941 
3942  case OUTER_VAR:
3943  /* get the tuple from the outer node */
3944  slot = econtext->ecxt_outertuple;
3945  break;
3946 
3947  /* INDEX_VAR is handled by default case */
3948 
3949  default:
3950  /* get the tuple from the relation being scanned */
3951  slot = econtext->ecxt_scantuple;
3952  break;
3953  }
3954 
3955  /* Apply the junkfilter if any */
3956  if (op->d.wholerow.junkFilter != NULL)
3957  slot = ExecFilterJunk(op->d.wholerow.junkFilter, slot);
3958 
3959  /*
3960  * If first time through, obtain tuple descriptor and check compatibility.
3961  *
3962  * XXX: It'd be great if this could be moved to the expression
3963  * initialization phase, but due to using slots that's currently not
3964  * feasible.
3965  */
3966  if (op->d.wholerow.first)
3967  {
3968  /* optimistically assume we don't need slow path */
3969  op->d.wholerow.slow = false;
3970 
3971  /*
3972  * If the Var identifies a named composite type, we must check that
3973  * the actual tuple type is compatible with it.
3974  */
3975  if (variable->vartype != RECORDOID)
3976  {
3977  TupleDesc var_tupdesc;
3978  TupleDesc slot_tupdesc;
3979 
3980  /*
3981  * We really only care about numbers of attributes and data types.
3982  * Also, we can ignore type mismatch on columns that are dropped
3983  * in the destination type, so long as (1) the physical storage
3984  * matches or (2) the actual column value is NULL. Case (1) is
3985  * helpful in some cases involving out-of-date cached plans, while
3986  * case (2) is expected behavior in situations such as an INSERT
3987  * into a table with dropped columns (the planner typically
3988  * generates an INT4 NULL regardless of the dropped column type).
3989  * If we find a dropped column and cannot verify that case (1)
3990  * holds, we have to use the slow path to check (2) for each row.
3991  *
3992  * If vartype is a domain over composite, just look through that
3993  * to the base composite type.
3994  */
3995  var_tupdesc = lookup_rowtype_tupdesc_domain(variable->vartype,
3996  -1, false);
3997 
3998  slot_tupdesc = slot->tts_tupleDescriptor;
3999 
4000  if (var_tupdesc->natts != slot_tupdesc->natts)
4001  ereport(ERROR,
4002  (errcode(ERRCODE_DATATYPE_MISMATCH),
4003  errmsg("table row type and query-specified row type do not match"),
4004  errdetail_plural("Table row contains %d attribute, but query expects %d.",
4005  "Table row contains %d attributes, but query expects %d.",
4006  slot_tupdesc->natts,
4007  slot_tupdesc->natts,
4008  var_tupdesc->natts)));
4009 
4010  for (int i = 0; i < var_tupdesc->natts; i++)
4011  {
4012  Form_pg_attribute vattr = TupleDescAttr(var_tupdesc, i);
4013  Form_pg_attribute sattr = TupleDescAttr(slot_tupdesc, i);
4014 
4015  if (vattr->atttypid == sattr->atttypid)
4016  continue; /* no worries */
4017  if (!vattr->attisdropped)
4018  ereport(ERROR,
4019  (errcode(ERRCODE_DATATYPE_MISMATCH),
4020  errmsg("table row type and query-specified row type do not match"),
4021  errdetail("Table has type %s at ordinal position %d, but query expects %s.",
4022  format_type_be(sattr->atttypid),
4023  i + 1,
4024  format_type_be(vattr->atttypid))));
4025 
4026  if (vattr->attlen != sattr->attlen ||
4027  vattr->attalign != sattr->attalign)
4028  op->d.wholerow.slow = true; /* need to check for nulls */
4029  }
4030 
4031  /*
4032  * Use the variable's declared rowtype as the descriptor for the
4033  * output values. In particular, we *must* absorb any
4034  * attisdropped markings.
4035  */
4036  oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
4037  output_tupdesc = CreateTupleDescCopy(var_tupdesc);
4038  MemoryContextSwitchTo(oldcontext);
4039 
4040  ReleaseTupleDesc(var_tupdesc);
4041  }
4042  else
4043  {
4044  /*
4045  * In the RECORD case, we use the input slot's rowtype as the
4046  * descriptor for the output values, modulo possibly assigning new
4047  * column names below.
4048  */
4049  oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
4050  output_tupdesc = CreateTupleDescCopy(slot->tts_tupleDescriptor);
4051  MemoryContextSwitchTo(oldcontext);
4052 
4053  /*
4054  * It's possible that the input slot is a relation scan slot and
4055  * so is marked with that relation's rowtype. But we're supposed
4056  * to be returning RECORD, so reset to that.
4057  */
4058  output_tupdesc->tdtypeid = RECORDOID;
4059  output_tupdesc->tdtypmod = -1;
4060 
4061  /*
4062  * We already got the correct physical datatype info above, but
4063  * now we should try to find the source RTE and adopt its column
4064  * aliases, since it's unlikely that the input slot has the
4065  * desired names.
4066  *
4067  * If we can't locate the RTE, assume the column names we've got
4068  * are OK. (As of this writing, the only cases where we can't
4069  * locate the RTE are in execution of trigger WHEN clauses, and
4070  * then the Var will have the trigger's relation's rowtype, so its
4071  * names are fine.) Also, if the creator of the RTE didn't bother
4072  * to fill in an eref field, assume our column names are OK. (This
4073  * happens in COPY, and perhaps other places.)
4074  */
4075  if (econtext->ecxt_estate &&
4076  variable->varno <= econtext->ecxt_estate->es_range_table_size)
4077  {
4078  RangeTblEntry *rte = exec_rt_fetch(variable->varno,
4079  econtext->ecxt_estate);
4080 
4081  if (rte->eref)
4082  ExecTypeSetColNames(output_tupdesc, rte->eref->colnames);
4083  }
4084  }
4085 
4086  /* Bless the tupdesc if needed, and save it in the execution state */
4087  op->d.wholerow.tupdesc = BlessTupleDesc(output_tupdesc);
4088 
4089  op->d.wholerow.first = false;
4090  }
4091 
4092  /*
4093  * Make sure all columns of the slot are accessible in the slot's
4094  * Datum/isnull arrays.
4095  */
4096  slot_getallattrs(slot);
4097 
4098  if (op->d.wholerow.slow)
4099  {
4100  /* Check to see if any dropped attributes are non-null */
4101  TupleDesc tupleDesc = slot->tts_tupleDescriptor;
4102  TupleDesc var_tupdesc = op->d.wholerow.tupdesc;
4103 
4104  Assert(var_tupdesc->natts == tupleDesc->natts);
4105 
4106  for (int i = 0; i < var_tupdesc->natts; i++)
4107  {
4108  Form_pg_attribute vattr = TupleDescAttr(var_tupdesc, i);
4109  Form_pg_attribute sattr = TupleDescAttr(tupleDesc, i);
4110 
4111  if (!vattr->attisdropped)
4112  continue; /* already checked non-dropped cols */
4113  if (slot->tts_isnull[i])
4114  continue; /* null is always okay */
4115  if (vattr->attlen != sattr->attlen ||
4116  vattr->attalign != sattr->attalign)
4117  ereport(ERROR,
4118  (errcode(ERRCODE_DATATYPE_MISMATCH),
4119  errmsg("table row type and query-specified row type do not match"),
4120  errdetail("Physical storage mismatch on dropped attribute at ordinal position %d.",
4121  i + 1)));
4122  }
4123  }
4124 
4125  /*
4126  * Build a composite datum, making sure any toasted fields get detoasted.
4127  *
4128  * (Note: it is critical that we not change the slot's state here.)
4129  */
4131  slot->tts_values,
4132  slot->tts_isnull);
4133  dtuple = tuple->t_data;
4134 
4135  /*
4136  * Label the datum with the composite type info we identified before.
4137  *
4138  * (Note: we could skip doing this by passing op->d.wholerow.tupdesc to
4139  * the tuple build step; but that seems a tad risky so let's not.)
4140  */
4141  HeapTupleHeaderSetTypeId(dtuple, op->d.wholerow.tupdesc->tdtypeid);
4142  HeapTupleHeaderSetTypMod(dtuple, op->d.wholerow.tupdesc->tdtypmod);
4143 
4144  *op->resvalue = PointerGetDatum(dtuple);
4145  *op->resnull = false;
4146 }
#define InvalidAttrNumber
Definition: attnum.h:23
int errdetail_plural(const char *fmt_singular, const char *fmt_plural, unsigned long n,...)
Definition: elog.c:1131
TupleTableSlot * ExecFilterJunk(JunkFilter *junkfilter, TupleTableSlot *slot)
Definition: execJunk.c:247
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:2071
void ExecTypeSetColNames(TupleDesc typeInfo, List *namesList)
Definition: execTuples.c:2030
static RangeTblEntry * exec_rt_fetch(Index rti, EState *estate)
Definition: executor.h:573
HeapTuple toast_build_flattened_tuple(TupleDesc tupleDesc, Datum *values, bool *isnull)
Definition: heaptoast.c:563
#define HeapTupleHeaderSetTypMod(tup, typmod)
Definition: htup_details.h:467
#define HeapTupleHeaderSetTypeId(tup, typeid)
Definition: htup_details.h:457
#define OUTER_VAR
Definition: primnodes.h:194
#define INNER_VAR
Definition: primnodes.h:193
List * colnames
Definition: primnodes.h:43
Index es_range_table_size
Definition: execnodes.h:615
struct EState * ecxt_estate
Definition: execnodes.h:283
struct ExprEvalStep::@50::@53 wholerow
Alias * eref
Definition: parsenodes.h:1176
int32 tdtypmod
Definition: tupdesc.h:83
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
Definition: primnodes.h:205
TupleDesc CreateTupleDescCopy(TupleDesc tupdesc)
Definition: tupdesc.c:111
#define ReleaseTupleDesc(tupdesc)
Definition: tupdesc.h:122
static void slot_getallattrs(TupleTableSlot *slot)
Definition: tuptable.h:362
TupleDesc lookup_rowtype_tupdesc_domain(Oid type_id, int32 typmod, bool noError)
Definition: typcache.c:1880

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

Referenced by ExecInterpExpr().

◆ ExecEvalXmlExpr()

void ExecEvalXmlExpr ( ExprState state,
ExprEvalStep op 
)

Definition at line 3661 of file execExprInterp.c.

3662 {
3663  XmlExpr *xexpr = op->d.xmlexpr.xexpr;
3664  Datum value;
3665 
3666  *op->resnull = true; /* until we get a result */
3667  *op->resvalue = (Datum) 0;
3668 
3669  switch (xexpr->op)
3670  {
3671  case IS_XMLCONCAT:
3672  {
3673  Datum *argvalue = op->d.xmlexpr.argvalue;
3674  bool *argnull = op->d.xmlexpr.argnull;
3675  List *values = NIL;
3676 
3677  for (int i = 0; i < list_length(xexpr->args); i++)
3678  {
3679  if (!argnull[i])
3680  values = lappend(values, DatumGetPointer(argvalue[i]));
3681  }
3682 
3683  if (values != NIL)
3684  {
3686  *op->resnull = false;
3687  }
3688  }
3689  break;
3690 
3691  case IS_XMLFOREST:
3692  {
3693  Datum *argvalue = op->d.xmlexpr.named_argvalue;
3694  bool *argnull = op->d.xmlexpr.named_argnull;
3696  ListCell *lc;
3697  ListCell *lc2;
3698  int i;
3699 
3700  initStringInfo(&buf);
3701 
3702  i = 0;
3703  forboth(lc, xexpr->named_args, lc2, xexpr->arg_names)
3704  {
3705  Expr *e = (Expr *) lfirst(lc);
3706  char *argname = strVal(lfirst(lc2));
3707 
3708  if (!argnull[i])
3709  {
3710  value = argvalue[i];
3711  appendStringInfo(&buf, "<%s>%s</%s>",
3712  argname,
3714  exprType((Node *) e), true),
3715  argname);
3716  *op->resnull = false;
3717  }
3718  i++;
3719  }
3720 
3721  if (!*op->resnull)
3722  {
3723  text *result;
3724 
3725  result = cstring_to_text_with_len(buf.data, buf.len);
3726  *op->resvalue = PointerGetDatum(result);
3727  }
3728 
3729  pfree(buf.data);
3730  }
3731  break;
3732 
3733  case IS_XMLELEMENT:
3734  *op->resvalue = PointerGetDatum(xmlelement(xexpr,
3735  op->d.xmlexpr.named_argvalue,
3736  op->d.xmlexpr.named_argnull,
3737  op->d.xmlexpr.argvalue,
3738  op->d.xmlexpr.argnull));
3739  *op->resnull = false;
3740  break;
3741 
3742  case IS_XMLPARSE:
3743  {
3744  Datum *argvalue = op->d.xmlexpr.argvalue;
3745  bool *argnull = op->d.xmlexpr.argnull;
3746  text *data;
3747  bool preserve_whitespace;
3748 
3749  /* arguments are known to be text, bool */
3750  Assert(list_length(xexpr->args) == 2);
3751 
3752  if (argnull[0])
3753  return;
3754  value = argvalue[0];
3756 
3757  if (argnull[1]) /* probably can't happen */
3758  return;
3759  value = argvalue[1];
3760  preserve_whitespace = DatumGetBool(value);
3761 
3763  xexpr->xmloption,
3764  preserve_whitespace));
3765  *op->resnull = false;
3766  }
3767  break;
3768 
3769  case IS_XMLPI:
3770  {
3771  text *arg;
3772  bool isnull;
3773 
3774  /* optional argument is known to be text */
3775  Assert(list_length(xexpr->args) <= 1);
3776 
3777  if (xexpr->args)
3778  {
3779  isnull = op->d.xmlexpr.argnull[0];
3780  if (isnull)
3781  arg = NULL;
3782  else
3783  arg = DatumGetTextPP(op->d.xmlexpr.argvalue[0]);
3784  }
3785  else
3786  {
3787  arg = NULL;
3788  isnull = false;
3789  }
3790 
3791  *op->resvalue = PointerGetDatum(xmlpi(xexpr->name,
3792  arg,
3793  isnull,
3794  op->resnull));
3795  }
3796  break;
3797 
3798  case IS_XMLROOT:
3799  {
3800  Datum *argvalue = op->d.xmlexpr.argvalue;
3801  bool *argnull = op->d.xmlexpr.argnull;
3802  xmltype *data;
3803  text *version;
3804  int standalone;
3805 
3806  /* arguments are known to be xml, text, int */
3807  Assert(list_length(xexpr->args) == 3);
3808 
3809  if (argnull[0])
3810  return;
3811  data = DatumGetXmlP(argvalue[0]);
3812 
3813  if (argnull[1])
3814  version = NULL;
3815  else
3816  version = DatumGetTextPP(argvalue[1]);
3817 
3818  Assert(!argnull[2]); /* always present */
3819  standalone = DatumGetInt32(argvalue[2]);
3820 
3822  version,
3823  standalone));
3824  *op->resnull = false;
3825  }
3826  break;
3827 
3828  case IS_XMLSERIALIZE:
3829  {
3830  Datum *argvalue = op->d.xmlexpr.argvalue;
3831  bool *argnull = op->d.xmlexpr.argnull;
3832 
3833  /* argument type is known to be xml */
3834  Assert(list_length(xexpr->args) == 1);
3835 
3836  if (argnull[0])
3837  return;
3838  value = argvalue[0];
3839 
3841  xexpr->xmloption));
3842  *op->resnull = false;
3843  }
3844  break;
3845 
3846  case IS_DOCUMENT:
3847  {
3848  Datum *argvalue = op->d.xmlexpr.argvalue;
3849  bool *argnull = op->d.xmlexpr.argnull;
3850 
3851  /* optional argument is known to be xml */
3852  Assert(list_length(xexpr->args) == 1);
3853 
3854  if (argnull[0])
3855  return;
3856  value = argvalue[0];
3857 
3858  *op->resvalue =
3860  *op->resnull = false;
3861  }
3862  break;
3863 
3864  default:
3865  elog(ERROR, "unrecognized XML operation");
3866  break;
3867  }
3868 }
#define DatumGetTextPP(X)
Definition: fmgr.h:292
List * lappend(List *list, void *datum)
Definition: list.c:338
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:43
void * arg
const void * data
#define lfirst(lc)
Definition: pg_list.h:170
static int list_length(const List *l)
Definition: pg_list.h:150
#define NIL
Definition: pg_list.h:66
#define forboth(cell1, list1, cell2, list2)
Definition: pg_list.h:465
static char * buf
Definition: pg_test_fsync.c:67
e
Definition: preproc-init.c:82
@ IS_DOCUMENT
Definition: primnodes.h:1315
@ IS_XMLFOREST
Definition: primnodes.h:1310
@ IS_XMLCONCAT
Definition: primnodes.h:1308
@ IS_XMLPI
Definition: primnodes.h:1312
@ IS_XMLPARSE
Definition: primnodes.h:1311
@ IS_XMLSERIALIZE
Definition: primnodes.h:1314
@ IS_XMLROOT
Definition: primnodes.h:1313
@ IS_XMLELEMENT
Definition: primnodes.h:1309
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:91
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
struct ExprEvalStep::@50::@82 xmlexpr
Definition: pg_list.h:52
List * args
Definition: primnodes.h:1331
char * name
Definition: primnodes.h:1328
List * arg_names
Definition: primnodes.h:1330
List * named_args
Definition: primnodes.h:1329
XmlExprOp op
Definition: primnodes.h:1327
XmlOptionType xmloption
Definition: primnodes.h:1332
Definition: c.h:623
#define strVal(v)
Definition: value.h:82
text * cstring_to_text_with_len(const char *s, int len)
Definition: varlena.c:201
xmltype * xmlconcat(List *args)
Definition: xml.c:511
xmltype * xmlparse(text *data, XmlOptionType xmloption_arg, bool preserve_whitespace)
Definition: xml.c:751
text * xmltotext_with_xmloption(xmltype *data, XmlOptionType xmloption_arg)
Definition: xml.c:614
bool xml_is_document(xmltype *arg)
Definition: xml.c:887
xmltype * xmlpi(const char *target, text *arg, bool arg_is_null, bool *result_is_null)
Definition: xml.c:769
char * map_sql_value_to_xml_value(Datum value, Oid type, bool xml_escape_strings)
Definition: xml.c:2133
xmltype * xmlelement(XmlExpr *xexpr, Datum *named_argvalue, bool *named_argnull, Datum *argvalue, bool *argnull)
Definition: xml.c:627
xmltype * xmlroot(xmltype *data, text *version, int standalone)
Definition: xml.c:821
static xmltype * DatumGetXmlP(Datum X)
Definition: xml.h:51

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

Referenced by ExecInterpExpr().

◆ ExecInterpExprStillValid()

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

Definition at line 1826 of file execExprInterp.c.

1827 {
1828  /*
1829  * First time through, check whether attribute matches Var. Might not be
1830  * ok anymore, due to schema changes.
1831  */
1832  CheckExprStillValid(state, econtext);
1833 
1834  /* skip the check during further executions */
1835  state->evalfunc = (ExprStateEvalFunc) state->evalfunc_private;
1836 
1837  /* and actually execute */
1838  return state->evalfunc(state, econtext, isNull);
1839 }
void CheckExprStillValid(ExprState *state, ExprContext *econtext)
Datum(* ExprStateEvalFunc)(struct ExprState *expression, struct ExprContext *econtext, bool *isNull)
Definition: execnodes.h:69

References CheckExprStillValid().

Referenced by ExecReadyInterpretedExpr().

◆ ExecReadyInterpretedExpr()

void ExecReadyInterpretedExpr ( ExprState state)

Definition at line 232 of file execExprInterp.c.

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

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 2418 of file execExpr.c.

2419 {
2420  if (es->steps_alloc == 0)
2421  {
2422  es->steps_alloc = 16;
2423  es->steps = palloc(sizeof(ExprEvalStep) * es->steps_alloc);
2424  }
2425  else if (es->steps_alloc == es->steps_len)
2426  {
2427  es->steps_alloc *= 2;
2428  es->steps = repalloc(es->steps,
2429  sizeof(ExprEvalStep) * es->steps_alloc);
2430  }
2431 
2432  memcpy(&es->steps[es->steps_len++], s, sizeof(ExprEvalStep));
2433 }
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:1321
struct ExprEvalStep * steps
Definition: execnodes.h:101
int steps_alloc
Definition: execnodes.h:121
int steps_len
Definition: execnodes.h:120

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

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