PostgreSQL Source Code  git master
execExprInterp.c File Reference
#include "postgres.h"
#include "access/tuptoaster.h"
#include "catalog/pg_type.h"
#include "commands/sequence.h"
#include "executor/execExpr.h"
#include "executor/nodeSubplan.h"
#include "funcapi.h"
#include "utils/array.h"
#include "utils/memutils.h"
#include "miscadmin.h"
#include "nodes/nodeFuncs.h"
#include "parser/parsetree.h"
#include "pgstat.h"
#include "utils/builtins.h"
#include "utils/date.h"
#include "utils/datum.h"
#include "utils/expandedrecord.h"
#include "utils/lsyscache.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 ExecJustConst (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)
 
void ExecReadyInterpretedExpr (ExprState *state)
 
Datum ExecInterpExprStillValid (ExprState *state, ExprContext *econtext, bool *isNull)
 
void CheckExprStillValid (ExprState *state, ExprContext *econtext)
 
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 123 of file execExprInterp.c.

Referenced by ExecInterpExpr().

◆ EEO_DISPATCH

#define EEO_DISPATCH ( )    goto starteval

Definition at line 124 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 135 of file execExprInterp.c.

Referenced by ExecInterpExpr().

◆ EEO_NEXT

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

Definition at line 129 of file execExprInterp.c.

Referenced by ExecInterpExpr().

◆ EEO_OPCODE

#define EEO_OPCODE (   opcode)    (opcode)

Definition at line 125 of file execExprInterp.c.

Referenced by ExecReadyInterpretedExpr().

◆ EEO_SWITCH

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

Definition at line 122 of file execExprInterp.c.

Referenced by ExecInterpExpr().

Function Documentation

◆ CheckExprStillValid()

void CheckExprStillValid ( ExprState state,
ExprContext econtext 
)

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

1779 {
1780  int i = 0;
1781  TupleTableSlot *innerslot;
1782  TupleTableSlot *outerslot;
1783  TupleTableSlot *scanslot;
1784 
1785  innerslot = econtext->ecxt_innertuple;
1786  outerslot = econtext->ecxt_outertuple;
1787  scanslot = econtext->ecxt_scantuple;
1788 
1789  for (i = 0; i < state->steps_len; i++)
1790  {
1791  ExprEvalStep *op = &state->steps[i];
1792 
1793  switch (ExecEvalStepOp(state, op))
1794  {
1795  case EEOP_INNER_VAR:
1796  {
1797  int attnum = op->d.var.attnum;
1798 
1799  CheckVarSlotCompatibility(innerslot, attnum + 1, op->d.var.vartype);
1800  break;
1801  }
1802 
1803  case EEOP_OUTER_VAR:
1804  {
1805  int attnum = op->d.var.attnum;
1806 
1807  CheckVarSlotCompatibility(outerslot, attnum + 1, op->d.var.vartype);
1808  break;
1809  }
1810 
1811  case EEOP_SCAN_VAR:
1812  {
1813  int attnum = op->d.var.attnum;
1814 
1815  CheckVarSlotCompatibility(scanslot, attnum + 1, op->d.var.vartype);
1816  break;
1817  }
1818  default:
1819  break;
1820  }
1821  }
1822 }
struct ExprEvalStep::@52::@54 var
struct ExprEvalStep * steps
Definition: execnodes.h:86
union ExprEvalStep::@52 d
static void CheckVarSlotCompatibility(TupleTableSlot *slot, int attnum, Oid vartype)
ExprEvalOp ExecEvalStepOp(ExprState *state, ExprEvalStep *op)
TupleTableSlot * ecxt_innertuple
Definition: execnodes.h:226
int16 attnum
Definition: pg_attribute.h:79
TupleTableSlot * ecxt_outertuple
Definition: execnodes.h:228
TupleTableSlot * ecxt_scantuple
Definition: execnodes.h:224
int steps_len
Definition: execnodes.h:105
int i

◆ CheckOpSlotCompatibility()

static void CheckOpSlotCompatibility ( ExprEvalStep op,
TupleTableSlot slot 
)
static

Definition at line 1881 of file execExprInterp.c.

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

Referenced by ExecInterpExpr(), ExecJustAssignInnerVar(), ExecJustAssignOuterVar(), ExecJustAssignScanVar(), ExecJustInnerVar(), ExecJustOuterVar(), and ExecJustScanVar().

1882 {
1883 #ifdef USE_ASSERT_CHECKING
1884  /* there's nothing to check */
1885  if (!op->d.fetch.fixed)
1886  return;
1887 
1888  /*
1889  * Should probably fixed at some point, but for now it's easier to allow
1890  * buffer and heap tuples to be used interchangeably.
1891  */
1892  if (slot->tts_ops == &TTSOpsBufferHeapTuple &&
1893  op->d.fetch.kind == &TTSOpsHeapTuple)
1894  return;
1895  if (slot->tts_ops == &TTSOpsHeapTuple &&
1896  op->d.fetch.kind == &TTSOpsBufferHeapTuple)
1897  return;
1898 
1899  /*
1900  * At the moment we consider it OK if a virtual slot is used instead of a
1901  * specific type of slot, as a virtual slot never needs to be deformed.
1902  */
1903  if (slot->tts_ops == &TTSOpsVirtual)
1904  return;
1905 
1906  Assert(op->d.fetch.kind == slot->tts_ops);
1907 #endif
1908 }
const TupleTableSlotOps TTSOpsBufferHeapTuple
Definition: execTuples.c:87
const TupleTableSlotOps TTSOpsVirtual
Definition: execTuples.c:84
const TupleTableSlotOps *const tts_ops
Definition: tuptable.h:122
union ExprEvalStep::@52 d
struct ExprEvalStep::@52::@53 fetch
#define Assert(condition)
Definition: c.h:732
const TupleTableSlotOps TTSOpsHeapTuple
Definition: execTuples.c:85

◆ CheckVarSlotCompatibility()

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

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

1831 {
1832  /*
1833  * What we have to check for here is the possibility of an attribute
1834  * having been dropped or changed in type since the plan tree was created.
1835  * Ideally the plan will get invalidated and not re-used, but just in
1836  * case, we keep these defenses. Fortunately it's sufficient to check
1837  * once on the first time through.
1838  *
1839  * Note: ideally we'd check typmod as well as typid, but that seems
1840  * impractical at the moment: in many cases the tupdesc will have been
1841  * generated by ExecTypeFromTL(), and that can't guarantee to generate an
1842  * accurate typmod in all cases, because some expression node types don't
1843  * carry typmod. Fortunately, for precisely that reason, there should be
1844  * no places with a critical dependency on the typmod of a value.
1845  *
1846  * System attributes don't require checking since their types never
1847  * change.
1848  */
1849  if (attnum > 0)
1850  {
1851  TupleDesc slot_tupdesc = slot->tts_tupleDescriptor;
1852  Form_pg_attribute attr;
1853 
1854  if (attnum > slot_tupdesc->natts) /* should never happen */
1855  elog(ERROR, "attribute number %d exceeds number of columns %d",
1856  attnum, slot_tupdesc->natts);
1857 
1858  attr = TupleDescAttr(slot_tupdesc, attnum - 1);
1859 
1860  if (attr->attisdropped)
1861  ereport(ERROR,
1862  (errcode(ERRCODE_UNDEFINED_COLUMN),
1863  errmsg("attribute %d of type %s has been dropped",
1864  attnum, format_type_be(slot_tupdesc->tdtypeid))));
1865 
1866  if (vartype != attr->atttypid)
1867  ereport(ERROR,
1868  (errcode(ERRCODE_DATATYPE_MISMATCH),
1869  errmsg("attribute %d of type %s has wrong type",
1870  attnum, format_type_be(slot_tupdesc->tdtypeid)),
1871  errdetail("Table has type %s, but query expects %s.",
1872  format_type_be(attr->atttypid),
1873  format_type_be(vartype))));
1874  }
1875 }
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
int errcode(int sqlerrcode)
Definition: elog.c:570
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:860
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:784
#define elog(elevel,...)
Definition: elog.h:226

◆ ExecAggInitGroup()

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

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

4060 {
4061  FunctionCallInfo fcinfo = pertrans->transfn_fcinfo;
4062  MemoryContext oldContext;
4063 
4064  /*
4065  * We must copy the datum into aggcontext if it is pass-by-ref. We do not
4066  * need to pfree the old transValue, since it's NULL. (We already checked
4067  * that the agg's input type is binary-compatible with its transtype, so
4068  * straight copy here is OK.)
4069  */
4070  oldContext = MemoryContextSwitchTo(
4072  pergroup->transValue = datumCopy(fcinfo->args[1].value,
4073  pertrans->transtypeByVal,
4074  pertrans->transtypeLen);
4075  pergroup->transValueIsNull = false;
4076  pergroup->noTransValue = false;
4077  MemoryContextSwitchTo(oldContext);
4078 }
MemoryContext ecxt_per_tuple_memory
Definition: execnodes.h:232
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
FunctionCallInfo transfn_fcinfo
Definition: nodeAgg.h:161
NullableDatum args[FLEXIBLE_ARRAY_MEMBER]
Definition: fmgr.h:95
Datum value
Definition: postgres.h:378
Datum datumCopy(Datum value, bool typByVal, int typLen)
Definition: datum.c:130
ExprContext * curaggcontext
Definition: execnodes.h:2000

◆ ExecAggTransReparent()

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

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

4090 {
4091  if (!newValueIsNull)
4092  {
4094  if (DatumIsReadWriteExpandedObject(newValue,
4095  false,
4096  pertrans->transtypeLen) &&
4097  MemoryContextGetParent(DatumGetEOHP(newValue)->eoh_context) == CurrentMemoryContext)
4098  /* do nothing */ ;
4099  else
4100  newValue = datumCopy(newValue,
4101  pertrans->transtypeByVal,
4102  pertrans->transtypeLen);
4103  }
4104  if (!oldValueIsNull)
4105  {
4106  if (DatumIsReadWriteExpandedObject(oldValue,
4107  false,
4108  pertrans->transtypeLen))
4109  DeleteExpandedObject(oldValue);
4110  else
4111  pfree(DatumGetPointer(oldValue));
4112  }
4113 
4114  return newValue;
4115 }
MemoryContext MemoryContextGetParent(MemoryContext context)
Definition: mcxt.c:439
MemoryContext ecxt_per_tuple_memory
Definition: execnodes.h:232
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
void pfree(void *pointer)
Definition: mcxt.c:1031
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:2000
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 4121 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

4123 {
4124  AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
4125  int setno = op->d.agg_trans.setno;
4126 
4127  tuplesort_putdatum(pertrans->sortstates[setno],
4128  *op->resvalue, *op->resnull);
4129 }
struct ExprEvalStep::@52::@94 agg_trans
void tuplesort_putdatum(Tuplesortstate *state, Datum val, bool isNull)
Definition: tuplesort.c:1555
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 4135 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().

4137 {
4138  AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
4139  int setno = op->d.agg_trans.setno;
4140 
4141  ExecClearTuple(pertrans->sortslot);
4142  pertrans->sortslot->tts_nvalid = pertrans->numInputs;
4143  ExecStoreVirtualTuple(pertrans->sortslot);
4144  tuplesort_puttupleslot(pertrans->sortstates[setno], pertrans->sortslot);
4145 }
struct ExprEvalStep::@52::@94 agg_trans
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:426
union ExprEvalStep::@52 d
Tuplesortstate ** sortstates
Definition: nodeAgg.h:153
AttrNumber tts_nvalid
Definition: tuptable.h:121
TupleTableSlot * sortslot
Definition: nodeAgg.h:135
TupleTableSlot * ExecStoreVirtualTuple(TupleTableSlot *slot)
Definition: execTuples.c:1517
void tuplesort_puttupleslot(Tuplesortstate *state, TupleTableSlot *slot)
Definition: tuplesort.c:1434

◆ ExecEvalAlternativeSubPlan()

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

Definition at line 3791 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

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

◆ ExecEvalArrayCoerce()

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

Definition at line 2747 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

2748 {
2749  Datum arraydatum;
2750 
2751  /* NULL array -> NULL result */
2752  if (*op->resnull)
2753  return;
2754 
2755  arraydatum = *op->resvalue;
2756 
2757  /*
2758  * If it's binary-compatible, modify the element type in the array header,
2759  * but otherwise leave the array as we received it.
2760  */
2761  if (op->d.arraycoerce.elemexprstate == NULL)
2762  {
2763  /* Detoast input array if necessary, and copy in any case */
2764  ArrayType *array = DatumGetArrayTypePCopy(arraydatum);
2765 
2766  ARR_ELEMTYPE(array) = op->d.arraycoerce.resultelemtype;
2767  *op->resvalue = PointerGetDatum(array);
2768  return;
2769  }
2770 
2771  /*
2772  * Use array_map to apply the sub-expression to each array element.
2773  */
2774  *op->resvalue = array_map(arraydatum,
2775  op->d.arraycoerce.elemexprstate,
2776  econtext,
2777  op->d.arraycoerce.resultelemtype,
2778  op->d.arraycoerce.amstate);
2779 }
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 2540 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().

2541 {
2542  ArrayType *result;
2543  Oid element_type = op->d.arrayexpr.elemtype;
2544  int nelems = op->d.arrayexpr.nelems;
2545  int ndims = 0;
2546  int dims[MAXDIM];
2547  int lbs[MAXDIM];
2548 
2549  /* Set non-null as default */
2550  *op->resnull = false;
2551 
2552  if (!op->d.arrayexpr.multidims)
2553  {
2554  /* Elements are presumably of scalar type */
2555  Datum *dvalues = op->d.arrayexpr.elemvalues;
2556  bool *dnulls = op->d.arrayexpr.elemnulls;
2557 
2558  /* setup for 1-D array of the given length */
2559  ndims = 1;
2560  dims[0] = nelems;
2561  lbs[0] = 1;
2562 
2563  result = construct_md_array(dvalues, dnulls, ndims, dims, lbs,
2564  element_type,
2565  op->d.arrayexpr.elemlength,
2566  op->d.arrayexpr.elembyval,
2567  op->d.arrayexpr.elemalign);
2568  }
2569  else
2570  {
2571  /* Must be nested array expressions */
2572  int nbytes = 0;
2573  int nitems = 0;
2574  int outer_nelems = 0;
2575  int elem_ndims = 0;
2576  int *elem_dims = NULL;
2577  int *elem_lbs = NULL;
2578  bool firstone = true;
2579  bool havenulls = false;
2580  bool haveempty = false;
2581  char **subdata;
2582  bits8 **subbitmaps;
2583  int *subbytes;
2584  int *subnitems;
2585  int32 dataoffset;
2586  char *dat;
2587  int iitem;
2588  int elemoff;
2589  int i;
2590 
2591  subdata = (char **) palloc(nelems * sizeof(char *));
2592  subbitmaps = (bits8 **) palloc(nelems * sizeof(bits8 *));
2593  subbytes = (int *) palloc(nelems * sizeof(int));
2594  subnitems = (int *) palloc(nelems * sizeof(int));
2595 
2596  /* loop through and get data area from each element */
2597  for (elemoff = 0; elemoff < nelems; elemoff++)
2598  {
2599  Datum arraydatum;
2600  bool eisnull;
2601  ArrayType *array;
2602  int this_ndims;
2603 
2604  arraydatum = op->d.arrayexpr.elemvalues[elemoff];
2605  eisnull = op->d.arrayexpr.elemnulls[elemoff];
2606 
2607  /* temporarily ignore null subarrays */
2608  if (eisnull)
2609  {
2610  haveempty = true;
2611  continue;
2612  }
2613 
2614  array = DatumGetArrayTypeP(arraydatum);
2615 
2616  /* run-time double-check on element type */
2617  if (element_type != ARR_ELEMTYPE(array))
2618  ereport(ERROR,
2619  (errcode(ERRCODE_DATATYPE_MISMATCH),
2620  errmsg("cannot merge incompatible arrays"),
2621  errdetail("Array with element type %s cannot be "
2622  "included in ARRAY construct with element type %s.",
2623  format_type_be(ARR_ELEMTYPE(array)),
2624  format_type_be(element_type))));
2625 
2626  this_ndims = ARR_NDIM(array);
2627  /* temporarily ignore zero-dimensional subarrays */
2628  if (this_ndims <= 0)
2629  {
2630  haveempty = true;
2631  continue;
2632  }
2633 
2634  if (firstone)
2635  {
2636  /* Get sub-array details from first member */
2637  elem_ndims = this_ndims;
2638  ndims = elem_ndims + 1;
2639  if (ndims <= 0 || ndims > MAXDIM)
2640  ereport(ERROR,
2641  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
2642  errmsg("number of array dimensions (%d) exceeds " \
2643  "the maximum allowed (%d)", ndims, MAXDIM)));
2644 
2645  elem_dims = (int *) palloc(elem_ndims * sizeof(int));
2646  memcpy(elem_dims, ARR_DIMS(array), elem_ndims * sizeof(int));
2647  elem_lbs = (int *) palloc(elem_ndims * sizeof(int));
2648  memcpy(elem_lbs, ARR_LBOUND(array), elem_ndims * sizeof(int));
2649 
2650  firstone = false;
2651  }
2652  else
2653  {
2654  /* Check other sub-arrays are compatible */
2655  if (elem_ndims != this_ndims ||
2656  memcmp(elem_dims, ARR_DIMS(array),
2657  elem_ndims * sizeof(int)) != 0 ||
2658  memcmp(elem_lbs, ARR_LBOUND(array),
2659  elem_ndims * sizeof(int)) != 0)
2660  ereport(ERROR,
2661  (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
2662  errmsg("multidimensional arrays must have array "
2663  "expressions with matching dimensions")));
2664  }
2665 
2666  subdata[outer_nelems] = ARR_DATA_PTR(array);
2667  subbitmaps[outer_nelems] = ARR_NULLBITMAP(array);
2668  subbytes[outer_nelems] = ARR_SIZE(array) - ARR_DATA_OFFSET(array);
2669  nbytes += subbytes[outer_nelems];
2670  subnitems[outer_nelems] = ArrayGetNItems(this_ndims,
2671  ARR_DIMS(array));
2672  nitems += subnitems[outer_nelems];
2673  havenulls |= ARR_HASNULL(array);
2674  outer_nelems++;
2675  }
2676 
2677  /*
2678  * If all items were null or empty arrays, return an empty array;
2679  * otherwise, if some were and some weren't, raise error. (Note: we
2680  * must special-case this somehow to avoid trying to generate a 1-D
2681  * array formed from empty arrays. It's not ideal...)
2682  */
2683  if (haveempty)
2684  {
2685  if (ndims == 0) /* didn't find any nonempty array */
2686  {
2687  *op->resvalue = PointerGetDatum(construct_empty_array(element_type));
2688  return;
2689  }
2690  ereport(ERROR,
2691  (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
2692  errmsg("multidimensional arrays must have array "
2693  "expressions with matching dimensions")));
2694  }
2695 
2696  /* setup for multi-D array */
2697  dims[0] = outer_nelems;
2698  lbs[0] = 1;
2699  for (i = 1; i < ndims; i++)
2700  {
2701  dims[i] = elem_dims[i - 1];
2702  lbs[i] = elem_lbs[i - 1];
2703  }
2704 
2705  if (havenulls)
2706  {
2707  dataoffset = ARR_OVERHEAD_WITHNULLS(ndims, nitems);
2708  nbytes += dataoffset;
2709  }
2710  else
2711  {
2712  dataoffset = 0; /* marker for no null bitmap */
2713  nbytes += ARR_OVERHEAD_NONULLS(ndims);
2714  }
2715 
2716  result = (ArrayType *) palloc(nbytes);
2717  SET_VARSIZE(result, nbytes);
2718  result->ndim = ndims;
2719  result->dataoffset = dataoffset;
2720  result->elemtype = element_type;
2721  memcpy(ARR_DIMS(result), dims, ndims * sizeof(int));
2722  memcpy(ARR_LBOUND(result), lbs, ndims * sizeof(int));
2723 
2724  dat = ARR_DATA_PTR(result);
2725  iitem = 0;
2726  for (i = 0; i < outer_nelems; i++)
2727  {
2728  memcpy(dat, subdata[i], subbytes[i]);
2729  dat += subbytes[i];
2730  if (havenulls)
2731  array_bitmap_copy(ARR_NULLBITMAP(result), iitem,
2732  subbitmaps[i], 0,
2733  subnitems[i]);
2734  iitem += subnitems[i];
2735  }
2736  }
2737 
2738  *op->resvalue = PointerGetDatum(result);
2739 }
#define ARR_OVERHEAD_NONULLS(ndims)
Definition: array.h:298
#define ARR_SIZE(a)
Definition: array.h:277
Datum * resvalue
Definition: execExpr.h:250
#define MAXDIM
Definition: c.h:529
#define PointerGetDatum(X)
Definition: postgres.h:556
void array_bitmap_copy(bits8 *destbitmap, int destoffset, const bits8 *srcbitmap, int srcoffset, int nitems)
Definition: arrayfuncs.c:4687
int32 dataoffset
Definition: array.h:84
bool * resnull
Definition: execExpr.h:251
int ArrayGetNItems(int ndim, const int *dims)
Definition: arrayutils.c:75
int errcode(int sqlerrcode)
Definition: elog.c:570
char * format_type_be(Oid type_oid)
Definition: format_type.c:326
ArrayType * construct_empty_array(Oid elmtype)
Definition: arrayfuncs.c:3410
unsigned int Oid
Definition: postgres_ext.h:31
union ExprEvalStep::@52 d
#define ARR_OVERHEAD_WITHNULLS(ndims, nitems)
Definition: array.h:300
signed int int32
Definition: c.h:346
#define ARR_DATA_OFFSET(a)
Definition: array.h:304
#define ARR_LBOUND(a)
Definition: array.h:284
#define ERROR
Definition: elog.h:43
Oid elemtype
Definition: array.h:85
#define ARR_DIMS(a)
Definition: array.h:282
#define ARR_DATA_PTR(a)
Definition: array.h:310
int errdetail(const char *fmt,...)
Definition: elog.c:860
#define ARR_HASNULL(a)
Definition: array.h:279
#define ereport(elevel, rest)
Definition: elog.h:141
struct ExprEvalStep::@52::@71 arrayexpr
uint8 bits8
Definition: c.h:365
uintptr_t Datum
Definition: postgres.h:367
#define ARR_NDIM(a)
Definition: array.h:278
void * palloc(Size size)
Definition: mcxt.c:924
int errmsg(const char *fmt,...)
Definition: elog.c:784
int i
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:329
ArrayType * construct_md_array(Datum *elems, bool *nulls, int ndims, int *dims, int *lbs, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3326
#define ARR_ELEMTYPE(a)
Definition: array.h:280
#define ARR_NULLBITMAP(a)
Definition: array.h:288
int ndim
Definition: array.h:83
#define DatumGetArrayTypeP(X)
Definition: array.h:249

◆ ExecEvalConstraintCheck()

void ExecEvalConstraintCheck ( ExprState state,
ExprEvalStep op 
)

Definition at line 3513 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

3514 {
3515  if (!*op->d.domaincheck.checknull &&
3516  !DatumGetBool(*op->d.domaincheck.checkvalue))
3517  ereport(ERROR,
3518  (errcode(ERRCODE_CHECK_VIOLATION),
3519  errmsg("value for domain %s violates check constraint \"%s\"",
3520  format_type_be(op->d.domaincheck.resulttype),
3521  op->d.domaincheck.constraintname),
3522  errdomainconstraint(op->d.domaincheck.resulttype,
3523  op->d.domaincheck.constraintname)));
3524 }
int errcode(int sqlerrcode)
Definition: elog.c:570
char * format_type_be(Oid type_oid)
Definition: format_type.c:326
union ExprEvalStep::@52 d
struct ExprEvalStep::@52::@81 domaincheck
#define ERROR
Definition: elog.h:43
int errdomainconstraint(Oid datatypeOid, const char *conname)
Definition: domains.c:384
#define DatumGetBool(X)
Definition: postgres.h:393
#define ereport(elevel, rest)
Definition: elog.h:141
int errmsg(const char *fmt,...)
Definition: elog.c:784

◆ ExecEvalConstraintNotNull()

void ExecEvalConstraintNotNull ( ExprState state,
ExprEvalStep op 
)

Definition at line 3499 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

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

◆ ExecEvalConvertRowtype()

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

Definition at line 3248 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(), gettext_noop, 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().

3249 {
3251  HeapTuple result;
3252  Datum tupDatum;
3253  HeapTupleHeader tuple;
3254  HeapTupleData tmptup;
3255  TupleDesc indesc,
3256  outdesc;
3257 
3258  /* NULL in -> NULL out */
3259  if (*op->resnull)
3260  return;
3261 
3262  tupDatum = *op->resvalue;
3263  tuple = DatumGetHeapTupleHeader(tupDatum);
3264 
3265  /* Lookup tupdescs if first time through or after rescan */
3266  if (op->d.convert_rowtype.indesc == NULL)
3267  {
3268  get_cached_rowtype(exprType((Node *) convert->arg), -1,
3269  &op->d.convert_rowtype.indesc,
3270  econtext);
3271  op->d.convert_rowtype.initialized = false;
3272  }
3273  if (op->d.convert_rowtype.outdesc == NULL)
3274  {
3275  get_cached_rowtype(convert->resulttype, -1,
3276  &op->d.convert_rowtype.outdesc,
3277  econtext);
3278  op->d.convert_rowtype.initialized = false;
3279  }
3280 
3281  indesc = op->d.convert_rowtype.indesc;
3282  outdesc = op->d.convert_rowtype.outdesc;
3283 
3284  /*
3285  * We used to be able to assert that incoming tuples are marked with
3286  * exactly the rowtype of indesc. However, now that ExecEvalWholeRowVar
3287  * might change the tuples' marking to plain RECORD due to inserting
3288  * aliases, we can only make this weak test:
3289  */
3290  Assert(HeapTupleHeaderGetTypeId(tuple) == indesc->tdtypeid ||
3291  HeapTupleHeaderGetTypeId(tuple) == RECORDOID);
3292 
3293  /* if first time through, initialize conversion map */
3294  if (!op->d.convert_rowtype.initialized)
3295  {
3296  MemoryContext old_cxt;
3297 
3298  /* allocate map in long-lived memory context */
3299  old_cxt = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
3300 
3301  /* prepare map from old to new attribute numbers */
3302  op->d.convert_rowtype.map =
3303  convert_tuples_by_name(indesc, outdesc,
3304  gettext_noop("could not convert row type"));
3305  op->d.convert_rowtype.initialized = true;
3306 
3307  MemoryContextSwitchTo(old_cxt);
3308  }
3309 
3310  /* Following steps need a HeapTuple not a bare HeapTupleHeader */
3311  tmptup.t_len = HeapTupleHeaderGetDatumLength(tuple);
3312  tmptup.t_data = tuple;
3313 
3314  if (op->d.convert_rowtype.map != NULL)
3315  {
3316  /* Full conversion with attribute rearrangement needed */
3317  result = execute_attr_map_tuple(&tmptup, op->d.convert_rowtype.map);
3318  /* Result already has appropriate composite-datum header fields */
3319  *op->resvalue = HeapTupleGetDatum(result);
3320  }
3321  else
3322  {
3323  /*
3324  * The tuple is physically compatible as-is, but we need to insert the
3325  * destination rowtype OID in its composite-datum header field, so we
3326  * have to copy it anyway. heap_copy_tuple_as_datum() is convenient
3327  * for this since it will both make the physical copy and insert the
3328  * correct composite header fields. Note that we aren't expecting to
3329  * have to flatten any toasted fields: the input was a composite
3330  * datum, so it shouldn't contain any. So heap_copy_tuple_as_datum()
3331  * is overkill here, but its check for external fields is cheap.
3332  */
3333  *op->resvalue = heap_copy_tuple_as_datum(&tmptup, outdesc);
3334  }
3335 }
Datum * resvalue
Definition: execExpr.h:250
bool * resnull
Definition: execExpr.h:251
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
#define gettext_noop(x)
Definition: c.h:1117
Definition: nodes.h:524
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
HeapTuple execute_attr_map_tuple(HeapTuple tuple, TupleConversionMap *map)
Definition: tupconvert.c:390
Datum heap_copy_tuple_as_datum(HeapTuple tuple, TupleDesc tupleDesc)
Definition: heaptuple.c:984
TupleConversionMap * convert_tuples_by_name(TupleDesc indesc, TupleDesc outdesc, const char *msg)
Definition: tupconvert.c:205
static TupleDesc get_cached_rowtype(Oid type_id, int32 typmod, TupleDesc *cache_field, ExprContext *econtext)
uintptr_t Datum
Definition: postgres.h:367
#define HeapTupleHeaderGetTypeId(tup)
Definition: htup_details.h:458
struct ExprEvalStep::@52::@82 convert_rowtype
#define Assert(condition)
Definition: c.h:732
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:42
#define HeapTupleGetDatum(tuple)
Definition: funcapi.h:221
MemoryContext ecxt_per_query_memory
Definition: execnodes.h:231
Oid tdtypeid
Definition: tupdesc.h:82
#define HeapTupleHeaderGetDatumLength(tup)
Definition: htup_details.h:452

◆ ExecEvalCurrentOfExpr()

void ExecEvalCurrentOfExpr ( ExprState state,
ExprEvalStep op 
)

Definition at line 2399 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

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

◆ ExecEvalFieldSelect()

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

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

2863 {
2864  AttrNumber fieldnum = op->d.fieldselect.fieldnum;
2865  Datum tupDatum;
2866  HeapTupleHeader tuple;
2867  Oid tupType;
2868  int32 tupTypmod;
2869  TupleDesc tupDesc;
2870  Form_pg_attribute attr;
2871  HeapTupleData tmptup;
2872 
2873  /* NULL record -> NULL result */
2874  if (*op->resnull)
2875  return;
2876 
2877  tupDatum = *op->resvalue;
2878 
2879  /* We can special-case expanded records for speed */
2881  {
2883 
2884  Assert(erh->er_magic == ER_MAGIC);
2885 
2886  /* Extract record's TupleDesc */
2887  tupDesc = expanded_record_get_tupdesc(erh);
2888 
2889  /*
2890  * Find field's attr record. Note we don't support system columns
2891  * here: a datum tuple doesn't have valid values for most of the
2892  * interesting system columns anyway.
2893  */
2894  if (fieldnum <= 0) /* should never happen */
2895  elog(ERROR, "unsupported reference to system column %d in FieldSelect",
2896  fieldnum);
2897  if (fieldnum > tupDesc->natts) /* should never happen */
2898  elog(ERROR, "attribute number %d exceeds number of columns %d",
2899  fieldnum, tupDesc->natts);
2900  attr = TupleDescAttr(tupDesc, fieldnum - 1);
2901 
2902  /* Check for dropped column, and force a NULL result if so */
2903  if (attr->attisdropped)
2904  {
2905  *op->resnull = true;
2906  return;
2907  }
2908 
2909  /* Check for type mismatch --- possible after ALTER COLUMN TYPE? */
2910  /* As in CheckVarSlotCompatibility, we should but can't check typmod */
2911  if (op->d.fieldselect.resulttype != attr->atttypid)
2912  ereport(ERROR,
2913  (errcode(ERRCODE_DATATYPE_MISMATCH),
2914  errmsg("attribute %d has wrong type", fieldnum),
2915  errdetail("Table has type %s, but query expects %s.",
2916  format_type_be(attr->atttypid),
2917  format_type_be(op->d.fieldselect.resulttype))));
2918 
2919  /* extract the field */
2920  *op->resvalue = expanded_record_get_field(erh, fieldnum,
2921  op->resnull);
2922  }
2923  else
2924  {
2925  /* Get the composite datum and extract its type fields */
2926  tuple = DatumGetHeapTupleHeader(tupDatum);
2927 
2928  tupType = HeapTupleHeaderGetTypeId(tuple);
2929  tupTypmod = HeapTupleHeaderGetTypMod(tuple);
2930 
2931  /* Lookup tupdesc if first time through or if type changes */
2932  tupDesc = get_cached_rowtype(tupType, tupTypmod,
2933  &op->d.fieldselect.argdesc,
2934  econtext);
2935 
2936  /*
2937  * Find field's attr record. Note we don't support system columns
2938  * here: a datum tuple doesn't have valid values for most of the
2939  * interesting system columns anyway.
2940  */
2941  if (fieldnum <= 0) /* should never happen */
2942  elog(ERROR, "unsupported reference to system column %d in FieldSelect",
2943  fieldnum);
2944  if (fieldnum > tupDesc->natts) /* should never happen */
2945  elog(ERROR, "attribute number %d exceeds number of columns %d",
2946  fieldnum, tupDesc->natts);
2947  attr = TupleDescAttr(tupDesc, fieldnum - 1);
2948 
2949  /* Check for dropped column, and force a NULL result if so */
2950  if (attr->attisdropped)
2951  {
2952  *op->resnull = true;
2953  return;
2954  }
2955 
2956  /* Check for type mismatch --- possible after ALTER COLUMN TYPE? */
2957  /* As in CheckVarSlotCompatibility, we should but can't check typmod */
2958  if (op->d.fieldselect.resulttype != attr->atttypid)
2959  ereport(ERROR,
2960  (errcode(ERRCODE_DATATYPE_MISMATCH),
2961  errmsg("attribute %d has wrong type", fieldnum),
2962  errdetail("Table has type %s, but query expects %s.",
2963  format_type_be(attr->atttypid),
2964  format_type_be(op->d.fieldselect.resulttype))));
2965 
2966  /* heap_getattr needs a HeapTuple not a bare HeapTupleHeader */
2967  tmptup.t_len = HeapTupleHeaderGetDatumLength(tuple);
2968  tmptup.t_data = tuple;
2969 
2970  /* extract the field */
2971  *op->resvalue = heap_getattr(&tmptup,
2972  fieldnum,
2973  tupDesc,
2974  op->resnull);
2975  }
2976 }
#define VARATT_IS_EXTERNAL_EXPANDED(PTR)
Definition: postgres.h:322
Datum * resvalue
Definition: execExpr.h:250
static Datum expanded_record_get_field(ExpandedRecordHeader *erh, int fnumber, bool *isnull)
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
bool * resnull
Definition: execExpr.h:251
int errcode(int sqlerrcode)
Definition: elog.c:570
char * format_type_be(Oid type_oid)
Definition: format_type.c:326
unsigned int Oid
Definition: postgres_ext.h:31
union ExprEvalStep::@52 d
#define DatumGetHeapTupleHeader(X)
Definition: fmgr.h:289
signed int int32
Definition: c.h:346
HeapTupleHeader t_data
Definition: htup.h:68
#define HeapTupleHeaderGetTypMod(tup)
Definition: htup_details.h:468
#define ERROR
Definition: elog.h:43
uint32 t_len
Definition: htup.h:64
int errdetail(const char *fmt,...)
Definition: elog.c:860
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:200
#define ereport(elevel, rest)
Definition: elog.h:141
static TupleDesc expanded_record_get_tupdesc(ExpandedRecordHeader *erh)
ExpandedObjectHeader * DatumGetEOHP(Datum d)
Definition: expandeddatum.c:29
#define heap_getattr(tup, attnum, tupleDesc, isnull)
Definition: htup_details.h:762
static TupleDesc get_cached_rowtype(Oid type_id, int32 typmod, TupleDesc *cache_field, ExprContext *econtext)
uintptr_t Datum
Definition: postgres.h:367
#define ER_MAGIC
#define HeapTupleHeaderGetTypeId(tup)
Definition: htup_details.h:458
#define Assert(condition)
Definition: c.h:732
#define DatumGetPointer(X)
Definition: postgres.h:549
int errmsg(const char *fmt,...)
Definition: elog.c:784
#define elog(elevel,...)
Definition: elog.h:226
struct ExprEvalStep::@52::@77 fieldselect
int16 AttrNumber
Definition: attnum.h:21
#define HeapTupleHeaderGetDatumLength(tup)
Definition: htup_details.h:452

◆ ExecEvalFieldStoreDeForm()

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

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

2989 {
2990  TupleDesc tupDesc;
2991 
2992  /* Lookup tupdesc if first time through or after rescan */
2993  tupDesc = get_cached_rowtype(op->d.fieldstore.fstore->resulttype, -1,
2994  op->d.fieldstore.argdesc, econtext);
2995 
2996  /* Check that current tupdesc doesn't have more fields than we allocated */
2997  if (unlikely(tupDesc->natts > op->d.fieldstore.ncolumns))
2998  elog(ERROR, "too many columns in composite type %u",
2999  op->d.fieldstore.fstore->resulttype);
3000 
3001  if (*op->resnull)
3002  {
3003  /* Convert null input tuple into an all-nulls row */
3004  memset(op->d.fieldstore.nulls, true,
3005  op->d.fieldstore.ncolumns * sizeof(bool));
3006  }
3007  else
3008  {
3009  /*
3010  * heap_deform_tuple needs a HeapTuple not a bare HeapTupleHeader. We
3011  * set all the fields in the struct just in case.
3012  */
3013  Datum tupDatum = *op->resvalue;
3014  HeapTupleHeader tuphdr;
3015  HeapTupleData tmptup;
3016 
3017  tuphdr = DatumGetHeapTupleHeader(tupDatum);
3018  tmptup.t_len = HeapTupleHeaderGetDatumLength(tuphdr);
3019  ItemPointerSetInvalid(&(tmptup.t_self));
3020  tmptup.t_tableOid = InvalidOid;
3021  tmptup.t_data = tuphdr;
3022 
3023  heap_deform_tuple(&tmptup, tupDesc,
3024  op->d.fieldstore.values,
3025  op->d.fieldstore.nulls);
3026  }
3027 }
Datum * resvalue
Definition: execExpr.h:250
bool * resnull
Definition: execExpr.h:251
union ExprEvalStep::@52 d
#define DatumGetHeapTupleHeader(X)
Definition: fmgr.h:289
HeapTupleHeader t_data
Definition: htup.h:68
#define ERROR
Definition: elog.h:43
ItemPointerData t_self
Definition: htup.h:65
struct ExprEvalStep::@52::@78 fieldstore
uint32 t_len
Definition: htup.h:64
Oid t_tableOid
Definition: htup.h:66
static TupleDesc get_cached_rowtype(Oid type_id, int32 typmod, TupleDesc *cache_field, ExprContext *econtext)
uintptr_t Datum
Definition: postgres.h:367
#define InvalidOid
Definition: postgres_ext.h:36
void heap_deform_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *values, bool *isnull)
Definition: heaptuple.c:1249
#define ItemPointerSetInvalid(pointer)
Definition: itemptr.h:172
#define elog(elevel,...)
Definition: elog.h:226
#define unlikely(x)
Definition: c.h:208
#define HeapTupleHeaderGetDatumLength(tup)
Definition: htup_details.h:452

◆ ExecEvalFieldStoreForm()

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

Definition at line 3034 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

3035 {
3036  HeapTuple tuple;
3037 
3038  /* argdesc should already be valid from the DeForm step */
3039  tuple = heap_form_tuple(*op->d.fieldstore.argdesc,
3040  op->d.fieldstore.values,
3041  op->d.fieldstore.nulls);
3042 
3043  *op->resvalue = HeapTupleGetDatum(tuple);
3044  *op->resnull = false;
3045 }
Datum * resvalue
Definition: execExpr.h:250
bool * resnull
Definition: execExpr.h:251
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1020
union ExprEvalStep::@52 d
struct ExprEvalStep::@52::@78 fieldstore
#define HeapTupleGetDatum(tuple)
Definition: funcapi.h:221

◆ ExecEvalFuncExprFusage()

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

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

2212 {
2213  FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
2214  PgStat_FunctionCallUsage fcusage;
2215  Datum d;
2216 
2217  pgstat_init_function_usage(fcinfo, &fcusage);
2218 
2219  fcinfo->isnull = false;
2220  d = op->d.func.fn_addr(fcinfo);
2221  *op->resvalue = d;
2222  *op->resnull = fcinfo->isnull;
2223 
2224  pgstat_end_function_usage(&fcusage, true);
2225 }
Datum * resvalue
Definition: execExpr.h:250
bool * resnull
Definition: execExpr.h:251
union ExprEvalStep::@52 d
void pgstat_init_function_usage(FunctionCallInfo fcinfo, PgStat_FunctionCallUsage *fcu)
Definition: pgstat.c:1622
uintptr_t Datum
Definition: postgres.h:367
struct ExprEvalStep::@52::@59 func
void pgstat_end_function_usage(PgStat_FunctionCallUsage *fcu, bool finalize)
Definition: pgstat.c:1694

◆ ExecEvalFuncExprStrictFusage()

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

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

2233 {
2234 
2235  FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
2236  PgStat_FunctionCallUsage fcusage;
2237  NullableDatum *args = fcinfo->args;
2238  int argno;
2239  Datum d;
2240 
2241  /* strict function, so check for NULL args */
2242  for (argno = 0; argno < op->d.func.nargs; argno++)
2243  {
2244  if (args[argno].isnull)
2245  {
2246  *op->resnull = true;
2247  return;
2248  }
2249  }
2250 
2251  pgstat_init_function_usage(fcinfo, &fcusage);
2252 
2253  fcinfo->isnull = false;
2254  d = op->d.func.fn_addr(fcinfo);
2255  *op->resvalue = d;
2256  *op->resnull = fcinfo->isnull;
2257 
2258  pgstat_end_function_usage(&fcusage, true);
2259 }
Datum * resvalue
Definition: execExpr.h:250
bool * resnull
Definition: execExpr.h:251
union ExprEvalStep::@52 d
void pgstat_init_function_usage(FunctionCallInfo fcinfo, PgStat_FunctionCallUsage *fcu)
Definition: pgstat.c:1622
NullableDatum args[FLEXIBLE_ARRAY_MEMBER]
Definition: fmgr.h:95
uintptr_t Datum
Definition: postgres.h:367
struct ExprEvalStep::@52::@59 func
void pgstat_end_function_usage(PgStat_FunctionCallUsage *fcu, bool finalize)
Definition: pgstat.c:1694

◆ ExecEvalGroupingFunc()

void ExecEvalGroupingFunc ( ExprState state,
ExprEvalStep op 
)

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

3754 {
3755  int result = 0;
3756  Bitmapset *grouped_cols = op->d.grouping_func.parent->grouped_cols;
3757  ListCell *lc;
3758 
3759  foreach(lc, op->d.grouping_func.clauses)
3760  {
3761  int attnum = lfirst_int(lc);
3762 
3763  result <<= 1;
3764 
3765  if (!bms_is_member(attnum, grouped_cols))
3766  result |= 1;
3767  }
3768 
3769  *op->resvalue = Int32GetDatum(result);
3770  *op->resnull = false;
3771 }
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 2808 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().

2809 {
2810  Datum *values = op->d.minmax.values;
2811  bool *nulls = op->d.minmax.nulls;
2812  FunctionCallInfo fcinfo = op->d.minmax.fcinfo_data;
2813  MinMaxOp operator = op->d.minmax.op;
2814  int off;
2815 
2816  /* set at initialization */
2817  Assert(fcinfo->args[0].isnull == false);
2818  Assert(fcinfo->args[1].isnull == false);
2819 
2820  /* default to null result */
2821  *op->resnull = true;
2822 
2823  for (off = 0; off < op->d.minmax.nelems; off++)
2824  {
2825  /* ignore NULL inputs */
2826  if (nulls[off])
2827  continue;
2828 
2829  if (*op->resnull)
2830  {
2831  /* first nonnull input, adopt value */
2832  *op->resvalue = values[off];
2833  *op->resnull = false;
2834  }
2835  else
2836  {
2837  int cmpresult;
2838 
2839  /* apply comparison function */
2840  fcinfo->args[0].value = *op->resvalue;
2841  fcinfo->args[1].value = values[off];
2842 
2843  fcinfo->isnull = false;
2844  cmpresult = DatumGetInt32(FunctionCallInvoke(fcinfo));
2845  if (fcinfo->isnull) /* probably should not happen */
2846  continue;
2847 
2848  if (cmpresult > 0 && operator == IS_LEAST)
2849  *op->resvalue = values[off];
2850  else if (cmpresult < 0 && operator == IS_GREATEST)
2851  *op->resvalue = values[off];
2852  }
2853  }
2854 }
Datum * resvalue
Definition: execExpr.h:250
#define DatumGetInt32(X)
Definition: postgres.h:472
bool * resnull
Definition: execExpr.h:251
union ExprEvalStep::@52 d
MinMaxOp
Definition: primnodes.h:1079
NullableDatum args[FLEXIBLE_ARRAY_MEMBER]
Definition: fmgr.h:95
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:167
Datum value
Definition: postgres.h:378
uintptr_t Datum
Definition: postgres.h:367
#define Assert(condition)
Definition: c.h:732
struct ExprEvalStep::@52::@76 minmax
static Datum values[MAXATTR]
Definition: bootstrap.c:167

◆ ExecEvalNextValueExpr()

void ExecEvalNextValueExpr ( ExprState state,
ExprEvalStep op 
)

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

2411 {
2412  int64 newval = nextval_internal(op->d.nextvalueexpr.seqid, false);
2413 
2414  switch (op->d.nextvalueexpr.seqtypid)
2415  {
2416  case INT2OID:
2417  *op->resvalue = Int16GetDatum((int16) newval);
2418  break;
2419  case INT4OID:
2420  *op->resvalue = Int32GetDatum((int32) newval);
2421  break;
2422  case INT8OID:
2423  *op->resvalue = Int64GetDatum((int64) newval);
2424  break;
2425  default:
2426  elog(ERROR, "unsupported sequence type %u",
2427  op->d.nextvalueexpr.seqtypid);
2428  }
2429  *op->resnull = false;
2430 }
signed short int16
Definition: c.h:345
Datum * resvalue
Definition: execExpr.h:250
int64 nextval_internal(Oid relid, bool check_permissions)
Definition: sequence.c:579
bool * resnull
Definition: execExpr.h:251
#define Int16GetDatum(X)
Definition: postgres.h:451
union ExprEvalStep::@52 d
signed int int32
Definition: c.h:346
#define ERROR
Definition: elog.h:43
Datum Int64GetDatum(int64 X)
Definition: fmgr.c:1699
struct ExprEvalStep::@52::@70 nextvalueexpr
#define newval
#define Int32GetDatum(X)
Definition: postgres.h:479
#define elog(elevel,...)
Definition: elog.h:226

◆ ExecEvalParamExec()

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

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

2269 {
2270  ParamExecData *prm;
2271 
2272  prm = &(econtext->ecxt_param_exec_vals[op->d.param.paramid]);
2273  if (unlikely(prm->execPlan != NULL))
2274  {
2275  /* Parameter not evaluated yet, so go do it */
2276  ExecSetParamPlan(prm->execPlan, econtext);
2277  /* ExecSetParamPlan should have processed this param... */
2278  Assert(prm->execPlan == NULL);
2279  }
2280  *op->resvalue = prm->value;
2281  *op->resnull = prm->isnull;
2282 }
void * execPlan
Definition: params.h:147
Datum * resvalue
Definition: execExpr.h:250
bool * resnull
Definition: execExpr.h:251
union ExprEvalStep::@52 d
void ExecSetParamPlan(SubPlanState *node, ExprContext *econtext)
Definition: nodeSubplan.c:1051
bool isnull
Definition: params.h:149
ParamExecData * ecxt_param_exec_vals
Definition: execnodes.h:235
struct ExprEvalStep::@52::@64 param
#define Assert(condition)
Definition: c.h:732
Datum value
Definition: params.h:148
#define unlikely(x)
Definition: c.h:208

◆ ExecEvalParamExtern()

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

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

2291 {
2292  ParamListInfo paramInfo = econtext->ecxt_param_list_info;
2293  int paramId = op->d.param.paramid;
2294 
2295  if (likely(paramInfo &&
2296  paramId > 0 && paramId <= paramInfo->numParams))
2297  {
2298  ParamExternData *prm;
2299  ParamExternData prmdata;
2300 
2301  /* give hook a chance in case parameter is dynamic */
2302  if (paramInfo->paramFetch != NULL)
2303  prm = paramInfo->paramFetch(paramInfo, paramId, false, &prmdata);
2304  else
2305  prm = &paramInfo->params[paramId - 1];
2306 
2307  if (likely(OidIsValid(prm->ptype)))
2308  {
2309  /* safety check in case hook did something unexpected */
2310  if (unlikely(prm->ptype != op->d.param.paramtype))
2311  ereport(ERROR,
2312  (errcode(ERRCODE_DATATYPE_MISMATCH),
2313  errmsg("type of parameter %d (%s) does not match that when preparing the plan (%s)",
2314  paramId,
2315  format_type_be(prm->ptype),
2316  format_type_be(op->d.param.paramtype))));
2317  *op->resvalue = prm->value;
2318  *op->resnull = prm->isnull;
2319  return;
2320  }
2321  }
2322 
2323  ereport(ERROR,
2324  (errcode(ERRCODE_UNDEFINED_OBJECT),
2325  errmsg("no value found for parameter %d", paramId)));
2326 }
ParamExternData params[FLEXIBLE_ARRAY_MEMBER]
Definition: params.h:124
Datum value
Definition: params.h:92
#define likely(x)
Definition: c.h:207
Datum * resvalue
Definition: execExpr.h:250
bool * resnull
Definition: execExpr.h:251
int errcode(int sqlerrcode)
Definition: elog.c:570
char * format_type_be(Oid type_oid)
Definition: format_type.c:326
union ExprEvalStep::@52 d
#define OidIsValid(objectId)
Definition: c.h:638
ParamFetchHook paramFetch
Definition: params.h:112
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:141
struct ExprEvalStep::@52::@64 param
int errmsg(const char *fmt,...)
Definition: elog.c:784
#define unlikely(x)
Definition: c.h:208
ParamListInfo ecxt_param_list_info
Definition: execnodes.h:236
bool isnull
Definition: params.h:93

◆ ExecEvalRow()

void ExecEvalRow ( ExprState state,
ExprEvalStep op 
)

Definition at line 2788 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

2789 {
2790  HeapTuple tuple;
2791 
2792  /* build tuple from evaluated field values */
2793  tuple = heap_form_tuple(op->d.row.tupdesc,
2794  op->d.row.elemvalues,
2795  op->d.row.elemnulls);
2796 
2797  *op->resvalue = HeapTupleGetDatum(tuple);
2798  *op->resnull = false;
2799 }
Datum * resvalue
Definition: execExpr.h:250
bool * resnull
Definition: execExpr.h:251
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1020
union ExprEvalStep::@52 d
struct ExprEvalStep::@52::@73 row
#define HeapTupleGetDatum(tuple)
Definition: funcapi.h:221

◆ ExecEvalRowNotNull()

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

Definition at line 2445 of file execExprInterp.c.

References ExecEvalRowNullInt().

Referenced by ExecInterpExpr().

2446 {
2447  ExecEvalRowNullInt(state, op, econtext, false);
2448 }
static void ExecEvalRowNullInt(ExprState *state, ExprEvalStep *op, ExprContext *econtext, bool checkisnull)

◆ ExecEvalRowNull()

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

Definition at line 2436 of file execExprInterp.c.

References ExecEvalRowNullInt().

Referenced by ExecInterpExpr().

2437 {
2438  ExecEvalRowNullInt(state, op, econtext, true);
2439 }
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 2452 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().

2454 {
2455  Datum value = *op->resvalue;
2456  bool isnull = *op->resnull;
2457  HeapTupleHeader tuple;
2458  Oid tupType;
2459  int32 tupTypmod;
2460  TupleDesc tupDesc;
2461  HeapTupleData tmptup;
2462  int att;
2463 
2464  *op->resnull = false;
2465 
2466  /* NULL row variables are treated just as NULL scalar columns */
2467  if (isnull)
2468  {
2469  *op->resvalue = BoolGetDatum(checkisnull);
2470  return;
2471  }
2472 
2473  /*
2474  * The SQL standard defines IS [NOT] NULL for a non-null rowtype argument
2475  * as:
2476  *
2477  * "R IS NULL" is true if every field is the null value.
2478  *
2479  * "R IS NOT NULL" is true if no field is the null value.
2480  *
2481  * This definition is (apparently intentionally) not recursive; so our
2482  * tests on the fields are primitive attisnull tests, not recursive checks
2483  * to see if they are all-nulls or no-nulls rowtypes.
2484  *
2485  * The standard does not consider the possibility of zero-field rows, but
2486  * here we consider them to vacuously satisfy both predicates.
2487  */
2488 
2489  tuple = DatumGetHeapTupleHeader(value);
2490 
2491  tupType = HeapTupleHeaderGetTypeId(tuple);
2492  tupTypmod = HeapTupleHeaderGetTypMod(tuple);
2493 
2494  /* Lookup tupdesc if first time through or if type changes */
2495  tupDesc = get_cached_rowtype(tupType, tupTypmod,
2496  &op->d.nulltest_row.argdesc,
2497  econtext);
2498 
2499  /*
2500  * heap_attisnull needs a HeapTuple not a bare HeapTupleHeader.
2501  */
2502  tmptup.t_len = HeapTupleHeaderGetDatumLength(tuple);
2503  tmptup.t_data = tuple;
2504 
2505  for (att = 1; att <= tupDesc->natts; att++)
2506  {
2507  /* ignore dropped columns */
2508  if (TupleDescAttr(tupDesc, att - 1)->attisdropped)
2509  continue;
2510  if (heap_attisnull(&tmptup, att, tupDesc))
2511  {
2512  /* null field disproves IS NOT NULL */
2513  if (!checkisnull)
2514  {
2515  *op->resvalue = BoolGetDatum(false);
2516  return;
2517  }
2518  }
2519  else
2520  {
2521  /* non-null field disproves IS NULL */
2522  if (checkisnull)
2523  {
2524  *op->resvalue = BoolGetDatum(false);
2525  return;
2526  }
2527  }
2528  }
2529 
2530  *op->resvalue = BoolGetDatum(true);
2531 }
Datum * resvalue
Definition: execExpr.h:250
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
bool * resnull
Definition: execExpr.h:251
static struct @144 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:346
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 3348 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().

3349 {
3350  FunctionCallInfo fcinfo = op->d.scalararrayop.fcinfo_data;
3351  bool useOr = op->d.scalararrayop.useOr;
3352  bool strictfunc = op->d.scalararrayop.finfo->fn_strict;
3353  ArrayType *arr;
3354  int nitems;
3355  Datum result;
3356  bool resultnull;
3357  int i;
3358  int16 typlen;
3359  bool typbyval;
3360  char typalign;
3361  char *s;
3362  bits8 *bitmap;
3363  int bitmask;
3364 
3365  /*
3366  * If the array is NULL then we return NULL --- it's not very meaningful
3367  * to do anything else, even if the operator isn't strict.
3368  */
3369  if (*op->resnull)
3370  return;
3371 
3372  /* Else okay to fetch and detoast the array */
3373  arr = DatumGetArrayTypeP(*op->resvalue);
3374 
3375  /*
3376  * If the array is empty, we return either FALSE or TRUE per the useOr
3377  * flag. This is correct even if the scalar is NULL; since we would
3378  * evaluate the operator zero times, it matters not whether it would want
3379  * to return NULL.
3380  */
3381  nitems = ArrayGetNItems(ARR_NDIM(arr), ARR_DIMS(arr));
3382  if (nitems <= 0)
3383  {
3384  *op->resvalue = BoolGetDatum(!useOr);
3385  *op->resnull = false;
3386  return;
3387  }
3388 
3389  /*
3390  * If the scalar is NULL, and the function is strict, return NULL; no
3391  * point in iterating the loop.
3392  */
3393  if (fcinfo->args[0].isnull && strictfunc)
3394  {
3395  *op->resnull = true;
3396  return;
3397  }
3398 
3399  /*
3400  * We arrange to look up info about the element type only once per series
3401  * of calls, assuming the element type doesn't change underneath us.
3402  */
3403  if (op->d.scalararrayop.element_type != ARR_ELEMTYPE(arr))
3404  {
3406  &op->d.scalararrayop.typlen,
3407  &op->d.scalararrayop.typbyval,
3408  &op->d.scalararrayop.typalign);
3409  op->d.scalararrayop.element_type = ARR_ELEMTYPE(arr);
3410  }
3411 
3412  typlen = op->d.scalararrayop.typlen;
3413  typbyval = op->d.scalararrayop.typbyval;
3414  typalign = op->d.scalararrayop.typalign;
3415 
3416  /* Initialize result appropriately depending on useOr */
3417  result = BoolGetDatum(!useOr);
3418  resultnull = false;
3419 
3420  /* Loop over the array elements */
3421  s = (char *) ARR_DATA_PTR(arr);
3422  bitmap = ARR_NULLBITMAP(arr);
3423  bitmask = 1;
3424 
3425  for (i = 0; i < nitems; i++)
3426  {
3427  Datum elt;
3428  Datum thisresult;
3429 
3430  /* Get array element, checking for NULL */
3431  if (bitmap && (*bitmap & bitmask) == 0)
3432  {
3433  fcinfo->args[1].value = (Datum) 0;
3434  fcinfo->args[1].isnull = true;
3435  }
3436  else
3437  {
3438  elt = fetch_att(s, typbyval, typlen);
3439  s = att_addlength_pointer(s, typlen, s);
3440  s = (char *) att_align_nominal(s, typalign);
3441  fcinfo->args[1].value = elt;
3442  fcinfo->args[1].isnull = false;
3443  }
3444 
3445  /* Call comparison function */
3446  if (fcinfo->args[1].isnull && strictfunc)
3447  {
3448  fcinfo->isnull = true;
3449  thisresult = (Datum) 0;
3450  }
3451  else
3452  {
3453  fcinfo->isnull = false;
3454  thisresult = op->d.scalararrayop.fn_addr(fcinfo);
3455  }
3456 
3457  /* Combine results per OR or AND semantics */
3458  if (fcinfo->isnull)
3459  resultnull = true;
3460  else if (useOr)
3461  {
3462  if (DatumGetBool(thisresult))
3463  {
3464  result = BoolGetDatum(true);
3465  resultnull = false;
3466  break; /* needn't look at any more elements */
3467  }
3468  }
3469  else
3470  {
3471  if (!DatumGetBool(thisresult))
3472  {
3473  result = BoolGetDatum(false);
3474  resultnull = false;
3475  break; /* needn't look at any more elements */
3476  }
3477  }
3478 
3479  /* advance bitmap pointer if any */
3480  if (bitmap)
3481  {
3482  bitmask <<= 1;
3483  if (bitmask == 0x100)
3484  {
3485  bitmap++;
3486  bitmask = 1;
3487  }
3488  }
3489  }
3490 
3491  *op->resvalue = result;
3492  *op->resnull = resultnull;
3493 }
signed short int16
Definition: c.h:345
#define att_align_nominal(cur_offset, attalign)
Definition: tupmacs.h:146
Datum * resvalue
Definition: execExpr.h:250
void get_typlenbyvalalign(Oid typid, int16 *typlen, bool *typbyval, char *typalign)
Definition: lsyscache.c:2049
bool * resnull
Definition: execExpr.h:251
int ArrayGetNItems(int ndim, const int *dims)
Definition: arrayutils.c:75
union ExprEvalStep::@52 d
char typalign
Definition: pg_type.h:170
NullableDatum args[FLEXIBLE_ARRAY_MEMBER]
Definition: fmgr.h:95
#define ARR_DIMS(a)
Definition: array.h:282
#define ARR_DATA_PTR(a)
Definition: array.h:310
#define DatumGetBool(X)
Definition: postgres.h:393
#define att_addlength_pointer(cur_offset, attlen, attptr)
Definition: tupmacs.h:174
Datum value
Definition: postgres.h:378
uint8 bits8
Definition: c.h:365
uintptr_t Datum
Definition: postgres.h:367
#define BoolGetDatum(X)
Definition: postgres.h:402
#define ARR_NDIM(a)
Definition: array.h:278
#define fetch_att(T, attbyval, attlen)
Definition: tupmacs.h:73
int i
struct ExprEvalStep::@52::@83 scalararrayop
#define ARR_ELEMTYPE(a)
Definition: array.h:280
#define ARR_NULLBITMAP(a)
Definition: array.h:288
#define DatumGetArrayTypeP(X)
Definition: array.h:249

◆ ExecEvalSQLValueFunction()

void ExecEvalSQLValueFunction ( ExprState state,
ExprEvalStep op 
)

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

2333 {
2334  LOCAL_FCINFO(fcinfo, 0);
2335  SQLValueFunction *svf = op->d.sqlvaluefunction.svf;
2336 
2337  *op->resnull = false;
2338 
2339  /*
2340  * Note: current_schema() can return NULL. current_user() etc currently
2341  * cannot, but might as well code those cases the same way for safety.
2342  */
2343  switch (svf->op)
2344  {
2345  case SVFOP_CURRENT_DATE:
2347  break;
2348  case SVFOP_CURRENT_TIME:
2349  case SVFOP_CURRENT_TIME_N:
2351  break;
2355  break;
2356  case SVFOP_LOCALTIME:
2357  case SVFOP_LOCALTIME_N:
2359  break;
2360  case SVFOP_LOCALTIMESTAMP:
2363  break;
2364  case SVFOP_CURRENT_ROLE:
2365  case SVFOP_CURRENT_USER:
2366  case SVFOP_USER:
2367  InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
2368  *op->resvalue = current_user(fcinfo);
2369  *op->resnull = fcinfo->isnull;
2370  break;
2371  case SVFOP_SESSION_USER:
2372  InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
2373  *op->resvalue = session_user(fcinfo);
2374  *op->resnull = fcinfo->isnull;
2375  break;
2376  case SVFOP_CURRENT_CATALOG:
2377  InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
2378  *op->resvalue = current_database(fcinfo);
2379  *op->resnull = fcinfo->isnull;
2380  break;
2381  case SVFOP_CURRENT_SCHEMA:
2382  InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
2383  *op->resvalue = current_schema(fcinfo);
2384  *op->resnull = fcinfo->isnull;
2385  break;
2386  }
2387 }
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:1587
#define DateADTGetDatum(X)
Definition: date.h:57
DateADT GetSQLCurrentDate(void)
Definition: date.c:304
union ExprEvalStep::@52 d
SQLValueFunctionOp op
Definition: primnodes.h:1129
Datum current_database(PG_FUNCTION_ARGS)
Definition: misc.c:170
#define TimestampTzGetDatum(X)
Definition: timestamp.h:32
TimeTzADT * GetSQLCurrentTime(int32 typmod)
Definition: date.c:326
Datum current_user(PG_FUNCTION_ARGS)
Definition: name.c:303
#define TimestampGetDatum(X)
Definition: timestamp.h:31
TimeADT GetSQLLocalTime(int32 typmod)
Definition: date.c:352
Datum session_user(PG_FUNCTION_ARGS)
Definition: name.c:309
#define TimeADTGetDatum(X)
Definition: date.h:58
Timestamp GetSQLLocalTimestamp(int32 typmod)
Definition: timestamp.c:1601
#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 2180 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().

2181 {
2182 #if defined(EEO_USE_COMPUTED_GOTO)
2183  if (state->flags & EEO_FLAG_DIRECT_THREADED)
2184  {
2185  ExprEvalOpLookup key;
2186  ExprEvalOpLookup *res;
2187 
2188  key.opcode = (void *) op->opcode;
2189  res = bsearch(&key,
2190  reverse_dispatch_table,
2191  EEOP_LAST /* nmembers */ ,
2192  sizeof(ExprEvalOpLookup),
2193  dispatch_compare_ptr);
2194  Assert(res); /* unknown ops shouldn't get looked up */
2195  return res->op;
2196  }
2197 #endif
2198  return (ExprEvalOp) op->opcode;
2199 }
ExprEvalOp
Definition: execExpr.h:44
#define Assert(condition)
Definition: c.h:732
intptr_t opcode
Definition: execExpr.h:247
uint8 flags
Definition: execnodes.h:66
#define EEO_FLAG_DIRECT_THREADED
Definition: execExpr.h:28

◆ ExecEvalSubPlan()

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

Definition at line 3777 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

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

◆ ExecEvalSubscriptingRef()

bool ExecEvalSubscriptingRef ( ExprState state,
ExprEvalStep op 
)

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

3060 {
3061  SubscriptingRefState *sbsrefstate = op->d.sbsref_subscript.state;
3062  int *indexes;
3063  int off;
3064 
3065  /* If any index expr yields NULL, result is NULL or error */
3066  if (sbsrefstate->subscriptnull)
3067  {
3068  if (sbsrefstate->isassignment)
3069  ereport(ERROR,
3070  (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
3071  errmsg("array subscript in assignment must not be null")));
3072  *op->resnull = true;
3073  return false;
3074  }
3075 
3076  /* Convert datum to int, save in appropriate place */
3077  if (op->d.sbsref_subscript.isupper)
3078  indexes = sbsrefstate->upperindex;
3079  else
3080  indexes = sbsrefstate->lowerindex;
3081  off = op->d.sbsref_subscript.off;
3082 
3083  indexes[off] = DatumGetInt32(sbsrefstate->subscriptvalue);
3084 
3085  return true;
3086 }
#define DatumGetInt32(X)
Definition: postgres.h:472
bool * resnull
Definition: execExpr.h:251
int errcode(int sqlerrcode)
Definition: elog.c:570
union ExprEvalStep::@52 d
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:141
int lowerindex[MAXDIM]
Definition: execExpr.h:681
int upperindex[MAXDIM]
Definition: execExpr.h:676
struct ExprEvalStep::@52::@79 sbsref_subscript
int errmsg(const char *fmt,...)
Definition: elog.c:784

◆ ExecEvalSubscriptingRefAssign()

void ExecEvalSubscriptingRefAssign ( ExprState state,
ExprEvalStep op 
)

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

3184 {
3185  SubscriptingRefState *sbsrefstate = op->d.sbsref_subscript.state;
3186 
3187  /*
3188  * For an assignment to a fixed-length container type, both the original
3189  * container and the value to be assigned into it must be non-NULL, else
3190  * we punt and return the original container.
3191  */
3192  if (sbsrefstate->refattrlength > 0)
3193  {
3194  if (*op->resnull || sbsrefstate->replacenull)
3195  return;
3196  }
3197 
3198  /*
3199  * For assignment to varlena arrays, we handle a NULL original array by
3200  * substituting an empty (zero-dimensional) array; insertion of the new
3201  * element will result in a singleton array value. It does not matter
3202  * whether the new element is NULL.
3203  */
3204  if (*op->resnull)
3205  {
3207  *op->resnull = false;
3208  }
3209 
3210  if (sbsrefstate->numlower == 0)
3211  {
3212  /* Scalar case */
3213  *op->resvalue = array_set_element(*op->resvalue,
3214  sbsrefstate->numupper,
3215  sbsrefstate->upperindex,
3216  sbsrefstate->replacevalue,
3217  sbsrefstate->replacenull,
3218  sbsrefstate->refattrlength,
3219  sbsrefstate->refelemlength,
3220  sbsrefstate->refelembyval,
3221  sbsrefstate->refelemalign);
3222  }
3223  else
3224  {
3225  /* Slice case */
3226  *op->resvalue = array_set_slice(*op->resvalue,
3227  sbsrefstate->numupper,
3228  sbsrefstate->upperindex,
3229  sbsrefstate->lowerindex,
3230  sbsrefstate->upperprovided,
3231  sbsrefstate->lowerprovided,
3232  sbsrefstate->replacevalue,
3233  sbsrefstate->replacenull,
3234  sbsrefstate->refattrlength,
3235  sbsrefstate->refelemlength,
3236  sbsrefstate->refelembyval,
3237  sbsrefstate->refelemalign);
3238  }
3239 }
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 3094 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().

3095 {
3096  SubscriptingRefState *sbsrefstate = op->d.sbsref.state;
3097 
3098  /* Should not get here if source container (or any subscript) is null */
3099  Assert(!(*op->resnull));
3100 
3101  if (sbsrefstate->numlower == 0)
3102  {
3103  /* Scalar case */
3104  *op->resvalue = array_get_element(*op->resvalue,
3105  sbsrefstate->numupper,
3106  sbsrefstate->upperindex,
3107  sbsrefstate->refattrlength,
3108  sbsrefstate->refelemlength,
3109  sbsrefstate->refelembyval,
3110  sbsrefstate->refelemalign,
3111  op->resnull);
3112  }
3113  else
3114  {
3115  /* Slice case */
3116  *op->resvalue = array_get_slice(*op->resvalue,
3117  sbsrefstate->numupper,
3118  sbsrefstate->upperindex,
3119  sbsrefstate->lowerindex,
3120  sbsrefstate->upperprovided,
3121  sbsrefstate->lowerprovided,
3122  sbsrefstate->refattrlength,
3123  sbsrefstate->refelemlength,
3124  sbsrefstate->refelembyval,
3125  sbsrefstate->refelemalign);
3126  }
3127 }
Datum array_get_slice(Datum arraydatum, int nSubscripts, int *upperIndx, int *lowerIndx, bool *upperProvided, bool *lowerProvided, int arraytyplen, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:2028
struct ExprEvalStep::@52::@80 sbsref
Datum * resvalue
Definition: execExpr.h:250
bool * resnull
Definition: execExpr.h:251
union ExprEvalStep::@52 d
bool upperprovided[MAXDIM]
Definition: execExpr.h:675
bool lowerprovided[MAXDIM]
Definition: execExpr.h:680
Datum array_get_element(Datum arraydatum, int nSubscripts, int *indx, int arraytyplen, int elmlen, bool elmbyval, char elmalign, bool *isNull)
Definition: arrayfuncs.c:1819
#define Assert(condition)
Definition: c.h:732
int lowerindex[MAXDIM]
Definition: execExpr.h:681
int upperindex[MAXDIM]
Definition: execExpr.h:676

◆ ExecEvalSubscriptingRefOld()

void ExecEvalSubscriptingRefOld ( ExprState state,
ExprEvalStep op 
)

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

3137 {
3138  SubscriptingRefState *sbsrefstate = op->d.sbsref.state;
3139 
3140  if (*op->resnull)
3141  {
3142  /* whole array is null, so any element or slice is too */
3143  sbsrefstate->prevvalue = (Datum) 0;
3144  sbsrefstate->prevnull = true;
3145  }
3146  else if (sbsrefstate->numlower == 0)
3147  {
3148  /* Scalar case */
3149  sbsrefstate->prevvalue = array_get_element(*op->resvalue,
3150  sbsrefstate->numupper,
3151  sbsrefstate->upperindex,
3152  sbsrefstate->refattrlength,
3153  sbsrefstate->refelemlength,
3154  sbsrefstate->refelembyval,
3155  sbsrefstate->refelemalign,
3156  &sbsrefstate->prevnull);
3157  }
3158  else
3159  {
3160  /* Slice case */
3161  /* this is currently unreachable */
3162  sbsrefstate->prevvalue = array_get_slice(*op->resvalue,
3163  sbsrefstate->numupper,
3164  sbsrefstate->upperindex,
3165  sbsrefstate->lowerindex,
3166  sbsrefstate->upperprovided,
3167  sbsrefstate->lowerprovided,
3168  sbsrefstate->refattrlength,
3169  sbsrefstate->refelemlength,
3170  sbsrefstate->refelembyval,
3171  sbsrefstate->refelemalign);
3172  sbsrefstate->prevnull = false;
3173  }
3174 }
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 4039 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

4041 {
4042  Datum d;
4043 
4044  /* slot_getsysattr has sufficient defenses against bad attnums */
4045  d = slot_getsysattr(slot,
4046  op->d.var.attnum,
4047  op->resnull);
4048  *op->resvalue = d;
4049  /* this ought to be unreachable, but it's cheap enough to check */
4050  if (unlikely(*op->resnull))
4051  elog(ERROR, "failed to fetch attribute from slot");
4052 }
struct ExprEvalStep::@52::@54 var
Datum * resvalue
Definition: execExpr.h:250
bool * resnull
Definition: execExpr.h:251
union ExprEvalStep::@52 d
#define ERROR
Definition: elog.h:43
uintptr_t Datum
Definition: postgres.h:367
#define elog(elevel,...)
Definition: elog.h:226
#define unlikely(x)
Definition: c.h:208
static Datum slot_getsysattr(TupleTableSlot *slot, int attnum, bool *isnull)
Definition: tuptable.h:403

◆ ExecEvalWholeRowVar()

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

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

3809 {
3810  Var *variable = op->d.wholerow.var;
3811  TupleTableSlot *slot;
3812  TupleDesc output_tupdesc;
3813  MemoryContext oldcontext;
3814  HeapTupleHeader dtuple;
3815  HeapTuple tuple;
3816 
3817  /* This was checked by ExecInitExpr */
3818  Assert(variable->varattno == InvalidAttrNumber);
3819 
3820  /* Get the input slot we want */
3821  switch (variable->varno)
3822  {
3823  case INNER_VAR:
3824  /* get the tuple from the inner node */
3825  slot = econtext->ecxt_innertuple;
3826  break;
3827 
3828  case OUTER_VAR:
3829  /* get the tuple from the outer node */
3830  slot = econtext->ecxt_outertuple;
3831  break;
3832 
3833  /* INDEX_VAR is handled by default case */
3834 
3835  default:
3836  /* get the tuple from the relation being scanned */
3837  slot = econtext->ecxt_scantuple;
3838  break;
3839  }
3840 
3841  /* Apply the junkfilter if any */
3842  if (op->d.wholerow.junkFilter != NULL)
3843  slot = ExecFilterJunk(op->d.wholerow.junkFilter, slot);
3844 
3845  /*
3846  * If first time through, obtain tuple descriptor and check compatibility.
3847  *
3848  * XXX: It'd be great if this could be moved to the expression
3849  * initialization phase, but due to using slots that's currently not
3850  * feasible.
3851  */
3852  if (op->d.wholerow.first)
3853  {
3854  /* optimistically assume we don't need slow path */
3855  op->d.wholerow.slow = false;
3856 
3857  /*
3858  * If the Var identifies a named composite type, we must check that
3859  * the actual tuple type is compatible with it.
3860  */
3861  if (variable->vartype != RECORDOID)
3862  {
3863  TupleDesc var_tupdesc;
3864  TupleDesc slot_tupdesc;
3865  int i;
3866 
3867  /*
3868  * We really only care about numbers of attributes and data types.
3869  * Also, we can ignore type mismatch on columns that are dropped
3870  * in the destination type, so long as (1) the physical storage
3871  * matches or (2) the actual column value is NULL. Case (1) is
3872  * helpful in some cases involving out-of-date cached plans, while
3873  * case (2) is expected behavior in situations such as an INSERT
3874  * into a table with dropped columns (the planner typically
3875  * generates an INT4 NULL regardless of the dropped column type).
3876  * If we find a dropped column and cannot verify that case (1)
3877  * holds, we have to use the slow path to check (2) for each row.
3878  *
3879  * If vartype is a domain over composite, just look through that
3880  * to the base composite type.
3881  */
3882  var_tupdesc = lookup_rowtype_tupdesc_domain(variable->vartype,
3883  -1, false);
3884 
3885  slot_tupdesc = slot->tts_tupleDescriptor;
3886 
3887  if (var_tupdesc->natts != slot_tupdesc->natts)
3888  ereport(ERROR,
3889  (errcode(ERRCODE_DATATYPE_MISMATCH),
3890  errmsg("table row type and query-specified row type do not match"),
3891  errdetail_plural("Table row contains %d attribute, but query expects %d.",
3892  "Table row contains %d attributes, but query expects %d.",
3893  slot_tupdesc->natts,
3894  slot_tupdesc->natts,
3895  var_tupdesc->natts)));
3896 
3897  for (i = 0; i < var_tupdesc->natts; i++)
3898  {
3899  Form_pg_attribute vattr = TupleDescAttr(var_tupdesc, i);
3900  Form_pg_attribute sattr = TupleDescAttr(slot_tupdesc, i);
3901 
3902  if (vattr->atttypid == sattr->atttypid)
3903  continue; /* no worries */
3904  if (!vattr->attisdropped)
3905  ereport(ERROR,
3906  (errcode(ERRCODE_DATATYPE_MISMATCH),
3907  errmsg("table row type and query-specified row type do not match"),
3908  errdetail("Table has type %s at ordinal position %d, but query expects %s.",
3909  format_type_be(sattr->atttypid),
3910  i + 1,
3911  format_type_be(vattr->atttypid))));
3912 
3913  if (vattr->attlen != sattr->attlen ||
3914  vattr->attalign != sattr->attalign)
3915  op->d.wholerow.slow = true; /* need to check for nulls */
3916  }
3917 
3918  /*
3919  * Use the variable's declared rowtype as the descriptor for the
3920  * output values, modulo possibly assigning new column names
3921  * below. In particular, we *must* absorb any attisdropped
3922  * markings.
3923  */
3924  oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
3925  output_tupdesc = CreateTupleDescCopy(var_tupdesc);
3926  MemoryContextSwitchTo(oldcontext);
3927 
3928  ReleaseTupleDesc(var_tupdesc);
3929  }
3930  else
3931  {
3932  /*
3933  * In the RECORD case, we use the input slot's rowtype as the
3934  * descriptor for the output values, modulo possibly assigning new
3935  * column names below.
3936  */
3937  oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
3938  output_tupdesc = CreateTupleDescCopy(slot->tts_tupleDescriptor);
3939  MemoryContextSwitchTo(oldcontext);
3940  }
3941 
3942  /*
3943  * Construct a tuple descriptor for the composite values we'll
3944  * produce, and make sure its record type is "blessed". The main
3945  * reason to do this is to be sure that operations such as
3946  * row_to_json() will see the desired column names when they look up
3947  * the descriptor from the type information embedded in the composite
3948  * values.
3949  *
3950  * We already got the correct physical datatype info above, but now we
3951  * should try to find the source RTE and adopt its column aliases, in
3952  * case they are different from the original rowtype's names. For
3953  * example, in "SELECT foo(t) FROM tab t(x,y)", the first two columns
3954  * in the composite output should be named "x" and "y" regardless of
3955  * tab's column names.
3956  *
3957  * If we can't locate the RTE, assume the column names we've got are
3958  * OK. (As of this writing, the only cases where we can't locate the
3959  * RTE are in execution of trigger WHEN clauses, and then the Var will
3960  * have the trigger's relation's rowtype, so its names are fine.)
3961  * Also, if the creator of the RTE didn't bother to fill in an eref
3962  * field, assume our column names are OK. (This happens in COPY, and
3963  * perhaps other places.)
3964  */
3965  if (econtext->ecxt_estate &&
3966  variable->varno <= econtext->ecxt_estate->es_range_table_size)
3967  {
3968  RangeTblEntry *rte = exec_rt_fetch(variable->varno,
3969  econtext->ecxt_estate);
3970 
3971  if (rte->eref)
3972  ExecTypeSetColNames(output_tupdesc, rte->eref->colnames);
3973  }
3974 
3975  /* Bless the tupdesc if needed, and save it in the execution state */
3976  op->d.wholerow.tupdesc = BlessTupleDesc(output_tupdesc);
3977 
3978  op->d.wholerow.first = false;
3979  }
3980 
3981  /*
3982  * Make sure all columns of the slot are accessible in the slot's
3983  * Datum/isnull arrays.
3984  */
3985  slot_getallattrs(slot);
3986 
3987  if (op->d.wholerow.slow)
3988  {
3989  /* Check to see if any dropped attributes are non-null */
3990  TupleDesc tupleDesc = slot->tts_tupleDescriptor;
3991  TupleDesc var_tupdesc = op->d.wholerow.tupdesc;
3992  int i;
3993 
3994  Assert(var_tupdesc->natts == tupleDesc->natts);
3995 
3996  for (i = 0; i < var_tupdesc->natts; i++)
3997  {
3998  Form_pg_attribute vattr = TupleDescAttr(var_tupdesc, i);
3999  Form_pg_attribute sattr = TupleDescAttr(tupleDesc, i);
4000 
4001  if (!vattr->attisdropped)
4002  continue; /* already checked non-dropped cols */
4003  if (slot->tts_isnull[i])
4004  continue; /* null is always okay */
4005  if (vattr->attlen != sattr->attlen ||
4006  vattr->attalign != sattr->attalign)
4007  ereport(ERROR,
4008  (errcode(ERRCODE_DATATYPE_MISMATCH),
4009  errmsg("table row type and query-specified row type do not match"),
4010  errdetail("Physical storage mismatch on dropped attribute at ordinal position %d.",
4011  i + 1)));
4012  }
4013  }
4014 
4015  /*
4016  * Build a composite datum, making sure any toasted fields get detoasted.
4017  *
4018  * (Note: it is critical that we not change the slot's state here.)
4019  */
4021  slot->tts_values,
4022  slot->tts_isnull);
4023  dtuple = tuple->t_data;
4024 
4025  /*
4026  * Label the datum with the composite type info we identified before.
4027  *
4028  * (Note: we could skip doing this by passing op->d.wholerow.tupdesc to
4029  * the tuple build step; but that seems a tad risky so let's not.)
4030  */
4031  HeapTupleHeaderSetTypeId(dtuple, op->d.wholerow.tupdesc->tdtypeid);
4032  HeapTupleHeaderSetTypMod(dtuple, op->d.wholerow.tupdesc->tdtypmod);
4033 
4034  *op->resvalue = PointerGetDatum(dtuple);
4035  *op->resnull = false;
4036 }
TupleDesc CreateTupleDescCopy(TupleDesc tupdesc)
Definition: tupdesc.c:110
#define HeapTupleHeaderSetTypeId(tup, typeid)
Definition: htup_details.h:463
Datum * resvalue
Definition: execExpr.h:250
List * colnames
Definition: primnodes.h:43
#define PointerGetDatum(X)
Definition: postgres.h:556
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
bool * resnull
Definition: execExpr.h:251
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
int errcode(int sqlerrcode)
Definition: elog.c:570
AttrNumber varattno
Definition: primnodes.h:172
char * format_type_be(Oid type_oid)
Definition: format_type.c:326
Datum * tts_values
Definition: tuptable.h:126
union ExprEvalStep::@52 d
Definition: primnodes.h:167
TupleDesc lookup_rowtype_tupdesc_domain(Oid type_id, int32 typmod, bool noError)
Definition: typcache.c:1708
HeapTupleHeader t_data
Definition: htup.h:68
HeapTuple toast_build_flattened_tuple(TupleDesc tupleDesc, Datum *values, bool *isnull)
Definition: tuptoaster.c:1295
#define ERROR
Definition: elog.h:43
Oid vartype
Definition: primnodes.h:174
static void slot_getallattrs(TupleTableSlot *slot)
Definition: tuptable.h:355
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:2048
bool * tts_isnull
Definition: tuptable.h:128
int errdetail(const char *fmt,...)
Definition: elog.c:860
TupleTableSlot * ecxt_innertuple
Definition: execnodes.h:226
struct EState * ecxt_estate
Definition: execnodes.h:260
static RangeTblEntry * exec_rt_fetch(Index rti, EState *estate)
Definition: executor.h:537
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:200
#define ereport(elevel, rest)
Definition: elog.h:141
Index varno
Definition: primnodes.h:170
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
TupleTableSlot * ExecFilterJunk(JunkFilter *junkfilter, TupleTableSlot *slot)
Definition: execJunk.c:261
#define HeapTupleHeaderSetTypMod(tup, typmod)
Definition: htup_details.h:473
#define INNER_VAR
Definition: primnodes.h:157
TupleTableSlot * ecxt_outertuple
Definition: execnodes.h:228
#define Assert(condition)
Definition: c.h:732
int errdetail_plural(const char *fmt_singular, const char *fmt_plural, unsigned long n,...)
Definition: elog.c:952
TupleTableSlot * ecxt_scantuple
Definition: execnodes.h:224
Index es_range_table_size
Definition: execnodes.h:506
MemoryContext ecxt_per_query_memory
Definition: execnodes.h:231
#define InvalidAttrNumber
Definition: attnum.h:23
int errmsg(const char *fmt,...)
Definition: elog.c:784
int i
struct ExprEvalStep::@52::@55 wholerow
Alias * eref
Definition: parsenodes.h:1092
#define ReleaseTupleDesc(tupdesc)
Definition: tupdesc.h:122
#define OUTER_VAR
Definition: primnodes.h:158
void ExecTypeSetColNames(TupleDesc typeInfo, List *namesList)
Definition: execTuples.c:2002

◆ ExecEvalXmlExpr()

void ExecEvalXmlExpr ( ExprState state,
ExprEvalStep op 
)

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

3534 {
3535  XmlExpr *xexpr = op->d.xmlexpr.xexpr;
3536  Datum value;
3537  int i;
3538 
3539  *op->resnull = true; /* until we get a result */
3540  *op->resvalue = (Datum) 0;
3541 
3542  switch (xexpr->op)
3543  {
3544  case IS_XMLCONCAT:
3545  {
3546  Datum *argvalue = op->d.xmlexpr.argvalue;
3547  bool *argnull = op->d.xmlexpr.argnull;
3548  List *values = NIL;
3549 
3550  for (i = 0; i < list_length(xexpr->args); i++)
3551  {
3552  if (!argnull[i])
3553  values = lappend(values, DatumGetPointer(argvalue[i]));
3554  }
3555 
3556  if (values != NIL)
3557  {
3558  *op->resvalue = PointerGetDatum(xmlconcat(values));
3559  *op->resnull = false;
3560  }
3561  }
3562  break;
3563 
3564  case IS_XMLFOREST:
3565  {
3566  Datum *argvalue = op->d.xmlexpr.named_argvalue;
3567  bool *argnull = op->d.xmlexpr.named_argnull;
3569  ListCell *lc;
3570  ListCell *lc2;
3571 
3572  initStringInfo(&buf);
3573 
3574  i = 0;
3575  forboth(lc, xexpr->named_args, lc2, xexpr->arg_names)
3576  {
3577  Expr *e = (Expr *) lfirst(lc);
3578  char *argname = strVal(lfirst(lc2));
3579 
3580  if (!argnull[i])
3581  {
3582  value = argvalue[i];
3583  appendStringInfo(&buf, "<%s>%s</%s>",
3584  argname,
3586  exprType((Node *) e), true),
3587  argname);
3588  *op->resnull = false;
3589  }
3590  i++;
3591  }
3592 
3593  if (!*op->resnull)
3594  {
3595  text *result;
3596 
3597  result = cstring_to_text_with_len(buf.data, buf.len);
3598  *op->resvalue = PointerGetDatum(result);
3599  }
3600 
3601  pfree(buf.data);
3602  }
3603  break;
3604 
3605  case IS_XMLELEMENT:
3606  *op->resvalue = PointerGetDatum(xmlelement(xexpr,
3607  op->d.xmlexpr.named_argvalue,
3608  op->d.xmlexpr.named_argnull,
3609  op->d.xmlexpr.argvalue,
3610  op->d.xmlexpr.argnull));
3611  *op->resnull = false;
3612  break;
3613 
3614  case IS_XMLPARSE:
3615  {
3616  Datum *argvalue = op->d.xmlexpr.argvalue;
3617  bool *argnull = op->d.xmlexpr.argnull;
3618  text *data;
3619  bool preserve_whitespace;
3620 
3621  /* arguments are known to be text, bool */
3622  Assert(list_length(xexpr->args) == 2);
3623 
3624  if (argnull[0])
3625  return;
3626  value = argvalue[0];
3627  data = DatumGetTextPP(value);
3628 
3629  if (argnull[1]) /* probably can't happen */
3630  return;
3631  value = argvalue[1];
3632  preserve_whitespace = DatumGetBool(value);
3633 
3634  *op->resvalue = PointerGetDatum(xmlparse(data,
3635  xexpr->xmloption,
3636  preserve_whitespace));
3637  *op->resnull = false;
3638  }
3639  break;
3640 
3641  case IS_XMLPI:
3642  {
3643  text *arg;
3644  bool isnull;
3645 
3646  /* optional argument is known to be text */
3647  Assert(list_length(xexpr->args) <= 1);
3648 
3649  if (xexpr->args)
3650  {
3651  isnull = op->d.xmlexpr.argnull[0];
3652  if (isnull)
3653  arg = NULL;
3654  else
3655  arg = DatumGetTextPP(op->d.xmlexpr.argvalue[0]);
3656  }
3657  else
3658  {
3659  arg = NULL;
3660  isnull = false;
3661  }
3662 
3663  *op->resvalue = PointerGetDatum(xmlpi(xexpr->name,
3664  arg,
3665  isnull,
3666  op->resnull));
3667  }
3668  break;
3669 
3670  case IS_XMLROOT:
3671  {
3672  Datum *argvalue = op->d.xmlexpr.argvalue;
3673  bool *argnull = op->d.xmlexpr.argnull;
3674  xmltype *data;
3675  text *version;
3676  int standalone;
3677 
3678  /* arguments are known to be xml, text, int */
3679  Assert(list_length(xexpr->args) == 3);
3680 
3681  if (argnull[0])
3682  return;
3683  data = DatumGetXmlP(argvalue[0]);
3684 
3685  if (argnull[1])
3686  version = NULL;
3687  else
3688  version = DatumGetTextPP(argvalue[1]);
3689 
3690  Assert(!argnull[2]); /* always present */
3691  standalone = DatumGetInt32(argvalue[2]);
3692 
3693  *op->resvalue = PointerGetDatum(xmlroot(data,
3694  version,
3695  standalone));
3696  *op->resnull = false;
3697  }
3698  break;
3699 
3700  case IS_XMLSERIALIZE:
3701  {
3702  Datum *argvalue = op->d.xmlexpr.argvalue;
3703  bool *argnull = op->d.xmlexpr.argnull;
3704 
3705  /* argument type is known to be xml */
3706  Assert(list_length(xexpr->args) == 1);
3707 
3708  if (argnull[0])
3709  return;
3710  value = argvalue[0];
3711 
3712  *op->resvalue = PointerGetDatum(
3714  xexpr->xmloption));
3715  *op->resnull = false;
3716  }
3717  break;
3718 
3719  case IS_DOCUMENT:
3720  {
3721  Datum *argvalue = op->d.xmlexpr.argvalue;
3722  bool *argnull = op->d.xmlexpr.argnull;
3723 
3724  /* optional argument is known to be xml */
3725  Assert(list_length(xexpr->args) == 1);
3726 
3727  if (argnull[0])
3728  return;
3729  value = argvalue[0];
3730 
3731  *op->resvalue =
3733  *op->resnull = false;
3734  }
3735  break;
3736 
3737  default:
3738  elog(ERROR, "unrecognized XML operation");
3739  break;
3740  }
3741 }
#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
static struct @144 value
xmltype * xmlconcat(List *args)
Definition: xml.c:512
Definition: nodes.h:524
#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:1031
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:78
#define ERROR
Definition: elog.h:43
text * xmltotext_with_xmloption(xmltype *data, XmlOptionType xmloption_arg)
Definition: xml.c:615
static char * buf
Definition: pg_test_fsync.c:68
text * cstring_to_text_with_len(const char *s, int len)
Definition: varlena.c:183
xmltype * xmlroot(xmltype *data, text *version, int standalone)
Definition: xml.c:822
#define DatumGetBool(X)
Definition: postgres.h:393
List * lappend(List *list, void *datum)
Definition: list.c:321
bool xml_is_document(xmltype *arg)
Definition: xml.c:888
void initStringInfo(StringInfo str)
Definition: stringinfo.c:46
XmlExprOp op
Definition: primnodes.h:1167
uintptr_t Datum
Definition: postgres.h:367
#define BoolGetDatum(X)
Definition: postgres.h:402
List * named_args
Definition: primnodes.h:1169
List * args
Definition: primnodes.h:1171
#define Assert(condition)
Definition: c.h:732
#define lfirst(lc)
Definition: pg_list.h:190
XmlOptionType xmloption
Definition: primnodes.h:1172
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:42
static int list_length(const List *l)
Definition: pg_list.h:169
#define DatumGetPointer(X)
Definition: postgres.h:549
static Datum values[MAXATTR]
Definition: bootstrap.c:167
e
Definition: preproc-init.c:82
#define elog(elevel,...)
Definition: elog.h:226
int i
xmltype * xmlelement(XmlExpr *xexpr, Datum *named_argvalue, bool *named_argnull, Datum *argvalue, bool *argnull)
Definition: xml.c:628
void * arg
Definition: c.h:549
char * map_sql_value_to_xml_value(Datum value, Oid type, bool xml_escape_strings)
Definition: xml.c:2154
Definition: pg_list.h:50
xmltype * xmlparse(text *data, XmlOptionType xmloption_arg, bool preserve_whitespace)
Definition: xml.c:752

◆ ExecInitInterpreter()

static void ExecInitInterpreter ( void  )
static

Definition at line 2146 of file execExprInterp.c.

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

Referenced by ExecReadyInterpretedExpr().

2147 {
2148 #if defined(EEO_USE_COMPUTED_GOTO)
2149  /* Set up externally-visible pointer to dispatch table */
2150  if (dispatch_table == NULL)
2151  {
2152  int i;
2153 
2154  dispatch_table = (const void **)
2155  DatumGetPointer(ExecInterpExpr(NULL, NULL, NULL));
2156 
2157  /* build reverse lookup table */
2158  for (i = 0; i < EEOP_LAST; i++)
2159  {
2160  reverse_dispatch_table[i].opcode = dispatch_table[i];
2161  reverse_dispatch_table[i].op = (ExprEvalOp) i;
2162  }
2163 
2164  /* make it bsearch()able */
2165  qsort(reverse_dispatch_table,
2166  EEOP_LAST /* nmembers */ ,
2167  sizeof(ExprEvalOpLookup),
2168  dispatch_compare_ptr);
2169  }
2170 #endif
2171 }
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:491

◆ ExecInterpExpr()

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

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

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