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

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

◆ ExecAggInitGroup()

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

Definition at line 4157 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().

4158 {
4159  FunctionCallInfo fcinfo = pertrans->transfn_fcinfo;
4160  MemoryContext oldContext;
4161 
4162  /*
4163  * We must copy the datum into aggcontext if it is pass-by-ref. We do not
4164  * need to pfree the old transValue, since it's NULL. (We already checked
4165  * that the agg's input type is binary-compatible with its transtype, so
4166  * straight copy here is OK.)
4167  */
4168  oldContext = MemoryContextSwitchTo(
4170  pergroup->transValue = datumCopy(fcinfo->args[1].value,
4171  pertrans->transtypeByVal,
4172  pertrans->transtypeLen);
4173  pergroup->transValueIsNull = false;
4174  pergroup->noTransValue = false;
4175  MemoryContextSwitchTo(oldContext);
4176 }
MemoryContext ecxt_per_tuple_memory
Definition: execnodes.h:231
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:2050

◆ ExecAggTransReparent()

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

Definition at line 4185 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().

4188 {
4189  if (!newValueIsNull)
4190  {
4192  if (DatumIsReadWriteExpandedObject(newValue,
4193  false,
4194  pertrans->transtypeLen) &&
4195  MemoryContextGetParent(DatumGetEOHP(newValue)->eoh_context) == CurrentMemoryContext)
4196  /* do nothing */ ;
4197  else
4198  newValue = datumCopy(newValue,
4199  pertrans->transtypeByVal,
4200  pertrans->transtypeLen);
4201  }
4202  if (!oldValueIsNull)
4203  {
4204  if (DatumIsReadWriteExpandedObject(oldValue,
4205  false,
4206  pertrans->transtypeLen))
4207  DeleteExpandedObject(oldValue);
4208  else
4209  pfree(DatumGetPointer(oldValue));
4210  }
4211 
4212  return newValue;
4213 }
MemoryContext MemoryContextGetParent(MemoryContext context)
Definition: mcxt.c:439
MemoryContext ecxt_per_tuple_memory
Definition: execnodes.h:231
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:2050
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 4219 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

4221 {
4222  AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
4223  int setno = op->d.agg_trans.setno;
4224 
4225  tuplesort_putdatum(pertrans->sortstates[setno],
4226  *op->resvalue, *op->resnull);
4227 }
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 4233 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().

4235 {
4236  AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
4237  int setno = op->d.agg_trans.setno;
4238 
4239  ExecClearTuple(pertrans->sortslot);
4240  pertrans->sortslot->tts_nvalid = pertrans->numInputs;
4241  ExecStoreVirtualTuple(pertrans->sortslot);
4242  tuplesort_puttupleslot(pertrans->sortstates[setno], pertrans->sortslot);
4243 }
struct ExprEvalStep::@52::@94 agg_trans
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:425
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:1522
void tuplesort_puttupleslot(Tuplesortstate *state, TupleTableSlot *slot)
Definition: tuplesort.c:1435

◆ ExecEvalAlternativeSubPlan()

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

Definition at line 3889 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

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

◆ ExecEvalArrayCoerce()

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

Definition at line 2847 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

2848 {
2849  Datum arraydatum;
2850 
2851  /* NULL array -> NULL result */
2852  if (*op->resnull)
2853  return;
2854 
2855  arraydatum = *op->resvalue;
2856 
2857  /*
2858  * If it's binary-compatible, modify the element type in the array header,
2859  * but otherwise leave the array as we received it.
2860  */
2861  if (op->d.arraycoerce.elemexprstate == NULL)
2862  {
2863  /* Detoast input array if necessary, and copy in any case */
2864  ArrayType *array = DatumGetArrayTypePCopy(arraydatum);
2865 
2866  ARR_ELEMTYPE(array) = op->d.arraycoerce.resultelemtype;
2867  *op->resvalue = PointerGetDatum(array);
2868  return;
2869  }
2870 
2871  /*
2872  * Use array_map to apply the sub-expression to each array element.
2873  */
2874  *op->resvalue = array_map(arraydatum,
2875  op->d.arraycoerce.elemexprstate,
2876  econtext,
2877  op->d.arraycoerce.resultelemtype,
2878  op->d.arraycoerce.amstate);
2879 }
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 2640 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().

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

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

Referenced by ExecInterpExpr().

3612 {
3613  if (!*op->d.domaincheck.checknull &&
3614  !DatumGetBool(*op->d.domaincheck.checkvalue))
3615  ereport(ERROR,
3616  (errcode(ERRCODE_CHECK_VIOLATION),
3617  errmsg("value for domain %s violates check constraint \"%s\"",
3618  format_type_be(op->d.domaincheck.resulttype),
3619  op->d.domaincheck.constraintname),
3620  errdomainconstraint(op->d.domaincheck.resulttype,
3621  op->d.domaincheck.constraintname)));
3622 }
int errcode(int sqlerrcode)
Definition: elog.c:608
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:822

◆ ExecEvalConstraintNotNull()

void ExecEvalConstraintNotNull ( ExprState state,
ExprEvalStep op 
)

Definition at line 3597 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

3598 {
3599  if (*op->resnull)
3600  ereport(ERROR,
3601  (errcode(ERRCODE_NOT_NULL_VIOLATION),
3602  errmsg("domain %s does not allow null values",
3603  format_type_be(op->d.domaincheck.resulttype)),
3604  errdatatype(op->d.domaincheck.resulttype)));
3605 }
bool * resnull
Definition: execExpr.h:251
int errcode(int sqlerrcode)
Definition: elog.c:608
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:822

◆ ExecEvalConvertRowtype()

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

Definition at line 3348 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().

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

◆ ExecEvalCurrentOfExpr()

void ExecEvalCurrentOfExpr ( ExprState state,
ExprEvalStep op 
)

Definition at line 2499 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

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

◆ ExecEvalFieldSelect()

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

Definition at line 2962 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().

2963 {
2964  AttrNumber fieldnum = op->d.fieldselect.fieldnum;
2965  Datum tupDatum;
2966  HeapTupleHeader tuple;
2967  Oid tupType;
2968  int32 tupTypmod;
2969  TupleDesc tupDesc;
2970  Form_pg_attribute attr;
2971  HeapTupleData tmptup;
2972 
2973  /* NULL record -> NULL result */
2974  if (*op->resnull)
2975  return;
2976 
2977  tupDatum = *op->resvalue;
2978 
2979  /* We can special-case expanded records for speed */
2981  {
2983 
2984  Assert(erh->er_magic == ER_MAGIC);
2985 
2986  /* Extract record's TupleDesc */
2987  tupDesc = expanded_record_get_tupdesc(erh);
2988 
2989  /*
2990  * Find field's attr record. Note we don't support system columns
2991  * here: a datum tuple doesn't have valid values for most of the
2992  * interesting system columns anyway.
2993  */
2994  if (fieldnum <= 0) /* should never happen */
2995  elog(ERROR, "unsupported reference to system column %d in FieldSelect",
2996  fieldnum);
2997  if (fieldnum > tupDesc->natts) /* should never happen */
2998  elog(ERROR, "attribute number %d exceeds number of columns %d",
2999  fieldnum, tupDesc->natts);
3000  attr = TupleDescAttr(tupDesc, fieldnum - 1);
3001 
3002  /* Check for dropped column, and force a NULL result if so */
3003  if (attr->attisdropped)
3004  {
3005  *op->resnull = true;
3006  return;
3007  }
3008 
3009  /* Check for type mismatch --- possible after ALTER COLUMN TYPE? */
3010  /* As in CheckVarSlotCompatibility, we should but can't check typmod */
3011  if (op->d.fieldselect.resulttype != attr->atttypid)
3012  ereport(ERROR,
3013  (errcode(ERRCODE_DATATYPE_MISMATCH),
3014  errmsg("attribute %d has wrong type", fieldnum),
3015  errdetail("Table has type %s, but query expects %s.",
3016  format_type_be(attr->atttypid),
3017  format_type_be(op->d.fieldselect.resulttype))));
3018 
3019  /* extract the field */
3020  *op->resvalue = expanded_record_get_field(erh, fieldnum,
3021  op->resnull);
3022  }
3023  else
3024  {
3025  /* Get the composite datum and extract its type fields */
3026  tuple = DatumGetHeapTupleHeader(tupDatum);
3027 
3028  tupType = HeapTupleHeaderGetTypeId(tuple);
3029  tupTypmod = HeapTupleHeaderGetTypMod(tuple);
3030 
3031  /* Lookup tupdesc if first time through or if type changes */
3032  tupDesc = get_cached_rowtype(tupType, tupTypmod,
3033  &op->d.fieldselect.argdesc,
3034  econtext);
3035 
3036  /*
3037  * Find field's attr record. Note we don't support system columns
3038  * here: a datum tuple doesn't have valid values for most of the
3039  * interesting system columns anyway.
3040  */
3041  if (fieldnum <= 0) /* should never happen */
3042  elog(ERROR, "unsupported reference to system column %d in FieldSelect",
3043  fieldnum);
3044  if (fieldnum > tupDesc->natts) /* should never happen */
3045  elog(ERROR, "attribute number %d exceeds number of columns %d",
3046  fieldnum, tupDesc->natts);
3047  attr = TupleDescAttr(tupDesc, fieldnum - 1);
3048 
3049  /* Check for dropped column, and force a NULL result if so */
3050  if (attr->attisdropped)
3051  {
3052  *op->resnull = true;
3053  return;
3054  }
3055 
3056  /* Check for type mismatch --- possible after ALTER COLUMN TYPE? */
3057  /* As in CheckVarSlotCompatibility, we should but can't check typmod */
3058  if (op->d.fieldselect.resulttype != attr->atttypid)
3059  ereport(ERROR,
3060  (errcode(ERRCODE_DATATYPE_MISMATCH),
3061  errmsg("attribute %d has wrong type", fieldnum),
3062  errdetail("Table has type %s, but query expects %s.",
3063  format_type_be(attr->atttypid),
3064  format_type_be(op->d.fieldselect.resulttype))));
3065 
3066  /* heap_getattr needs a HeapTuple not a bare HeapTupleHeader */
3067  tmptup.t_len = HeapTupleHeaderGetDatumLength(tuple);
3068  tmptup.t_data = tuple;
3069 
3070  /* extract the field */
3071  *op->resvalue = heap_getattr(&tmptup,
3072  fieldnum,
3073  tupDesc,
3074  op->resnull);
3075  }
3076 }
#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:608
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:347
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:955
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:739
#define DatumGetPointer(X)
Definition: postgres.h:549
int errmsg(const char *fmt,...)
Definition: elog.c:822
#define elog(elevel,...)
Definition: elog.h:228
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 3088 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().

3089 {
3090  TupleDesc tupDesc;
3091 
3092  /* Lookup tupdesc if first time through or after rescan */
3093  tupDesc = get_cached_rowtype(op->d.fieldstore.fstore->resulttype, -1,
3094  op->d.fieldstore.argdesc, econtext);
3095 
3096  /* Check that current tupdesc doesn't have more fields than we allocated */
3097  if (unlikely(tupDesc->natts > op->d.fieldstore.ncolumns))
3098  elog(ERROR, "too many columns in composite type %u",
3099  op->d.fieldstore.fstore->resulttype);
3100 
3101  if (*op->resnull)
3102  {
3103  /* Convert null input tuple into an all-nulls row */
3104  memset(op->d.fieldstore.nulls, true,
3105  op->d.fieldstore.ncolumns * sizeof(bool));
3106  }
3107  else
3108  {
3109  /*
3110  * heap_deform_tuple needs a HeapTuple not a bare HeapTupleHeader. We
3111  * set all the fields in the struct just in case.
3112  */
3113  Datum tupDatum = *op->resvalue;
3114  HeapTupleHeader tuphdr;
3115  HeapTupleData tmptup;
3116 
3117  tuphdr = DatumGetHeapTupleHeader(tupDatum);
3118  tmptup.t_len = HeapTupleHeaderGetDatumLength(tuphdr);
3119  ItemPointerSetInvalid(&(tmptup.t_self));
3120  tmptup.t_tableOid = InvalidOid;
3121  tmptup.t_data = tuphdr;
3122 
3123  heap_deform_tuple(&tmptup, tupDesc,
3124  op->d.fieldstore.values,
3125  op->d.fieldstore.nulls);
3126  }
3127 }
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:228
#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 3134 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

3135 {
3136  HeapTuple tuple;
3137 
3138  /* argdesc should already be valid from the DeForm step */
3139  tuple = heap_form_tuple(*op->d.fieldstore.argdesc,
3140  op->d.fieldstore.values,
3141  op->d.fieldstore.nulls);
3142 
3143  *op->resvalue = HeapTupleGetDatum(tuple);
3144  *op->resnull = false;
3145 }
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:220

◆ ExecEvalFuncExprFusage()

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

Definition at line 2310 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().

2312 {
2313  FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
2314  PgStat_FunctionCallUsage fcusage;
2315  Datum d;
2316 
2317  pgstat_init_function_usage(fcinfo, &fcusage);
2318 
2319  fcinfo->isnull = false;
2320  d = op->d.func.fn_addr(fcinfo);
2321  *op->resvalue = d;
2322  *op->resnull = fcinfo->isnull;
2323 
2324  pgstat_end_function_usage(&fcusage, true);
2325 }
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:1620
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:1692

◆ ExecEvalFuncExprStrictFusage()

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

Definition at line 2331 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().

2333 {
2334 
2335  FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
2336  PgStat_FunctionCallUsage fcusage;
2337  NullableDatum *args = fcinfo->args;
2338  int argno;
2339  Datum d;
2340 
2341  /* strict function, so check for NULL args */
2342  for (argno = 0; argno < op->d.func.nargs; argno++)
2343  {
2344  if (args[argno].isnull)
2345  {
2346  *op->resnull = true;
2347  return;
2348  }
2349  }
2350 
2351  pgstat_init_function_usage(fcinfo, &fcusage);
2352 
2353  fcinfo->isnull = false;
2354  d = op->d.func.fn_addr(fcinfo);
2355  *op->resvalue = d;
2356  *op->resnull = fcinfo->isnull;
2357 
2358  pgstat_end_function_usage(&fcusage, true);
2359 }
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:1620
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:1692

◆ ExecEvalGroupingFunc()

void ExecEvalGroupingFunc ( ExprState state,
ExprEvalStep op 
)

Definition at line 3851 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().

3852 {
3853  int result = 0;
3854  Bitmapset *grouped_cols = op->d.grouping_func.parent->grouped_cols;
3855  ListCell *lc;
3856 
3857  foreach(lc, op->d.grouping_func.clauses)
3858  {
3859  int attnum = lfirst_int(lc);
3860 
3861  result <<= 1;
3862 
3863  if (!bms_is_member(attnum, grouped_cols))
3864  result |= 1;
3865  }
3866 
3867  *op->resvalue = Int32GetDatum(result);
3868  *op->resnull = false;
3869 }
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 2908 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().

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

◆ ExecEvalNextValueExpr()

void ExecEvalNextValueExpr ( ExprState state,
ExprEvalStep op 
)

Definition at line 2510 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().

2511 {
2512  int64 newval = nextval_internal(op->d.nextvalueexpr.seqid, false);
2513 
2514  switch (op->d.nextvalueexpr.seqtypid)
2515  {
2516  case INT2OID:
2517  *op->resvalue = Int16GetDatum((int16) newval);
2518  break;
2519  case INT4OID:
2520  *op->resvalue = Int32GetDatum((int32) newval);
2521  break;
2522  case INT8OID:
2523  *op->resvalue = Int64GetDatum((int64) newval);
2524  break;
2525  default:
2526  elog(ERROR, "unsupported sequence type %u",
2527  op->d.nextvalueexpr.seqtypid);
2528  }
2529  *op->resnull = false;
2530 }
signed short int16
Definition: c.h:346
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:347
#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:228

◆ ExecEvalParamExec()

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

Definition at line 2368 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().

2369 {
2370  ParamExecData *prm;
2371 
2372  prm = &(econtext->ecxt_param_exec_vals[op->d.param.paramid]);
2373  if (unlikely(prm->execPlan != NULL))
2374  {
2375  /* Parameter not evaluated yet, so go do it */
2376  ExecSetParamPlan(prm->execPlan, econtext);
2377  /* ExecSetParamPlan should have processed this param... */
2378  Assert(prm->execPlan == NULL);
2379  }
2380  *op->resvalue = prm->value;
2381  *op->resnull = prm->isnull;
2382 }
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:1050
bool isnull
Definition: params.h:149
ParamExecData * ecxt_param_exec_vals
Definition: execnodes.h:234
struct ExprEvalStep::@52::@64 param
#define Assert(condition)
Definition: c.h:739
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 2390 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().

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

◆ ExecEvalRow()

void ExecEvalRow ( ExprState state,
ExprEvalStep op 
)

Definition at line 2888 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

2889 {
2890  HeapTuple tuple;
2891 
2892  /* build tuple from evaluated field values */
2893  tuple = heap_form_tuple(op->d.row.tupdesc,
2894  op->d.row.elemvalues,
2895  op->d.row.elemnulls);
2896 
2897  *op->resvalue = HeapTupleGetDatum(tuple);
2898  *op->resnull = false;
2899 }
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:220

◆ ExecEvalRowNotNull()

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

Definition at line 2545 of file execExprInterp.c.

References ExecEvalRowNullInt().

Referenced by ExecInterpExpr().

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

◆ ExecEvalRowNull()

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

Definition at line 2536 of file execExprInterp.c.

References ExecEvalRowNullInt().

Referenced by ExecInterpExpr().

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

◆ ExecEvalScalarArrayOp()

void ExecEvalScalarArrayOp ( ExprState state,
ExprEvalStep op 
)

Definition at line 3446 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().

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

2433 {
2434  LOCAL_FCINFO(fcinfo, 0);
2435  SQLValueFunction *svf = op->d.sqlvaluefunction.svf;
2436 
2437  *op->resnull = false;
2438 
2439  /*
2440  * Note: current_schema() can return NULL. current_user() etc currently
2441  * cannot, but might as well code those cases the same way for safety.
2442  */
2443  switch (svf->op)
2444  {
2445  case SVFOP_CURRENT_DATE:
2447  break;
2448  case SVFOP_CURRENT_TIME:
2449  case SVFOP_CURRENT_TIME_N:
2451  break;
2455  break;
2456  case SVFOP_LOCALTIME:
2457  case SVFOP_LOCALTIME_N:
2459  break;
2460  case SVFOP_LOCALTIMESTAMP:
2463  break;
2464  case SVFOP_CURRENT_ROLE:
2465  case SVFOP_CURRENT_USER:
2466  case SVFOP_USER:
2467  InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
2468  *op->resvalue = current_user(fcinfo);
2469  *op->resnull = fcinfo->isnull;
2470  break;
2471  case SVFOP_SESSION_USER:
2472  InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
2473  *op->resvalue = session_user(fcinfo);
2474  *op->resnull = fcinfo->isnull;
2475  break;
2476  case SVFOP_CURRENT_CATALOG:
2477  InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
2478  *op->resvalue = current_database(fcinfo);
2479  *op->resnull = fcinfo->isnull;
2480  break;
2481  case SVFOP_CURRENT_SCHEMA:
2482  InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
2483  *op->resvalue = current_schema(fcinfo);
2484  *op->resnull = fcinfo->isnull;
2485  break;
2486  }
2487 }
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:169
#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 2280 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().

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

◆ ExecEvalSubPlan()

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

Definition at line 3875 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

3876 {
3877  SubPlanState *sstate = op->d.subplan.sstate;
3878 
3879  /* could potentially be nested, so make sure there's enough stack */
3881 
3882  *op->resvalue = ExecSubPlan(sstate, econtext, op->resnull);
3883 }
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:3284
Datum ExecSubPlan(SubPlanState *node, ExprContext *econtext, bool *isNull)
Definition: nodeSubplan.c:62

◆ ExecEvalSubscriptingRef()

bool ExecEvalSubscriptingRef ( ExprState state,
ExprEvalStep op 
)

Definition at line 3159 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().

3160 {
3161  SubscriptingRefState *sbsrefstate = op->d.sbsref_subscript.state;
3162  int *indexes;
3163  int off;
3164 
3165  /* If any index expr yields NULL, result is NULL or error */
3166  if (sbsrefstate->subscriptnull)
3167  {
3168  if (sbsrefstate->isassignment)
3169  ereport(ERROR,
3170  (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
3171  errmsg("array subscript in assignment must not be null")));
3172  *op->resnull = true;
3173  return false;
3174  }
3175 
3176  /* Convert datum to int, save in appropriate place */
3177  if (op->d.sbsref_subscript.isupper)
3178  indexes = sbsrefstate->upperindex;
3179  else
3180  indexes = sbsrefstate->lowerindex;
3181  off = op->d.sbsref_subscript.off;
3182 
3183  indexes[off] = DatumGetInt32(sbsrefstate->subscriptvalue);
3184 
3185  return true;
3186 }
#define DatumGetInt32(X)
Definition: postgres.h:472
bool * resnull
Definition: execExpr.h:251
int errcode(int sqlerrcode)
Definition: elog.c:608
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:822

◆ ExecEvalSubscriptingRefAssign()

void ExecEvalSubscriptingRefAssign ( ExprState state,
ExprEvalStep op 
)

Definition at line 3283 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().

3284 {
3285  SubscriptingRefState *sbsrefstate = op->d.sbsref_subscript.state;
3286 
3287  /*
3288  * For an assignment to a fixed-length container type, both the original
3289  * container and the value to be assigned into it must be non-NULL, else
3290  * we punt and return the original container.
3291  */
3292  if (sbsrefstate->refattrlength > 0)
3293  {
3294  if (*op->resnull || sbsrefstate->replacenull)
3295  return;
3296  }
3297 
3298  /*
3299  * For assignment to varlena arrays, we handle a NULL original array by
3300  * substituting an empty (zero-dimensional) array; insertion of the new
3301  * element will result in a singleton array value. It does not matter
3302  * whether the new element is NULL.
3303  */
3304  if (*op->resnull)
3305  {
3307  *op->resnull = false;
3308  }
3309 
3310  if (sbsrefstate->numlower == 0)
3311  {
3312  /* Scalar case */
3313  *op->resvalue = array_set_element(*op->resvalue,
3314  sbsrefstate->numupper,
3315  sbsrefstate->upperindex,
3316  sbsrefstate->replacevalue,
3317  sbsrefstate->replacenull,
3318  sbsrefstate->refattrlength,
3319  sbsrefstate->refelemlength,
3320  sbsrefstate->refelembyval,
3321  sbsrefstate->refelemalign);
3322  }
3323  else
3324  {
3325  /* Slice case */
3326  *op->resvalue = array_set_slice(*op->resvalue,
3327  sbsrefstate->numupper,
3328  sbsrefstate->upperindex,
3329  sbsrefstate->lowerindex,
3330  sbsrefstate->upperprovided,
3331  sbsrefstate->lowerprovided,
3332  sbsrefstate->replacevalue,
3333  sbsrefstate->replacenull,
3334  sbsrefstate->refattrlength,
3335  sbsrefstate->refelemlength,
3336  sbsrefstate->refelembyval,
3337  sbsrefstate->refelemalign);
3338  }
3339 }
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 3194 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().

3195 {
3196  SubscriptingRefState *sbsrefstate = op->d.sbsref.state;
3197 
3198  /* Should not get here if source container (or any subscript) is null */
3199  Assert(!(*op->resnull));
3200 
3201  if (sbsrefstate->numlower == 0)
3202  {
3203  /* Scalar case */
3204  *op->resvalue = array_get_element(*op->resvalue,
3205  sbsrefstate->numupper,
3206  sbsrefstate->upperindex,
3207  sbsrefstate->refattrlength,
3208  sbsrefstate->refelemlength,
3209  sbsrefstate->refelembyval,
3210  sbsrefstate->refelemalign,
3211  op->resnull);
3212  }
3213  else
3214  {
3215  /* Slice case */
3216  *op->resvalue = array_get_slice(*op->resvalue,
3217  sbsrefstate->numupper,
3218  sbsrefstate->upperindex,
3219  sbsrefstate->lowerindex,
3220  sbsrefstate->upperprovided,
3221  sbsrefstate->lowerprovided,
3222  sbsrefstate->refattrlength,
3223  sbsrefstate->refelemlength,
3224  sbsrefstate->refelembyval,
3225  sbsrefstate->refelemalign);
3226  }
3227 }
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:739
int lowerindex[MAXDIM]
Definition: execExpr.h:681
int upperindex[MAXDIM]
Definition: execExpr.h:676

◆ ExecEvalSubscriptingRefOld()

void ExecEvalSubscriptingRefOld ( ExprState state,
ExprEvalStep op 
)

Definition at line 3236 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().

3237 {
3238  SubscriptingRefState *sbsrefstate = op->d.sbsref.state;
3239 
3240  if (*op->resnull)
3241  {
3242  /* whole array is null, so any element or slice is too */
3243  sbsrefstate->prevvalue = (Datum) 0;
3244  sbsrefstate->prevnull = true;
3245  }
3246  else if (sbsrefstate->numlower == 0)
3247  {
3248  /* Scalar case */
3249  sbsrefstate->prevvalue = array_get_element(*op->resvalue,
3250  sbsrefstate->numupper,
3251  sbsrefstate->upperindex,
3252  sbsrefstate->refattrlength,
3253  sbsrefstate->refelemlength,
3254  sbsrefstate->refelembyval,
3255  sbsrefstate->refelemalign,
3256  &sbsrefstate->prevnull);
3257  }
3258  else
3259  {
3260  /* Slice case */
3261  /* this is currently unreachable */
3262  sbsrefstate->prevvalue = array_get_slice(*op->resvalue,
3263  sbsrefstate->numupper,
3264  sbsrefstate->upperindex,
3265  sbsrefstate->lowerindex,
3266  sbsrefstate->upperprovided,
3267  sbsrefstate->lowerprovided,
3268  sbsrefstate->refattrlength,
3269  sbsrefstate->refelemlength,
3270  sbsrefstate->refelembyval,
3271  sbsrefstate->refelemalign);
3272  sbsrefstate->prevnull = false;
3273  }
3274 }
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 4137 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

4139 {
4140  Datum d;
4141 
4142  /* slot_getsysattr has sufficient defenses against bad attnums */
4143  d = slot_getsysattr(slot,
4144  op->d.var.attnum,
4145  op->resnull);
4146  *op->resvalue = d;
4147  /* this ought to be unreachable, but it's cheap enough to check */
4148  if (unlikely(*op->resnull))
4149  elog(ERROR, "failed to fetch attribute from slot");
4150 }
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:228
#define unlikely(x)
Definition: c.h:208
static Datum slot_getsysattr(TupleTableSlot *slot, int attnum, bool *isnull)
Definition: tuptable.h:402

◆ ExecEvalWholeRowVar()

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

Definition at line 3906 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().

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

◆ ExecEvalXmlExpr()

void ExecEvalXmlExpr ( ExprState state,
ExprEvalStep op 
)

Definition at line 3631 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().

3632 {
3633  XmlExpr *xexpr = op->d.xmlexpr.xexpr;
3634  Datum value;
3635  int i;
3636 
3637  *op->resnull = true; /* until we get a result */
3638  *op->resvalue = (Datum) 0;
3639 
3640  switch (xexpr->op)
3641  {
3642  case IS_XMLCONCAT:
3643  {
3644  Datum *argvalue = op->d.xmlexpr.argvalue;
3645  bool *argnull = op->d.xmlexpr.argnull;
3646  List *values = NIL;
3647 
3648  for (i = 0; i < list_length(xexpr->args); i++)
3649  {
3650  if (!argnull[i])
3651  values = lappend(values, DatumGetPointer(argvalue[i]));
3652  }
3653 
3654  if (values != NIL)
3655  {
3656  *op->resvalue = PointerGetDatum(xmlconcat(values));
3657  *op->resnull = false;
3658  }
3659  }
3660  break;
3661 
3662  case IS_XMLFOREST:
3663  {
3664  Datum *argvalue = op->d.xmlexpr.named_argvalue;
3665  bool *argnull = op->d.xmlexpr.named_argnull;
3667  ListCell *lc;
3668  ListCell *lc2;
3669 
3670  initStringInfo(&buf);
3671 
3672  i = 0;
3673  forboth(lc, xexpr->named_args, lc2, xexpr->arg_names)
3674  {
3675  Expr *e = (Expr *) lfirst(lc);
3676  char *argname = strVal(lfirst(lc2));
3677 
3678  if (!argnull[i])
3679  {
3680  value = argvalue[i];
3681  appendStringInfo(&buf, "<%s>%s</%s>",
3682  argname,
3684  exprType((Node *) e), true),
3685  argname);
3686  *op->resnull = false;
3687  }
3688  i++;
3689  }
3690 
3691  if (!*op->resnull)
3692  {
3693  text *result;
3694 
3695  result = cstring_to_text_with_len(buf.data, buf.len);
3696  *op->resvalue = PointerGetDatum(result);
3697  }
3698 
3699  pfree(buf.data);
3700  }
3701  break;
3702 
3703  case IS_XMLELEMENT:
3704  *op->resvalue = PointerGetDatum(xmlelement(xexpr,
3705  op->d.xmlexpr.named_argvalue,
3706  op->d.xmlexpr.named_argnull,
3707  op->d.xmlexpr.argvalue,
3708  op->d.xmlexpr.argnull));
3709  *op->resnull = false;
3710  break;
3711 
3712  case IS_XMLPARSE:
3713  {
3714  Datum *argvalue = op->d.xmlexpr.argvalue;
3715  bool *argnull = op->d.xmlexpr.argnull;
3716  text *data;
3717  bool preserve_whitespace;
3718 
3719  /* arguments are known to be text, bool */
3720  Assert(list_length(xexpr->args) == 2);
3721 
3722  if (argnull[0])
3723  return;
3724  value = argvalue[0];
3725  data = DatumGetTextPP(value);
3726 
3727  if (argnull[1]) /* probably can't happen */
3728  return;
3729  value = argvalue[1];
3730  preserve_whitespace = DatumGetBool(value);
3731 
3732  *op->resvalue = PointerGetDatum(xmlparse(data,
3733  xexpr->xmloption,
3734  preserve_whitespace));
3735  *op->resnull = false;
3736  }
3737  break;
3738 
3739  case IS_XMLPI:
3740  {
3741  text *arg;
3742  bool isnull;
3743 
3744  /* optional argument is known to be text */
3745  Assert(list_length(xexpr->args) <= 1);
3746 
3747  if (xexpr->args)
3748  {
3749  isnull = op->d.xmlexpr.argnull[0];
3750  if (isnull)
3751  arg = NULL;
3752  else
3753  arg = DatumGetTextPP(op->d.xmlexpr.argvalue[0]);
3754  }
3755  else
3756  {
3757  arg = NULL;
3758  isnull = false;
3759  }
3760 
3761  *op->resvalue = PointerGetDatum(xmlpi(xexpr->name,
3762  arg,
3763  isnull,
3764  op->resnull));
3765  }
3766  break;
3767 
3768  case IS_XMLROOT:
3769  {
3770  Datum *argvalue = op->d.xmlexpr.argvalue;
3771  bool *argnull = op->d.xmlexpr.argnull;
3772  xmltype *data;
3773  text *version;
3774  int standalone;
3775 
3776  /* arguments are known to be xml, text, int */
3777  Assert(list_length(xexpr->args) == 3);
3778 
3779  if (argnull[0])
3780  return;
3781  data = DatumGetXmlP(argvalue[0]);
3782 
3783  if (argnull[1])
3784  version = NULL;
3785  else
3786  version = DatumGetTextPP(argvalue[1]);
3787 
3788  Assert(!argnull[2]); /* always present */
3789  standalone = DatumGetInt32(argvalue[2]);
3790 
3791  *op->resvalue = PointerGetDatum(xmlroot(data,
3792  version,
3793  standalone));
3794  *op->resnull = false;
3795  }
3796  break;
3797 
3798  case IS_XMLSERIALIZE:
3799  {
3800  Datum *argvalue = op->d.xmlexpr.argvalue;
3801  bool *argnull = op->d.xmlexpr.argnull;
3802 
3803  /* argument type is known to be xml */
3804  Assert(list_length(xexpr->args) == 1);
3805 
3806  if (argnull[0])
3807  return;
3808  value = argvalue[0];
3809 
3810  *op->resvalue = PointerGetDatum(
3812  xexpr->xmloption));
3813  *op->resnull = false;
3814  }
3815  break;
3816 
3817  case IS_DOCUMENT:
3818  {
3819  Datum *argvalue = op->d.xmlexpr.argvalue;
3820  bool *argnull = op->d.xmlexpr.argnull;
3821 
3822  /* optional argument is known to be xml */
3823  Assert(list_length(xexpr->args) == 1);
3824 
3825  if (argnull[0])
3826  return;
3827  value = argvalue[0];
3828 
3829  *op->resvalue =
3831  *op->resnull = false;
3832  }
3833  break;
3834 
3835  default:
3836  elog(ERROR, "unrecognized XML operation");
3837  break;
3838  }
3839 }
#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:91
#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:67
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:59
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:739
#define lfirst(lc)
Definition: pg_list.h:190
XmlOptionType xmloption
Definition: primnodes.h:1172
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:41
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:228
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:556
char * map_sql_value_to_xml_value(Datum value, Oid type, bool xml_escape_strings)
Definition: xml.c:2152
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 1797 of file execExprInterp.c.

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

Referenced by ExecReadyInterpretedExpr().

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

◆ ExecReadyInterpretedExpr()

void ExecReadyInterpretedExpr ( ExprState state)

Definition at line 174 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().

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