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  ExprEvalStep
 
struct  SubscriptingRefState
 

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 enum ExprEvalOp ExprEvalOp
 
typedef struct ExprEvalStep ExprEvalStep
 
typedef struct SubscriptingRefState SubscriptingRefState
 

Enumerations

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

Functions

void ExprEvalPushStep (ExprState *es, const ExprEvalStep *s)
 
void ExecReadyInterpretedExpr (ExprState *state)
 
ExprEvalOp ExecEvalStepOp (ExprState *state, ExprEvalStep *op)
 
Datum ExecInterpExprStillValid (ExprState *state, ExprContext *econtext, bool *isNull)
 
void CheckExprStillValid (ExprState *state, ExprContext *econtext)
 
void ExecEvalFuncExprFusage (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalFuncExprStrictFusage (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalParamExec (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalParamExtern (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalSQLValueFunction (ExprState *state, ExprEvalStep *op)
 
void ExecEvalCurrentOfExpr (ExprState *state, ExprEvalStep *op)
 
void ExecEvalNextValueExpr (ExprState *state, ExprEvalStep *op)
 
void ExecEvalRowNull (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalRowNotNull (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalArrayExpr (ExprState *state, ExprEvalStep *op)
 
void ExecEvalArrayCoerce (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalRow (ExprState *state, ExprEvalStep *op)
 
void ExecEvalMinMax (ExprState *state, ExprEvalStep *op)
 
void ExecEvalFieldSelect (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalFieldStoreDeForm (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalFieldStoreForm (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
bool ExecEvalSubscriptingRef (ExprState *state, ExprEvalStep *op)
 
void ExecEvalSubscriptingRefFetch (ExprState *state, ExprEvalStep *op)
 
void ExecEvalSubscriptingRefOld (ExprState *state, ExprEvalStep *op)
 
void ExecEvalSubscriptingRefAssign (ExprState *state, ExprEvalStep *op)
 
void ExecEvalConvertRowtype (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalScalarArrayOp (ExprState *state, ExprEvalStep *op)
 
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 ExecEvalAlternativeSubPlan (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)
 
Datum ExecAggTransReparent (AggState *aggstate, AggStatePerTrans pertrans, Datum newValue, bool newValueIsNull, Datum oldValue, bool oldValueIsNull)
 
void ExecEvalAggOrderedTransDatum (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalAggOrderedTransTuple (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 

Macro Definition Documentation

◆ EEO_FLAG_DIRECT_THREADED

#define EEO_FLAG_DIRECT_THREADED   (1 << 2)

Definition at line 28 of file execExpr.h.

Referenced by ExecEvalStepOp(), and ExecReadyInterpretedExpr().

◆ EEO_FLAG_INTERPRETER_INITIALIZED

#define EEO_FLAG_INTERPRETER_INITIALIZED   (1 << 1)

Definition at line 26 of file execExpr.h.

Referenced by ExecReadyInterpretedExpr().

Typedef Documentation

◆ ExecEvalSubroutine

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

Definition at line 31 of file execExpr.h.

◆ ExprEvalOp

typedef enum ExprEvalOp ExprEvalOp

◆ ExprEvalStep

typedef struct ExprEvalStep ExprEvalStep

◆ SubscriptingRefState

Enumeration Type Documentation

◆ ExprEvalOp

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

Definition at line 44 of file execExpr.h.

45 {
46  /* entire expression has been evaluated completely, return */
47  EEOP_DONE,
48 
49  /* apply slot_getsomeattrs on corresponding tuple slot */
53 
54  /* compute non-system Var value */
58 
59  /* compute system Var value */
63 
64  /* compute wholerow Var */
66 
67  /*
68  * Compute non-system Var value, assign it into ExprState's resultslot.
69  * These are not used if a CheckVarSlotCompatibility() check would be
70  * needed.
71  */
75 
76  /* assign ExprState's resvalue/resnull to a column of its resultslot */
78  /* ditto, applying MakeExpandedObjectReadOnly() */
80 
81  /* evaluate Const value */
82  EEOP_CONST,
83 
84  /*
85  * Evaluate function call (including OpExprs etc). For speed, we
86  * distinguish in the opcode whether the function is strict and/or
87  * requires usage stats tracking.
88  */
93 
94  /*
95  * Evaluate boolean AND expression, one step per subexpression. FIRST/LAST
96  * subexpressions are special-cased for performance. Since AND always has
97  * at least two subexpressions, FIRST and LAST never apply to the same
98  * subexpression.
99  */
103 
104  /* similarly for boolean OR expression */
108 
109  /* evaluate boolean NOT expression */
111 
112  /* simplified version of BOOL_AND_STEP for use by ExecQual() */
113  EEOP_QUAL,
114 
115  /* unconditional jump to another step */
116  EEOP_JUMP,
117 
118  /* conditional jumps based on current result value */
122 
123  /* perform NULL tests for scalar values */
126 
127  /* perform NULL tests for row values */
130 
131  /* evaluate a BooleanTest expression */
136 
137  /* evaluate PARAM_EXEC/EXTERN parameters */
141 
142  /* return CaseTestExpr value */
144 
145  /* apply MakeExpandedObjectReadOnly() to target value */
147 
148  /* evaluate assorted special-purpose expression types */
152  EEOP_NULLIF,
158  EEOP_ROW,
159 
160  /*
161  * Compare two individual elements of each of two compared ROW()
162  * expressions. Skip to ROWCOMPARE_FINAL if elements are not equal.
163  */
165 
166  /* evaluate boolean value based on previous ROWCOMPARE_STEP operations */
168 
169  /* evaluate GREATEST() or LEAST() */
170  EEOP_MINMAX,
171 
172  /* evaluate FieldSelect expression */
174 
175  /*
176  * Deform tuple before evaluating new values for individual fields in a
177  * FieldStore expression.
178  */
180 
181  /*
182  * Form the new tuple for a FieldStore expression. Individual fields will
183  * have been evaluated into columns of the tuple deformed by the preceding
184  * DEFORM step.
185  */
187 
188  /* Process a container subscript; short-circuit expression to NULL if NULL */
190 
191  /*
192  * Compute old container element/slice when a SubscriptingRef assignment
193  * expression contains SubscriptingRef/FieldStore subexpressions. Value is
194  * accessed using the CaseTest mechanism.
195  */
197 
198  /* compute new value for SubscriptingRef assignment expression */
200 
201  /* compute element/slice for SubscriptingRef fetch expression */
203 
204  /* evaluate value for CoerceToDomainValue */
206 
207  /* evaluate a domain's NOT NULL constraint */
209 
210  /* evaluate a single domain CHECK constraint */
212 
213  /* evaluate assorted special-purpose expression types */
216  EEOP_XMLEXPR,
217  EEOP_AGGREF,
220  EEOP_SUBPLAN,
222 
223  /* aggregation related nodes */
234 
235  /* non-existent operation, used e.g. to check array lengths */
236  EEOP_LAST
237 } ExprEvalOp;
ExprEvalOp
Definition: execExpr.h:44

Function Documentation

◆ CheckExprStillValid()

void CheckExprStillValid ( ExprState state,
ExprContext econtext 
)

Definition at line 1818 of file execExprInterp.c.

References attnum, CheckVarSlotCompatibility(), ExprEvalStep::d, ExprContext::ecxt_innertuple, ExprContext::ecxt_outertuple, ExprContext::ecxt_scantuple, EEOP_INNER_VAR, EEOP_OUTER_VAR, EEOP_SCAN_VAR, ExecEvalStepOp(), i, ExprState::steps, ExprState::steps_len, and ExprEvalStep::var.

Referenced by ExecInterpExprStillValid(), and ExecRunCompiledExpr().

1819 {
1820  int i = 0;
1821  TupleTableSlot *innerslot;
1822  TupleTableSlot *outerslot;
1823  TupleTableSlot *scanslot;
1824 
1825  innerslot = econtext->ecxt_innertuple;
1826  outerslot = econtext->ecxt_outertuple;
1827  scanslot = econtext->ecxt_scantuple;
1828 
1829  for (i = 0; i < state->steps_len; i++)
1830  {
1831  ExprEvalStep *op = &state->steps[i];
1832 
1833  switch (ExecEvalStepOp(state, op))
1834  {
1835  case EEOP_INNER_VAR:
1836  {
1837  int attnum = op->d.var.attnum;
1838 
1839  CheckVarSlotCompatibility(innerslot, attnum + 1, op->d.var.vartype);
1840  break;
1841  }
1842 
1843  case EEOP_OUTER_VAR:
1844  {
1845  int attnum = op->d.var.attnum;
1846 
1847  CheckVarSlotCompatibility(outerslot, attnum + 1, op->d.var.vartype);
1848  break;
1849  }
1850 
1851  case EEOP_SCAN_VAR:
1852  {
1853  int attnum = op->d.var.attnum;
1854 
1855  CheckVarSlotCompatibility(scanslot, attnum + 1, op->d.var.vartype);
1856  break;
1857  }
1858  default:
1859  break;
1860  }
1861  }
1862 }
struct ExprEvalStep::@52::@54 var
struct ExprEvalStep * steps
Definition: execnodes.h:86
union ExprEvalStep::@52 d
static void CheckVarSlotCompatibility(TupleTableSlot *slot, int attnum, Oid vartype)
ExprEvalOp ExecEvalStepOp(ExprState *state, ExprEvalStep *op)
TupleTableSlot * ecxt_innertuple
Definition: execnodes.h:226
int16 attnum
Definition: pg_attribute.h:79
TupleTableSlot * ecxt_outertuple
Definition: execnodes.h:228
TupleTableSlot * ecxt_scantuple
Definition: execnodes.h:224
int steps_len
Definition: execnodes.h:105
int i

◆ ExecAggInitGroup()

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

Definition at line 4158 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

4159 {
4160  FunctionCallInfo fcinfo = pertrans->transfn_fcinfo;
4161  MemoryContext oldContext;
4162 
4163  /*
4164  * We must copy the datum into aggcontext if it is pass-by-ref. We do not
4165  * need to pfree the old transValue, since it's NULL. (We already checked
4166  * that the agg's input type is binary-compatible with its transtype, so
4167  * straight copy here is OK.)
4168  */
4169  oldContext = MemoryContextSwitchTo(
4171  pergroup->transValue = datumCopy(fcinfo->args[1].value,
4172  pertrans->transtypeByVal,
4173  pertrans->transtypeLen);
4174  pergroup->transValueIsNull = false;
4175  pergroup->noTransValue = false;
4176  MemoryContextSwitchTo(oldContext);
4177 }
MemoryContext ecxt_per_tuple_memory
Definition: execnodes.h:232
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
FunctionCallInfo transfn_fcinfo
Definition: nodeAgg.h:161
NullableDatum args[FLEXIBLE_ARRAY_MEMBER]
Definition: fmgr.h:95
Datum value
Definition: postgres.h:378
Datum datumCopy(Datum value, bool typByVal, int typLen)
Definition: datum.c:130
ExprContext * curaggcontext
Definition: execnodes.h:2051

◆ ExecAggTransReparent()

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

Definition at line 4186 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

4189 {
4190  if (!newValueIsNull)
4191  {
4193  if (DatumIsReadWriteExpandedObject(newValue,
4194  false,
4195  pertrans->transtypeLen) &&
4196  MemoryContextGetParent(DatumGetEOHP(newValue)->eoh_context) == CurrentMemoryContext)
4197  /* do nothing */ ;
4198  else
4199  newValue = datumCopy(newValue,
4200  pertrans->transtypeByVal,
4201  pertrans->transtypeLen);
4202  }
4203  if (!oldValueIsNull)
4204  {
4205  if (DatumIsReadWriteExpandedObject(oldValue,
4206  false,
4207  pertrans->transtypeLen))
4208  DeleteExpandedObject(oldValue);
4209  else
4210  pfree(DatumGetPointer(oldValue));
4211  }
4212 
4213  return newValue;
4214 }
MemoryContext MemoryContextGetParent(MemoryContext context)
Definition: mcxt.c:439
MemoryContext ecxt_per_tuple_memory
Definition: execnodes.h:232
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
void pfree(void *pointer)
Definition: mcxt.c:1056
MemoryContext CurrentMemoryContext
Definition: mcxt.c:38
Datum datumCopy(Datum value, bool typByVal, int typLen)
Definition: datum.c:130
ExpandedObjectHeader * DatumGetEOHP(Datum d)
Definition: expandeddatum.c:29
ExprContext * curaggcontext
Definition: execnodes.h:2051
void DeleteExpandedObject(Datum d)
#define DatumIsReadWriteExpandedObject(d, isnull, typlen)
#define DatumGetPointer(X)
Definition: postgres.h:549

◆ ExecEvalAggOrderedTransDatum()

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

Definition at line 4220 of file execExprInterp.c.

References ExprEvalStep::agg_trans, ExprEvalStep::d, ExprEvalStep::resnull, ExprEvalStep::resvalue, AggStatePerTransData::sortstates, and tuplesort_putdatum().

Referenced by ExecInterpExpr().

4222 {
4223  AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
4224  int setno = op->d.agg_trans.setno;
4225 
4226  tuplesort_putdatum(pertrans->sortstates[setno],
4227  *op->resvalue, *op->resnull);
4228 }
struct ExprEvalStep::@52::@94 agg_trans
void tuplesort_putdatum(Tuplesortstate *state, Datum val, bool isNull)
Definition: tuplesort.c:1556
Datum * resvalue
Definition: execExpr.h:250
bool * resnull
Definition: execExpr.h:251
union ExprEvalStep::@52 d
Tuplesortstate ** sortstates
Definition: nodeAgg.h:153

◆ ExecEvalAggOrderedTransTuple()

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

Definition at line 4234 of file execExprInterp.c.

References ExprEvalStep::agg_trans, ExprEvalStep::d, ExecClearTuple(), ExecStoreVirtualTuple(), AggStatePerTransData::numInputs, AggStatePerTransData::sortslot, AggStatePerTransData::sortstates, TupleTableSlot::tts_nvalid, and tuplesort_puttupleslot().

Referenced by ExecInterpExpr().

4236 {
4237  AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
4238  int setno = op->d.agg_trans.setno;
4239 
4240  ExecClearTuple(pertrans->sortslot);
4241  pertrans->sortslot->tts_nvalid = pertrans->numInputs;
4242  ExecStoreVirtualTuple(pertrans->sortslot);
4243  tuplesort_puttupleslot(pertrans->sortstates[setno], pertrans->sortslot);
4244 }
struct ExprEvalStep::@52::@94 agg_trans
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:426
union ExprEvalStep::@52 d
Tuplesortstate ** sortstates
Definition: nodeAgg.h:153
AttrNumber tts_nvalid
Definition: tuptable.h:121
TupleTableSlot * sortslot
Definition: nodeAgg.h:135
TupleTableSlot * ExecStoreVirtualTuple(TupleTableSlot *slot)
Definition: execTuples.c:1517
void tuplesort_puttupleslot(Tuplesortstate *state, TupleTableSlot *slot)
Definition: tuplesort.c:1435

◆ ExecEvalAlternativeSubPlan()

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

Definition at line 3890 of file execExprInterp.c.

References ExprEvalStep::alternative_subplan, check_stack_depth(), ExprEvalStep::d, ExecAlternativeSubPlan(), ExprEvalStep::resnull, and ExprEvalStep::resvalue.

Referenced by ExecInterpExpr().

3891 {
3892  AlternativeSubPlanState *asstate = op->d.alternative_subplan.asstate;
3893 
3894  /* could potentially be nested, so make sure there's enough stack */
3896 
3897  *op->resvalue = ExecAlternativeSubPlan(asstate, econtext, op->resnull);
3898 }
Datum * resvalue
Definition: execExpr.h:250
bool * resnull
Definition: execExpr.h:251
Datum ExecAlternativeSubPlan(AlternativeSubPlanState *node, ExprContext *econtext, bool *isNull)
Definition: nodeSubplan.c:1377
union ExprEvalStep::@52 d
struct ExprEvalStep::@52::@89 alternative_subplan
void check_stack_depth(void)
Definition: postgres.c:3262

◆ ExecEvalArrayCoerce()

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

Definition at line 2848 of file execExprInterp.c.

References ARR_ELEMTYPE, array_map(), ExprEvalStep::arraycoerce, ExprEvalStep::d, DatumGetArrayTypePCopy, PointerGetDatum, ExprEvalStep::resnull, and ExprEvalStep::resvalue.

Referenced by ExecInterpExpr().

2849 {
2850  Datum arraydatum;
2851 
2852  /* NULL array -> NULL result */
2853  if (*op->resnull)
2854  return;
2855 
2856  arraydatum = *op->resvalue;
2857 
2858  /*
2859  * If it's binary-compatible, modify the element type in the array header,
2860  * but otherwise leave the array as we received it.
2861  */
2862  if (op->d.arraycoerce.elemexprstate == NULL)
2863  {
2864  /* Detoast input array if necessary, and copy in any case */
2865  ArrayType *array = DatumGetArrayTypePCopy(arraydatum);
2866 
2867  ARR_ELEMTYPE(array) = op->d.arraycoerce.resultelemtype;
2868  *op->resvalue = PointerGetDatum(array);
2869  return;
2870  }
2871 
2872  /*
2873  * Use array_map to apply the sub-expression to each array element.
2874  */
2875  *op->resvalue = array_map(arraydatum,
2876  op->d.arraycoerce.elemexprstate,
2877  econtext,
2878  op->d.arraycoerce.resultelemtype,
2879  op->d.arraycoerce.amstate);
2880 }
Datum * resvalue
Definition: execExpr.h:250
#define PointerGetDatum(X)
Definition: postgres.h:556
bool * resnull
Definition: execExpr.h:251
union ExprEvalStep::@52 d
struct ExprEvalStep::@52::@72 arraycoerce
uintptr_t Datum
Definition: postgres.h:367
#define DatumGetArrayTypePCopy(X)
Definition: array.h:250
Datum array_map(Datum arrayd, ExprState *exprstate, ExprContext *econtext, Oid retType, ArrayMapState *amstate)
Definition: arrayfuncs.c:3131
#define ARR_ELEMTYPE(a)
Definition: array.h:280

◆ ExecEvalArrayExpr()

void ExecEvalArrayExpr ( ExprState state,
ExprEvalStep op 
)

Definition at line 2641 of file execExprInterp.c.

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(), ExprEvalStep::arrayexpr, ArrayGetNItems(), construct_empty_array(), construct_md_array(), ExprEvalStep::d, ArrayType::dataoffset, DatumGetArrayTypeP, ArrayType::elemtype, ereport, errcode(), errdetail(), errmsg(), ERROR, format_type_be(), i, MAXDIM, ArrayType::ndim, palloc(), PointerGetDatum, ExprEvalStep::resnull, ExprEvalStep::resvalue, and SET_VARSIZE.

Referenced by ExecInterpExpr().

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

◆ ExecEvalConstraintCheck()

void ExecEvalConstraintCheck ( ExprState state,
ExprEvalStep op 
)

Definition at line 3612 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

3613 {
3614  if (!*op->d.domaincheck.checknull &&
3615  !DatumGetBool(*op->d.domaincheck.checkvalue))
3616  ereport(ERROR,
3617  (errcode(ERRCODE_CHECK_VIOLATION),
3618  errmsg("value for domain %s violates check constraint \"%s\"",
3619  format_type_be(op->d.domaincheck.resulttype),
3620  op->d.domaincheck.constraintname),
3621  errdomainconstraint(op->d.domaincheck.resulttype,
3622  op->d.domaincheck.constraintname)));
3623 }
int errcode(int sqlerrcode)
Definition: elog.c:570
char * format_type_be(Oid type_oid)
Definition: format_type.c:326
union ExprEvalStep::@52 d
struct ExprEvalStep::@52::@81 domaincheck
#define ERROR
Definition: elog.h:43
int errdomainconstraint(Oid datatypeOid, const char *conname)
Definition: domains.c:384
#define DatumGetBool(X)
Definition: postgres.h:393
#define ereport(elevel, rest)
Definition: elog.h:141
int errmsg(const char *fmt,...)
Definition: elog.c:784

◆ ExecEvalConstraintNotNull()

void ExecEvalConstraintNotNull ( ExprState state,
ExprEvalStep op 
)

Definition at line 3598 of file execExprInterp.c.

References ExprEvalStep::d, ExprEvalStep::domaincheck, ereport, errcode(), errdatatype(), errmsg(), ERROR, format_type_be(), and ExprEvalStep::resnull.

Referenced by ExecInterpExpr().

3599 {
3600  if (*op->resnull)
3601  ereport(ERROR,
3602  (errcode(ERRCODE_NOT_NULL_VIOLATION),
3603  errmsg("domain %s does not allow null values",
3604  format_type_be(op->d.domaincheck.resulttype)),
3605  errdatatype(op->d.domaincheck.resulttype)));
3606 }
bool * resnull
Definition: execExpr.h:251
int errcode(int sqlerrcode)
Definition: elog.c:570
char * format_type_be(Oid type_oid)
Definition: format_type.c:326
union ExprEvalStep::@52 d
struct ExprEvalStep::@52::@81 domaincheck
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:141
int errdatatype(Oid datatypeOid)
Definition: domains.c:360
int errmsg(const char *fmt,...)
Definition: elog.c:784

◆ ExecEvalConvertRowtype()

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

Definition at line 3349 of file execExprInterp.c.

References ConvertRowtypeExpr::arg, Assert, convert(), ExprEvalStep::convert_rowtype, convert_tuples_by_name(), ExprEvalStep::d, DatumGetHeapTupleHeader, ExprContext::ecxt_per_query_memory, execute_attr_map_tuple(), exprType(), get_cached_rowtype(), heap_copy_tuple_as_datum(), HeapTupleGetDatum, HeapTupleHeaderGetDatumLength, HeapTupleHeaderGetTypeId, MemoryContextSwitchTo(), ExprEvalStep::resnull, ConvertRowtypeExpr::resulttype, ExprEvalStep::resvalue, HeapTupleData::t_data, HeapTupleData::t_len, and TupleDescData::tdtypeid.

Referenced by ExecInterpExpr().

3350 {
3352  HeapTuple result;
3353  Datum tupDatum;
3354  HeapTupleHeader tuple;
3355  HeapTupleData tmptup;
3356  TupleDesc indesc,
3357  outdesc;
3358 
3359  /* NULL in -> NULL out */
3360  if (*op->resnull)
3361  return;
3362 
3363  tupDatum = *op->resvalue;
3364  tuple = DatumGetHeapTupleHeader(tupDatum);
3365 
3366  /* Lookup tupdescs if first time through or after rescan */
3367  if (op->d.convert_rowtype.indesc == NULL)
3368  {
3369  get_cached_rowtype(exprType((Node *) convert->arg), -1,
3370  &op->d.convert_rowtype.indesc,
3371  econtext);
3372  op->d.convert_rowtype.initialized = false;
3373  }
3374  if (op->d.convert_rowtype.outdesc == NULL)
3375  {
3376  get_cached_rowtype(convert->resulttype, -1,
3377  &op->d.convert_rowtype.outdesc,
3378  econtext);
3379  op->d.convert_rowtype.initialized = false;
3380  }
3381 
3382  indesc = op->d.convert_rowtype.indesc;
3383  outdesc = op->d.convert_rowtype.outdesc;
3384 
3385  /*
3386  * We used to be able to assert that incoming tuples are marked with
3387  * exactly the rowtype of indesc. However, now that ExecEvalWholeRowVar
3388  * might change the tuples' marking to plain RECORD due to inserting
3389  * aliases, we can only make this weak test:
3390  */
3391  Assert(HeapTupleHeaderGetTypeId(tuple) == indesc->tdtypeid ||
3392  HeapTupleHeaderGetTypeId(tuple) == RECORDOID);
3393 
3394  /* if first time through, initialize conversion map */
3395  if (!op->d.convert_rowtype.initialized)
3396  {
3397  MemoryContext old_cxt;
3398 
3399  /* allocate map in long-lived memory context */
3400  old_cxt = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
3401 
3402  /* prepare map from old to new attribute numbers */
3403  op->d.convert_rowtype.map = convert_tuples_by_name(indesc, outdesc);
3404  op->d.convert_rowtype.initialized = true;
3405 
3406  MemoryContextSwitchTo(old_cxt);
3407  }
3408 
3409  /* Following steps need a HeapTuple not a bare HeapTupleHeader */
3410  tmptup.t_len = HeapTupleHeaderGetDatumLength(tuple);
3411  tmptup.t_data = tuple;
3412 
3413  if (op->d.convert_rowtype.map != NULL)
3414  {
3415  /* Full conversion with attribute rearrangement needed */
3416  result = execute_attr_map_tuple(&tmptup, op->d.convert_rowtype.map);
3417  /* Result already has appropriate composite-datum header fields */
3418  *op->resvalue = HeapTupleGetDatum(result);
3419  }
3420  else
3421  {
3422  /*
3423  * The tuple is physically compatible as-is, but we need to insert the
3424  * destination rowtype OID in its composite-datum header field, so we
3425  * have to copy it anyway. heap_copy_tuple_as_datum() is convenient
3426  * for this since it will both make the physical copy and insert the
3427  * correct composite header fields. Note that we aren't expecting to
3428  * have to flatten any toasted fields: the input was a composite
3429  * datum, so it shouldn't contain any. So heap_copy_tuple_as_datum()
3430  * is overkill here, but its check for external fields is cheap.
3431  */
3432  *op->resvalue = heap_copy_tuple_as_datum(&tmptup, outdesc);
3433  }
3434 }
Datum * resvalue
Definition: execExpr.h:250
bool * resnull
Definition: execExpr.h:251
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
Definition: nodes.h:525
union ExprEvalStep::@52 d
#define DatumGetHeapTupleHeader(X)
Definition: fmgr.h:289
HeapTupleHeader t_data
Definition: htup.h:68
static void convert(const int32 val, char *const buf)
Definition: zic.c:1959
uint32 t_len
Definition: htup.h:64
TupleConversionMap * convert_tuples_by_name(TupleDesc indesc, TupleDesc outdesc)
Definition: tupconvert.c:205
HeapTuple execute_attr_map_tuple(HeapTuple tuple, TupleConversionMap *map)
Definition: tupconvert.c:387
Datum heap_copy_tuple_as_datum(HeapTuple tuple, TupleDesc tupleDesc)
Definition: heaptuple.c:984
static TupleDesc get_cached_rowtype(Oid type_id, int32 typmod, TupleDesc *cache_field, ExprContext *econtext)
uintptr_t Datum
Definition: postgres.h:367
#define HeapTupleHeaderGetTypeId(tup)
Definition: htup_details.h:458
struct ExprEvalStep::@52::@82 convert_rowtype
#define Assert(condition)
Definition: c.h:732
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:42
#define HeapTupleGetDatum(tuple)
Definition: funcapi.h:221
MemoryContext ecxt_per_query_memory
Definition: execnodes.h:231
Oid tdtypeid
Definition: tupdesc.h:82
#define HeapTupleHeaderGetDatumLength(tup)
Definition: htup_details.h:452

◆ ExecEvalCurrentOfExpr()

void ExecEvalCurrentOfExpr ( ExprState state,
ExprEvalStep op 
)

Definition at line 2500 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

2501 {
2502  ereport(ERROR,
2503  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2504  errmsg("WHERE CURRENT OF is not supported for this table type")));
2505 }
int errcode(int sqlerrcode)
Definition: elog.c:570
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:141
int errmsg(const char *fmt,...)
Definition: elog.c:784

◆ ExecEvalFieldSelect()

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

Definition at line 2963 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

2964 {
2965  AttrNumber fieldnum = op->d.fieldselect.fieldnum;
2966  Datum tupDatum;
2967  HeapTupleHeader tuple;
2968  Oid tupType;
2969  int32 tupTypmod;
2970  TupleDesc tupDesc;
2971  Form_pg_attribute attr;
2972  HeapTupleData tmptup;
2973 
2974  /* NULL record -> NULL result */
2975  if (*op->resnull)
2976  return;
2977 
2978  tupDatum = *op->resvalue;
2979 
2980  /* We can special-case expanded records for speed */
2982  {
2984 
2985  Assert(erh->er_magic == ER_MAGIC);
2986 
2987  /* Extract record's TupleDesc */
2988  tupDesc = expanded_record_get_tupdesc(erh);
2989 
2990  /*
2991  * Find field's attr record. Note we don't support system columns
2992  * here: a datum tuple doesn't have valid values for most of the
2993  * interesting system columns anyway.
2994  */
2995  if (fieldnum <= 0) /* should never happen */
2996  elog(ERROR, "unsupported reference to system column %d in FieldSelect",
2997  fieldnum);
2998  if (fieldnum > tupDesc->natts) /* should never happen */
2999  elog(ERROR, "attribute number %d exceeds number of columns %d",
3000  fieldnum, tupDesc->natts);
3001  attr = TupleDescAttr(tupDesc, fieldnum - 1);
3002 
3003  /* Check for dropped column, and force a NULL result if so */
3004  if (attr->attisdropped)
3005  {
3006  *op->resnull = true;
3007  return;
3008  }
3009 
3010  /* Check for type mismatch --- possible after ALTER COLUMN TYPE? */
3011  /* As in CheckVarSlotCompatibility, we should but can't check typmod */
3012  if (op->d.fieldselect.resulttype != attr->atttypid)
3013  ereport(ERROR,
3014  (errcode(ERRCODE_DATATYPE_MISMATCH),
3015  errmsg("attribute %d has wrong type", fieldnum),
3016  errdetail("Table has type %s, but query expects %s.",
3017  format_type_be(attr->atttypid),
3018  format_type_be(op->d.fieldselect.resulttype))));
3019 
3020  /* extract the field */
3021  *op->resvalue = expanded_record_get_field(erh, fieldnum,
3022  op->resnull);
3023  }
3024  else
3025  {
3026  /* Get the composite datum and extract its type fields */
3027  tuple = DatumGetHeapTupleHeader(tupDatum);
3028 
3029  tupType = HeapTupleHeaderGetTypeId(tuple);
3030  tupTypmod = HeapTupleHeaderGetTypMod(tuple);
3031 
3032  /* Lookup tupdesc if first time through or if type changes */
3033  tupDesc = get_cached_rowtype(tupType, tupTypmod,
3034  &op->d.fieldselect.argdesc,
3035  econtext);
3036 
3037  /*
3038  * Find field's attr record. Note we don't support system columns
3039  * here: a datum tuple doesn't have valid values for most of the
3040  * interesting system columns anyway.
3041  */
3042  if (fieldnum <= 0) /* should never happen */
3043  elog(ERROR, "unsupported reference to system column %d in FieldSelect",
3044  fieldnum);
3045  if (fieldnum > tupDesc->natts) /* should never happen */
3046  elog(ERROR, "attribute number %d exceeds number of columns %d",
3047  fieldnum, tupDesc->natts);
3048  attr = TupleDescAttr(tupDesc, fieldnum - 1);
3049 
3050  /* Check for dropped column, and force a NULL result if so */
3051  if (attr->attisdropped)
3052  {
3053  *op->resnull = true;
3054  return;
3055  }
3056 
3057  /* Check for type mismatch --- possible after ALTER COLUMN TYPE? */
3058  /* As in CheckVarSlotCompatibility, we should but can't check typmod */
3059  if (op->d.fieldselect.resulttype != attr->atttypid)
3060  ereport(ERROR,
3061  (errcode(ERRCODE_DATATYPE_MISMATCH),
3062  errmsg("attribute %d has wrong type", fieldnum),
3063  errdetail("Table has type %s, but query expects %s.",
3064  format_type_be(attr->atttypid),
3065  format_type_be(op->d.fieldselect.resulttype))));
3066 
3067  /* heap_getattr needs a HeapTuple not a bare HeapTupleHeader */
3068  tmptup.t_len = HeapTupleHeaderGetDatumLength(tuple);
3069  tmptup.t_data = tuple;
3070 
3071  /* extract the field */
3072  *op->resvalue = heap_getattr(&tmptup,
3073  fieldnum,
3074  tupDesc,
3075  op->resnull);
3076  }
3077 }
#define VARATT_IS_EXTERNAL_EXPANDED(PTR)
Definition: postgres.h:322
Datum * resvalue
Definition: execExpr.h:250
static Datum expanded_record_get_field(ExpandedRecordHeader *erh, int fnumber, bool *isnull)
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
bool * resnull
Definition: execExpr.h:251
int errcode(int sqlerrcode)
Definition: elog.c:570
char * format_type_be(Oid type_oid)
Definition: format_type.c:326
unsigned int Oid
Definition: postgres_ext.h:31
union ExprEvalStep::@52 d
#define DatumGetHeapTupleHeader(X)
Definition: fmgr.h:289
signed int int32
Definition: c.h:346
HeapTupleHeader t_data
Definition: htup.h:68
#define HeapTupleHeaderGetTypMod(tup)
Definition: htup_details.h:468
#define ERROR
Definition: elog.h:43
uint32 t_len
Definition: htup.h:64
int errdetail(const char *fmt,...)
Definition: elog.c:860
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:200
#define ereport(elevel, rest)
Definition: elog.h:141
static TupleDesc expanded_record_get_tupdesc(ExpandedRecordHeader *erh)
ExpandedObjectHeader * DatumGetEOHP(Datum d)
Definition: expandeddatum.c:29
#define heap_getattr(tup, attnum, tupleDesc, isnull)
Definition: htup_details.h:762
static TupleDesc get_cached_rowtype(Oid type_id, int32 typmod, TupleDesc *cache_field, ExprContext *econtext)
uintptr_t Datum
Definition: postgres.h:367
#define ER_MAGIC
#define HeapTupleHeaderGetTypeId(tup)
Definition: htup_details.h:458
#define Assert(condition)
Definition: c.h:732
#define DatumGetPointer(X)
Definition: postgres.h:549
int errmsg(const char *fmt,...)
Definition: elog.c:784
#define elog(elevel,...)
Definition: elog.h:226
struct ExprEvalStep::@52::@77 fieldselect
int16 AttrNumber
Definition: attnum.h:21
#define HeapTupleHeaderGetDatumLength(tup)
Definition: htup_details.h:452

◆ ExecEvalFieldStoreDeForm()

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

Definition at line 3089 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

3090 {
3091  TupleDesc tupDesc;
3092 
3093  /* Lookup tupdesc if first time through or after rescan */
3094  tupDesc = get_cached_rowtype(op->d.fieldstore.fstore->resulttype, -1,
3095  op->d.fieldstore.argdesc, econtext);
3096 
3097  /* Check that current tupdesc doesn't have more fields than we allocated */
3098  if (unlikely(tupDesc->natts > op->d.fieldstore.ncolumns))
3099  elog(ERROR, "too many columns in composite type %u",
3100  op->d.fieldstore.fstore->resulttype);
3101 
3102  if (*op->resnull)
3103  {
3104  /* Convert null input tuple into an all-nulls row */
3105  memset(op->d.fieldstore.nulls, true,
3106  op->d.fieldstore.ncolumns * sizeof(bool));
3107  }
3108  else
3109  {
3110  /*
3111  * heap_deform_tuple needs a HeapTuple not a bare HeapTupleHeader. We
3112  * set all the fields in the struct just in case.
3113  */
3114  Datum tupDatum = *op->resvalue;
3115  HeapTupleHeader tuphdr;
3116  HeapTupleData tmptup;
3117 
3118  tuphdr = DatumGetHeapTupleHeader(tupDatum);
3119  tmptup.t_len = HeapTupleHeaderGetDatumLength(tuphdr);
3120  ItemPointerSetInvalid(&(tmptup.t_self));
3121  tmptup.t_tableOid = InvalidOid;
3122  tmptup.t_data = tuphdr;
3123 
3124  heap_deform_tuple(&tmptup, tupDesc,
3125  op->d.fieldstore.values,
3126  op->d.fieldstore.nulls);
3127  }
3128 }
Datum * resvalue
Definition: execExpr.h:250
bool * resnull
Definition: execExpr.h:251
union ExprEvalStep::@52 d
#define DatumGetHeapTupleHeader(X)
Definition: fmgr.h:289
HeapTupleHeader t_data
Definition: htup.h:68
#define ERROR
Definition: elog.h:43
ItemPointerData t_self
Definition: htup.h:65
struct ExprEvalStep::@52::@78 fieldstore
uint32 t_len
Definition: htup.h:64
Oid t_tableOid
Definition: htup.h:66
static TupleDesc get_cached_rowtype(Oid type_id, int32 typmod, TupleDesc *cache_field, ExprContext *econtext)
uintptr_t Datum
Definition: postgres.h:367
#define InvalidOid
Definition: postgres_ext.h:36
void heap_deform_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *values, bool *isnull)
Definition: heaptuple.c:1249
#define ItemPointerSetInvalid(pointer)
Definition: itemptr.h:172
#define elog(elevel,...)
Definition: elog.h:226
#define unlikely(x)
Definition: c.h:208
#define HeapTupleHeaderGetDatumLength(tup)
Definition: htup_details.h:452

◆ ExecEvalFieldStoreForm()

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

Definition at line 3135 of file execExprInterp.c.

References ExprEvalStep::d, ExprEvalStep::fieldstore, heap_form_tuple(), HeapTupleGetDatum, ExprEvalStep::resnull, and ExprEvalStep::resvalue.

Referenced by ExecInterpExpr().

3136 {
3137  HeapTuple tuple;
3138 
3139  /* argdesc should already be valid from the DeForm step */
3140  tuple = heap_form_tuple(*op->d.fieldstore.argdesc,
3141  op->d.fieldstore.values,
3142  op->d.fieldstore.nulls);
3143 
3144  *op->resvalue = HeapTupleGetDatum(tuple);
3145  *op->resnull = false;
3146 }
Datum * resvalue
Definition: execExpr.h:250
bool * resnull
Definition: execExpr.h:251
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1020
union ExprEvalStep::@52 d
struct ExprEvalStep::@52::@78 fieldstore
#define HeapTupleGetDatum(tuple)
Definition: funcapi.h:221

◆ ExecEvalFuncExprFusage()

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

Definition at line 2311 of file execExprInterp.c.

References ExprEvalStep::d, ExprEvalStep::func, FunctionCallInfoBaseData::isnull, pgstat_end_function_usage(), pgstat_init_function_usage(), ExprEvalStep::resnull, and ExprEvalStep::resvalue.

Referenced by ExecInterpExpr().

2313 {
2314  FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
2315  PgStat_FunctionCallUsage fcusage;
2316  Datum d;
2317 
2318  pgstat_init_function_usage(fcinfo, &fcusage);
2319 
2320  fcinfo->isnull = false;
2321  d = op->d.func.fn_addr(fcinfo);
2322  *op->resvalue = d;
2323  *op->resnull = fcinfo->isnull;
2324 
2325  pgstat_end_function_usage(&fcusage, true);
2326 }
Datum * resvalue
Definition: execExpr.h:250
bool * resnull
Definition: execExpr.h:251
union ExprEvalStep::@52 d
void pgstat_init_function_usage(FunctionCallInfo fcinfo, PgStat_FunctionCallUsage *fcu)
Definition: pgstat.c:1622
uintptr_t Datum
Definition: postgres.h:367
struct ExprEvalStep::@52::@59 func
void pgstat_end_function_usage(PgStat_FunctionCallUsage *fcu, bool finalize)
Definition: pgstat.c:1694

◆ ExecEvalFuncExprStrictFusage()

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

Definition at line 2332 of file execExprInterp.c.

References FunctionCallInfoBaseData::args, generate_unaccent_rules::args, ExprEvalStep::d, ExprEvalStep::func, FunctionCallInfoBaseData::isnull, pgstat_end_function_usage(), pgstat_init_function_usage(), ExprEvalStep::resnull, and ExprEvalStep::resvalue.

Referenced by ExecInterpExpr().

2334 {
2335 
2336  FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
2337  PgStat_FunctionCallUsage fcusage;
2338  NullableDatum *args = fcinfo->args;
2339  int argno;
2340  Datum d;
2341 
2342  /* strict function, so check for NULL args */
2343  for (argno = 0; argno < op->d.func.nargs; argno++)
2344  {
2345  if (args[argno].isnull)
2346  {
2347  *op->resnull = true;
2348  return;
2349  }
2350  }
2351 
2352  pgstat_init_function_usage(fcinfo, &fcusage);
2353 
2354  fcinfo->isnull = false;
2355  d = op->d.func.fn_addr(fcinfo);
2356  *op->resvalue = d;
2357  *op->resnull = fcinfo->isnull;
2358 
2359  pgstat_end_function_usage(&fcusage, true);
2360 }
Datum * resvalue
Definition: execExpr.h:250
bool * resnull
Definition: execExpr.h:251
union ExprEvalStep::@52 d
void pgstat_init_function_usage(FunctionCallInfo fcinfo, PgStat_FunctionCallUsage *fcu)
Definition: pgstat.c:1622
NullableDatum args[FLEXIBLE_ARRAY_MEMBER]
Definition: fmgr.h:95
uintptr_t Datum
Definition: postgres.h:367
struct ExprEvalStep::@52::@59 func
void pgstat_end_function_usage(PgStat_FunctionCallUsage *fcu, bool finalize)
Definition: pgstat.c:1694

◆ ExecEvalGroupingFunc()

void ExecEvalGroupingFunc ( ExprState state,
ExprEvalStep op 
)

Definition at line 3852 of file execExprInterp.c.

References attnum, bms_is_member(), ExprEvalStep::d, ExprEvalStep::grouping_func, Int32GetDatum, lfirst_int, ExprEvalStep::resnull, and ExprEvalStep::resvalue.

Referenced by ExecInterpExpr().

3853 {
3854  int result = 0;
3855  Bitmapset *grouped_cols = op->d.grouping_func.parent->grouped_cols;
3856  ListCell *lc;
3857 
3858  foreach(lc, op->d.grouping_func.clauses)
3859  {
3860  int attnum = lfirst_int(lc);
3861 
3862  result <<= 1;
3863 
3864  if (!bms_is_member(attnum, grouped_cols))
3865  result |= 1;
3866  }
3867 
3868  *op->resvalue = Int32GetDatum(result);
3869  *op->resnull = false;
3870 }
Datum * resvalue
Definition: execExpr.h:250
bool * resnull
Definition: execExpr.h:251
union ExprEvalStep::@52 d
struct ExprEvalStep::@52::@86 grouping_func
#define lfirst_int(lc)
Definition: pg_list.h:191
int16 attnum
Definition: pg_attribute.h:79
#define Int32GetDatum(X)
Definition: postgres.h:479
bool bms_is_member(int x, const Bitmapset *a)
Definition: bitmapset.c:427

◆ ExecEvalMinMax()

void ExecEvalMinMax ( ExprState state,
ExprEvalStep op 
)

Definition at line 2909 of file execExprInterp.c.

References FunctionCallInfoBaseData::args, Assert, ExprEvalStep::d, DatumGetInt32, FunctionCallInvoke, IS_GREATEST, IS_LEAST, FunctionCallInfoBaseData::isnull, NullableDatum::isnull, ExprEvalStep::minmax, ExprEvalStep::resnull, ExprEvalStep::resvalue, NullableDatum::value, and values.

Referenced by ExecInterpExpr().

2910 {
2911  Datum *values = op->d.minmax.values;
2912  bool *nulls = op->d.minmax.nulls;
2913  FunctionCallInfo fcinfo = op->d.minmax.fcinfo_data;
2914  MinMaxOp operator = op->d.minmax.op;
2915  int off;
2916 
2917  /* set at initialization */
2918  Assert(fcinfo->args[0].isnull == false);
2919  Assert(fcinfo->args[1].isnull == false);
2920 
2921  /* default to null result */
2922  *op->resnull = true;
2923 
2924  for (off = 0; off < op->d.minmax.nelems; off++)
2925  {
2926  /* ignore NULL inputs */
2927  if (nulls[off])
2928  continue;
2929 
2930  if (*op->resnull)
2931  {
2932  /* first nonnull input, adopt value */
2933  *op->resvalue = values[off];
2934  *op->resnull = false;
2935  }
2936  else
2937  {
2938  int cmpresult;
2939 
2940  /* apply comparison function */
2941  fcinfo->args[0].value = *op->resvalue;
2942  fcinfo->args[1].value = values[off];
2943 
2944  fcinfo->isnull = false;
2945  cmpresult = DatumGetInt32(FunctionCallInvoke(fcinfo));
2946  if (fcinfo->isnull) /* probably should not happen */
2947  continue;
2948 
2949  if (cmpresult > 0 && operator == IS_LEAST)
2950  *op->resvalue = values[off];
2951  else if (cmpresult < 0 && operator == IS_GREATEST)
2952  *op->resvalue = values[off];
2953  }
2954  }
2955 }
Datum * resvalue
Definition: execExpr.h:250
#define DatumGetInt32(X)
Definition: postgres.h:472
bool * resnull
Definition: execExpr.h:251
union ExprEvalStep::@52 d
MinMaxOp
Definition: primnodes.h:1079
NullableDatum args[FLEXIBLE_ARRAY_MEMBER]
Definition: fmgr.h:95
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:167
Datum value
Definition: postgres.h:378
uintptr_t Datum
Definition: postgres.h:367
#define Assert(condition)
Definition: c.h:732
struct ExprEvalStep::@52::@76 minmax
static Datum values[MAXATTR]
Definition: bootstrap.c:167

◆ ExecEvalNextValueExpr()

void ExecEvalNextValueExpr ( ExprState state,
ExprEvalStep op 
)

Definition at line 2511 of file execExprInterp.c.

References ExprEvalStep::d, elog, ERROR, Int16GetDatum, Int32GetDatum, Int64GetDatum(), newval, nextval_internal(), ExprEvalStep::nextvalueexpr, ExprEvalStep::resnull, and ExprEvalStep::resvalue.

Referenced by ExecInterpExpr().

2512 {
2513  int64 newval = nextval_internal(op->d.nextvalueexpr.seqid, false);
2514 
2515  switch (op->d.nextvalueexpr.seqtypid)
2516  {
2517  case INT2OID:
2518  *op->resvalue = Int16GetDatum((int16) newval);
2519  break;
2520  case INT4OID:
2521  *op->resvalue = Int32GetDatum((int32) newval);
2522  break;
2523  case INT8OID:
2524  *op->resvalue = Int64GetDatum((int64) newval);
2525  break;
2526  default:
2527  elog(ERROR, "unsupported sequence type %u",
2528  op->d.nextvalueexpr.seqtypid);
2529  }
2530  *op->resnull = false;
2531 }
signed short int16
Definition: c.h:345
Datum * resvalue
Definition: execExpr.h:250
int64 nextval_internal(Oid relid, bool check_permissions)
Definition: sequence.c:579
bool * resnull
Definition: execExpr.h:251
#define Int16GetDatum(X)
Definition: postgres.h:451
union ExprEvalStep::@52 d
signed int int32
Definition: c.h:346
#define ERROR
Definition: elog.h:43
Datum Int64GetDatum(int64 X)
Definition: fmgr.c:1699
struct ExprEvalStep::@52::@70 nextvalueexpr
#define newval
#define Int32GetDatum(X)
Definition: postgres.h:479
#define elog(elevel,...)
Definition: elog.h:226

◆ ExecEvalParamExec()

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

Definition at line 2369 of file execExprInterp.c.

References Assert, ExprEvalStep::d, ExprContext::ecxt_param_exec_vals, ParamExecData::execPlan, ExecSetParamPlan(), ParamExecData::isnull, ExprEvalStep::param, ExprEvalStep::resnull, ExprEvalStep::resvalue, unlikely, and ParamExecData::value.

Referenced by ExecInterpExpr().

2370 {
2371  ParamExecData *prm;
2372 
2373  prm = &(econtext->ecxt_param_exec_vals[op->d.param.paramid]);
2374  if (unlikely(prm->execPlan != NULL))
2375  {
2376  /* Parameter not evaluated yet, so go do it */
2377  ExecSetParamPlan(prm->execPlan, econtext);
2378  /* ExecSetParamPlan should have processed this param... */
2379  Assert(prm->execPlan == NULL);
2380  }
2381  *op->resvalue = prm->value;
2382  *op->resnull = prm->isnull;
2383 }
void * execPlan
Definition: params.h:147
Datum * resvalue
Definition: execExpr.h:250
bool * resnull
Definition: execExpr.h:251
union ExprEvalStep::@52 d
void ExecSetParamPlan(SubPlanState *node, ExprContext *econtext)
Definition: nodeSubplan.c:1051
bool isnull
Definition: params.h:149
ParamExecData * ecxt_param_exec_vals
Definition: execnodes.h:235
struct ExprEvalStep::@52::@64 param
#define Assert(condition)
Definition: c.h:732
Datum value
Definition: params.h:148
#define unlikely(x)
Definition: c.h:208

◆ ExecEvalParamExtern()

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

Definition at line 2391 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

2392 {
2393  ParamListInfo paramInfo = econtext->ecxt_param_list_info;
2394  int paramId = op->d.param.paramid;
2395 
2396  if (likely(paramInfo &&
2397  paramId > 0 && paramId <= paramInfo->numParams))
2398  {
2399  ParamExternData *prm;
2400  ParamExternData prmdata;
2401 
2402  /* give hook a chance in case parameter is dynamic */
2403  if (paramInfo->paramFetch != NULL)
2404  prm = paramInfo->paramFetch(paramInfo, paramId, false, &prmdata);
2405  else
2406  prm = &paramInfo->params[paramId - 1];
2407 
2408  if (likely(OidIsValid(prm->ptype)))
2409  {
2410  /* safety check in case hook did something unexpected */
2411  if (unlikely(prm->ptype != op->d.param.paramtype))
2412  ereport(ERROR,
2413  (errcode(ERRCODE_DATATYPE_MISMATCH),
2414  errmsg("type of parameter %d (%s) does not match that when preparing the plan (%s)",
2415  paramId,
2416  format_type_be(prm->ptype),
2417  format_type_be(op->d.param.paramtype))));
2418  *op->resvalue = prm->value;
2419  *op->resnull = prm->isnull;
2420  return;
2421  }
2422  }
2423 
2424  ereport(ERROR,
2425  (errcode(ERRCODE_UNDEFINED_OBJECT),
2426  errmsg("no value found for parameter %d", paramId)));
2427 }
ParamExternData params[FLEXIBLE_ARRAY_MEMBER]
Definition: params.h:124
Datum value
Definition: params.h:92
#define likely(x)
Definition: c.h:207
Datum * resvalue
Definition: execExpr.h:250
bool * resnull
Definition: execExpr.h:251
int errcode(int sqlerrcode)
Definition: elog.c:570
char * format_type_be(Oid type_oid)
Definition: format_type.c:326
union ExprEvalStep::@52 d
#define OidIsValid(objectId)
Definition: c.h:638
ParamFetchHook paramFetch
Definition: params.h:112
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:141
struct ExprEvalStep::@52::@64 param
int errmsg(const char *fmt,...)
Definition: elog.c:784
#define unlikely(x)
Definition: c.h:208
ParamListInfo ecxt_param_list_info
Definition: execnodes.h:236
bool isnull
Definition: params.h:93

◆ ExecEvalRow()

void ExecEvalRow ( ExprState state,
ExprEvalStep op 
)

Definition at line 2889 of file execExprInterp.c.

References ExprEvalStep::d, heap_form_tuple(), HeapTupleGetDatum, ExprEvalStep::resnull, ExprEvalStep::resvalue, and ExprEvalStep::row.

Referenced by ExecInterpExpr().

2890 {
2891  HeapTuple tuple;
2892 
2893  /* build tuple from evaluated field values */
2894  tuple = heap_form_tuple(op->d.row.tupdesc,
2895  op->d.row.elemvalues,
2896  op->d.row.elemnulls);
2897 
2898  *op->resvalue = HeapTupleGetDatum(tuple);
2899  *op->resnull = false;
2900 }
Datum * resvalue
Definition: execExpr.h:250
bool * resnull
Definition: execExpr.h:251
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1020
union ExprEvalStep::@52 d
struct ExprEvalStep::@52::@73 row
#define HeapTupleGetDatum(tuple)
Definition: funcapi.h:221

◆ ExecEvalRowNotNull()

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

Definition at line 2546 of file execExprInterp.c.

References ExecEvalRowNullInt().

Referenced by ExecInterpExpr().

2547 {
2548  ExecEvalRowNullInt(state, op, econtext, false);
2549 }
static void ExecEvalRowNullInt(ExprState *state, ExprEvalStep *op, ExprContext *econtext, bool checkisnull)

◆ ExecEvalRowNull()

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

Definition at line 2537 of file execExprInterp.c.

References ExecEvalRowNullInt().

Referenced by ExecInterpExpr().

2538 {
2539  ExecEvalRowNullInt(state, op, econtext, true);
2540 }
static void ExecEvalRowNullInt(ExprState *state, ExprEvalStep *op, ExprContext *econtext, bool checkisnull)

◆ ExecEvalScalarArrayOp()

void ExecEvalScalarArrayOp ( ExprState state,
ExprEvalStep op 
)

Definition at line 3447 of file execExprInterp.c.

References FunctionCallInfoBaseData::args, ARR_DATA_PTR, ARR_DIMS, ARR_ELEMTYPE, ARR_NDIM, ARR_NULLBITMAP, ArrayGetNItems(), att_addlength_pointer, att_align_nominal, BoolGetDatum, ExprEvalStep::d, DatumGetArrayTypeP, DatumGetBool, fetch_att, get_typlenbyvalalign(), i, FunctionCallInfoBaseData::isnull, NullableDatum::isnull, ExprEvalStep::resnull, ExprEvalStep::resvalue, ExprEvalStep::scalararrayop, typalign, and NullableDatum::value.

Referenced by ExecInterpExpr().

3448 {
3449  FunctionCallInfo fcinfo = op->d.scalararrayop.fcinfo_data;
3450  bool useOr = op->d.scalararrayop.useOr;
3451  bool strictfunc = op->d.scalararrayop.finfo->fn_strict;
3452  ArrayType *arr;
3453  int nitems;
3454  Datum result;
3455  bool resultnull;
3456  int i;
3457  int16 typlen;
3458  bool typbyval;
3459  char typalign;
3460  char *s;
3461  bits8 *bitmap;
3462  int bitmask;
3463 
3464  /*
3465  * If the array is NULL then we return NULL --- it's not very meaningful
3466  * to do anything else, even if the operator isn't strict.
3467  */
3468  if (*op->resnull)
3469  return;
3470 
3471  /* Else okay to fetch and detoast the array */
3472  arr = DatumGetArrayTypeP(*op->resvalue);
3473 
3474  /*
3475  * If the array is empty, we return either FALSE or TRUE per the useOr
3476  * flag. This is correct even if the scalar is NULL; since we would
3477  * evaluate the operator zero times, it matters not whether it would want
3478  * to return NULL.
3479  */
3480  nitems = ArrayGetNItems(ARR_NDIM(arr), ARR_DIMS(arr));
3481  if (nitems <= 0)
3482  {
3483  *op->resvalue = BoolGetDatum(!useOr);
3484  *op->resnull = false;
3485  return;
3486  }
3487 
3488  /*
3489  * If the scalar is NULL, and the function is strict, return NULL; no
3490  * point in iterating the loop.
3491  */
3492  if (fcinfo->args[0].isnull && strictfunc)
3493  {
3494  *op->resnull = true;
3495  return;
3496  }
3497 
3498  /*
3499  * We arrange to look up info about the element type only once per series
3500  * of calls, assuming the element type doesn't change underneath us.
3501  */
3502  if (op->d.scalararrayop.element_type != ARR_ELEMTYPE(arr))
3503  {
3505  &op->d.scalararrayop.typlen,
3506  &op->d.scalararrayop.typbyval,
3507  &op->d.scalararrayop.typalign);
3508  op->d.scalararrayop.element_type = ARR_ELEMTYPE(arr);
3509  }
3510 
3511  typlen = op->d.scalararrayop.typlen;
3512  typbyval = op->d.scalararrayop.typbyval;
3513  typalign = op->d.scalararrayop.typalign;
3514 
3515  /* Initialize result appropriately depending on useOr */
3516  result = BoolGetDatum(!useOr);
3517  resultnull = false;
3518 
3519  /* Loop over the array elements */
3520  s = (char *) ARR_DATA_PTR(arr);
3521  bitmap = ARR_NULLBITMAP(arr);
3522  bitmask = 1;
3523 
3524  for (i = 0; i < nitems; i++)
3525  {
3526  Datum elt;
3527  Datum thisresult;
3528 
3529  /* Get array element, checking for NULL */
3530  if (bitmap && (*bitmap & bitmask) == 0)
3531  {
3532  fcinfo->args[1].value = (Datum) 0;
3533  fcinfo->args[1].isnull = true;
3534  }
3535  else
3536  {
3537  elt = fetch_att(s, typbyval, typlen);
3538  s = att_addlength_pointer(s, typlen, s);
3539  s = (char *) att_align_nominal(s, typalign);
3540  fcinfo->args[1].value = elt;
3541  fcinfo->args[1].isnull = false;
3542  }
3543 
3544  /* Call comparison function */
3545  if (fcinfo->args[1].isnull && strictfunc)
3546  {
3547  fcinfo->isnull = true;
3548  thisresult = (Datum) 0;
3549  }
3550  else
3551  {
3552  fcinfo->isnull = false;
3553  thisresult = op->d.scalararrayop.fn_addr(fcinfo);
3554  }
3555 
3556  /* Combine results per OR or AND semantics */
3557  if (fcinfo->isnull)
3558  resultnull = true;
3559  else if (useOr)
3560  {
3561  if (DatumGetBool(thisresult))
3562  {
3563  result = BoolGetDatum(true);
3564  resultnull = false;
3565  break; /* needn't look at any more elements */
3566  }
3567  }
3568  else
3569  {
3570  if (!DatumGetBool(thisresult))
3571  {
3572  result = BoolGetDatum(false);
3573  resultnull = false;
3574  break; /* needn't look at any more elements */
3575  }
3576  }
3577 
3578  /* advance bitmap pointer if any */
3579  if (bitmap)
3580  {
3581  bitmask <<= 1;
3582  if (bitmask == 0x100)
3583  {
3584  bitmap++;
3585  bitmask = 1;
3586  }
3587  }
3588  }
3589 
3590  *op->resvalue = result;
3591  *op->resnull = resultnull;
3592 }
signed short int16
Definition: c.h:345
#define att_align_nominal(cur_offset, attalign)
Definition: tupmacs.h:146
Datum * resvalue
Definition: execExpr.h:250
void get_typlenbyvalalign(Oid typid, int16 *typlen, bool *typbyval, char *typalign)
Definition: lsyscache.c:2049
bool * resnull
Definition: execExpr.h:251
int ArrayGetNItems(int ndim, const int *dims)
Definition: arrayutils.c:75
union ExprEvalStep::@52 d
char typalign
Definition: pg_type.h:170
NullableDatum args[FLEXIBLE_ARRAY_MEMBER]
Definition: fmgr.h:95
#define ARR_DIMS(a)
Definition: array.h:282
#define ARR_DATA_PTR(a)
Definition: array.h:310
#define DatumGetBool(X)
Definition: postgres.h:393
#define att_addlength_pointer(cur_offset, attlen, attptr)
Definition: tupmacs.h:174
Datum value
Definition: postgres.h:378
uint8 bits8
Definition: c.h:365
uintptr_t Datum
Definition: postgres.h:367
#define BoolGetDatum(X)
Definition: postgres.h:402
#define ARR_NDIM(a)
Definition: array.h:278
#define fetch_att(T, attbyval, attlen)
Definition: tupmacs.h:73
int i
struct ExprEvalStep::@52::@83 scalararrayop
#define ARR_ELEMTYPE(a)
Definition: array.h:280
#define ARR_NULLBITMAP(a)
Definition: array.h:288
#define DatumGetArrayTypeP(X)
Definition: array.h:249

◆ ExecEvalSQLValueFunction()

void ExecEvalSQLValueFunction ( ExprState state,
ExprEvalStep op 
)

Definition at line 2433 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

2434 {
2435  LOCAL_FCINFO(fcinfo, 0);
2436  SQLValueFunction *svf = op->d.sqlvaluefunction.svf;
2437 
2438  *op->resnull = false;
2439 
2440  /*
2441  * Note: current_schema() can return NULL. current_user() etc currently
2442  * cannot, but might as well code those cases the same way for safety.
2443  */
2444  switch (svf->op)
2445  {
2446  case SVFOP_CURRENT_DATE:
2448  break;
2449  case SVFOP_CURRENT_TIME:
2450  case SVFOP_CURRENT_TIME_N:
2452  break;
2456  break;
2457  case SVFOP_LOCALTIME:
2458  case SVFOP_LOCALTIME_N:
2460  break;
2461  case SVFOP_LOCALTIMESTAMP:
2464  break;
2465  case SVFOP_CURRENT_ROLE:
2466  case SVFOP_CURRENT_USER:
2467  case SVFOP_USER:
2468  InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
2469  *op->resvalue = current_user(fcinfo);
2470  *op->resnull = fcinfo->isnull;
2471  break;
2472  case SVFOP_SESSION_USER:
2473  InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
2474  *op->resvalue = session_user(fcinfo);
2475  *op->resnull = fcinfo->isnull;
2476  break;
2477  case SVFOP_CURRENT_CATALOG:
2478  InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
2479  *op->resvalue = current_database(fcinfo);
2480  *op->resnull = fcinfo->isnull;
2481  break;
2482  case SVFOP_CURRENT_SCHEMA:
2483  InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
2484  *op->resvalue = current_schema(fcinfo);
2485  *op->resnull = fcinfo->isnull;
2486  break;
2487  }
2488 }
Datum current_schema(PG_FUNCTION_ARGS)
Definition: name.c:319
Datum * resvalue
Definition: execExpr.h:250
bool * resnull
Definition: execExpr.h:251
#define TimeTzADTPGetDatum(X)
Definition: date.h:59
TimestampTz GetSQLCurrentTimestamp(int32 typmod)
Definition: timestamp.c:1601
#define DateADTGetDatum(X)
Definition: date.h:57
DateADT GetSQLCurrentDate(void)
Definition: date.c:299
union ExprEvalStep::@52 d
SQLValueFunctionOp op
Definition: primnodes.h:1129
Datum current_database(PG_FUNCTION_ARGS)
Definition: misc.c:170
#define TimestampTzGetDatum(X)
Definition: timestamp.h:32
TimeTzADT * GetSQLCurrentTime(int32 typmod)
Definition: date.c:321
Datum current_user(PG_FUNCTION_ARGS)
Definition: name.c:303
#define TimestampGetDatum(X)
Definition: timestamp.h:31
TimeADT GetSQLLocalTime(int32 typmod)
Definition: date.c:347
Datum session_user(PG_FUNCTION_ARGS)
Definition: name.c:309
#define TimeADTGetDatum(X)
Definition: date.h:58
Timestamp GetSQLLocalTimestamp(int32 typmod)
Definition: timestamp.c:1615
#define InvalidOid
Definition: postgres_ext.h:36
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
struct ExprEvalStep::@52::@69 sqlvaluefunction

◆ ExecEvalStepOp()

ExprEvalOp ExecEvalStepOp ( ExprState state,
ExprEvalStep op 
)

Definition at line 2281 of file execExprInterp.c.

References Assert, EEO_FLAG_DIRECT_THREADED, EEOP_LAST, ExprState::flags, sort-test::key, and ExprEvalStep::opcode.

Referenced by CheckExprStillValid(), and llvm_compile_expr().

2282 {
2283 #if defined(EEO_USE_COMPUTED_GOTO)
2284  if (state->flags & EEO_FLAG_DIRECT_THREADED)
2285  {
2286  ExprEvalOpLookup key;
2287  ExprEvalOpLookup *res;
2288 
2289  key.opcode = (void *) op->opcode;
2290  res = bsearch(&key,
2291  reverse_dispatch_table,
2292  EEOP_LAST /* nmembers */ ,
2293  sizeof(ExprEvalOpLookup),
2294  dispatch_compare_ptr);
2295  Assert(res); /* unknown ops shouldn't get looked up */
2296  return res->op;
2297  }
2298 #endif
2299  return (ExprEvalOp) op->opcode;
2300 }
ExprEvalOp
Definition: execExpr.h:44
#define Assert(condition)
Definition: c.h:732
intptr_t opcode
Definition: execExpr.h:247
uint8 flags
Definition: execnodes.h:66
#define EEO_FLAG_DIRECT_THREADED
Definition: execExpr.h:28

◆ ExecEvalSubPlan()

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

Definition at line 3876 of file execExprInterp.c.

References check_stack_depth(), ExprEvalStep::d, ExecSubPlan(), ExprEvalStep::resnull, ExprEvalStep::resvalue, and ExprEvalStep::subplan.

Referenced by ExecInterpExpr().

3877 {
3878  SubPlanState *sstate = op->d.subplan.sstate;
3879 
3880  /* could potentially be nested, so make sure there's enough stack */
3882 
3883  *op->resvalue = ExecSubPlan(sstate, econtext, op->resnull);
3884 }
struct ExprEvalStep::@52::@88 subplan
Datum * resvalue
Definition: execExpr.h:250
bool * resnull
Definition: execExpr.h:251
union ExprEvalStep::@52 d
void check_stack_depth(void)
Definition: postgres.c:3262
Datum ExecSubPlan(SubPlanState *node, ExprContext *econtext, bool *isNull)
Definition: nodeSubplan.c:63

◆ ExecEvalSubscriptingRef()

bool ExecEvalSubscriptingRef ( ExprState state,
ExprEvalStep op 
)

Definition at line 3160 of file execExprInterp.c.

References ExprEvalStep::d, DatumGetInt32, ereport, errcode(), errmsg(), ERROR, SubscriptingRefState::isassignment, SubscriptingRefState::lowerindex, ExprEvalStep::resnull, ExprEvalStep::sbsref_subscript, SubscriptingRefState::subscriptnull, SubscriptingRefState::subscriptvalue, and SubscriptingRefState::upperindex.

Referenced by ExecInterpExpr().

3161 {
3162  SubscriptingRefState *sbsrefstate = op->d.sbsref_subscript.state;
3163  int *indexes;
3164  int off;
3165 
3166  /* If any index expr yields NULL, result is NULL or error */
3167  if (sbsrefstate->subscriptnull)
3168  {
3169  if (sbsrefstate->isassignment)
3170  ereport(ERROR,
3171  (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
3172  errmsg("array subscript in assignment must not be null")));
3173  *op->resnull = true;
3174  return false;
3175  }
3176 
3177  /* Convert datum to int, save in appropriate place */
3178  if (op->d.sbsref_subscript.isupper)
3179  indexes = sbsrefstate->upperindex;
3180  else
3181  indexes = sbsrefstate->lowerindex;
3182  off = op->d.sbsref_subscript.off;
3183 
3184  indexes[off] = DatumGetInt32(sbsrefstate->subscriptvalue);
3185 
3186  return true;
3187 }
#define DatumGetInt32(X)
Definition: postgres.h:472
bool * resnull
Definition: execExpr.h:251
int errcode(int sqlerrcode)
Definition: elog.c:570
union ExprEvalStep::@52 d
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:141
int lowerindex[MAXDIM]
Definition: execExpr.h:681
int upperindex[MAXDIM]
Definition: execExpr.h:676
struct ExprEvalStep::@52::@79 sbsref_subscript
int errmsg(const char *fmt,...)
Definition: elog.c:784

◆ ExecEvalSubscriptingRefAssign()

void ExecEvalSubscriptingRefAssign ( ExprState state,
ExprEvalStep op 
)

Definition at line 3284 of file execExprInterp.c.

References array_set_element(), array_set_slice(), construct_empty_array(), ExprEvalStep::d, SubscriptingRefState::lowerindex, SubscriptingRefState::lowerprovided, SubscriptingRefState::numlower, SubscriptingRefState::numupper, PointerGetDatum, SubscriptingRefState::refattrlength, SubscriptingRefState::refelemalign, SubscriptingRefState::refelembyval, SubscriptingRefState::refelemlength, SubscriptingRefState::refelemtype, SubscriptingRefState::replacenull, SubscriptingRefState::replacevalue, ExprEvalStep::resnull, ExprEvalStep::resvalue, ExprEvalStep::sbsref_subscript, SubscriptingRefState::upperindex, and SubscriptingRefState::upperprovided.

Referenced by ExecInterpExpr().

3285 {
3286  SubscriptingRefState *sbsrefstate = op->d.sbsref_subscript.state;
3287 
3288  /*
3289  * For an assignment to a fixed-length container type, both the original
3290  * container and the value to be assigned into it must be non-NULL, else
3291  * we punt and return the original container.
3292  */
3293  if (sbsrefstate->refattrlength > 0)
3294  {
3295  if (*op->resnull || sbsrefstate->replacenull)
3296  return;
3297  }
3298 
3299  /*
3300  * For assignment to varlena arrays, we handle a NULL original array by
3301  * substituting an empty (zero-dimensional) array; insertion of the new
3302  * element will result in a singleton array value. It does not matter
3303  * whether the new element is NULL.
3304  */
3305  if (*op->resnull)
3306  {
3308  *op->resnull = false;
3309  }
3310 
3311  if (sbsrefstate->numlower == 0)
3312  {
3313  /* Scalar case */
3314  *op->resvalue = array_set_element(*op->resvalue,
3315  sbsrefstate->numupper,
3316  sbsrefstate->upperindex,
3317  sbsrefstate->replacevalue,
3318  sbsrefstate->replacenull,
3319  sbsrefstate->refattrlength,
3320  sbsrefstate->refelemlength,
3321  sbsrefstate->refelembyval,
3322  sbsrefstate->refelemalign);
3323  }
3324  else
3325  {
3326  /* Slice case */
3327  *op->resvalue = array_set_slice(*op->resvalue,
3328  sbsrefstate->numupper,
3329  sbsrefstate->upperindex,
3330  sbsrefstate->lowerindex,
3331  sbsrefstate->upperprovided,
3332  sbsrefstate->lowerprovided,
3333  sbsrefstate->replacevalue,
3334  sbsrefstate->replacenull,
3335  sbsrefstate->refattrlength,
3336  sbsrefstate->refelemlength,
3337  sbsrefstate->refelembyval,
3338  sbsrefstate->refelemalign);
3339  }
3340 }
Datum * resvalue
Definition: execExpr.h:250
#define PointerGetDatum(X)
Definition: postgres.h:556
bool * resnull
Definition: execExpr.h:251
Datum array_set_element(Datum arraydatum, int nSubscripts, int *indx, Datum dataValue, bool isNull, int arraytyplen, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:2199
ArrayType * construct_empty_array(Oid elmtype)
Definition: arrayfuncs.c:3410
union ExprEvalStep::@52 d
Datum array_set_slice(Datum arraydatum, int nSubscripts, int *upperIndx, int *lowerIndx, bool *upperProvided, bool *lowerProvided, Datum srcArrayDatum, bool isNull, int arraytyplen, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:2759
bool upperprovided[MAXDIM]
Definition: execExpr.h:675
bool lowerprovided[MAXDIM]
Definition: execExpr.h:680
int lowerindex[MAXDIM]
Definition: execExpr.h:681
int upperindex[MAXDIM]
Definition: execExpr.h:676
struct ExprEvalStep::@52::@79 sbsref_subscript

◆ ExecEvalSubscriptingRefFetch()

void ExecEvalSubscriptingRefFetch ( ExprState state,
ExprEvalStep op 
)

Definition at line 3195 of file execExprInterp.c.

References array_get_element(), array_get_slice(), Assert, ExprEvalStep::d, SubscriptingRefState::lowerindex, SubscriptingRefState::lowerprovided, SubscriptingRefState::numlower, SubscriptingRefState::numupper, SubscriptingRefState::refattrlength, SubscriptingRefState::refelemalign, SubscriptingRefState::refelembyval, SubscriptingRefState::refelemlength, ExprEvalStep::resnull, ExprEvalStep::resvalue, ExprEvalStep::sbsref, SubscriptingRefState::upperindex, and SubscriptingRefState::upperprovided.

Referenced by ExecInterpExpr().

3196 {
3197  SubscriptingRefState *sbsrefstate = op->d.sbsref.state;
3198 
3199  /* Should not get here if source container (or any subscript) is null */
3200  Assert(!(*op->resnull));
3201 
3202  if (sbsrefstate->numlower == 0)
3203  {
3204  /* Scalar case */
3205  *op->resvalue = array_get_element(*op->resvalue,
3206  sbsrefstate->numupper,
3207  sbsrefstate->upperindex,
3208  sbsrefstate->refattrlength,
3209  sbsrefstate->refelemlength,
3210  sbsrefstate->refelembyval,
3211  sbsrefstate->refelemalign,
3212  op->resnull);
3213  }
3214  else
3215  {
3216  /* Slice case */
3217  *op->resvalue = array_get_slice(*op->resvalue,
3218  sbsrefstate->numupper,
3219  sbsrefstate->upperindex,
3220  sbsrefstate->lowerindex,
3221  sbsrefstate->upperprovided,
3222  sbsrefstate->lowerprovided,
3223  sbsrefstate->refattrlength,
3224  sbsrefstate->refelemlength,
3225  sbsrefstate->refelembyval,
3226  sbsrefstate->refelemalign);
3227  }
3228 }
Datum array_get_slice(Datum arraydatum, int nSubscripts, int *upperIndx, int *lowerIndx, bool *upperProvided, bool *lowerProvided, int arraytyplen, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:2028
struct ExprEvalStep::@52::@80 sbsref
Datum * resvalue
Definition: execExpr.h:250
bool * resnull
Definition: execExpr.h:251
union ExprEvalStep::@52 d
bool upperprovided[MAXDIM]
Definition: execExpr.h:675
bool lowerprovided[MAXDIM]
Definition: execExpr.h:680
Datum array_get_element(Datum arraydatum, int nSubscripts, int *indx, int arraytyplen, int elmlen, bool elmbyval, char elmalign, bool *isNull)
Definition: arrayfuncs.c:1819
#define Assert(condition)
Definition: c.h:732
int lowerindex[MAXDIM]
Definition: execExpr.h:681
int upperindex[MAXDIM]
Definition: execExpr.h:676

◆ ExecEvalSubscriptingRefOld()

void ExecEvalSubscriptingRefOld ( ExprState state,
ExprEvalStep op 
)

Definition at line 3237 of file execExprInterp.c.

References array_get_element(), array_get_slice(), ExprEvalStep::d, SubscriptingRefState::lowerindex, SubscriptingRefState::lowerprovided, SubscriptingRefState::numlower, SubscriptingRefState::numupper, SubscriptingRefState::prevnull, SubscriptingRefState::prevvalue, SubscriptingRefState::refattrlength, SubscriptingRefState::refelemalign, SubscriptingRefState::refelembyval, SubscriptingRefState::refelemlength, ExprEvalStep::resnull, ExprEvalStep::resvalue, ExprEvalStep::sbsref, SubscriptingRefState::upperindex, and SubscriptingRefState::upperprovided.

Referenced by ExecInterpExpr().

3238 {
3239  SubscriptingRefState *sbsrefstate = op->d.sbsref.state;
3240 
3241  if (*op->resnull)
3242  {
3243  /* whole array is null, so any element or slice is too */
3244  sbsrefstate->prevvalue = (Datum) 0;
3245  sbsrefstate->prevnull = true;
3246  }
3247  else if (sbsrefstate->numlower == 0)
3248  {
3249  /* Scalar case */
3250  sbsrefstate->prevvalue = array_get_element(*op->resvalue,
3251  sbsrefstate->numupper,
3252  sbsrefstate->upperindex,
3253  sbsrefstate->refattrlength,
3254  sbsrefstate->refelemlength,
3255  sbsrefstate->refelembyval,
3256  sbsrefstate->refelemalign,
3257  &sbsrefstate->prevnull);
3258  }
3259  else
3260  {
3261  /* Slice case */
3262  /* this is currently unreachable */
3263  sbsrefstate->prevvalue = array_get_slice(*op->resvalue,
3264  sbsrefstate->numupper,
3265  sbsrefstate->upperindex,
3266  sbsrefstate->lowerindex,
3267  sbsrefstate->upperprovided,
3268  sbsrefstate->lowerprovided,
3269  sbsrefstate->refattrlength,
3270  sbsrefstate->refelemlength,
3271  sbsrefstate->refelembyval,
3272  sbsrefstate->refelemalign);
3273  sbsrefstate->prevnull = false;
3274  }
3275 }
Datum array_get_slice(Datum arraydatum, int nSubscripts, int *upperIndx, int *lowerIndx, bool *upperProvided, bool *lowerProvided, int arraytyplen, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:2028
struct ExprEvalStep::@52::@80 sbsref
Datum * resvalue
Definition: execExpr.h:250
bool * resnull
Definition: execExpr.h:251
union ExprEvalStep::@52 d
bool upperprovided[MAXDIM]
Definition: execExpr.h:675
uintptr_t Datum
Definition: postgres.h:367
bool lowerprovided[MAXDIM]
Definition: execExpr.h:680
Datum array_get_element(Datum arraydatum, int nSubscripts, int *indx, int arraytyplen, int elmlen, bool elmbyval, char elmalign, bool *isNull)
Definition: arrayfuncs.c:1819
int lowerindex[MAXDIM]
Definition: execExpr.h:681
int upperindex[MAXDIM]
Definition: execExpr.h:676

◆ ExecEvalSysVar()

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

Definition at line 4138 of file execExprInterp.c.

References ExprEvalStep::d, elog, ERROR, ExprEvalStep::resnull, ExprEvalStep::resvalue, slot_getsysattr(), unlikely, and ExprEvalStep::var.

Referenced by ExecInterpExpr().

4140 {
4141  Datum d;
4142 
4143  /* slot_getsysattr has sufficient defenses against bad attnums */
4144  d = slot_getsysattr(slot,
4145  op->d.var.attnum,
4146  op->resnull);
4147  *op->resvalue = d;
4148  /* this ought to be unreachable, but it's cheap enough to check */
4149  if (unlikely(*op->resnull))
4150  elog(ERROR, "failed to fetch attribute from slot");
4151 }
struct ExprEvalStep::@52::@54 var
Datum * resvalue
Definition: execExpr.h:250
bool * resnull
Definition: execExpr.h:251
union ExprEvalStep::@52 d
#define ERROR
Definition: elog.h:43
uintptr_t Datum
Definition: postgres.h:367
#define elog(elevel,...)
Definition: elog.h:226
#define unlikely(x)
Definition: c.h:208
static Datum slot_getsysattr(TupleTableSlot *slot, int attnum, bool *isnull)
Definition: tuptable.h:403

◆ ExecEvalWholeRowVar()

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

Definition at line 3907 of file execExprInterp.c.

References Assert, BlessTupleDesc(), Alias::colnames, CreateTupleDescCopy(), ExprEvalStep::d, 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, OUTER_VAR, PointerGetDatum, ReleaseTupleDesc, ExprEvalStep::resnull, ExprEvalStep::resvalue, slot_getallattrs(), HeapTupleData::t_data, toast_build_flattened_tuple(), TupleTableSlot::tts_isnull, TupleTableSlot::tts_tupleDescriptor, TupleTableSlot::tts_values, TupleDescAttr, Var::varattno, Var::varno, Var::vartype, and ExprEvalStep::wholerow.

Referenced by ExecInterpExpr().

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

◆ ExecEvalXmlExpr()

void ExecEvalXmlExpr ( ExprState state,
ExprEvalStep op 
)

Definition at line 3632 of file execExprInterp.c.

References appendStringInfo(), arg, XmlExpr::arg_names, XmlExpr::args, Assert, BoolGetDatum, buf, cstring_to_text_with_len(), ExprEvalStep::d, StringInfoData::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, lappend(), StringInfoData::len, lfirst, list_length(), map_sql_value_to_xml_value(), XmlExpr::name, XmlExpr::named_args, NIL, XmlExpr::op, pfree(), PointerGetDatum, ExprEvalStep::resnull, ExprEvalStep::resvalue, strVal, value, values, xml_is_document(), xmlconcat(), xmlelement(), ExprEvalStep::xmlexpr, XmlExpr::xmloption, xmlparse(), xmlpi(), xmlroot(), and xmltotext_with_xmloption().

Referenced by ExecInterpExpr().

3633 {
3634  XmlExpr *xexpr = op->d.xmlexpr.xexpr;
3635  Datum value;
3636  int i;
3637 
3638  *op->resnull = true; /* until we get a result */
3639  *op->resvalue = (Datum) 0;
3640 
3641  switch (xexpr->op)
3642  {
3643  case IS_XMLCONCAT:
3644  {
3645  Datum *argvalue = op->d.xmlexpr.argvalue;
3646  bool *argnull = op->d.xmlexpr.argnull;
3647  List *values = NIL;
3648 
3649  for (i = 0; i < list_length(xexpr->args); i++)
3650  {
3651  if (!argnull[i])
3652  values = lappend(values, DatumGetPointer(argvalue[i]));
3653  }
3654 
3655  if (values != NIL)
3656  {
3657  *op->resvalue = PointerGetDatum(xmlconcat(values));
3658  *op->resnull = false;
3659  }
3660  }
3661  break;
3662 
3663  case IS_XMLFOREST:
3664  {
3665  Datum *argvalue = op->d.xmlexpr.named_argvalue;
3666  bool *argnull = op->d.xmlexpr.named_argnull;
3668  ListCell *lc;
3669  ListCell *lc2;
3670 
3671  initStringInfo(&buf);
3672 
3673  i = 0;
3674  forboth(lc, xexpr->named_args, lc2, xexpr->arg_names)
3675  {
3676  Expr *e = (Expr *) lfirst(lc);
3677  char *argname = strVal(lfirst(lc2));
3678 
3679  if (!argnull[i])
3680  {
3681  value = argvalue[i];
3682  appendStringInfo(&buf, "<%s>%s</%s>",
3683  argname,
3685  exprType((Node *) e), true),
3686  argname);
3687  *op->resnull = false;
3688  }
3689  i++;
3690  }
3691 
3692  if (!*op->resnull)
3693  {
3694  text *result;
3695 
3696  result = cstring_to_text_with_len(buf.data, buf.len);
3697  *op->resvalue = PointerGetDatum(result);
3698  }
3699 
3700  pfree(buf.data);
3701  }
3702  break;
3703 
3704  case IS_XMLELEMENT:
3705  *op->resvalue = PointerGetDatum(xmlelement(xexpr,
3706  op->d.xmlexpr.named_argvalue,
3707  op->d.xmlexpr.named_argnull,
3708  op->d.xmlexpr.argvalue,
3709  op->d.xmlexpr.argnull));
3710  *op->resnull = false;
3711  break;
3712 
3713  case IS_XMLPARSE:
3714  {
3715  Datum *argvalue = op->d.xmlexpr.argvalue;
3716  bool *argnull = op->d.xmlexpr.argnull;
3717  text *data;
3718  bool preserve_whitespace;
3719 
3720  /* arguments are known to be text, bool */
3721  Assert(list_length(xexpr->args) == 2);
3722 
3723  if (argnull[0])
3724  return;
3725  value = argvalue[0];
3726  data = DatumGetTextPP(value);
3727 
3728  if (argnull[1]) /* probably can't happen */
3729  return;
3730  value = argvalue[1];
3731  preserve_whitespace = DatumGetBool(value);
3732 
3733  *op->resvalue = PointerGetDatum(xmlparse(data,
3734  xexpr->xmloption,
3735  preserve_whitespace));
3736  *op->resnull = false;
3737  }
3738  break;
3739 
3740  case IS_XMLPI:
3741  {
3742  text *arg;
3743  bool isnull;
3744 
3745  /* optional argument is known to be text */
3746  Assert(list_length(xexpr->args) <= 1);
3747 
3748  if (xexpr->args)
3749  {
3750  isnull = op->d.xmlexpr.argnull[0];
3751  if (isnull)
3752  arg = NULL;
3753  else
3754  arg = DatumGetTextPP(op->d.xmlexpr.argvalue[0]);
3755  }
3756  else
3757  {
3758  arg = NULL;
3759  isnull = false;
3760  }
3761 
3762  *op->resvalue = PointerGetDatum(xmlpi(xexpr->name,
3763  arg,
3764  isnull,
3765  op->resnull));
3766  }
3767  break;
3768 
3769  case IS_XMLROOT:
3770  {
3771  Datum *argvalue = op->d.xmlexpr.argvalue;
3772  bool *argnull = op->d.xmlexpr.argnull;
3773  xmltype *data;
3774  text *version;
3775  int standalone;
3776 
3777  /* arguments are known to be xml, text, int */
3778  Assert(list_length(xexpr->args) == 3);
3779 
3780  if (argnull[0])
3781  return;
3782  data = DatumGetXmlP(argvalue[0]);
3783 
3784  if (argnull[1])
3785  version = NULL;
3786  else
3787  version = DatumGetTextPP(argvalue[1]);
3788 
3789  Assert(!argnull[2]); /* always present */
3790  standalone = DatumGetInt32(argvalue[2]);
3791 
3792  *op->resvalue = PointerGetDatum(xmlroot(data,
3793  version,
3794  standalone));
3795  *op->resnull = false;
3796  }
3797  break;
3798 
3799  case IS_XMLSERIALIZE:
3800  {
3801  Datum *argvalue = op->d.xmlexpr.argvalue;
3802  bool *argnull = op->d.xmlexpr.argnull;
3803 
3804  /* argument type is known to be xml */
3805  Assert(list_length(xexpr->args) == 1);
3806 
3807  if (argnull[0])
3808  return;
3809  value = argvalue[0];
3810 
3811  *op->resvalue = PointerGetDatum(
3813  xexpr->xmloption));
3814  *op->resnull = false;
3815  }
3816  break;
3817 
3818  case IS_DOCUMENT:
3819  {
3820  Datum *argvalue = op->d.xmlexpr.argvalue;
3821  bool *argnull = op->d.xmlexpr.argnull;
3822 
3823  /* optional argument is known to be xml */
3824  Assert(list_length(xexpr->args) == 1);
3825 
3826  if (argnull[0])
3827  return;
3828  value = argvalue[0];
3829 
3830  *op->resvalue =
3832  *op->resnull = false;
3833  }
3834  break;
3835 
3836  default:
3837  elog(ERROR, "unrecognized XML operation");
3838  break;
3839  }
3840 }
#define NIL
Definition: pg_list.h:65
struct ExprEvalStep::@52::@84 xmlexpr
#define forboth(cell1, list1, cell2, list2)
Definition: pg_list.h:419
char * name
Definition: primnodes.h:1168
Datum * resvalue
Definition: execExpr.h:250
#define DatumGetInt32(X)
Definition: postgres.h:472
#define PointerGetDatum(X)
Definition: postgres.h:556
#define DatumGetTextPP(X)
Definition: fmgr.h:286
bool * resnull
Definition: execExpr.h:251
xmltype * xmlconcat(List *args)
Definition: xml.c:512
static struct @145 value
Definition: nodes.h:525
#define strVal(v)
Definition: value.h:54
union ExprEvalStep::@52 d
List * arg_names
Definition: primnodes.h:1170
#define DatumGetXmlP(X)
Definition: xml.h:50
xmltype * xmlpi(const char *target, text *arg, bool arg_is_null, bool *result_is_null)
Definition: xml.c:770
void pfree(void *pointer)
Definition: mcxt.c:1056
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:78
#define ERROR
Definition: elog.h:43
text * xmltotext_with_xmloption(xmltype *data, XmlOptionType xmloption_arg)
Definition: xml.c:615
static char * buf
Definition: pg_test_fsync.c:68
text * cstring_to_text_with_len(const char *s, int len)
Definition: varlena.c:183
xmltype * xmlroot(xmltype *data, text *version, int standalone)
Definition: xml.c:822
#define DatumGetBool(X)
Definition: postgres.h:393
List * lappend(List *list, void *datum)
Definition: list.c:322
bool xml_is_document(xmltype *arg)
Definition: xml.c:888
void initStringInfo(StringInfo str)
Definition: stringinfo.c:46
XmlExprOp op
Definition: primnodes.h:1167
uintptr_t Datum
Definition: postgres.h:367
#define BoolGetDatum(X)
Definition: postgres.h:402
List * named_args
Definition: primnodes.h:1169
List * args
Definition: primnodes.h:1171
#define Assert(condition)
Definition: c.h:732
#define lfirst(lc)
Definition: pg_list.h:190
XmlOptionType xmloption
Definition: primnodes.h:1172
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:42
static int list_length(const List *l)
Definition: pg_list.h:169
#define DatumGetPointer(X)
Definition: postgres.h:549
static Datum values[MAXATTR]
Definition: bootstrap.c:167
e
Definition: preproc-init.c:82
#define elog(elevel,...)
Definition: elog.h:226
int i
xmltype * xmlelement(XmlExpr *xexpr, Datum *named_argvalue, bool *named_argnull, Datum *argvalue, bool *argnull)
Definition: xml.c:628
void * arg
Definition: c.h:549
char * map_sql_value_to_xml_value(Datum value, Oid type, bool xml_escape_strings)
Definition: xml.c:2154
Definition: pg_list.h:50
xmltype * xmlparse(text *data, XmlOptionType xmloption_arg, bool preserve_whitespace)
Definition: xml.c:752

◆ ExecInterpExprStillValid()

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

Definition at line 1798 of file execExprInterp.c.

References CheckExprStillValid(), ExprState::evalfunc, and ExprState::evalfunc_private.

Referenced by ExecReadyInterpretedExpr().

1799 {
1800  /*
1801  * First time through, check whether attribute matches Var. Might not be
1802  * ok anymore, due to schema changes.
1803  */
1804  CheckExprStillValid(state, econtext);
1805 
1806  /* skip the check during further executions */
1807  state->evalfunc = (ExprStateEvalFunc) state->evalfunc_private;
1808 
1809  /* and actually execute */
1810  return state->evalfunc(state, econtext, isNull);
1811 }
Datum(* ExprStateEvalFunc)(struct ExprState *expression, struct ExprContext *econtext, bool *isNull)
Definition: execnodes.h:54
ExprStateEvalFunc evalfunc
Definition: execnodes.h:92
void * evalfunc_private
Definition: execnodes.h:98
void CheckExprStillValid(ExprState *state, ExprContext *econtext)

◆ ExecReadyInterpretedExpr()

void ExecReadyInterpretedExpr ( ExprState state)

Definition at line 175 of file execExprInterp.c.

References Assert, ExprEvalStep::casetest, ExprEvalStep::d, 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, ExprState::evalfunc, ExprState::evalfunc_private, ExecInitInterpreter(), ExecInterpExpr(), ExecInterpExprStillValid(), ExecJustApplyFuncToCase(), ExecJustAssignInnerVar(), ExecJustAssignInnerVarVirt(), ExecJustAssignOuterVar(), ExecJustAssignOuterVarVirt(), ExecJustAssignScanVar(), ExecJustAssignScanVarVirt(), ExecJustConst(), ExecJustInnerVar(), ExecJustInnerVarVirt(), ExecJustOuterVar(), ExecJustOuterVarVirt(), ExecJustScanVar(), ExecJustScanVarVirt(), ExprState::flags, ExprEvalStep::opcode, ExprState::steps, and ExprState::steps_len.

Referenced by ExecReadyExpr().

176 {
177  /* Ensure one-time interpreter setup has been done */
179 
180  /* Simple validity checks on expression */
181  Assert(state->steps_len >= 1);
182  Assert(state->steps[state->steps_len - 1].opcode == EEOP_DONE);
183 
184  /*
185  * Don't perform redundant initialization. This is unreachable in current
186  * cases, but might be hit if there's additional expression evaluation
187  * methods that rely on interpreted execution to work.
188  */
190  return;
191 
192  /*
193  * First time through, check whether attribute matches Var. Might not be
194  * ok anymore, due to schema changes. We do that by setting up a callback
195  * that does checking on the first call, which then sets the evalfunc
196  * callback to the actual method of execution.
197  */
199 
200  /* DIRECT_THREADED should not already be set */
201  Assert((state->flags & EEO_FLAG_DIRECT_THREADED) == 0);
202 
203  /*
204  * There shouldn't be any errors before the expression is fully
205  * initialized, and even if so, it'd lead to the expression being
206  * abandoned. So we can set the flag now and save some code.
207  */
209 
210  /*
211  * Select fast-path evalfuncs for very simple expressions. "Starting up"
212  * the full interpreter is a measurable overhead for these, and these
213  * patterns occur often enough to be worth optimizing.
214  */
215  if (state->steps_len == 3)
216  {
217  ExprEvalOp step0 = state->steps[0].opcode;
218  ExprEvalOp step1 = state->steps[1].opcode;
219 
220  if (step0 == EEOP_INNER_FETCHSOME &&
221  step1 == EEOP_INNER_VAR)
222  {
223  state->evalfunc_private = (void *) ExecJustInnerVar;
224  return;
225  }
226  else if (step0 == EEOP_OUTER_FETCHSOME &&
227  step1 == EEOP_OUTER_VAR)
228  {
229  state->evalfunc_private = (void *) ExecJustOuterVar;
230  return;
231  }
232  else if (step0 == EEOP_SCAN_FETCHSOME &&
233  step1 == EEOP_SCAN_VAR)
234  {
235  state->evalfunc_private = (void *) ExecJustScanVar;
236  return;
237  }
238  else if (step0 == EEOP_INNER_FETCHSOME &&
239  step1 == EEOP_ASSIGN_INNER_VAR)
240  {
241  state->evalfunc_private = (void *) ExecJustAssignInnerVar;
242  return;
243  }
244  else if (step0 == EEOP_OUTER_FETCHSOME &&
245  step1 == EEOP_ASSIGN_OUTER_VAR)
246  {
247  state->evalfunc_private = (void *) ExecJustAssignOuterVar;
248  return;
249  }
250  else if (step0 == EEOP_SCAN_FETCHSOME &&
251  step1 == EEOP_ASSIGN_SCAN_VAR)
252  {
253  state->evalfunc_private = (void *) ExecJustAssignScanVar;
254  return;
255  }
256  else if (step0 == EEOP_CASE_TESTVAL &&
257  step1 == EEOP_FUNCEXPR_STRICT &&
258  state->steps[0].d.casetest.value)
259  {
260  state->evalfunc_private = (void *) ExecJustApplyFuncToCase;
261  return;
262  }
263  }
264  else if (state->steps_len == 2)
265  {
266  ExprEvalOp step0 = state->steps[0].opcode;
267 
268  if (step0 == EEOP_CONST)
269  {
270  state->evalfunc_private = (void *) ExecJustConst;
271  return;
272  }
273  else if (step0 == EEOP_INNER_VAR)
274  {
275  state->evalfunc_private = (void *) ExecJustInnerVarVirt;
276  return;
277  }
278  else if (step0 == EEOP_OUTER_VAR)
279  {
280  state->evalfunc_private = (void *) ExecJustOuterVarVirt;
281  return;
282  }
283  else if (step0 == EEOP_SCAN_VAR)
284  {
285  state->evalfunc_private = (void *) ExecJustScanVarVirt;
286  return;
287  }
288  else if (step0 == EEOP_ASSIGN_INNER_VAR)
289  {
291  return;
292  }
293  else if (step0 == EEOP_ASSIGN_OUTER_VAR)
294  {
296  return;
297  }
298  else if (step0 == EEOP_ASSIGN_SCAN_VAR)
299  {
301  return;
302  }
303  }
304 
305 #if defined(EEO_USE_COMPUTED_GOTO)
306 
307  /*
308  * In the direct-threaded implementation, replace each opcode with the
309  * address to jump to. (Use ExecEvalStepOp() to get back the opcode.)
310  */
311  {
312  int off;
313 
314  for (off = 0; off < state->steps_len; off++)
315  {
316  ExprEvalStep *op = &state->steps[off];
317 
318  op->opcode = EEO_OPCODE(op->opcode);
319  }
320 
322  }
323 #endif /* EEO_USE_COMPUTED_GOTO */
324 
325  state->evalfunc_private = (void *) ExecInterpExpr;
326 }
Datum ExecInterpExprStillValid(ExprState *state, ExprContext *econtext, bool *isNull)
static Datum ExecJustOuterVar(ExprState *state, ExprContext *econtext, bool *isnull)
static Datum ExecJustScanVar(ExprState *state, ExprContext *econtext, bool *isnull)
static Datum ExecJustInnerVarVirt(ExprState *state, ExprContext *econtext, bool *isnull)
struct ExprEvalStep * steps
Definition: execnodes.h:86
ExprEvalOp
Definition: execExpr.h:44
union ExprEvalStep::@52 d
static Datum ExecJustConst(ExprState *state, ExprContext *econtext, bool *isnull)
ExprStateEvalFunc evalfunc
Definition: execnodes.h:92
static Datum ExecJustInnerVar(ExprState *state, ExprContext *econtext, bool *isnull)
struct ExprEvalStep::@52::@66 casetest
static Datum ExecJustAssignOuterVar(ExprState *state, ExprContext *econtext, bool *isnull)
void * evalfunc_private
Definition: execnodes.h:98
static Datum ExecJustApplyFuncToCase(ExprState *state, ExprContext *econtext, bool *isnull)
static Datum ExecJustAssignOuterVarVirt(ExprState *state, ExprContext *econtext, bool *isnull)
static Datum ExecJustScanVarVirt(ExprState *state, ExprContext *econtext, bool *isnull)
static Datum ExecJustAssignScanVarVirt(ExprState *state, ExprContext *econtext, bool *isnull)
#define Assert(condition)
Definition: c.h:732
intptr_t opcode
Definition: execExpr.h:247
static Datum ExecJustAssignScanVar(ExprState *state, ExprContext *econtext, bool *isnull)
static void ExecInitInterpreter(void)
static Datum ExecInterpExpr(ExprState *state, ExprContext *econtext, bool *isnull)
static Datum ExecJustOuterVarVirt(ExprState *state, ExprContext *econtext, bool *isnull)
int steps_len
Definition: execnodes.h:105
static Datum ExecJustAssignInnerVarVirt(ExprState *state, ExprContext *econtext, bool *isnull)
static Datum ExecJustAssignInnerVar(ExprState *state, ExprContext *econtext, bool *isnull)
uint8 flags
Definition: execnodes.h:66
#define EEO_OPCODE(opcode)
#define EEO_FLAG_INTERPRETER_INITIALIZED
Definition: execExpr.h:26
#define EEO_FLAG_DIRECT_THREADED
Definition: execExpr.h:28

◆ ExprEvalPushStep()

void ExprEvalPushStep ( ExprState es,
const ExprEvalStep s 
)

Definition at line 2124 of file execExpr.c.

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

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

2125 {
2126  if (es->steps_alloc == 0)
2127  {
2128  es->steps_alloc = 16;
2129  es->steps = palloc(sizeof(ExprEvalStep) * es->steps_alloc);
2130  }
2131  else if (es->steps_alloc == es->steps_len)
2132  {
2133  es->steps_alloc *= 2;
2134  es->steps = repalloc(es->steps,
2135  sizeof(ExprEvalStep) * es->steps_alloc);
2136  }
2137 
2138  memcpy(&es->steps[es->steps_len++], s, sizeof(ExprEvalStep));
2139 }
struct ExprEvalStep * steps
Definition: execnodes.h:86
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:1069
int steps_alloc
Definition: execnodes.h:106
void * palloc(Size size)
Definition: mcxt.c:949
int steps_len
Definition: execnodes.h:105