PostgreSQL Source Code  git master
execExprInterp.c File Reference
#include "postgres.h"
#include "access/heaptoast.h"
#include "catalog/pg_type.h"
#include "commands/sequence.h"
#include "executor/execExpr.h"
#include "executor/nodeSubplan.h"
#include "funcapi.h"
#include "miscadmin.h"
#include "nodes/nodeFuncs.h"
#include "parser/parsetree.h"
#include "pgstat.h"
#include "utils/array.h"
#include "utils/builtins.h"
#include "utils/date.h"
#include "utils/datum.h"
#include "utils/expandedrecord.h"
#include "utils/lsyscache.h"
#include "utils/memutils.h"
#include "utils/timestamp.h"
#include "utils/typcache.h"
#include "utils/xml.h"
Include dependency graph for execExprInterp.c:

Go to the source code of this file.

Macros

#define EEO_SWITCH()   starteval: switch ((ExprEvalOp) op->opcode)
 
#define EEO_CASE(name)   case name:
 
#define EEO_DISPATCH()   goto starteval
 
#define EEO_OPCODE(opcode)   (opcode)
 
#define EEO_NEXT()
 
#define EEO_JUMP(stepno)
 

Functions

static Datum ExecInterpExpr (ExprState *state, ExprContext *econtext, bool *isnull)
 
static void ExecInitInterpreter (void)
 
static void CheckVarSlotCompatibility (TupleTableSlot *slot, int attnum, Oid vartype)
 
static void CheckOpSlotCompatibility (ExprEvalStep *op, TupleTableSlot *slot)
 
static TupleDesc get_cached_rowtype (Oid type_id, int32 typmod, TupleDesc *cache_field, ExprContext *econtext)
 
static void ShutdownTupleDescRef (Datum arg)
 
static void ExecEvalRowNullInt (ExprState *state, ExprEvalStep *op, ExprContext *econtext, bool checkisnull)
 
static Datum ExecJustInnerVar (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 ExecJustAssignInnerVar (ExprState *state, ExprContext *econtext, bool *isnull)
 
static Datum ExecJustAssignOuterVar (ExprState *state, ExprContext *econtext, bool *isnull)
 
static Datum ExecJustAssignScanVar (ExprState *state, ExprContext *econtext, bool *isnull)
 
static Datum ExecJustApplyFuncToCase (ExprState *state, ExprContext *econtext, bool *isnull)
 
static Datum ExecJustConst (ExprState *state, ExprContext *econtext, bool *isnull)
 
static Datum ExecJustInnerVarVirt (ExprState *state, ExprContext *econtext, bool *isnull)
 
static Datum ExecJustOuterVarVirt (ExprState *state, ExprContext *econtext, bool *isnull)
 
static Datum ExecJustScanVarVirt (ExprState *state, ExprContext *econtext, bool *isnull)
 
static Datum ExecJustAssignInnerVarVirt (ExprState *state, ExprContext *econtext, bool *isnull)
 
static Datum ExecJustAssignOuterVarVirt (ExprState *state, ExprContext *econtext, bool *isnull)
 
static Datum ExecJustAssignScanVarVirt (ExprState *state, ExprContext *econtext, bool *isnull)
 
void ExecReadyInterpretedExpr (ExprState *state)
 
Datum ExecInterpExprStillValid (ExprState *state, ExprContext *econtext, bool *isNull)
 
void CheckExprStillValid (ExprState *state, ExprContext *econtext)
 
static pg_attribute_always_inline Datum ExecJustVarImpl (ExprState *state, TupleTableSlot *slot, bool *isnull)
 
static pg_attribute_always_inline Datum ExecJustAssignVarImpl (ExprState *state, TupleTableSlot *inslot, bool *isnull)
 
static pg_attribute_always_inline Datum ExecJustVarVirtImpl (ExprState *state, TupleTableSlot *slot, bool *isnull)
 
static pg_attribute_always_inline Datum ExecJustAssignVarVirtImpl (ExprState *state, TupleTableSlot *inslot, bool *isnull)
 
ExprEvalOp ExecEvalStepOp (ExprState *state, ExprEvalStep *op)
 
void ExecEvalFuncExprFusage (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalFuncExprStrictFusage (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalParamExec (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalParamExtern (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalSQLValueFunction (ExprState *state, ExprEvalStep *op)
 
void ExecEvalCurrentOfExpr (ExprState *state, ExprEvalStep *op)
 
void ExecEvalNextValueExpr (ExprState *state, ExprEvalStep *op)
 
void ExecEvalRowNull (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalRowNotNull (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalArrayExpr (ExprState *state, ExprEvalStep *op)
 
void ExecEvalArrayCoerce (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalRow (ExprState *state, ExprEvalStep *op)
 
void ExecEvalMinMax (ExprState *state, ExprEvalStep *op)
 
void ExecEvalFieldSelect (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalFieldStoreDeForm (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalFieldStoreForm (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
bool ExecEvalSubscriptingRef (ExprState *state, ExprEvalStep *op)
 
void ExecEvalSubscriptingRefFetch (ExprState *state, ExprEvalStep *op)
 
void ExecEvalSubscriptingRefOld (ExprState *state, ExprEvalStep *op)
 
void ExecEvalSubscriptingRefAssign (ExprState *state, ExprEvalStep *op)
 
void ExecEvalConvertRowtype (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalScalarArrayOp (ExprState *state, ExprEvalStep *op)
 
void ExecEvalConstraintNotNull (ExprState *state, ExprEvalStep *op)
 
void ExecEvalConstraintCheck (ExprState *state, ExprEvalStep *op)
 
void ExecEvalXmlExpr (ExprState *state, ExprEvalStep *op)
 
void ExecEvalGroupingFunc (ExprState *state, ExprEvalStep *op)
 
void ExecEvalSubPlan (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalAlternativeSubPlan (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalWholeRowVar (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalSysVar (ExprState *state, ExprEvalStep *op, ExprContext *econtext, TupleTableSlot *slot)
 
void ExecAggInitGroup (AggState *aggstate, AggStatePerTrans pertrans, AggStatePerGroup pergroup)
 
Datum ExecAggTransReparent (AggState *aggstate, AggStatePerTrans pertrans, Datum newValue, bool newValueIsNull, Datum oldValue, bool oldValueIsNull)
 
void ExecEvalAggOrderedTransDatum (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalAggOrderedTransTuple (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 

Macro Definition Documentation

◆ EEO_CASE

#define EEO_CASE (   name)    case name:

Definition at line 122 of file execExprInterp.c.

Referenced by ExecInterpExpr().

◆ EEO_DISPATCH

#define EEO_DISPATCH ( )    goto starteval

Definition at line 123 of file execExprInterp.c.

Referenced by ExecInterpExpr().

◆ EEO_JUMP

#define EEO_JUMP (   stepno)
Value:
do { \
op = &state->steps[stepno]; \
EEO_DISPATCH(); \
} while (0)
Definition: regguts.h:298

Definition at line 134 of file execExprInterp.c.

Referenced by ExecInterpExpr().

◆ EEO_NEXT

#define EEO_NEXT ( )
Value:
do { \
op++; \
EEO_DISPATCH(); \
} while (0)

Definition at line 128 of file execExprInterp.c.

Referenced by ExecInterpExpr().

◆ EEO_OPCODE

#define EEO_OPCODE (   opcode)    (opcode)

Definition at line 124 of file execExprInterp.c.

Referenced by ExecReadyInterpretedExpr().

◆ EEO_SWITCH

#define EEO_SWITCH ( )    starteval: switch ((ExprEvalOp) op->opcode)

Definition at line 121 of file execExprInterp.c.

Referenced by ExecInterpExpr().

Function Documentation

◆ CheckExprStillValid()

void CheckExprStillValid ( ExprState state,
ExprContext econtext 
)

Definition at line 1817 of file execExprInterp.c.

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

Referenced by ExecInterpExprStillValid(), and ExecRunCompiledExpr().

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

◆ CheckOpSlotCompatibility()

static void CheckOpSlotCompatibility ( ExprEvalStep op,
TupleTableSlot slot 
)
static

Definition at line 1920 of file execExprInterp.c.

References Assert, ExprEvalStep::d, ExprEvalStep::fetch, TupleTableSlot::tts_ops, TTSOpsBufferHeapTuple, TTSOpsHeapTuple, and TTSOpsVirtual.

Referenced by ExecInterpExpr(), ExecJustAssignVarImpl(), and ExecJustVarImpl().

1921 {
1922 #ifdef USE_ASSERT_CHECKING
1923  /* there's nothing to check */
1924  if (!op->d.fetch.fixed)
1925  return;
1926 
1927  /*
1928  * Should probably fixed at some point, but for now it's easier to allow
1929  * buffer and heap tuples to be used interchangeably.
1930  */
1931  if (slot->tts_ops == &TTSOpsBufferHeapTuple &&
1932  op->d.fetch.kind == &TTSOpsHeapTuple)
1933  return;
1934  if (slot->tts_ops == &TTSOpsHeapTuple &&
1935  op->d.fetch.kind == &TTSOpsBufferHeapTuple)
1936  return;
1937 
1938  /*
1939  * At the moment we consider it OK if a virtual slot is used instead of a
1940  * specific type of slot, as a virtual slot never needs to be deformed.
1941  */
1942  if (slot->tts_ops == &TTSOpsVirtual)
1943  return;
1944 
1945  Assert(op->d.fetch.kind == slot->tts_ops);
1946 #endif
1947 }
const TupleTableSlotOps TTSOpsBufferHeapTuple
Definition: execTuples.c:86
const TupleTableSlotOps TTSOpsVirtual
Definition: execTuples.c:83
const TupleTableSlotOps *const tts_ops
Definition: tuptable.h:122
union ExprEvalStep::@52 d
struct ExprEvalStep::@52::@53 fetch
#define Assert(condition)
Definition: c.h:739
const TupleTableSlotOps TTSOpsHeapTuple
Definition: execTuples.c:84

◆ CheckVarSlotCompatibility()

static void CheckVarSlotCompatibility ( TupleTableSlot slot,
int  attnum,
Oid  vartype 
)
static

Definition at line 1869 of file execExprInterp.c.

References elog, ereport, errcode(), errdetail(), errmsg(), ERROR, format_type_be(), TupleDescData::natts, TupleDescData::tdtypeid, TupleTableSlot::tts_tupleDescriptor, and TupleDescAttr.

Referenced by CheckExprStillValid().

1870 {
1871  /*
1872  * What we have to check for here is the possibility of an attribute
1873  * having been dropped or changed in type since the plan tree was created.
1874  * Ideally the plan will get invalidated and not re-used, but just in
1875  * case, we keep these defenses. Fortunately it's sufficient to check
1876  * once on the first time through.
1877  *
1878  * Note: ideally we'd check typmod as well as typid, but that seems
1879  * impractical at the moment: in many cases the tupdesc will have been
1880  * generated by ExecTypeFromTL(), and that can't guarantee to generate an
1881  * accurate typmod in all cases, because some expression node types don't
1882  * carry typmod. Fortunately, for precisely that reason, there should be
1883  * no places with a critical dependency on the typmod of a value.
1884  *
1885  * System attributes don't require checking since their types never
1886  * change.
1887  */
1888  if (attnum > 0)
1889  {
1890  TupleDesc slot_tupdesc = slot->tts_tupleDescriptor;
1891  Form_pg_attribute attr;
1892 
1893  if (attnum > slot_tupdesc->natts) /* should never happen */
1894  elog(ERROR, "attribute number %d exceeds number of columns %d",
1895  attnum, slot_tupdesc->natts);
1896 
1897  attr = TupleDescAttr(slot_tupdesc, attnum - 1);
1898 
1899  if (attr->attisdropped)
1900  ereport(ERROR,
1901  (errcode(ERRCODE_UNDEFINED_COLUMN),
1902  errmsg("attribute %d of type %s has been dropped",
1903  attnum, format_type_be(slot_tupdesc->tdtypeid))));
1904 
1905  if (vartype != attr->atttypid)
1906  ereport(ERROR,
1907  (errcode(ERRCODE_DATATYPE_MISMATCH),
1908  errmsg("attribute %d of type %s has wrong type",
1909  attnum, format_type_be(slot_tupdesc->tdtypeid)),
1910  errdetail("Table has type %s, but query expects %s.",
1911  format_type_be(attr->atttypid),
1912  format_type_be(vartype))));
1913  }
1914 }
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
int errcode(int sqlerrcode)
Definition: elog.c:608
char * format_type_be(Oid type_oid)
Definition: format_type.c:326
#define ERROR
Definition: elog.h:43
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
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
int16 attnum
Definition: pg_attribute.h:79
Oid tdtypeid
Definition: tupdesc.h:82
int errmsg(const char *fmt,...)
Definition: elog.c:822
#define elog(elevel,...)
Definition: elog.h:228

◆ ExecAggInitGroup()

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

Definition at line 4157 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

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

◆ ExecAggTransReparent()

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

Definition at line 4185 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

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

◆ ExecEvalAggOrderedTransDatum()

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

Definition at line 4219 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

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

◆ ExecEvalAggOrderedTransTuple()

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

Definition at line 4233 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

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

◆ ExecEvalAlternativeSubPlan()

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

Definition at line 3889 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

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

◆ ExecEvalArrayCoerce()

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

Definition at line 2847 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

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

◆ ExecEvalArrayExpr()

void ExecEvalArrayExpr ( ExprState state,
ExprEvalStep op 
)

Definition at line 2640 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

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

◆ ExecEvalConstraintCheck()

void ExecEvalConstraintCheck ( ExprState state,
ExprEvalStep op 
)

Definition at line 3611 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

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

◆ ExecEvalConstraintNotNull()

void ExecEvalConstraintNotNull ( ExprState state,
ExprEvalStep op 
)

Definition at line 3597 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

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

◆ ExecEvalConvertRowtype()

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

Definition at line 3348 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

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

◆ ExecEvalCurrentOfExpr()

void ExecEvalCurrentOfExpr ( ExprState state,
ExprEvalStep op 
)

Definition at line 2499 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

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

◆ ExecEvalFieldSelect()

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

Definition at line 2962 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

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

◆ ExecEvalFieldStoreDeForm()

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

Definition at line 3088 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

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

◆ ExecEvalFieldStoreForm()

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

Definition at line 3134 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

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

◆ ExecEvalFuncExprFusage()

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

Definition at line 2310 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

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

◆ ExecEvalFuncExprStrictFusage()

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

Definition at line 2331 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

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

◆ ExecEvalGroupingFunc()

void ExecEvalGroupingFunc ( ExprState state,
ExprEvalStep op 
)

Definition at line 3851 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

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

◆ ExecEvalMinMax()

void ExecEvalMinMax ( ExprState state,
ExprEvalStep op 
)

Definition at line 2908 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

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

◆ ExecEvalNextValueExpr()

void ExecEvalNextValueExpr ( ExprState state,
ExprEvalStep op 
)

Definition at line 2510 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

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

◆ ExecEvalParamExec()

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

Definition at line 2368 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

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

◆ ExecEvalParamExtern()

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

Definition at line 2390 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

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

◆ ExecEvalRow()

void ExecEvalRow ( ExprState state,
ExprEvalStep op 
)

Definition at line 2888 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

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

◆ ExecEvalRowNotNull()

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

Definition at line 2545 of file execExprInterp.c.

References ExecEvalRowNullInt().

Referenced by ExecInterpExpr().

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

◆ ExecEvalRowNull()

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

Definition at line 2536 of file execExprInterp.c.

References ExecEvalRowNullInt().

Referenced by ExecInterpExpr().

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

◆ ExecEvalRowNullInt()

static void ExecEvalRowNullInt ( ExprState state,
ExprEvalStep op,
ExprContext econtext,
bool  checkisnull 
)
static

Definition at line 2552 of file execExprInterp.c.

References BoolGetDatum, ExprEvalStep::d, DatumGetHeapTupleHeader, get_cached_rowtype(), heap_attisnull(), HeapTupleHeaderGetDatumLength, HeapTupleHeaderGetTypeId, HeapTupleHeaderGetTypMod, TupleDescData::natts, ExprEvalStep::nulltest_row, ExprEvalStep::resnull, ExprEvalStep::resvalue, HeapTupleData::t_data, HeapTupleData::t_len, TupleDescAttr, and value.

Referenced by ExecEvalRowNotNull(), and ExecEvalRowNull().

2554 {
2555  Datum value = *op->resvalue;
2556  bool isnull = *op->resnull;
2557  HeapTupleHeader tuple;
2558  Oid tupType;
2559  int32 tupTypmod;
2560  TupleDesc tupDesc;
2561  HeapTupleData tmptup;
2562  int att;
2563 
2564  *op->resnull = false;
2565 
2566  /* NULL row variables are treated just as NULL scalar columns */
2567  if (isnull)
2568  {
2569  *op->resvalue = BoolGetDatum(checkisnull);
2570  return;
2571  }
2572 
2573  /*
2574  * The SQL standard defines IS [NOT] NULL for a non-null rowtype argument
2575  * as:
2576  *
2577  * "R IS NULL" is true if every field is the null value.
2578  *
2579  * "R IS NOT NULL" is true if no field is the null value.
2580  *
2581  * This definition is (apparently intentionally) not recursive; so our
2582  * tests on the fields are primitive attisnull tests, not recursive checks
2583  * to see if they are all-nulls or no-nulls rowtypes.
2584  *
2585  * The standard does not consider the possibility of zero-field rows, but
2586  * here we consider them to vacuously satisfy both predicates.
2587  */
2588 
2589  tuple = DatumGetHeapTupleHeader(value);
2590 
2591  tupType = HeapTupleHeaderGetTypeId(tuple);
2592  tupTypmod = HeapTupleHeaderGetTypMod(tuple);
2593 
2594  /* Lookup tupdesc if first time through or if type changes */
2595  tupDesc = get_cached_rowtype(tupType, tupTypmod,
2596  &op->d.nulltest_row.argdesc,
2597  econtext);
2598 
2599  /*
2600  * heap_attisnull needs a HeapTuple not a bare HeapTupleHeader.
2601  */
2602  tmptup.t_len = HeapTupleHeaderGetDatumLength(tuple);
2603  tmptup.t_data = tuple;
2604 
2605  for (att = 1; att <= tupDesc->natts; att++)
2606  {
2607  /* ignore dropped columns */
2608  if (TupleDescAttr(tupDesc, att - 1)->attisdropped)
2609  continue;
2610  if (heap_attisnull(&tmptup, att, tupDesc))
2611  {
2612  /* null field disproves IS NOT NULL */
2613  if (!checkisnull)
2614  {
2615  *op->resvalue = BoolGetDatum(false);
2616  return;
2617  }
2618  }
2619  else
2620  {
2621  /* non-null field disproves IS NULL */
2622  if (checkisnull)
2623  {
2624  *op->resvalue = BoolGetDatum(false);
2625  return;
2626  }
2627  }
2628  }
2629 
2630  *op->resvalue = BoolGetDatum(true);
2631 }
Datum * resvalue
Definition: execExpr.h:250
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
bool * resnull
Definition: execExpr.h:251
static struct @145 value
bool heap_attisnull(HeapTuple tup, int attnum, TupleDesc tupleDesc)
Definition: heaptuple.c:359
unsigned int Oid
Definition: postgres_ext.h:31
union ExprEvalStep::@52 d
#define DatumGetHeapTupleHeader(X)
Definition: fmgr.h:289
signed int int32
Definition: c.h:347
HeapTupleHeader t_data
Definition: htup.h:68
#define HeapTupleHeaderGetTypMod(tup)
Definition: htup_details.h:468
struct ExprEvalStep::@52::@63 nulltest_row
uint32 t_len
Definition: htup.h:64
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
#define BoolGetDatum(X)
Definition: postgres.h:402
#define HeapTupleHeaderGetDatumLength(tup)
Definition: htup_details.h:452

◆ ExecEvalScalarArrayOp()

void ExecEvalScalarArrayOp ( ExprState state,
ExprEvalStep op 
)

Definition at line 3446 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

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

◆ ExecEvalSQLValueFunction()

void ExecEvalSQLValueFunction ( ExprState state,
ExprEvalStep op 
)

Definition at line 2432 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

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

◆ ExecEvalStepOp()

ExprEvalOp ExecEvalStepOp ( ExprState state,
ExprEvalStep op 
)

Definition at line 2280 of file execExprInterp.c.

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

Referenced by CheckExprStillValid(), and llvm_compile_expr().

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

◆ ExecEvalSubPlan()

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

Definition at line 3875 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

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

◆ ExecEvalSubscriptingRef()

bool ExecEvalSubscriptingRef ( ExprState state,
ExprEvalStep op 
)

Definition at line 3159 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

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

◆ ExecEvalSubscriptingRefAssign()

void ExecEvalSubscriptingRefAssign ( ExprState state,
ExprEvalStep op 
)

Definition at line 3283 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

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

◆ ExecEvalSubscriptingRefFetch()

void ExecEvalSubscriptingRefFetch ( ExprState state,
ExprEvalStep op 
)

Definition at line 3194 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

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

◆ ExecEvalSubscriptingRefOld()

void ExecEvalSubscriptingRefOld ( ExprState state,
ExprEvalStep op 
)

Definition at line 3236 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

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

◆ ExecEvalSysVar()

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

Definition at line 4137 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

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

◆ ExecEvalWholeRowVar()

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

Definition at line 3906 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

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

◆ ExecEvalXmlExpr()

void ExecEvalXmlExpr ( ExprState state,
ExprEvalStep op 
)

Definition at line 3631 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

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

◆ ExecInitInterpreter()

static void ExecInitInterpreter ( void  )
static

Definition at line 2246 of file execExprInterp.c.

References DatumGetPointer, EEOP_LAST, ExecInterpExpr(), i, and qsort.

Referenced by ExecReadyInterpretedExpr().

2247 {
2248 #if defined(EEO_USE_COMPUTED_GOTO)
2249  /* Set up externally-visible pointer to dispatch table */
2250  if (dispatch_table == NULL)
2251  {
2252  int i;
2253 
2254  dispatch_table = (const void **)
2255  DatumGetPointer(ExecInterpExpr(NULL, NULL, NULL));
2256 
2257  /* build reverse lookup table */
2258  for (i = 0; i < EEOP_LAST; i++)
2259  {
2260  reverse_dispatch_table[i].opcode = dispatch_table[i];
2261  reverse_dispatch_table[i].op = (ExprEvalOp) i;
2262  }
2263 
2264  /* make it bsearch()able */
2265  qsort(reverse_dispatch_table,
2266  EEOP_LAST /* nmembers */ ,
2267  sizeof(ExprEvalOpLookup),
2268  dispatch_compare_ptr);
2269  }
2270 #endif
2271 }
ExprEvalOp
Definition: execExpr.h:44
static Datum ExecInterpExpr(ExprState *state, ExprContext *econtext, bool *isnull)
#define DatumGetPointer(X)
Definition: postgres.h:549
int i
#define qsort(a, b, c, d)
Definition: port.h:488

◆ ExecInterpExpr()

static Datum ExecInterpExpr ( ExprState state,
ExprContext econtext,
bool isnull 
)
static

Definition at line 338 of file execExprInterp.c.

References ExprEvalStep::agg_deserialize, ExprEvalStep::agg_init_trans, ExprEvalStep::agg_strict_input_check, ExprEvalStep::agg_strict_trans_check, ExprEvalStep::agg_trans, AggrefExprState::aggno, ExprEvalStep::aggref, AggState::all_pergroups, FunctionCallInfoBaseData::args, generate_unaccent_rules::args, Assert, ExprEvalStep::assign_tmp, ExprEvalStep::assign_var, attnum, ExprEvalStep::boolexpr, BoolGetDatum, ExprEvalStep::casetest, ExprContext::caseValue_datum, ExprContext::caseValue_isNull, CheckOpSlotCompatibility(), ExprEvalStep::constval, ExprEvalStep::cparam, AggState::curaggcontext, AggState::curpertrans, AggState::current_set, ExprEvalStep::d, DatumGetBool, DatumGetCString, DatumGetInt32, DatumGetPointer, ExprContext::domainValue_datum, ExprContext::domainValue_isNull, ExprContext::ecxt_aggnulls, ExprContext::ecxt_aggvalues, ExprContext::ecxt_innertuple, ExprContext::ecxt_outertuple, ExprContext::ecxt_per_tuple_memory, ExprContext::ecxt_scantuple, EEO_CASE, EEO_DISPATCH, EEO_JUMP, EEO_NEXT, EEO_SWITCH, EEOP_AGG_DESERIALIZE, EEOP_AGG_INIT_TRANS, EEOP_AGG_ORDERED_TRANS_DATUM, EEOP_AGG_ORDERED_TRANS_TUPLE, EEOP_AGG_PLAIN_TRANS, EEOP_AGG_PLAIN_TRANS_BYVAL, EEOP_AGG_STRICT_DESERIALIZE, EEOP_AGG_STRICT_INPUT_CHECK_ARGS, EEOP_AGG_STRICT_INPUT_CHECK_NULLS, EEOP_AGG_STRICT_TRANS_CHECK, EEOP_AGGREF, EEOP_ALTERNATIVE_SUBPLAN, EEOP_ARRAYCOERCE, EEOP_ARRAYEXPR, EEOP_ASSIGN_INNER_VAR, EEOP_ASSIGN_OUTER_VAR, EEOP_ASSIGN_SCAN_VAR, EEOP_ASSIGN_TMP, EEOP_ASSIGN_TMP_MAKE_RO, EEOP_BOOL_AND_STEP, EEOP_BOOL_AND_STEP_FIRST, EEOP_BOOL_AND_STEP_LAST, EEOP_BOOL_NOT_STEP, EEOP_BOOL_OR_STEP, EEOP_BOOL_OR_STEP_FIRST, EEOP_BOOL_OR_STEP_LAST, EEOP_BOOLTEST_IS_FALSE, EEOP_BOOLTEST_IS_NOT_FALSE, EEOP_BOOLTEST_IS_NOT_TRUE, EEOP_BOOLTEST_IS_TRUE, EEOP_CASE_TESTVAL, EEOP_CONST, EEOP_CONVERT_ROWTYPE, EEOP_CURRENTOFEXPR, EEOP_DISTINCT, EEOP_DOMAIN_CHECK, EEOP_DOMAIN_NOTNULL, EEOP_DOMAIN_TESTVAL, EEOP_DONE, EEOP_FIELDSELECT, EEOP_FIELDSTORE_DEFORM, EEOP_FIELDSTORE_FORM, EEOP_FUNCEXPR, EEOP_FUNCEXPR_FUSAGE, EEOP_FUNCEXPR_STRICT, EEOP_FUNCEXPR_STRICT_FUSAGE, EEOP_GROUPING_FUNC, EEOP_INNER_FETCHSOME, EEOP_INNER_SYSVAR, EEOP_INNER_VAR, EEOP_IOCOERCE, EEOP_JUMP, EEOP_JUMP_IF_NOT_NULL, EEOP_JUMP_IF_NOT_TRUE, EEOP_JUMP_IF_NULL, EEOP_LAST, EEOP_MAKE_READONLY, EEOP_MINMAX, EEOP_NEXTVALUEEXPR, EEOP_NOT_DISTINCT, EEOP_NULLIF, EEOP_NULLTEST_ISNOTNULL, EEOP_NULLTEST_ISNULL, EEOP_NULLTEST_ROWISNOTNULL, EEOP_NULLTEST_ROWISNULL, EEOP_OUTER_FETCHSOME, EEOP_OUTER_SYSVAR, EEOP_OUTER_VAR, EEOP_PARAM_CALLBACK, EEOP_PARAM_EXEC, EEOP_PARAM_EXTERN, EEOP_QUAL, EEOP_ROW, EEOP_ROWCOMPARE_FINAL, EEOP_ROWCOMPARE_STEP, EEOP_SBSREF_ASSIGN, EEOP_SBSREF_FETCH, EEOP_SBSREF_OLD, EEOP_SBSREF_SUBSCRIPT, EEOP_SCALARARRAYOP, EEOP_SCAN_FETCHSOME, EEOP_SCAN_SYSVAR, EEOP_SCAN_VAR, EEOP_SQLVALUEFUNCTION, EEOP_SUBPLAN, EEOP_WHOLEROW, EEOP_WINDOW_FUNC, EEOP_XMLEXPR, ExecAggInitGroup(), ExecAggTransReparent(), ExecEvalAggOrderedTransDatum(), ExecEvalAggOrderedTransTuple(), ExecEvalAlternativeSubPlan(), ExecEvalArrayCoerce(), ExecEvalArrayExpr(), ExecEvalConstraintCheck(), ExecEvalConstraintNotNull(), ExecEvalConvertRowtype(), ExecEvalCurrentOfExpr(), ExecEvalFieldSelect(), ExecEvalFieldStoreDeForm(), ExecEvalFieldStoreForm(), ExecEvalFuncExprFusage(), ExecEvalFuncExprStrictFusage(), ExecEvalGroupingFunc(), ExecEvalMinMax(), ExecEvalNextValueExpr(), ExecEvalParamExec(), ExecEvalParamExtern(), ExecEvalRow(), ExecEvalRowNotNull(), ExecEvalRowNull(), ExecEvalScalarArrayOp(), ExecEvalSQLValueFunction(), ExecEvalSubPlan(), ExecEvalSubscriptingRef(), ExecEvalSubscriptingRefAssign(), ExecEvalSubscriptingRefFetch(), ExecEvalSubscriptingRefOld(), ExecEvalSysVar(), ExecEvalWholeRowVar(), ExecEvalXmlExpr(), ExprEvalStep::fetch, ExprEvalStep::func, FunctionCallInvoke, ExprEvalStep::iocoerce, FunctionCallInfoBaseData::isnull, NullableDatum::isnull, ExprEvalStep::jump, lengthof, ExprEvalStep::make_readonly, MakeExpandedObjectReadOnlyInternal(), MemoryContextSwitchTo(), AggStatePerGroupData::noTransValue, PointerGetDatum, ExprEvalStep::qualexpr, ExprState::resnull, ExprEvalStep::resnull, ExprState::resultslot, ExprState::resvalue, ExprEvalStep::resvalue, ExprEvalStep::rowcompare_final, ROWCOMPARE_GE, ROWCOMPARE_GT, ROWCOMPARE_LE, ROWCOMPARE_LT, ExprEvalStep::rowcompare_step, ExprEvalStep::sbsref_subscript, slot_getsomeattrs(), StaticAssertStmt, ExprState::steps, generate_unaccent_rules::str, AggState::tmpcontext, AggStatePerTransData::transfn_fcinfo, AggStatePerTransData::transtypeByVal, AggStatePerGroupData::transValue, AggStatePerGroupData::transValueIsNull, TupleTableSlot::tts_isnull, TupleTableSlot::tts_values, unlikely, NullableDatum::value, ExprEvalStep::var, WindowFuncExprState::wfuncno, and ExprEvalStep::window_func.

Referenced by ExecInitInterpreter(), and ExecReadyInterpretedExpr().

339 {
340  ExprEvalStep *op;
341  TupleTableSlot *resultslot;
342  TupleTableSlot *innerslot;
343  TupleTableSlot *outerslot;
344  TupleTableSlot *scanslot;
345 
346  /*
347  * This array has to be in the same order as enum ExprEvalOp.
348  */
349 #if defined(EEO_USE_COMPUTED_GOTO)
350  static const void *const dispatch_table[] = {
351  &&CASE_EEOP_DONE,
352  &&CASE_EEOP_INNER_FETCHSOME,
353  &&CASE_EEOP_OUTER_FETCHSOME,
354  &&CASE_EEOP_SCAN_FETCHSOME,
355  &&CASE_EEOP_INNER_VAR,
356  &&CASE_EEOP_OUTER_VAR,
357  &&CASE_EEOP_SCAN_VAR,
358  &&CASE_EEOP_INNER_SYSVAR,
359  &&CASE_EEOP_OUTER_SYSVAR,
360  &&CASE_EEOP_SCAN_SYSVAR,
361  &&CASE_EEOP_WHOLEROW,
362  &&CASE_EEOP_ASSIGN_INNER_VAR,
363  &&CASE_EEOP_ASSIGN_OUTER_VAR,
364  &&CASE_EEOP_ASSIGN_SCAN_VAR,
365  &&CASE_EEOP_ASSIGN_TMP,
366  &&CASE_EEOP_ASSIGN_TMP_MAKE_RO,
367  &&CASE_EEOP_CONST,
368  &&CASE_EEOP_FUNCEXPR,
369  &&CASE_EEOP_FUNCEXPR_STRICT,
370  &&CASE_EEOP_FUNCEXPR_FUSAGE,
371  &&CASE_EEOP_FUNCEXPR_STRICT_FUSAGE,
372  &&CASE_EEOP_BOOL_AND_STEP_FIRST,
373  &&CASE_EEOP_BOOL_AND_STEP,
374  &&CASE_EEOP_BOOL_AND_STEP_LAST,
375  &&CASE_EEOP_BOOL_OR_STEP_FIRST,
376  &&CASE_EEOP_BOOL_OR_STEP,
377  &&CASE_EEOP_BOOL_OR_STEP_LAST,
378  &&CASE_EEOP_BOOL_NOT_STEP,
379  &&CASE_EEOP_QUAL,
380  &&CASE_EEOP_JUMP,
381  &&CASE_EEOP_JUMP_IF_NULL,
382  &&CASE_EEOP_JUMP_IF_NOT_NULL,
383  &&CASE_EEOP_JUMP_IF_NOT_TRUE,
384  &&CASE_EEOP_NULLTEST_ISNULL,
385  &&CASE_EEOP_NULLTEST_ISNOTNULL,
386  &&CASE_EEOP_NULLTEST_ROWISNULL,
387  &&CASE_EEOP_NULLTEST_ROWISNOTNULL,
388  &&CASE_EEOP_BOOLTEST_IS_TRUE,
389  &&CASE_EEOP_BOOLTEST_IS_NOT_TRUE,
390  &&CASE_EEOP_BOOLTEST_IS_FALSE,
391  &&CASE_EEOP_BOOLTEST_IS_NOT_FALSE,
392  &&CASE_EEOP_PARAM_EXEC,
393  &&CASE_EEOP_PARAM_EXTERN,
394  &&CASE_EEOP_PARAM_CALLBACK,
395  &&CASE_EEOP_CASE_TESTVAL,
396  &&CASE_EEOP_MAKE_READONLY,
397  &&CASE_EEOP_IOCOERCE,
398  &&CASE_EEOP_DISTINCT,
399  &&CASE_EEOP_NOT_DISTINCT,
400  &&CASE_EEOP_NULLIF,
401  &&CASE_EEOP_SQLVALUEFUNCTION,
402  &&CASE_EEOP_CURRENTOFEXPR,
403  &&CASE_EEOP_NEXTVALUEEXPR,
404  &&CASE_EEOP_ARRAYEXPR,
405  &&CASE_EEOP_ARRAYCOERCE,
406  &&CASE_EEOP_ROW,
407  &&CASE_EEOP_ROWCOMPARE_STEP,
408  &&CASE_EEOP_ROWCOMPARE_FINAL,
409  &&CASE_EEOP_MINMAX,
410  &&CASE_EEOP_FIELDSELECT,
411  &&CASE_EEOP_FIELDSTORE_DEFORM,
412  &&CASE_EEOP_FIELDSTORE_FORM,
413  &&CASE_EEOP_SBSREF_SUBSCRIPT,
414  &&CASE_EEOP_SBSREF_OLD,
415  &&CASE_EEOP_SBSREF_ASSIGN,
416  &&CASE_EEOP_SBSREF_FETCH,
417  &&CASE_EEOP_DOMAIN_TESTVAL,
418  &&CASE_EEOP_DOMAIN_NOTNULL,
419  &&CASE_EEOP_DOMAIN_CHECK,
420  &&CASE_EEOP_CONVERT_ROWTYPE,
421  &&CASE_EEOP_SCALARARRAYOP,
422  &&CASE_EEOP_XMLEXPR,
423  &&CASE_EEOP_AGGREF,
424  &&CASE_EEOP_GROUPING_FUNC,
425  &&CASE_EEOP_WINDOW_FUNC,
426  &&CASE_EEOP_SUBPLAN,
427  &&CASE_EEOP_ALTERNATIVE_SUBPLAN,
428  &&CASE_EEOP_AGG_STRICT_DESERIALIZE,
429  &&CASE_EEOP_AGG_DESERIALIZE,
430  &&CASE_EEOP_AGG_STRICT_INPUT_CHECK_ARGS,
431  &&CASE_EEOP_AGG_STRICT_INPUT_CHECK_NULLS,
432  &&CASE_EEOP_AGG_INIT_TRANS,
433  &&CASE_EEOP_AGG_STRICT_TRANS_CHECK,
434  &&CASE_EEOP_AGG_PLAIN_TRANS_BYVAL,
435  &&CASE_EEOP_AGG_PLAIN_TRANS,
436  &&CASE_EEOP_AGG_ORDERED_TRANS_DATUM,
437  &&CASE_EEOP_AGG_ORDERED_TRANS_TUPLE,
438  &&CASE_EEOP_LAST
439  };
440 
441  StaticAssertStmt(EEOP_LAST + 1 == lengthof(dispatch_table),
442  "dispatch_table out of whack with ExprEvalOp");
443 
444  if (unlikely(state == NULL))
445  return PointerGetDatum(dispatch_table);
446 #else
447  Assert(state != NULL);
448 #endif /* EEO_USE_COMPUTED_GOTO */
449 
450  /* setup state */
451  op = state->steps;
452  resultslot = state->resultslot;
453  innerslot = econtext->ecxt_innertuple;
454  outerslot = econtext->ecxt_outertuple;
455  scanslot = econtext->ecxt_scantuple;
456 
457 #if defined(EEO_USE_COMPUTED_GOTO)
458  EEO_DISPATCH();
459 #endif
460 
461  EEO_SWITCH()
462  {
464  {
465  goto out;
466  }
467 
469  {
470  CheckOpSlotCompatibility(op, innerslot);
471 
472  slot_getsomeattrs(innerslot, op->d.fetch.last_var);
473 
474  EEO_NEXT();
475  }
476 
478  {
479  CheckOpSlotCompatibility(op, outerslot);
480 
481  slot_getsomeattrs(outerslot, op->d.fetch.last_var);
482 
483  EEO_NEXT();
484  }
485 
487  {
488  CheckOpSlotCompatibility(op, scanslot);
489 
490  slot_getsomeattrs(scanslot, op->d.fetch.last_var);
491 
492  EEO_NEXT();
493  }
494 
496  {
497  int attnum = op->d.var.attnum;
498 
499  /*
500  * Since we already extracted all referenced columns from the
501  * tuple with a FETCHSOME step, we can just grab the value
502  * directly out of the slot's decomposed-data arrays. But let's
503  * have an Assert to check that that did happen.
504  */
505  Assert(attnum >= 0 && attnum < innerslot->tts_nvalid);
506  *op->resvalue = innerslot->tts_values[attnum];
507  *op->resnull = innerslot->tts_isnull[attnum];
508 
509  EEO_NEXT();
510  }
511 
513  {
514  int attnum = op->d.var.attnum;
515 
516  /* See EEOP_INNER_VAR comments */
517 
518  Assert(attnum >= 0 && attnum < outerslot->tts_nvalid);
519  *op->resvalue = outerslot->tts_values[attnum];
520  *op->resnull = outerslot->tts_isnull[attnum];
521 
522  EEO_NEXT();
523  }
524 
526  {
527  int attnum = op->d.var.attnum;
528 
529  /* See EEOP_INNER_VAR comments */
530 
531  Assert(attnum >= 0 && attnum < scanslot->tts_nvalid);
532  *op->resvalue = scanslot->tts_values[attnum];
533  *op->resnull = scanslot->tts_isnull[attnum];
534 
535  EEO_NEXT();
536  }
537 
539  {
540  ExecEvalSysVar(state, op, econtext, innerslot);
541  EEO_NEXT();
542  }
543 
545  {
546  ExecEvalSysVar(state, op, econtext, outerslot);
547  EEO_NEXT();
548  }
549 
551  {
552  ExecEvalSysVar(state, op, econtext, scanslot);
553  EEO_NEXT();
554  }
555 
557  {
558  /* too complex for an inline implementation */
559  ExecEvalWholeRowVar(state, op, econtext);
560 
561  EEO_NEXT();
562  }
563 
565  {
566  int resultnum = op->d.assign_var.resultnum;
567  int attnum = op->d.assign_var.attnum;
568 
569  /*
570  * We do not need CheckVarSlotCompatibility here; that was taken
571  * care of at compilation time. But see EEOP_INNER_VAR comments.
572  */
573  Assert(attnum >= 0 && attnum < innerslot->tts_nvalid);
574  resultslot->tts_values[resultnum] = innerslot->tts_values[attnum];
575  resultslot->tts_isnull[resultnum] = innerslot->tts_isnull[attnum];
576 
577  EEO_NEXT();
578  }
579 
581  {
582  int resultnum = op->d.assign_var.resultnum;
583  int attnum = op->d.assign_var.attnum;
584 
585  /*
586  * We do not need CheckVarSlotCompatibility here; that was taken
587  * care of at compilation time. But see EEOP_INNER_VAR comments.
588  */
589  Assert(attnum >= 0 && attnum < outerslot->tts_nvalid);
590  resultslot->tts_values[resultnum] = outerslot->tts_values[attnum];
591  resultslot->tts_isnull[resultnum] = outerslot->tts_isnull[attnum];
592 
593  EEO_NEXT();
594  }
595 
597  {
598  int resultnum = op->d.assign_var.resultnum;
599  int attnum = op->d.assign_var.attnum;
600 
601  /*
602  * We do not need CheckVarSlotCompatibility here; that was taken
603  * care of at compilation time. But see EEOP_INNER_VAR comments.
604  */
605  Assert(attnum >= 0 && attnum < scanslot->tts_nvalid);
606  resultslot->tts_values[resultnum] = scanslot->tts_values[attnum];
607  resultslot->tts_isnull[resultnum] = scanslot->tts_isnull[attnum];
608 
609  EEO_NEXT();
610  }
611 
613  {
614  int resultnum = op->d.assign_tmp.resultnum;
615 
616  resultslot->tts_values[resultnum] = state->resvalue;
617  resultslot->tts_isnull[resultnum] = state->resnull;
618 
619  EEO_NEXT();
620  }
621 
623  {
624  int resultnum = op->d.assign_tmp.resultnum;
625 
626  resultslot->tts_isnull[resultnum] = state->resnull;
627  if (!resultslot->tts_isnull[resultnum])
628  resultslot->tts_values[resultnum] =
630  else
631  resultslot->tts_values[resultnum] = state->resvalue;
632 
633  EEO_NEXT();
634  }
635 
637  {
638  *op->resnull = op->d.constval.isnull;
639  *op->resvalue = op->d.constval.value;
640 
641  EEO_NEXT();
642  }
643 
644  /*
645  * Function-call implementations. Arguments have previously been
646  * evaluated directly into fcinfo->args.
647  *
648  * As both STRICT checks and function-usage are noticeable performance
649  * wise, and function calls are a very hot-path (they also back
650  * operators!), it's worth having so many separate opcodes.
651  *
652  * Note: the reason for using a temporary variable "d", here and in
653  * other places, is that some compilers think "*op->resvalue = f();"
654  * requires them to evaluate op->resvalue into a register before
655  * calling f(), just in case f() is able to modify op->resvalue
656  * somehow. The extra line of code can save a useless register spill
657  * and reload across the function call.
658  */
660  {
661  FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
662  Datum d;
663 
664  fcinfo->isnull = false;
665  d = op->d.func.fn_addr(fcinfo);
666  *op->resvalue = d;
667  *op->resnull = fcinfo->isnull;
668 
669  EEO_NEXT();
670  }
671 
673  {
674  FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
675  NullableDatum *args = fcinfo->args;
676  int argno;
677  Datum d;
678 
679  /* strict function, so check for NULL args */
680  for (argno = 0; argno < op->d.func.nargs; argno++)
681  {
682  if (args[argno].isnull)
683  {
684  *op->resnull = true;
685  goto strictfail;
686  }
687  }
688  fcinfo->isnull = false;
689  d = op->d.func.fn_addr(fcinfo);
690  *op->resvalue = d;
691  *op->resnull = fcinfo->isnull;
692 
693  strictfail:
694  EEO_NEXT();
695  }
696 
698  {
699  /* not common enough to inline */
700  ExecEvalFuncExprFusage(state, op, econtext);
701 
702  EEO_NEXT();
703  }
704 
706  {
707  /* not common enough to inline */
708  ExecEvalFuncExprStrictFusage(state, op, econtext);
709 
710  EEO_NEXT();
711  }
712 
713  /*
714  * If any of its clauses is FALSE, an AND's result is FALSE regardless
715  * of the states of the rest of the clauses, so we can stop evaluating
716  * and return FALSE immediately. If none are FALSE and one or more is
717  * NULL, we return NULL; otherwise we return TRUE. This makes sense
718  * when you interpret NULL as "don't know": perhaps one of the "don't
719  * knows" would have been FALSE if we'd known its value. Only when
720  * all the inputs are known to be TRUE can we state confidently that
721  * the AND's result is TRUE.
722  */
724  {
725  *op->d.boolexpr.anynull = false;
726 
727  /*
728  * EEOP_BOOL_AND_STEP_FIRST resets anynull, otherwise it's the
729  * same as EEOP_BOOL_AND_STEP - so fall through to that.
730  */
731 
732  /* FALL THROUGH */
733  }
734 
736  {
737  if (*op->resnull)
738  {
739  *op->d.boolexpr.anynull = true;
740  }
741  else if (!DatumGetBool(*op->resvalue))
742  {
743  /* result is already set to FALSE, need not change it */
744  /* bail out early */
745  EEO_JUMP(op->d.boolexpr.jumpdone);
746  }
747 
748  EEO_NEXT();
749  }
750 
752  {
753  if (*op->resnull)
754  {
755  /* result is already set to NULL, need not change it */
756  }
757  else if (!DatumGetBool(*op->resvalue))
758  {
759  /* result is already set to FALSE, need not change it */
760 
761  /*
762  * No point jumping early to jumpdone - would be same target
763  * (as this is the last argument to the AND expression),
764  * except more expensive.
765  */
766  }
767  else if (*op->d.boolexpr.anynull)
768  {
769  *op->resvalue = (Datum) 0;
770  *op->resnull = true;
771  }
772  else
773  {
774  /* result is already set to TRUE, need not change it */
775  }
776 
777  EEO_NEXT();
778  }
779 
780  /*
781  * If any of its clauses is TRUE, an OR's result is TRUE regardless of
782  * the states of the rest of the clauses, so we can stop evaluating
783  * and return TRUE immediately. If none are TRUE and one or more is
784  * NULL, we return NULL; otherwise we return FALSE. This makes sense
785  * when you interpret NULL as "don't know": perhaps one of the "don't
786  * knows" would have been TRUE if we'd known its value. Only when all
787  * the inputs are known to be FALSE can we state confidently that the
788  * OR's result is FALSE.
789  */
791  {
792  *op->d.boolexpr.anynull = false;
793 
794  /*
795  * EEOP_BOOL_OR_STEP_FIRST resets anynull, otherwise it's the same
796  * as EEOP_BOOL_OR_STEP - so fall through to that.
797  */
798 
799  /* FALL THROUGH */
800  }
801 
803  {
804  if (*op->resnull)
805  {
806  *op->d.boolexpr.anynull = true;
807  }
808  else if (DatumGetBool(*op->resvalue))
809  {
810  /* result is already set to TRUE, need not change it */
811  /* bail out early */
812  EEO_JUMP(op->d.boolexpr.jumpdone);
813  }
814 
815  EEO_NEXT();
816  }
817 
819  {
820  if (*op->resnull)
821  {
822  /* result is already set to NULL, need not change it */
823  }
824  else if (DatumGetBool(*op->resvalue))
825  {
826  /* result is already set to TRUE, need not change it */
827 
828  /*
829  * No point jumping to jumpdone - would be same target (as
830  * this is the last argument to the AND expression), except
831  * more expensive.
832  */
833  }
834  else if (*op->d.boolexpr.anynull)
835  {
836  *op->resvalue = (Datum) 0;
837  *op->resnull = true;
838  }
839  else
840  {
841  /* result is already set to FALSE, need not change it */
842  }
843 
844  EEO_NEXT();
845  }
846 
848  {
849  /*
850  * Evaluation of 'not' is simple... if expr is false, then return
851  * 'true' and vice versa. It's safe to do this even on a
852  * nominally null value, so we ignore resnull; that means that
853  * NULL in produces NULL out, which is what we want.
854  */
856 
857  EEO_NEXT();
858  }
859 
861  {
862  /* simplified version of BOOL_AND_STEP for use by ExecQual() */
863 
864  /* If argument (also result) is false or null ... */
865  if (*op->resnull ||
866  !DatumGetBool(*op->resvalue))
867  {
868  /* ... bail out early, returning FALSE */
869  *op->resnull = false;
870  *op->resvalue = BoolGetDatum(false);
871  EEO_JUMP(op->d.qualexpr.jumpdone);
872  }
873 
874  /*
875  * Otherwise, leave the TRUE value in place, in case this is the
876  * last qual. Then, TRUE is the correct answer.
877  */
878 
879  EEO_NEXT();
880  }
881 
883  {
884  /* Unconditionally jump to target step */
885  EEO_JUMP(op->d.jump.jumpdone);
886  }
887 
889  {
890  /* Transfer control if current result is null */
891  if (*op->resnull)
892  EEO_JUMP(op->d.jump.jumpdone);
893 
894  EEO_NEXT();
895  }
896 
898  {
899  /* Transfer control if current result is non-null */
900  if (!*op->resnull)
901  EEO_JUMP(op->d.jump.jumpdone);
902 
903  EEO_NEXT();
904  }
905 
907  {
908  /* Transfer control if current result is null or false */
909  if (*op->resnull || !DatumGetBool(*op->resvalue))
910  EEO_JUMP(op->d.jump.jumpdone);
911 
912  EEO_NEXT();
913  }
914 
916  {
917  *op->resvalue = BoolGetDatum(*op->resnull);
918  *op->resnull = false;
919 
920  EEO_NEXT();
921  }
922 
924  {
925  *op->resvalue = BoolGetDatum(!*op->resnull);
926  *op->resnull = false;
927 
928  EEO_NEXT();
929  }
930 
932  {
933  /* out of line implementation: too large */
934  ExecEvalRowNull(state, op, econtext);
935 
936  EEO_NEXT();
937  }
938 
940  {
941  /* out of line implementation: too large */
942  ExecEvalRowNotNull(state, op, econtext);
943 
944  EEO_NEXT();
945  }
946 
947  /* BooleanTest implementations for all booltesttypes */
948 
950  {
951  if (*op->resnull)
952  {
953  *op->resvalue = BoolGetDatum(false);
954  *op->resnull = false;
955  }
956  /* else, input value is the correct output as well */
957 
958  EEO_NEXT();
959  }
960 
962  {
963  if (*op->resnull)
964  {
965  *op->resvalue = BoolGetDatum(true);
966  *op->resnull = false;
967  }
968  else
970 
971  EEO_NEXT();
972  }
973 
975  {
976  if (*op->resnull)
977  {
978  *op->resvalue = BoolGetDatum(false);
979  *op->resnull = false;
980  }
981  else
983 
984  EEO_NEXT();
985  }
986 
988  {
989  if (*op->resnull)
990  {
991  *op->resvalue = BoolGetDatum(true);
992  *op->resnull = false;
993  }
994  /* else, input value is the correct output as well */
995 
996  EEO_NEXT();
997  }
998 
1000  {
1001  /* out of line implementation: too large */
1002  ExecEvalParamExec(state, op, econtext);
1003 
1004  EEO_NEXT();
1005  }
1006 
1008  {
1009  /* out of line implementation: too large */
1010  ExecEvalParamExtern(state, op, econtext);
1011  EEO_NEXT();
1012  }
1013 
1015  {
1016  /* allow an extension module to supply a PARAM_EXTERN value */
1017  op->d.cparam.paramfunc(state, op, econtext);
1018  EEO_NEXT();
1019  }
1020 
1022  {
1023  /*
1024  * Normally upper parts of the expression tree have setup the
1025  * values to be returned here, but some parts of the system
1026  * currently misuse {caseValue,domainValue}_{datum,isNull} to set
1027  * run-time data. So if no values have been set-up, use
1028  * ExprContext's. This isn't pretty, but also not *that* ugly,
1029  * and this is unlikely to be performance sensitive enough to
1030  * worry about an extra branch.
1031  */
1032  if (op->d.casetest.value)
1033  {
1034  *op->resvalue = *op->d.casetest.value;
1035  *op->resnull = *op->d.casetest.isnull;
1036  }
1037  else
1038  {
1039  *op->resvalue = econtext->caseValue_datum;
1040  *op->resnull = econtext->caseValue_isNull;
1041  }
1042 
1043  EEO_NEXT();
1044  }
1045 
1047  {
1048  /*
1049  * See EEOP_CASE_TESTVAL comment.
1050  */
1051  if (op->d.casetest.value)
1052  {
1053  *op->resvalue = *op->d.casetest.value;
1054  *op->resnull = *op->d.casetest.isnull;
1055  }
1056  else
1057  {
1058  *op->resvalue = econtext->domainValue_datum;
1059  *op->resnull = econtext->domainValue_isNull;
1060  }
1061 
1062  EEO_NEXT();
1063  }
1064 
1066  {
1067  /*
1068  * Force a varlena value that might be read multiple times to R/O
1069  */
1070  if (!*op->d.make_readonly.isnull)
1071  *op->resvalue =
1073  *op->resnull = *op->d.make_readonly.isnull;
1074 
1075  EEO_NEXT();
1076  }
1077 
1079  {
1080  /*
1081  * Evaluate a CoerceViaIO node. This can be quite a hot path, so
1082  * inline as much work as possible. The source value is in our
1083  * result variable.
1084  */
1085  char *str;
1086 
1087  /* call output function (similar to OutputFunctionCall) */
1088  if (*op->resnull)
1089  {
1090  /* output functions are not called on nulls */
1091  str = NULL;
1092  }
1093  else
1094  {
1095  FunctionCallInfo fcinfo_out;
1096 
1097  fcinfo_out = op->d.iocoerce.fcinfo_data_out;
1098  fcinfo_out->args[0].value = *op->resvalue;
1099  fcinfo_out->args[0].isnull = false;
1100 
1101  fcinfo_out->isnull = false;
1102  str = DatumGetCString(FunctionCallInvoke(fcinfo_out));
1103 
1104  /* OutputFunctionCall assumes result isn't null */
1105  Assert(!fcinfo_out->isnull);
1106  }
1107 
1108  /* call input function (similar to InputFunctionCall) */
1109  if (!op->d.iocoerce.finfo_in->fn_strict || str != NULL)
1110  {
1111  FunctionCallInfo fcinfo_in;
1112  Datum d;
1113 
1114  fcinfo_in = op->d.iocoerce.fcinfo_data_in;
1115  fcinfo_in->args[0].value = PointerGetDatum(str);
1116  fcinfo_in->args[0].isnull = *op->resnull;
1117  /* second and third arguments are already set up */
1118 
1119  fcinfo_in->isnull = false;
1120  d = FunctionCallInvoke(fcinfo_in);
1121  *op->resvalue = d;
1122 
1123  /* Should get null result if and only if str is NULL */
1124  if (str == NULL)
1125  {
1126  Assert(*op->resnull);
1127  Assert(fcinfo_in->isnull);
1128  }
1129  else
1130  {
1131  Assert(!*op->resnull);
1132  Assert(!fcinfo_in->isnull);
1133  }
1134  }
1135 
1136  EEO_NEXT();
1137  }
1138 
1140  {
1141  /*
1142  * IS DISTINCT FROM must evaluate arguments (already done into
1143  * fcinfo->args) to determine whether they are NULL; if either is
1144  * NULL then the result is determined. If neither is NULL, then
1145  * proceed to evaluate the comparison function, which is just the
1146  * type's standard equality operator. We need not care whether
1147  * that function is strict. Because the handling of nulls is
1148  * different, we can't just reuse EEOP_FUNCEXPR.
1149  */
1150  FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
1151 
1152  /* check function arguments for NULLness */
1153  if (fcinfo->args[0].isnull && fcinfo->args[1].isnull)
1154  {
1155  /* Both NULL? Then is not distinct... */
1156  *op->resvalue = BoolGetDatum(false);
1157  *op->resnull = false;
1158  }
1159  else if (fcinfo->args[0].isnull || fcinfo->args[1].isnull)
1160  {
1161  /* Only one is NULL? Then is distinct... */
1162  *op->resvalue = BoolGetDatum(true);
1163  *op->resnull = false;
1164  }
1165  else
1166  {
1167  /* Neither null, so apply the equality function */
1168  Datum eqresult;
1169 
1170  fcinfo->isnull = false;
1171  eqresult = op->d.func.fn_addr(fcinfo);
1172  /* Must invert result of "="; safe to do even if null */
1173  *op->resvalue = BoolGetDatum(!DatumGetBool(eqresult));
1174  *op->resnull = fcinfo->isnull;
1175  }
1176 
1177  EEO_NEXT();
1178  }
1179 
1180  /* see EEOP_DISTINCT for comments, this is just inverted */
1182  {
1183  FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
1184 
1185  if (fcinfo->args[0].isnull && fcinfo->args[1].isnull)
1186  {
1187  *op->resvalue = BoolGetDatum(true);
1188  *op->resnull = false;
1189  }
1190  else if (fcinfo->args[0].isnull || fcinfo->args[1].isnull)
1191  {
1192  *op->resvalue = BoolGetDatum(false);
1193  *op->resnull = false;
1194  }
1195  else
1196  {
1197  Datum eqresult;
1198 
1199  fcinfo->isnull = false;
1200  eqresult = op->d.func.fn_addr(fcinfo);
1201  *op->resvalue = eqresult;
1202  *op->resnull = fcinfo->isnull;
1203  }
1204 
1205  EEO_NEXT();
1206  }
1207 
1209  {
1210  /*
1211  * The arguments are already evaluated into fcinfo->args.
1212  */
1213  FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
1214 
1215  /* if either argument is NULL they can't be equal */
1216  if (!fcinfo->args[0].isnull && !fcinfo->args[1].isnull)
1217  {
1218  Datum result;
1219 
1220  fcinfo->isnull = false;
1221  result = op->d.func.fn_addr(fcinfo);
1222 
1223  /* if the arguments are equal return null */
1224  if (!fcinfo->isnull && DatumGetBool(result))
1225  {
1226  *op->resvalue = (Datum) 0;
1227  *op->resnull = true;
1228 
1229  EEO_NEXT();
1230  }
1231  }
1232 
1233  /* Arguments aren't equal, so return the first one */
1234  *op->resvalue = fcinfo->args[0].value;
1235  *op->resnull = fcinfo->args[0].isnull;
1236 
1237  EEO_NEXT();
1238  }
1239 
1241  {
1242  /*
1243  * Doesn't seem worthwhile to have an inline implementation
1244  * efficiency-wise.
1245  */
1246  ExecEvalSQLValueFunction(state, op);
1247 
1248  EEO_NEXT();
1249  }
1250 
1252  {
1253  /* error invocation uses space, and shouldn't ever occur */
1254  ExecEvalCurrentOfExpr(state, op);
1255 
1256  EEO_NEXT();
1257  }
1258 
1260  {
1261  /*
1262  * Doesn't seem worthwhile to have an inline implementation
1263  * efficiency-wise.
1264  */
1265  ExecEvalNextValueExpr(state, op);
1266 
1267  EEO_NEXT();
1268  }
1269 
1271  {
1272  /* too complex for an inline implementation */
1273  ExecEvalArrayExpr(state, op);
1274 
1275  EEO_NEXT();
1276  }
1277 
1279  {
1280  /* too complex for an inline implementation */
1281  ExecEvalArrayCoerce(state, op, econtext);
1282 
1283  EEO_NEXT();
1284  }
1285 
1287  {
1288  /* too complex for an inline implementation */
1289  ExecEvalRow(state, op);
1290 
1291  EEO_NEXT();
1292  }
1293 
1295  {
1296  FunctionCallInfo fcinfo = op->d.rowcompare_step.fcinfo_data;
1297  Datum d;
1298 
1299  /* force NULL result if strict fn and NULL input */
1300  if (op->d.rowcompare_step.finfo->fn_strict &&
1301  (fcinfo->args[0].isnull || fcinfo->args[1].isnull))
1302  {
1303  *op->resnull = true;
1304  EEO_JUMP(op->d.rowcompare_step.jumpnull);
1305  }
1306 
1307  /* Apply comparison function */
1308  fcinfo->isnull = false;
1309  d = op->d.rowcompare_step.fn_addr(fcinfo);
1310  *op->resvalue = d;
1311 
1312  /* force NULL result if NULL function result */
1313  if (fcinfo->isnull)
1314  {
1315  *op->resnull = true;
1316  EEO_JUMP(op->d.rowcompare_step.jumpnull);
1317  }
1318  *op->resnull = false;
1319 
1320  /* If unequal, no need to compare remaining columns */
1321  if (DatumGetInt32(*op->resvalue) != 0)
1322  {
1323  EEO_JUMP(op->d.rowcompare_step.jumpdone);
1324  }
1325 
1326  EEO_NEXT();
1327  }
1328 
1330  {
1331  int32 cmpresult = DatumGetInt32(*op->resvalue);
1332  RowCompareType rctype = op->d.rowcompare_final.rctype;
1333 
1334  *op->resnull = false;
1335  switch (rctype)
1336  {
1337  /* EQ and NE cases aren't allowed here */
1338  case ROWCOMPARE_LT:
1339  *op->resvalue = BoolGetDatum(cmpresult < 0);
1340  break;
1341  case ROWCOMPARE_LE:
1342  *op->resvalue = BoolGetDatum(cmpresult <= 0);
1343  break;
1344  case ROWCOMPARE_GE:
1345  *op->resvalue = BoolGetDatum(cmpresult >= 0);
1346  break;
1347  case ROWCOMPARE_GT:
1348  *op->resvalue = BoolGetDatum(cmpresult > 0);
1349  break;
1350  default:
1351  Assert(false);
1352  break;
1353  }
1354 
1355  EEO_NEXT();
1356  }
1357 
1359  {
1360  /* too complex for an inline implementation */
1361  ExecEvalMinMax(state, op);
1362 
1363  EEO_NEXT();
1364  }
1365 
1367  {
1368  /* too complex for an inline implementation */
1369  ExecEvalFieldSelect(state, op, econtext);
1370 
1371  EEO_NEXT();
1372  }
1373 
1375  {
1376  /* too complex for an inline implementation */
1377  ExecEvalFieldStoreDeForm(state, op, econtext);
1378 
1379  EEO_NEXT();
1380  }
1381 
1383  {
1384  /* too complex for an inline implementation */
1385  ExecEvalFieldStoreForm(state, op, econtext);
1386 
1387  EEO_NEXT();
1388  }
1389 
1391  {
1392  /* Process an array subscript */
1393 
1394  /* too complex for an inline implementation */
1395  if (ExecEvalSubscriptingRef(state, op))
1396  {
1397  EEO_NEXT();
1398  }
1399  else
1400  {
1401  /* Subscript is null, short-circuit SubscriptingRef to NULL */
1402  EEO_JUMP(op->d.sbsref_subscript.jumpdone);
1403  }
1404  }
1405 
1407  {
1408  /*
1409  * Fetch the old value in an sbsref assignment, in case it's
1410  * referenced (via a CaseTestExpr) inside the assignment
1411  * expression.
1412  */
1413 
1414  /* too complex for an inline implementation */
1415  ExecEvalSubscriptingRefOld(state, op);
1416 
1417  EEO_NEXT();
1418  }
1419 
1420  /*
1421  * Perform SubscriptingRef assignment
1422  */
1424  {
1425  /* too complex for an inline implementation */
1426  ExecEvalSubscriptingRefAssign(state, op);
1427 
1428  EEO_NEXT();
1429  }
1430 
1431  /*
1432  * Fetch subset of an array.
1433  */
1435  {
1436  /* too complex for an inline implementation */
1437  ExecEvalSubscriptingRefFetch(state, op);
1438 
1439  EEO_NEXT();
1440  }
1441 
1443  {
1444  /* too complex for an inline implementation */
1445  ExecEvalConvertRowtype(state, op, econtext);
1446 
1447  EEO_NEXT();
1448  }
1449 
1451  {
1452  /* too complex for an inline implementation */
1453  ExecEvalScalarArrayOp(state, op);
1454 
1455  EEO_NEXT();
1456  }
1457 
1459  {
1460  /* too complex for an inline implementation */
1461  ExecEvalConstraintNotNull(state, op);
1462 
1463  EEO_NEXT();
1464  }
1465 
1467  {
1468  /* too complex for an inline implementation */
1469  ExecEvalConstraintCheck(state, op);
1470 
1471  EEO_NEXT();
1472  }
1473 
1475  {
1476  /* too complex for an inline implementation */
1477  ExecEvalXmlExpr(state, op);
1478 
1479  EEO_NEXT();
1480  }
1481 
1483  {
1484  /*
1485  * Returns a Datum whose value is the precomputed aggregate value
1486  * found in the given expression context.
1487  */
1488  AggrefExprState *aggref = op->d.aggref.astate;
1489 
1490  Assert(econtext->ecxt_aggvalues != NULL);
1491 
1492  *op->resvalue = econtext->ecxt_aggvalues[aggref->aggno];
1493  *op->resnull = econtext->ecxt_aggnulls[aggref->aggno];
1494 
1495  EEO_NEXT();
1496  }
1497 
1499  {
1500  /* too complex/uncommon for an inline implementation */
1501  ExecEvalGroupingFunc(state, op);
1502 
1503  EEO_NEXT();
1504  }
1505 
1507  {
1508  /*
1509  * Like Aggref, just return a precomputed value from the econtext.
1510  */
1511  WindowFuncExprState *wfunc = op->d.window_func.wfstate;
1512 
1513  Assert(econtext->ecxt_aggvalues != NULL);
1514 
1515  *op->resvalue = econtext->ecxt_aggvalues[wfunc->wfuncno];
1516  *op->resnull = econtext->ecxt_aggnulls[wfunc->wfuncno];
1517 
1518  EEO_NEXT();
1519  }
1520 
1522  {
1523  /* too complex for an inline implementation */
1524  ExecEvalSubPlan(state, op, econtext);
1525 
1526  EEO_NEXT();
1527  }
1528 
1530  {
1531  /* too complex for an inline implementation */
1532  ExecEvalAlternativeSubPlan(state, op, econtext);
1533 
1534  EEO_NEXT();
1535  }
1536 
1537  /* evaluate a strict aggregate deserialization function */
1539  {
1540  /* Don't call a strict deserialization function with NULL input */
1541  if (op->d.agg_deserialize.fcinfo_data->args[0].isnull)
1542  EEO_JUMP(op->d.agg_deserialize.jumpnull);
1543 
1544  /* fallthrough */
1545  }
1546 
1547  /* evaluate aggregate deserialization function (non-strict portion) */
1549  {
1550  FunctionCallInfo fcinfo = op->d.agg_deserialize.fcinfo_data;
1551  AggState *aggstate = op->d.agg_deserialize.aggstate;
1552  MemoryContext oldContext;
1553 
1554  /*
1555  * We run the deserialization functions in per-input-tuple memory
1556  * context.
1557  */
1558  oldContext = MemoryContextSwitchTo(aggstate->tmpcontext->ecxt_per_tuple_memory);
1559  fcinfo->isnull = false;
1560  *op->resvalue = FunctionCallInvoke(fcinfo);
1561  *op->resnull = fcinfo->isnull;
1562  MemoryContextSwitchTo(oldContext);
1563 
1564  EEO_NEXT();
1565  }
1566 
1567  /*
1568  * Check that a strict aggregate transition / combination function's
1569  * input is not NULL.
1570  */
1572  {
1573  int argno;
1574  bool *nulls = op->d.agg_strict_input_check.nulls;
1575  int nargs = op->d.agg_strict_input_check.nargs;
1576 
1577  for (argno = 0; argno < nargs; argno++)
1578  {
1579  if (nulls[argno])
1580  EEO_JUMP(op->d.agg_strict_input_check.jumpnull);
1581  }
1582  EEO_NEXT();
1583  }
1584 
1586  {
1587  int argno;
1588  NullableDatum *args = op->d.agg_strict_input_check.args;
1589  int nargs = op->d.agg_strict_input_check.nargs;
1590 
1591  for (argno = 0; argno < nargs; argno++)
1592  {
1593  if (args[argno].isnull)
1594  EEO_JUMP(op->d.agg_strict_input_check.jumpnull);
1595  }
1596  EEO_NEXT();
1597  }
1598 
1599  /*
1600  * Initialize an aggregate's first value if necessary.
1601  */
1603  {
1604  AggState *aggstate;
1605  AggStatePerGroup pergroup;
1606 
1607  aggstate = op->d.agg_init_trans.aggstate;
1608  pergroup = &aggstate->all_pergroups
1609  [op->d.agg_init_trans.setoff]
1610  [op->d.agg_init_trans.transno];
1611 
1612  /* If transValue has not yet been initialized, do so now. */
1613  if (pergroup->noTransValue)
1614  {
1615  AggStatePerTrans pertrans = op->d.agg_init_trans.pertrans;
1616 
1617  aggstate->curaggcontext = op->d.agg_init_trans.aggcontext;
1618  aggstate->current_set = op->d.agg_init_trans.setno;
1619 
1620  ExecAggInitGroup(aggstate, pertrans, pergroup);
1621 
1622  /* copied trans value from input, done this round */
1623  EEO_JUMP(op->d.agg_init_trans.jumpnull);
1624  }
1625 
1626  EEO_NEXT();
1627  }
1628 
1629  /* check that a strict aggregate's input isn't NULL */
1631  {
1632  AggState *aggstate;
1633  AggStatePerGroup pergroup;
1634 
1635  aggstate = op->d.agg_strict_trans_check.aggstate;
1636  pergroup = &aggstate->all_pergroups
1637  [op->d.agg_strict_trans_check.setoff]
1638  [op->d.agg_strict_trans_check.transno];
1639 
1640  if (unlikely(pergroup->transValueIsNull))
1641  EEO_JUMP(op->d.agg_strict_trans_check.jumpnull);
1642 
1643  EEO_NEXT();
1644  }
1645 
1646  /*
1647  * Evaluate aggregate transition / combine function that has a
1648  * by-value transition type. That's a separate case from the
1649  * by-reference implementation because it's a bit simpler.
1650  */
1652  {
1653  AggState *aggstate;
1654  AggStatePerTrans pertrans;
1655  AggStatePerGroup pergroup;
1656  FunctionCallInfo fcinfo;
1657  MemoryContext oldContext;
1658  Datum newVal;
1659 
1660  aggstate = op->d.agg_trans.aggstate;
1661  pertrans = op->d.agg_trans.pertrans;
1662 
1663  pergroup = &aggstate->all_pergroups
1664  [op->d.agg_trans.setoff]
1665  [op->d.agg_trans.transno];
1666 
1667  Assert(pertrans->transtypeByVal);
1668 
1669  fcinfo = pertrans->transfn_fcinfo;
1670 
1671  /* cf. select_current_set() */
1672  aggstate->curaggcontext = op->d.agg_trans.aggcontext;
1673  aggstate->current_set = op->d.agg_trans.setno;
1674 
1675  /* set up aggstate->curpertrans for AggGetAggref() */
1676  aggstate->curpertrans = pertrans;
1677 
1678  /* invoke transition function in per-tuple context */
1679  oldContext = MemoryContextSwitchTo(aggstate->tmpcontext->ecxt_per_tuple_memory);
1680 
1681  fcinfo->args[0].value = pergroup->transValue;
1682  fcinfo->args[0].isnull = pergroup->transValueIsNull;
1683  fcinfo->isnull = false; /* just in case transfn doesn't set it */
1684 
1685  newVal = FunctionCallInvoke(fcinfo);
1686 
1687  pergroup->transValue = newVal;
1688  pergroup->transValueIsNull = fcinfo->isnull;
1689 
1690  MemoryContextSwitchTo(oldContext);
1691 
1692  EEO_NEXT();
1693  }
1694 
1695  /*
1696  * Evaluate aggregate transition / combine function that has a
1697  * by-reference transition type.
1698  *
1699  * Could optimize a bit further by splitting off by-reference
1700  * fixed-length types, but currently that doesn't seem worth it.
1701  */
1703  {
1704  AggState *aggstate;
1705  AggStatePerTrans pertrans;
1706  AggStatePerGroup pergroup;
1707  FunctionCallInfo fcinfo;
1708  MemoryContext oldContext;
1709  Datum newVal;
1710 
1711  aggstate = op->d.agg_trans.aggstate;
1712  pertrans = op->d.agg_trans.pertrans;
1713 
1714  pergroup = &aggstate->all_pergroups
1715  [op->d.agg_trans.setoff]
1716  [op->d.agg_trans.transno];
1717 
1718  Assert(!pertrans->transtypeByVal);
1719 
1720  fcinfo = pertrans->transfn_fcinfo;
1721 
1722  /* cf. select_current_set() */
1723  aggstate->curaggcontext = op->d.agg_trans.aggcontext;
1724  aggstate->current_set = op->d.agg_trans.setno;
1725 
1726  /* set up aggstate->curpertrans for AggGetAggref() */
1727  aggstate->curpertrans = pertrans;
1728 
1729  /* invoke transition function in per-tuple context */
1730  oldContext = MemoryContextSwitchTo(aggstate->tmpcontext->ecxt_per_tuple_memory);
1731 
1732  fcinfo->args[0].value = pergroup->transValue;
1733  fcinfo->args[0].isnull = pergroup->transValueIsNull;
1734  fcinfo->isnull = false; /* just in case transfn doesn't set it */
1735 
1736  newVal = FunctionCallInvoke(fcinfo);
1737 
1738  /*
1739  * For pass-by-ref datatype, must copy the new value into
1740  * aggcontext and free the prior transValue. But if transfn
1741  * returned a pointer to its first input, we don't need to do
1742  * anything. Also, if transfn returned a pointer to a R/W
1743  * expanded object that is already a child of the aggcontext,
1744  * assume we can adopt that value without copying it.
1745  */
1746  if (DatumGetPointer(newVal) != DatumGetPointer(pergroup->transValue))
1747  newVal = ExecAggTransReparent(aggstate, pertrans,
1748  newVal, fcinfo->isnull,
1749  pergroup->transValue,
1750  pergroup->transValueIsNull);
1751 
1752  pergroup->transValue = newVal;
1753  pergroup->transValueIsNull = fcinfo->isnull;
1754 
1755  MemoryContextSwitchTo(oldContext);
1756 
1757  EEO_NEXT();
1758  }
1759 
1760  /* process single-column ordered aggregate datum */
1762  {
1763  /* too complex for an inline implementation */
1764  ExecEvalAggOrderedTransDatum(state, op, econtext);
1765 
1766  EEO_NEXT();
1767  }
1768 
1769  /* process multi-column ordered aggregate tuple */
1771  {
1772  /* too complex for an inline implementation */
1773  ExecEvalAggOrderedTransTuple(state, op, econtext);
1774 
1775  EEO_NEXT();
1776  }
1777 
1779  {
1780  /* unreachable */
1781  Assert(false);
1782  goto out;
1783  }
1784  }
1785 
1786 out:
1787  *isnull = state->resnull;
1788  return state->resvalue;
1789 }
void ExecEvalScalarArrayOp(ExprState *state, ExprEvalStep *op)
struct ExprEvalStep::@52::@94 agg_trans
Datum * ecxt_aggvalues
Definition: execnodes.h:242
void ExecAggInitGroup(AggState *aggstate, AggStatePerTrans pertrans, AggStatePerGroup pergroup)
Datum MakeExpandedObjectReadOnlyInternal(Datum d)
Definition: expandeddatum.c:95
struct ExprEvalStep::@52::@54 var
Datum * resvalue
Definition: execExpr.h:250
#define DatumGetInt32(X)
Definition: postgres.h:472
struct ExprEvalStep::@52::@92 agg_init_trans
#define EEO_SWITCH()
#define PointerGetDatum(X)
Definition: postgres.h:556
struct ExprEvalStep * steps
Definition: execnodes.h:85
MemoryContext ecxt_per_tuple_memory
Definition: execnodes.h:231
struct ExprEvalStep::@52::@85 aggref
#define EEO_JUMP(stepno)
void ExecEvalParamExec(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
bool * resnull
Definition: execExpr.h:251
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
static void slot_getsomeattrs(TupleTableSlot *slot, int attnum)
Definition: tuptable.h:341
void ExecEvalConvertRowtype(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
Datum * tts_values
Definition: tuptable.h:126
void ExecEvalSubscriptingRefAssign(ExprState *state, ExprEvalStep *op)
bool ExecEvalSubscriptingRef(ExprState *state, ExprEvalStep *op)
#define lengthof(array)
Definition: c.h:669
TupleTableSlot * resultslot
Definition: execnodes.h:80
Datum domainValue_datum
Definition: execnodes.h:254
union ExprEvalStep::@52 d
int current_set
Definition: execnodes.h:2054
void ExecEvalFieldStoreForm(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
FunctionCallInfo transfn_fcinfo
Definition: nodeAgg.h:161
struct ExprEvalStep::@52::@65 cparam
struct ExprEvalStep::@52::@61 qualexpr
Datum ExecAggTransReparent(AggState *aggstate, AggStatePerTrans pertrans, Datum newValue, bool newValueIsNull, Datum oldValue, bool oldValueIsNull)
ExprContext * tmpcontext
Definition: execnodes.h:2044
signed int int32
Definition: c.h:347
struct ExprEvalStep::@52::@90 agg_deserialize
void ExecEvalRow(ExprState *state, ExprEvalStep *op)
#define StaticAssertStmt(condition, errmessage)
Definition: c.h:849
void ExecEvalMinMax(ExprState *state, ExprEvalStep *op)
struct ExprEvalStep::@52::@53 fetch
bool resnull
Definition: execnodes.h:72
#define DatumGetCString(X)
Definition: postgres.h:566
Datum caseValue_datum
Definition: execnodes.h:248