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_PLAIN_TRANS_INIT_STRICT_BYVAL, EEOP_AGG_PLAIN_TRANS_STRICT_BYVAL, EEOP_AGG_PLAIN_TRANS_BYVAL,
  EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYREF, EEOP_AGG_PLAIN_TRANS_STRICT_BYREF, EEOP_AGG_PLAIN_TRANS_BYREF, EEOP_AGG_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, ExprContext *aggcontext)
 
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_PLAIN_TRANS_INIT_STRICT_BYVAL 
EEOP_AGG_PLAIN_TRANS_STRICT_BYVAL 
EEOP_AGG_PLAIN_TRANS_BYVAL 
EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYREF 
EEOP_AGG_PLAIN_TRANS_STRICT_BYREF 
EEOP_AGG_PLAIN_TRANS_BYREF 
EEOP_AGG_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 */
236 
237  /* non-existent operation, used e.g. to check array lengths */
238  EEOP_LAST
239 } ExprEvalOp;
ExprEvalOp
Definition: execExpr.h:44

Function Documentation

◆ CheckExprStillValid()

void CheckExprStillValid ( ExprState state,
ExprContext econtext 
)

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

1799 {
1800  TupleTableSlot *innerslot;
1801  TupleTableSlot *outerslot;
1802  TupleTableSlot *scanslot;
1803 
1804  innerslot = econtext->ecxt_innertuple;
1805  outerslot = econtext->ecxt_outertuple;
1806  scanslot = econtext->ecxt_scantuple;
1807 
1808  for (int i = 0; i < state->steps_len; i++)
1809  {
1810  ExprEvalStep *op = &state->steps[i];
1811 
1812  switch (ExecEvalStepOp(state, op))
1813  {
1814  case EEOP_INNER_VAR:
1815  {
1816  int attnum = op->d.var.attnum;
1817 
1818  CheckVarSlotCompatibility(innerslot, attnum + 1, op->d.var.vartype);
1819  break;
1820  }
1821 
1822  case EEOP_OUTER_VAR:
1823  {
1824  int attnum = op->d.var.attnum;
1825 
1826  CheckVarSlotCompatibility(outerslot, attnum + 1, op->d.var.vartype);
1827  break;
1828  }
1829 
1830  case EEOP_SCAN_VAR:
1831  {
1832  int attnum = op->d.var.attnum;
1833 
1834  CheckVarSlotCompatibility(scanslot, attnum + 1, op->d.var.vartype);
1835  break;
1836  }
1837  default:
1838  break;
1839  }
1840  }
1841 }
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:226
int16 attnum
Definition: pg_attribute.h:79
TupleTableSlot * ecxt_outertuple
Definition: execnodes.h:228
TupleTableSlot * ecxt_scantuple
Definition: execnodes.h:224
int steps_len
Definition: execnodes.h:104
int i

◆ ExecAggInitGroup()

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

Definition at line 4129 of file execExprInterp.c.

References FunctionCallInfoBaseData::args, 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().

4131 {
4132  FunctionCallInfo fcinfo = pertrans->transfn_fcinfo;
4133  MemoryContext oldContext;
4134 
4135  /*
4136  * We must copy the datum into aggcontext if it is pass-by-ref. We do not
4137  * need to pfree the old transValue, since it's NULL. (We already checked
4138  * that the agg's input type is binary-compatible with its transtype, so
4139  * straight copy here is OK.)
4140  */
4141  oldContext = MemoryContextSwitchTo(aggcontext->ecxt_per_tuple_memory);
4142  pergroup->transValue = datumCopy(fcinfo->args[1].value,
4143  pertrans->transtypeByVal,
4144  pertrans->transtypeLen);
4145  pergroup->transValueIsNull = false;
4146  pergroup->noTransValue = false;
4147  MemoryContextSwitchTo(oldContext);
4148 }
MemoryContext ecxt_per_tuple_memory
Definition: execnodes.h:232
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
FunctionCallInfo transfn_fcinfo
Definition: nodeAgg.h:161
NullableDatum args[FLEXIBLE_ARRAY_MEMBER]
Definition: fmgr.h:95
Datum value
Definition: postgres.h:378
Datum datumCopy(Datum value, bool typByVal, int typLen)
Definition: datum.c:131

◆ ExecAggTransReparent()

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

Definition at line 4157 of file execExprInterp.c.

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

Referenced by advance_transition_function(), and ExecAggPlainTransByRef().

4160 {
4161  Assert(newValue != oldValue);
4162 
4163  if (!newValueIsNull)
4164  {
4166  if (DatumIsReadWriteExpandedObject(newValue,
4167  false,
4168  pertrans->transtypeLen) &&
4169  MemoryContextGetParent(DatumGetEOHP(newValue)->eoh_context) == CurrentMemoryContext)
4170  /* do nothing */ ;
4171  else
4172  newValue = datumCopy(newValue,
4173  pertrans->transtypeByVal,
4174  pertrans->transtypeLen);
4175  }
4176  else
4177  {
4178  /*
4179  * Ensure that AggStatePerGroup->transValue ends up being 0, so
4180  * callers can safely compare newValue/oldValue without having to
4181  * check their respective nullness.
4182  */
4183  newValue = (Datum) 0;
4184  }
4185 
4186  if (!oldValueIsNull)
4187  {
4188  if (DatumIsReadWriteExpandedObject(oldValue,
4189  false,
4190  pertrans->transtypeLen))
4191  DeleteExpandedObject(oldValue);
4192  else
4193  pfree(DatumGetPointer(oldValue));
4194  }
4195 
4196  return newValue;
4197 }
MemoryContext MemoryContextGetParent(MemoryContext context)
Definition: mcxt.c:439
MemoryContext ecxt_per_tuple_memory
Definition: execnodes.h:232
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
void pfree(void *pointer)
Definition: mcxt.c:1056
MemoryContext CurrentMemoryContext
Definition: mcxt.c:38
Datum datumCopy(Datum value, bool typByVal, int typLen)
Definition: datum.c:131
ExpandedObjectHeader * DatumGetEOHP(Datum d)
Definition: expandeddatum.c:29
ExprContext * curaggcontext
Definition: execnodes.h:2058
uintptr_t Datum
Definition: postgres.h:367
void DeleteExpandedObject(Datum d)
#define Assert(condition)
Definition: c.h:738
#define DatumIsReadWriteExpandedObject(d, isnull, typlen)
#define DatumGetPointer(X)
Definition: postgres.h:549

◆ ExecEvalAggOrderedTransDatum()

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

Definition at line 4203 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

4205 {
4206  AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
4207  int setno = op->d.agg_trans.setno;
4208 
4209  tuplesort_putdatum(pertrans->sortstates[setno],
4210  *op->resvalue, *op->resnull);
4211 }
void tuplesort_putdatum(Tuplesortstate *state, Datum val, bool isNull)
Definition: tuplesort.c:1556
Datum * resvalue
Definition: execExpr.h:252
bool * resnull
Definition: execExpr.h:253
union ExprEvalStep::@52 d
Tuplesortstate ** sortstates
Definition: nodeAgg.h:153
struct ExprEvalStep::@52::@92 agg_trans

◆ ExecEvalAggOrderedTransTuple()

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

Definition at line 4217 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

4219 {
4220  AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
4221  int setno = op->d.agg_trans.setno;
4222 
4223  ExecClearTuple(pertrans->sortslot);
4224  pertrans->sortslot->tts_nvalid = pertrans->numInputs;
4225  ExecStoreVirtualTuple(pertrans->sortslot);
4226  tuplesort_puttupleslot(pertrans->sortstates[setno], pertrans->sortslot);
4227 }
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:425
union ExprEvalStep::@52 d
Tuplesortstate ** sortstates
Definition: nodeAgg.h:153
struct ExprEvalStep::@52::@92 agg_trans
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 3863 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

3864 {
3865  AlternativeSubPlanState *asstate = op->d.alternative_subplan.asstate;
3866 
3867  /* could potentially be nested, so make sure there's enough stack */
3869 
3870  *op->resvalue = ExecAlternativeSubPlan(asstate, econtext, op->resnull);
3871 }
Datum * resvalue
Definition: execExpr.h:252
bool * resnull
Definition: execExpr.h:253
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:3297

◆ ExecEvalArrayCoerce()

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

Definition at line 2823 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

2824 {
2825  Datum arraydatum;
2826 
2827  /* NULL array -> NULL result */
2828  if (*op->resnull)
2829  return;
2830 
2831  arraydatum = *op->resvalue;
2832 
2833  /*
2834  * If it's binary-compatible, modify the element type in the array header,
2835  * but otherwise leave the array as we received it.
2836  */
2837  if (op->d.arraycoerce.elemexprstate == NULL)
2838  {
2839  /* Detoast input array if necessary, and copy in any case */
2840  ArrayType *array = DatumGetArrayTypePCopy(arraydatum);
2841 
2842  ARR_ELEMTYPE(array) = op->d.arraycoerce.resultelemtype;
2843  *op->resvalue = PointerGetDatum(array);
2844  return;
2845  }
2846 
2847  /*
2848  * Use array_map to apply the sub-expression to each array element.
2849  */
2850  *op->resvalue = array_map(arraydatum,
2851  op->d.arraycoerce.elemexprstate,
2852  econtext,
2853  op->d.arraycoerce.resultelemtype,
2854  op->d.arraycoerce.amstate);
2855 }
Datum * resvalue
Definition: execExpr.h:252
#define PointerGetDatum(X)
Definition: postgres.h:556
bool * resnull
Definition: execExpr.h:253
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 2618 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().

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

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

Referenced by ExecInterpExpr().

3586 {
3587  if (!*op->d.domaincheck.checknull &&
3588  !DatumGetBool(*op->d.domaincheck.checkvalue))
3589  ereport(ERROR,
3590  (errcode(ERRCODE_CHECK_VIOLATION),
3591  errmsg("value for domain %s violates check constraint \"%s\"",
3592  format_type_be(op->d.domaincheck.resulttype),
3593  op->d.domaincheck.constraintname),
3594  errdomainconstraint(op->d.domaincheck.resulttype,
3595  op->d.domaincheck.constraintname)));
3596 }
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 3571 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

3572 {
3573  if (*op->resnull)
3574  ereport(ERROR,
3575  (errcode(ERRCODE_NOT_NULL_VIOLATION),
3576  errmsg("domain %s does not allow null values",
3577  format_type_be(op->d.domaincheck.resulttype)),
3578  errdatatype(op->d.domaincheck.resulttype)));
3579 }
bool * resnull
Definition: execExpr.h:253
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 3323 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().

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

◆ ExecEvalCurrentOfExpr()

void ExecEvalCurrentOfExpr ( ExprState state,
ExprEvalStep op 
)

Definition at line 2478 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

2479 {
2480  ereport(ERROR,
2481  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2482  errmsg("WHERE CURRENT OF is not supported for this table type")));
2483 }
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 2937 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().

2938 {
2939  AttrNumber fieldnum = op->d.fieldselect.fieldnum;
2940  Datum tupDatum;
2941  HeapTupleHeader tuple;
2942  Oid tupType;
2943  int32 tupTypmod;
2944  TupleDesc tupDesc;
2945  Form_pg_attribute attr;
2946  HeapTupleData tmptup;
2947 
2948  /* NULL record -> NULL result */
2949  if (*op->resnull)
2950  return;
2951 
2952  tupDatum = *op->resvalue;
2953 
2954  /* We can special-case expanded records for speed */
2956  {
2958 
2959  Assert(erh->er_magic == ER_MAGIC);
2960 
2961  /* Extract record's TupleDesc */
2962  tupDesc = expanded_record_get_tupdesc(erh);
2963 
2964  /*
2965  * Find field's attr record. Note we don't support system columns
2966  * here: a datum tuple doesn't have valid values for most of the
2967  * interesting system columns anyway.
2968  */
2969  if (fieldnum <= 0) /* should never happen */
2970  elog(ERROR, "unsupported reference to system column %d in FieldSelect",
2971  fieldnum);
2972  if (fieldnum > tupDesc->natts) /* should never happen */
2973  elog(ERROR, "attribute number %d exceeds number of columns %d",
2974  fieldnum, tupDesc->natts);
2975  attr = TupleDescAttr(tupDesc, fieldnum - 1);
2976 
2977  /* Check for dropped column, and force a NULL result if so */
2978  if (attr->attisdropped)
2979  {
2980  *op->resnull = true;
2981  return;
2982  }
2983 
2984  /* Check for type mismatch --- possible after ALTER COLUMN TYPE? */
2985  /* As in CheckVarSlotCompatibility, we should but can't check typmod */
2986  if (op->d.fieldselect.resulttype != attr->atttypid)
2987  ereport(ERROR,
2988  (errcode(ERRCODE_DATATYPE_MISMATCH),
2989  errmsg("attribute %d has wrong type", fieldnum),
2990  errdetail("Table has type %s, but query expects %s.",
2991  format_type_be(attr->atttypid),
2992  format_type_be(op->d.fieldselect.resulttype))));
2993 
2994  /* extract the field */
2995  *op->resvalue = expanded_record_get_field(erh, fieldnum,
2996  op->resnull);
2997  }
2998  else
2999  {
3000  /* Get the composite datum and extract its type fields */
3001  tuple = DatumGetHeapTupleHeader(tupDatum);
3002 
3003  tupType = HeapTupleHeaderGetTypeId(tuple);
3004  tupTypmod = HeapTupleHeaderGetTypMod(tuple);
3005 
3006  /* Lookup tupdesc if first time through or if type changes */
3007  tupDesc = get_cached_rowtype(tupType, tupTypmod,
3008  &op->d.fieldselect.argdesc,
3009  econtext);
3010 
3011  /*
3012  * Find field's attr record. Note we don't support system columns
3013  * here: a datum tuple doesn't have valid values for most of the
3014  * interesting system columns anyway.
3015  */
3016  if (fieldnum <= 0) /* should never happen */
3017  elog(ERROR, "unsupported reference to system column %d in FieldSelect",
3018  fieldnum);
3019  if (fieldnum > tupDesc->natts) /* should never happen */
3020  elog(ERROR, "attribute number %d exceeds number of columns %d",
3021  fieldnum, tupDesc->natts);
3022  attr = TupleDescAttr(tupDesc, fieldnum - 1);
3023 
3024  /* Check for dropped column, and force a NULL result if so */
3025  if (attr->attisdropped)
3026  {
3027  *op->resnull = true;
3028  return;
3029  }
3030 
3031  /* Check for type mismatch --- possible after ALTER COLUMN TYPE? */
3032  /* As in CheckVarSlotCompatibility, we should but can't check typmod */
3033  if (op->d.fieldselect.resulttype != attr->atttypid)
3034  ereport(ERROR,
3035  (errcode(ERRCODE_DATATYPE_MISMATCH),
3036  errmsg("attribute %d has wrong type", fieldnum),
3037  errdetail("Table has type %s, but query expects %s.",
3038  format_type_be(attr->atttypid),
3039  format_type_be(op->d.fieldselect.resulttype))));
3040 
3041  /* heap_getattr needs a HeapTuple not a bare HeapTupleHeader */
3042  tmptup.t_len = HeapTupleHeaderGetDatumLength(tuple);
3043  tmptup.t_data = tuple;
3044 
3045  /* extract the field */
3046  *op->resvalue = heap_getattr(&tmptup,
3047  fieldnum,
3048  tupDesc,
3049  op->resnull);
3050  }
3051 }
#define VARATT_IS_EXTERNAL_EXPANDED(PTR)
Definition: postgres.h:322
Datum * resvalue
Definition: execExpr.h:252
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:253
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:355
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:738
#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 3063 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().

3064 {
3065  TupleDesc tupDesc;
3066 
3067  /* Lookup tupdesc if first time through or after rescan */
3068  tupDesc = get_cached_rowtype(op->d.fieldstore.fstore->resulttype, -1,
3069  op->d.fieldstore.argdesc, econtext);
3070 
3071  /* Check that current tupdesc doesn't have more fields than we allocated */
3072  if (unlikely(tupDesc->natts > op->d.fieldstore.ncolumns))
3073  elog(ERROR, "too many columns in composite type %u",
3074  op->d.fieldstore.fstore->resulttype);
3075 
3076  if (*op->resnull)
3077  {
3078  /* Convert null input tuple into an all-nulls row */
3079  memset(op->d.fieldstore.nulls, true,
3080  op->d.fieldstore.ncolumns * sizeof(bool));
3081  }
3082  else
3083  {
3084  /*
3085  * heap_deform_tuple needs a HeapTuple not a bare HeapTupleHeader. We
3086  * set all the fields in the struct just in case.
3087  */
3088  Datum tupDatum = *op->resvalue;
3089  HeapTupleHeader tuphdr;
3090  HeapTupleData tmptup;
3091 
3092  tuphdr = DatumGetHeapTupleHeader(tupDatum);
3093  tmptup.t_len = HeapTupleHeaderGetDatumLength(tuphdr);
3094  ItemPointerSetInvalid(&(tmptup.t_self));
3095  tmptup.t_tableOid = InvalidOid;
3096  tmptup.t_data = tuphdr;
3097 
3098  heap_deform_tuple(&tmptup, tupDesc,
3099  op->d.fieldstore.values,
3100  op->d.fieldstore.nulls);
3101  }
3102 }
Datum * resvalue
Definition: execExpr.h:252
bool * resnull
Definition: execExpr.h:253
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:206
#define HeapTupleHeaderGetDatumLength(tup)
Definition: htup_details.h:452

◆ ExecEvalFieldStoreForm()

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

Definition at line 3109 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

3110 {
3111  HeapTuple tuple;
3112 
3113  /* argdesc should already be valid from the DeForm step */
3114  tuple = heap_form_tuple(*op->d.fieldstore.argdesc,
3115  op->d.fieldstore.values,
3116  op->d.fieldstore.nulls);
3117 
3118  *op->resvalue = HeapTupleGetDatum(tuple);
3119  *op->resnull = false;
3120 }
Datum * resvalue
Definition: execExpr.h:252
bool * resnull
Definition: execExpr.h:253
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 2289 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().

2291 {
2292  FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
2293  PgStat_FunctionCallUsage fcusage;
2294  Datum d;
2295 
2296  pgstat_init_function_usage(fcinfo, &fcusage);
2297 
2298  fcinfo->isnull = false;
2299  d = op->d.func.fn_addr(fcinfo);
2300  *op->resvalue = d;
2301  *op->resnull = fcinfo->isnull;
2302 
2303  pgstat_end_function_usage(&fcusage, true);
2304 }
Datum * resvalue
Definition: execExpr.h:252
bool * resnull
Definition: execExpr.h:253
union ExprEvalStep::@52 d
void pgstat_init_function_usage(FunctionCallInfo fcinfo, PgStat_FunctionCallUsage *fcu)
Definition: pgstat.c:1618
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:1690

◆ ExecEvalFuncExprStrictFusage()

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

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

2312 {
2313 
2314  FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
2315  PgStat_FunctionCallUsage fcusage;
2316  NullableDatum *args = fcinfo->args;
2317  int nargs = op->d.func.nargs;
2318  Datum d;
2319 
2320  /* strict function, so check for NULL args */
2321  for (int argno = 0; argno < nargs; argno++)
2322  {
2323  if (args[argno].isnull)
2324  {
2325  *op->resnull = true;
2326  return;
2327  }
2328  }
2329 
2330  pgstat_init_function_usage(fcinfo, &fcusage);
2331 
2332  fcinfo->isnull = false;
2333  d = op->d.func.fn_addr(fcinfo);
2334  *op->resvalue = d;
2335  *op->resnull = fcinfo->isnull;
2336 
2337  pgstat_end_function_usage(&fcusage, true);
2338 }
Datum * resvalue
Definition: execExpr.h:252
bool * resnull
Definition: execExpr.h:253
union ExprEvalStep::@52 d
void pgstat_init_function_usage(FunctionCallInfo fcinfo, PgStat_FunctionCallUsage *fcu)
Definition: pgstat.c:1618
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:1690

◆ ExecEvalGroupingFunc()

void ExecEvalGroupingFunc ( ExprState state,
ExprEvalStep op 
)

Definition at line 3824 of file execExprInterp.c.

References attnum, bms_is_member(), castNode, ExprEvalStep::d, AggState::grouped_cols, ExprEvalStep::grouping_func, Int32GetDatum, lfirst_int, ExprState::parent, ExprEvalStep::resnull, and ExprEvalStep::resvalue.

Referenced by ExecInterpExpr().

3825 {
3826  AggState *aggstate = castNode(AggState, state->parent);
3827  int result = 0;
3828  Bitmapset *grouped_cols = aggstate->grouped_cols;
3829  ListCell *lc;
3830 
3831  foreach(lc, op->d.grouping_func.clauses)
3832  {
3833  int attnum = lfirst_int(lc);
3834 
3835  result <<= 1;
3836 
3837  if (!bms_is_member(attnum, grouped_cols))
3838  result |= 1;
3839  }
3840 
3841  *op->resvalue = Int32GetDatum(result);
3842  *op->resnull = false;
3843 }
struct PlanState * parent
Definition: execnodes.h:108
Datum * resvalue
Definition: execExpr.h:252
#define castNode(_type_, nodeptr)
Definition: nodes.h:594
bool * resnull
Definition: execExpr.h:253
union ExprEvalStep::@52 d
struct ExprEvalStep::@52::@86 grouping_func
#define lfirst_int(lc)
Definition: pg_list.h:191
Bitmapset * grouped_cols
Definition: execnodes.h:2067
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 2884 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().

2885 {
2886  Datum *values = op->d.minmax.values;
2887  bool *nulls = op->d.minmax.nulls;
2888  FunctionCallInfo fcinfo = op->d.minmax.fcinfo_data;
2889  MinMaxOp operator = op->d.minmax.op;
2890 
2891  /* set at initialization */
2892  Assert(fcinfo->args[0].isnull == false);
2893  Assert(fcinfo->args[1].isnull == false);
2894 
2895  /* default to null result */
2896  *op->resnull = true;
2897 
2898  for (int off = 0; off < op->d.minmax.nelems; off++)
2899  {
2900  /* ignore NULL inputs */
2901  if (nulls[off])
2902  continue;
2903 
2904  if (*op->resnull)
2905  {
2906  /* first nonnull input, adopt value */
2907  *op->resvalue = values[off];
2908  *op->resnull = false;
2909  }
2910  else
2911  {
2912  int cmpresult;
2913 
2914  /* apply comparison function */
2915  fcinfo->args[0].value = *op->resvalue;
2916  fcinfo->args[1].value = values[off];
2917 
2918  fcinfo->isnull = false;
2919  cmpresult = DatumGetInt32(FunctionCallInvoke(fcinfo));
2920  if (fcinfo->isnull) /* probably should not happen */
2921  continue;
2922 
2923  if (cmpresult > 0 && operator == IS_LEAST)
2924  *op->resvalue = values[off];
2925  else if (cmpresult < 0 && operator == IS_GREATEST)
2926  *op->resvalue = values[off];
2927  }
2928  }
2929 }
Datum * resvalue
Definition: execExpr.h:252
#define DatumGetInt32(X)
Definition: postgres.h:472
bool * resnull
Definition: execExpr.h:253
union ExprEvalStep::@52 d
MinMaxOp
Definition: primnodes.h:1093
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:738
struct ExprEvalStep::@52::@76 minmax
static Datum values[MAXATTR]
Definition: bootstrap.c:167

◆ ExecEvalNextValueExpr()

void ExecEvalNextValueExpr ( ExprState state,
ExprEvalStep op 
)

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

2490 {
2491  int64 newval = nextval_internal(op->d.nextvalueexpr.seqid, false);
2492 
2493  switch (op->d.nextvalueexpr.seqtypid)
2494  {
2495  case INT2OID:
2496  *op->resvalue = Int16GetDatum((int16) newval);
2497  break;
2498  case INT4OID:
2499  *op->resvalue = Int32GetDatum((int32) newval);
2500  break;
2501  case INT8OID:
2502  *op->resvalue = Int64GetDatum((int64) newval);
2503  break;
2504  default:
2505  elog(ERROR, "unsupported sequence type %u",
2506  op->d.nextvalueexpr.seqtypid);
2507  }
2508  *op->resnull = false;
2509 }
signed short int16
Definition: c.h:354
Datum * resvalue
Definition: execExpr.h:252
int64 nextval_internal(Oid relid, bool check_permissions)
Definition: sequence.c:579
bool * resnull
Definition: execExpr.h:253
#define Int16GetDatum(X)
Definition: postgres.h:451
union ExprEvalStep::@52 d
signed int int32
Definition: c.h:355
#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 2347 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().

2348 {
2349  ParamExecData *prm;
2350 
2351  prm = &(econtext->ecxt_param_exec_vals[op->d.param.paramid]);
2352  if (unlikely(prm->execPlan != NULL))
2353  {
2354  /* Parameter not evaluated yet, so go do it */
2355  ExecSetParamPlan(prm->execPlan, econtext);
2356  /* ExecSetParamPlan should have processed this param... */
2357  Assert(prm->execPlan == NULL);
2358  }
2359  *op->resvalue = prm->value;
2360  *op->resnull = prm->isnull;
2361 }
void * execPlan
Definition: params.h:148
Datum * resvalue
Definition: execExpr.h:252
bool * resnull
Definition: execExpr.h:253
union ExprEvalStep::@52 d
void ExecSetParamPlan(SubPlanState *node, ExprContext *econtext)
Definition: nodeSubplan.c:1050
bool isnull
Definition: params.h:150
ParamExecData * ecxt_param_exec_vals
Definition: execnodes.h:235
struct ExprEvalStep::@52::@64 param
#define Assert(condition)
Definition: c.h:738
Datum value
Definition: params.h:149
#define unlikely(x)
Definition: c.h:206

◆ ExecEvalParamExtern()

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

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

2370 {
2371  ParamListInfo paramInfo = econtext->ecxt_param_list_info;
2372  int paramId = op->d.param.paramid;
2373 
2374  if (likely(paramInfo &&
2375  paramId > 0 && paramId <= paramInfo->numParams))
2376  {
2377  ParamExternData *prm;
2378  ParamExternData prmdata;
2379 
2380  /* give hook a chance in case parameter is dynamic */
2381  if (paramInfo->paramFetch != NULL)
2382  prm = paramInfo->paramFetch(paramInfo, paramId, false, &prmdata);
2383  else
2384  prm = &paramInfo->params[paramId - 1];
2385 
2386  if (likely(OidIsValid(prm->ptype)))
2387  {
2388  /* safety check in case hook did something unexpected */
2389  if (unlikely(prm->ptype != op->d.param.paramtype))
2390  ereport(ERROR,
2391  (errcode(ERRCODE_DATATYPE_MISMATCH),
2392  errmsg("type of parameter %d (%s) does not match that when preparing the plan (%s)",
2393  paramId,
2394  format_type_be(prm->ptype),
2395  format_type_be(op->d.param.paramtype))));
2396  *op->resvalue = prm->value;
2397  *op->resnull = prm->isnull;
2398  return;
2399  }
2400  }
2401 
2402  ereport(ERROR,
2403  (errcode(ERRCODE_UNDEFINED_OBJECT),
2404  errmsg("no value found for parameter %d", paramId)));
2405 }
ParamExternData params[FLEXIBLE_ARRAY_MEMBER]
Definition: params.h:125
Datum value
Definition: params.h:92
#define likely(x)
Definition: c.h:205
Datum * resvalue
Definition: execExpr.h:252
bool * resnull
Definition: execExpr.h:253
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:644
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:206
ParamListInfo ecxt_param_list_info
Definition: execnodes.h:236
bool isnull
Definition: params.h:93

◆ ExecEvalRow()

void ExecEvalRow ( ExprState state,
ExprEvalStep op 
)

Definition at line 2864 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

2865 {
2866  HeapTuple tuple;
2867 
2868  /* build tuple from evaluated field values */
2869  tuple = heap_form_tuple(op->d.row.tupdesc,
2870  op->d.row.elemvalues,
2871  op->d.row.elemnulls);
2872 
2873  *op->resvalue = HeapTupleGetDatum(tuple);
2874  *op->resnull = false;
2875 }
Datum * resvalue
Definition: execExpr.h:252
bool * resnull
Definition: execExpr.h:253
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 2524 of file execExprInterp.c.

References ExecEvalRowNullInt().

Referenced by ExecInterpExpr().

2525 {
2526  ExecEvalRowNullInt(state, op, econtext, false);
2527 }
static void ExecEvalRowNullInt(ExprState *state, ExprEvalStep *op, ExprContext *econtext, bool checkisnull)

◆ ExecEvalRowNull()

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

Definition at line 2515 of file execExprInterp.c.

References ExecEvalRowNullInt().

Referenced by ExecInterpExpr().

2516 {
2517  ExecEvalRowNullInt(state, op, econtext, true);
2518 }
static void ExecEvalRowNullInt(ExprState *state, ExprEvalStep *op, ExprContext *econtext, bool checkisnull)

◆ ExecEvalScalarArrayOp()

void ExecEvalScalarArrayOp ( ExprState state,
ExprEvalStep op 
)

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

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

2412 {
2413  LOCAL_FCINFO(fcinfo, 0);
2414  SQLValueFunction *svf = op->d.sqlvaluefunction.svf;
2415 
2416  *op->resnull = false;
2417 
2418  /*
2419  * Note: current_schema() can return NULL. current_user() etc currently
2420  * cannot, but might as well code those cases the same way for safety.
2421  */
2422  switch (svf->op)
2423  {
2424  case SVFOP_CURRENT_DATE:
2426  break;
2427  case SVFOP_CURRENT_TIME:
2428  case SVFOP_CURRENT_TIME_N:
2430  break;
2434  break;
2435  case SVFOP_LOCALTIME:
2436  case SVFOP_LOCALTIME_N:
2438  break;
2439  case SVFOP_LOCALTIMESTAMP:
2442  break;
2443  case SVFOP_CURRENT_ROLE:
2444  case SVFOP_CURRENT_USER:
2445  case SVFOP_USER:
2446  InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
2447  *op->resvalue = current_user(fcinfo);
2448  *op->resnull = fcinfo->isnull;
2449  break;
2450  case SVFOP_SESSION_USER:
2451  InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
2452  *op->resvalue = session_user(fcinfo);
2453  *op->resnull = fcinfo->isnull;
2454  break;
2455  case SVFOP_CURRENT_CATALOG:
2456  InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
2457  *op->resvalue = current_database(fcinfo);
2458  *op->resnull = fcinfo->isnull;
2459  break;
2460  case SVFOP_CURRENT_SCHEMA:
2461  InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
2462  *op->resvalue = current_schema(fcinfo);
2463  *op->resnull = fcinfo->isnull;
2464  break;
2465  }
2466 }
Datum current_schema(PG_FUNCTION_ARGS)
Definition: name.c:319
Datum * resvalue
Definition: execExpr.h:252
bool * resnull
Definition: execExpr.h:253
#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:1143
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 2259 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().

2260 {
2261 #if defined(EEO_USE_COMPUTED_GOTO)
2262  if (state->flags & EEO_FLAG_DIRECT_THREADED)
2263  {
2264  ExprEvalOpLookup key;
2265  ExprEvalOpLookup *res;
2266 
2267  key.opcode = (void *) op->opcode;
2268  res = bsearch(&key,
2269  reverse_dispatch_table,
2270  EEOP_LAST /* nmembers */ ,
2271  sizeof(ExprEvalOpLookup),
2272  dispatch_compare_ptr);
2273  Assert(res); /* unknown ops shouldn't get looked up */
2274  return res->op;
2275  }
2276 #endif
2277  return (ExprEvalOp) op->opcode;
2278 }
ExprEvalOp
Definition: execExpr.h:44
#define Assert(condition)
Definition: c.h:738
intptr_t opcode
Definition: execExpr.h:249
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 3849 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

3850 {
3851  SubPlanState *sstate = op->d.subplan.sstate;
3852 
3853  /* could potentially be nested, so make sure there's enough stack */
3855 
3856  *op->resvalue = ExecSubPlan(sstate, econtext, op->resnull);
3857 }
struct ExprEvalStep::@52::@88 subplan
Datum * resvalue
Definition: execExpr.h:252
bool * resnull
Definition: execExpr.h:253
union ExprEvalStep::@52 d
void check_stack_depth(void)
Definition: postgres.c:3297
Datum ExecSubPlan(SubPlanState *node, ExprContext *econtext, bool *isNull)
Definition: nodeSubplan.c:62

◆ ExecEvalSubscriptingRef()

bool ExecEvalSubscriptingRef ( ExprState state,
ExprEvalStep op 
)

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

3135 {
3136  SubscriptingRefState *sbsrefstate = op->d.sbsref_subscript.state;
3137  int *indexes;
3138  int off;
3139 
3140  /* If any index expr yields NULL, result is NULL or error */
3141  if (sbsrefstate->subscriptnull)
3142  {
3143  if (sbsrefstate->isassignment)
3144  ereport(ERROR,
3145  (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
3146  errmsg("array subscript in assignment must not be null")));
3147  *op->resnull = true;
3148  return false;
3149  }
3150 
3151  /* Convert datum to int, save in appropriate place */
3152  if (op->d.sbsref_subscript.isupper)
3153  indexes = sbsrefstate->upperindex;
3154  else
3155  indexes = sbsrefstate->lowerindex;
3156  off = op->d.sbsref_subscript.off;
3157 
3158  indexes[off] = DatumGetInt32(sbsrefstate->subscriptvalue);
3159 
3160  return true;
3161 }
#define DatumGetInt32(X)
Definition: postgres.h:472
bool * resnull
Definition: execExpr.h:253
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:659
int upperindex[MAXDIM]
Definition: execExpr.h:654
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 3258 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().

3259 {
3260  SubscriptingRefState *sbsrefstate = op->d.sbsref_subscript.state;
3261 
3262  /*
3263  * For an assignment to a fixed-length container type, both the original
3264  * container and the value to be assigned into it must be non-NULL, else
3265  * we punt and return the original container.
3266  */
3267  if (sbsrefstate->refattrlength > 0)
3268  {
3269  if (*op->resnull || sbsrefstate->replacenull)
3270  return;
3271  }
3272 
3273  /*
3274  * For assignment to varlena arrays, we handle a NULL original array by
3275  * substituting an empty (zero-dimensional) array; insertion of the new
3276  * element will result in a singleton array value. It does not matter
3277  * whether the new element is NULL.
3278  */
3279  if (*op->resnull)
3280  {
3282  *op->resnull = false;
3283  }
3284 
3285  if (sbsrefstate->numlower == 0)
3286  {
3287  /* Scalar case */
3288  *op->resvalue = array_set_element(*op->resvalue,
3289  sbsrefstate->numupper,
3290  sbsrefstate->upperindex,
3291  sbsrefstate->replacevalue,
3292  sbsrefstate->replacenull,
3293  sbsrefstate->refattrlength,
3294  sbsrefstate->refelemlength,
3295  sbsrefstate->refelembyval,
3296  sbsrefstate->refelemalign);
3297  }
3298  else
3299  {
3300  /* Slice case */
3301  *op->resvalue = array_set_slice(*op->resvalue,
3302  sbsrefstate->numupper,
3303  sbsrefstate->upperindex,
3304  sbsrefstate->lowerindex,
3305  sbsrefstate->upperprovided,
3306  sbsrefstate->lowerprovided,
3307  sbsrefstate->replacevalue,
3308  sbsrefstate->replacenull,
3309  sbsrefstate->refattrlength,
3310  sbsrefstate->refelemlength,
3311  sbsrefstate->refelembyval,
3312  sbsrefstate->refelemalign);
3313  }
3314 }
Datum * resvalue
Definition: execExpr.h:252
#define PointerGetDatum(X)
Definition: postgres.h:556
bool * resnull
Definition: execExpr.h:253
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:653
bool lowerprovided[MAXDIM]
Definition: execExpr.h:658
int lowerindex[MAXDIM]
Definition: execExpr.h:659
int upperindex[MAXDIM]
Definition: execExpr.h:654
struct ExprEvalStep::@52::@79 sbsref_subscript

◆ ExecEvalSubscriptingRefFetch()

void ExecEvalSubscriptingRefFetch ( ExprState state,
ExprEvalStep op 
)

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

3170 {
3171  SubscriptingRefState *sbsrefstate = op->d.sbsref.state;
3172 
3173  /* Should not get here if source container (or any subscript) is null */
3174  Assert(!(*op->resnull));
3175 
3176  if (sbsrefstate->numlower == 0)
3177  {
3178  /* Scalar case */
3179  *op->resvalue = array_get_element(*op->resvalue,
3180  sbsrefstate->numupper,
3181  sbsrefstate->upperindex,
3182  sbsrefstate->refattrlength,
3183  sbsrefstate->refelemlength,
3184  sbsrefstate->refelembyval,
3185  sbsrefstate->refelemalign,
3186  op->resnull);
3187  }
3188  else
3189  {
3190  /* Slice case */
3191  *op->resvalue = array_get_slice(*op->resvalue,
3192  sbsrefstate->numupper,
3193  sbsrefstate->upperindex,
3194  sbsrefstate->lowerindex,
3195  sbsrefstate->upperprovided,
3196  sbsrefstate->lowerprovided,
3197  sbsrefstate->refattrlength,
3198  sbsrefstate->refelemlength,
3199  sbsrefstate->refelembyval,
3200  sbsrefstate->refelemalign);
3201  }
3202 }
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:252
bool * resnull
Definition: execExpr.h:253
union ExprEvalStep::@52 d
bool upperprovided[MAXDIM]
Definition: execExpr.h:653
bool lowerprovided[MAXDIM]
Definition: execExpr.h:658
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:738
int lowerindex[MAXDIM]
Definition: execExpr.h:659
int upperindex[MAXDIM]
Definition: execExpr.h:654

◆ ExecEvalSubscriptingRefOld()

void ExecEvalSubscriptingRefOld ( ExprState state,
ExprEvalStep op 
)

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

3212 {
3213  SubscriptingRefState *sbsrefstate = op->d.sbsref.state;
3214 
3215  if (*op->resnull)
3216  {
3217  /* whole array is null, so any element or slice is too */
3218  sbsrefstate->prevvalue = (Datum) 0;
3219  sbsrefstate->prevnull = true;
3220  }
3221  else if (sbsrefstate->numlower == 0)
3222  {
3223  /* Scalar case */
3224  sbsrefstate->prevvalue = array_get_element(*op->resvalue,
3225  sbsrefstate->numupper,
3226  sbsrefstate->upperindex,
3227  sbsrefstate->refattrlength,
3228  sbsrefstate->refelemlength,
3229  sbsrefstate->refelembyval,
3230  sbsrefstate->refelemalign,
3231  &sbsrefstate->prevnull);
3232  }
3233  else
3234  {
3235  /* Slice case */
3236  /* this is currently unreachable */
3237  sbsrefstate->prevvalue = array_get_slice(*op->resvalue,
3238  sbsrefstate->numupper,
3239  sbsrefstate->upperindex,
3240  sbsrefstate->lowerindex,
3241  sbsrefstate->upperprovided,
3242  sbsrefstate->lowerprovided,
3243  sbsrefstate->refattrlength,
3244  sbsrefstate->refelemlength,
3245  sbsrefstate->refelembyval,
3246  sbsrefstate->refelemalign);
3247  sbsrefstate->prevnull = false;
3248  }
3249 }
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:252
bool * resnull
Definition: execExpr.h:253
union ExprEvalStep::@52 d
bool upperprovided[MAXDIM]
Definition: execExpr.h:653
uintptr_t Datum
Definition: postgres.h:367
bool lowerprovided[MAXDIM]
Definition: execExpr.h:658
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:659
int upperindex[MAXDIM]
Definition: execExpr.h:654

◆ ExecEvalSysVar()

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

Definition at line 4109 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

4111 {
4112  Datum d;
4113 
4114  /* slot_getsysattr has sufficient defenses against bad attnums */
4115  d = slot_getsysattr(slot,
4116  op->d.var.attnum,
4117  op->resnull);
4118  *op->resvalue = d;
4119  /* this ought to be unreachable, but it's cheap enough to check */
4120  if (unlikely(*op->resnull))
4121  elog(ERROR, "failed to fetch attribute from slot");
4122 }
struct ExprEvalStep::@52::@54 var
Datum * resvalue
Definition: execExpr.h:252
bool * resnull
Definition: execExpr.h:253
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:206
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 3880 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().

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

◆ ExecEvalXmlExpr()

void ExecEvalXmlExpr ( ExprState state,
ExprEvalStep op 
)

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

3606 {
3607  XmlExpr *xexpr = op->d.xmlexpr.xexpr;
3608  Datum value;
3609 
3610  *op->resnull = true; /* until we get a result */
3611  *op->resvalue = (Datum) 0;
3612 
3613  switch (xexpr->op)
3614  {
3615  case IS_XMLCONCAT:
3616  {
3617  Datum *argvalue = op->d.xmlexpr.argvalue;
3618  bool *argnull = op->d.xmlexpr.argnull;
3619  List *values = NIL;
3620 
3621  for (int i = 0; i < list_length(xexpr->args); i++)
3622  {
3623  if (!argnull[i])
3624  values = lappend(values, DatumGetPointer(argvalue[i]));
3625  }
3626 
3627  if (values != NIL)
3628  {
3629  *op->resvalue = PointerGetDatum(xmlconcat(values));
3630  *op->resnull = false;
3631  }
3632  }
3633  break;
3634 
3635  case IS_XMLFOREST:
3636  {
3637  Datum *argvalue = op->d.xmlexpr.named_argvalue;
3638  bool *argnull = op->d.xmlexpr.named_argnull;
3640  ListCell *lc;
3641  ListCell *lc2;
3642  int i;
3643 
3644  initStringInfo(&buf);
3645 
3646  i = 0;
3647  forboth(lc, xexpr->named_args, lc2, xexpr->arg_names)
3648  {
3649  Expr *e = (Expr *) lfirst(lc);
3650  char *argname = strVal(lfirst(lc2));
3651 
3652  if (!argnull[i])
3653  {
3654  value = argvalue[i];
3655  appendStringInfo(&buf, "<%s>%s</%s>",
3656  argname,
3658  exprType((Node *) e), true),
3659  argname);
3660  *op->resnull = false;
3661  }
3662  i++;
3663  }
3664 
3665  if (!*op->resnull)
3666  {
3667  text *result;
3668 
3669  result = cstring_to_text_with_len(buf.data, buf.len);
3670  *op->resvalue = PointerGetDatum(result);
3671  }
3672 
3673  pfree(buf.data);
3674  }
3675  break;
3676 
3677  case IS_XMLELEMENT:
3678  *op->resvalue = PointerGetDatum(xmlelement(xexpr,
3679  op->d.xmlexpr.named_argvalue,
3680  op->d.xmlexpr.named_argnull,
3681  op->d.xmlexpr.argvalue,
3682  op->d.xmlexpr.argnull));
3683  *op->resnull = false;
3684  break;
3685 
3686  case IS_XMLPARSE:
3687  {
3688  Datum *argvalue = op->d.xmlexpr.argvalue;
3689  bool *argnull = op->d.xmlexpr.argnull;
3690  text *data;
3691  bool preserve_whitespace;
3692 
3693  /* arguments are known to be text, bool */
3694  Assert(list_length(xexpr->args) == 2);
3695 
3696  if (argnull[0])
3697  return;
3698  value = argvalue[0];
3699  data = DatumGetTextPP(value);
3700 
3701  if (argnull[1]) /* probably can't happen */
3702  return;
3703  value = argvalue[1];
3704  preserve_whitespace = DatumGetBool(value);
3705 
3706  *op->resvalue = PointerGetDatum(xmlparse(data,
3707  xexpr->xmloption,
3708  preserve_whitespace));
3709  *op->resnull = false;
3710  }
3711  break;
3712 
3713  case IS_XMLPI:
3714  {
3715  text *arg;
3716  bool isnull;
3717 
3718  /* optional argument is known to be text */
3719  Assert(list_length(xexpr->args) <= 1);
3720 
3721  if (xexpr->args)
3722  {
3723  isnull = op->d.xmlexpr.argnull[0];
3724  if (isnull)
3725  arg = NULL;
3726  else
3727  arg = DatumGetTextPP(op->d.xmlexpr.argvalue[0]);
3728  }
3729  else
3730  {
3731  arg = NULL;
3732  isnull = false;
3733  }
3734 
3735  *op->resvalue = PointerGetDatum(xmlpi(xexpr->name,
3736  arg,
3737  isnull,
3738  op->resnull));
3739  }
3740  break;
3741 
3742  case IS_XMLROOT:
3743  {
3744  Datum *argvalue = op->d.xmlexpr.argvalue;
3745  bool *argnull = op->d.xmlexpr.argnull;
3746  xmltype *data;
3747  text *version;
3748  int standalone;
3749 
3750  /* arguments are known to be xml, text, int */
3751  Assert(list_length(xexpr->args) == 3);
3752 
3753  if (argnull[0])
3754  return;
3755  data = DatumGetXmlP(argvalue[0]);
3756 
3757  if (argnull[1])
3758  version = NULL;
3759  else
3760  version = DatumGetTextPP(argvalue[1]);
3761 
3762  Assert(!argnull[2]); /* always present */
3763  standalone = DatumGetInt32(argvalue[2]);
3764 
3765  *op->resvalue = PointerGetDatum(xmlroot(data,
3766  version,
3767  standalone));
3768  *op->resnull = false;
3769  }
3770  break;
3771 
3772  case IS_XMLSERIALIZE:
3773  {
3774  Datum *argvalue = op->d.xmlexpr.argvalue;
3775  bool *argnull = op->d.xmlexpr.argnull;
3776 
3777  /* argument type is known to be xml */
3778  Assert(list_length(xexpr->args) == 1);
3779 
3780  if (argnull[0])
3781  return;
3782  value = argvalue[0];
3783 
3785  xexpr->xmloption));
3786  *op->resnull = false;
3787  }
3788  break;
3789 
3790  case IS_DOCUMENT:
3791  {
3792  Datum *argvalue = op->d.xmlexpr.argvalue;
3793  bool *argnull = op->d.xmlexpr.argnull;
3794 
3795  /* optional argument is known to be xml */
3796  Assert(list_length(xexpr->args) == 1);
3797 
3798  if (argnull[0])
3799  return;
3800  value = argvalue[0];
3801 
3802  *op->resvalue =
3804  *op->resnull = false;
3805  }
3806  break;
3807 
3808  default:
3809  elog(ERROR, "unrecognized XML operation");
3810  break;
3811  }
3812 }
#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:1182
Datum * resvalue
Definition: execExpr.h:252
#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:253
xmltype * xmlconcat(List *args)
Definition: xml.c:512
Definition: nodes.h:525
#define strVal(v)
Definition: value.h:54
union ExprEvalStep::@52 d
List * arg_names
Definition: primnodes.h:1184
#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:1181
uintptr_t Datum
Definition: postgres.h:367
#define BoolGetDatum(X)
Definition: postgres.h:402
List * named_args
Definition: primnodes.h:1183
static struct @143 value
List * args
Definition: primnodes.h:1185
#define Assert(condition)
Definition: c.h:738
#define lfirst(lc)
Definition: pg_list.h:190
XmlOptionType xmloption
Definition: primnodes.h:1186
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:555
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 1778 of file execExprInterp.c.

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

Referenced by ExecReadyInterpretedExpr().

1779 {
1780  /*
1781  * First time through, check whether attribute matches Var. Might not be
1782  * ok anymore, due to schema changes.
1783  */
1784  CheckExprStillValid(state, econtext);
1785 
1786  /* skip the check during further executions */
1787  state->evalfunc = (ExprStateEvalFunc) state->evalfunc_private;
1788 
1789  /* and actually execute */
1790  return state->evalfunc(state, econtext, isNull);
1791 }
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 184 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().

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

2124 {
2125  if (es->steps_alloc == 0)
2126  {
2127  es->steps_alloc = 16;
2128  es->steps = palloc(sizeof(ExprEvalStep) * es->steps_alloc);
2129  }
2130  else if (es->steps_alloc == es->steps_len)
2131  {
2132  es->steps_alloc *= 2;
2133  es->steps = repalloc(es->steps,
2134  sizeof(ExprEvalStep) * es->steps_alloc);
2135  }
2136 
2137  memcpy(&es->steps[es->steps_len++], s, sizeof(ExprEvalStep));
2138 }
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