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

Go to the source code of this file.

Macros

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

Functions

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

Macro Definition Documentation

◆ EEO_CASE

#define EEO_CASE (   name)    case name:

Definition at line 122 of file execExprInterp.c.

Referenced by ExecInterpExpr().

◆ EEO_DISPATCH

#define EEO_DISPATCH ( )    goto starteval

Definition at line 123 of file execExprInterp.c.

Referenced by ExecInterpExpr().

◆ EEO_JUMP

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

Definition at line 134 of file execExprInterp.c.

Referenced by ExecInterpExpr().

◆ EEO_NEXT

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

Definition at line 128 of file execExprInterp.c.

Referenced by ExecInterpExpr().

◆ EEO_OPCODE

#define EEO_OPCODE (   opcode)    (opcode)

Definition at line 124 of file execExprInterp.c.

Referenced by ExecReadyInterpretedExpr().

◆ EEO_SWITCH

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

Definition at line 121 of file execExprInterp.c.

Referenced by ExecInterpExpr().

Function Documentation

◆ CheckExprStillValid()

void CheckExprStillValid ( ExprState state,
ExprContext econtext 
)

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

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

◆ CheckOpSlotCompatibility()

static void CheckOpSlotCompatibility ( ExprEvalStep op,
TupleTableSlot slot 
)
static

Definition at line 1912 of file execExprInterp.c.

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

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

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

◆ CheckVarSlotCompatibility()

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

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

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

◆ ExecAggInitGroup()

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

Definition at line 4141 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

4143 {
4144  FunctionCallInfo fcinfo = pertrans->transfn_fcinfo;
4145  MemoryContext oldContext;
4146 
4147  /*
4148  * We must copy the datum into aggcontext if it is pass-by-ref. We do not
4149  * need to pfree the old transValue, since it's NULL. (We already checked
4150  * that the agg's input type is binary-compatible with its transtype, so
4151  * straight copy here is OK.)
4152  */
4153  oldContext = MemoryContextSwitchTo(aggcontext->ecxt_per_tuple_memory);
4154  pergroup->transValue = datumCopy(fcinfo->args[1].value,
4155  pertrans->transtypeByVal,
4156  pertrans->transtypeLen);
4157  pergroup->transValueIsNull = false;
4158  pergroup->noTransValue = false;
4159  MemoryContextSwitchTo(oldContext);
4160 }
MemoryContext ecxt_per_tuple_memory
Definition: execnodes.h:234
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
FunctionCallInfo transfn_fcinfo
Definition: nodeAgg.h:162
NullableDatum args[FLEXIBLE_ARRAY_MEMBER]
Definition: fmgr.h:95
Datum value
Definition: postgres.h:378
Datum datumCopy(Datum value, bool typByVal, int typLen)
Definition: datum.c:131

◆ ExecAggPlainTransByRef()

static pg_attribute_always_inline void ExecAggPlainTransByRef ( AggState aggstate,
AggStatePerTrans  pertrans,
AggStatePerGroup  pergroup,
ExprContext aggcontext,
int  setno 
)
static

Definition at line 4275 of file execExprInterp.c.

References FunctionCallInfoBaseData::args, AggState::curaggcontext, AggState::curpertrans, AggState::current_set, DatumGetPointer, ExprContext::ecxt_per_tuple_memory, ExecAggTransReparent(), FunctionCallInvoke, FunctionCallInfoBaseData::isnull, NullableDatum::isnull, MemoryContextSwitchTo(), AggState::tmpcontext, AggStatePerTransData::transfn_fcinfo, AggStatePerGroupData::transValue, AggStatePerGroupData::transValueIsNull, and NullableDatum::value.

Referenced by ExecInterpExpr().

4278 {
4279  FunctionCallInfo fcinfo = pertrans->transfn_fcinfo;
4280  MemoryContext oldContext;
4281  Datum newVal;
4282 
4283  /* cf. select_current_set() */
4284  aggstate->curaggcontext = aggcontext;
4285  aggstate->current_set = setno;
4286 
4287  /* set up aggstate->curpertrans for AggGetAggref() */
4288  aggstate->curpertrans = pertrans;
4289 
4290  /* invoke transition function in per-tuple context */
4291  oldContext = MemoryContextSwitchTo(aggstate->tmpcontext->ecxt_per_tuple_memory);
4292 
4293  fcinfo->args[0].value = pergroup->transValue;
4294  fcinfo->args[0].isnull = pergroup->transValueIsNull;
4295  fcinfo->isnull = false; /* just in case transfn doesn't set it */
4296 
4297  newVal = FunctionCallInvoke(fcinfo);
4298 
4299  /*
4300  * For pass-by-ref datatype, must copy the new value into aggcontext and
4301  * free the prior transValue. But if transfn returned a pointer to its
4302  * first input, we don't need to do anything. Also, if transfn returned a
4303  * pointer to a R/W expanded object that is already a child of the
4304  * aggcontext, assume we can adopt that value without copying it.
4305  *
4306  * It's safe to compare newVal with pergroup->transValue without regard
4307  * for either being NULL, because ExecAggTransReparent() takes care to set
4308  * transValue to 0 when NULL. Otherwise we could end up accidentally not
4309  * reparenting, when the transValue has the same numerical value as
4310  * newValue, despite being NULL. This is a somewhat hot path, making it
4311  * undesirable to instead solve this with another branch for the common
4312  * case of the transition function returning its (modified) input
4313  * argument.
4314  */
4315  if (DatumGetPointer(newVal) != DatumGetPointer(pergroup->transValue))
4316  newVal = ExecAggTransReparent(aggstate, pertrans,
4317  newVal, fcinfo->isnull,
4318  pergroup->transValue,
4319  pergroup->transValueIsNull);
4320 
4321  pergroup->transValue = newVal;
4322  pergroup->transValueIsNull = fcinfo->isnull;
4323 
4324  MemoryContextSwitchTo(oldContext);
4325 }
MemoryContext ecxt_per_tuple_memory
Definition: execnodes.h:234
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
int current_set
Definition: execnodes.h:2169
FunctionCallInfo transfn_fcinfo
Definition: nodeAgg.h:162
Datum ExecAggTransReparent(AggState *aggstate, AggStatePerTrans pertrans, Datum newValue, bool newValueIsNull, Datum oldValue, bool oldValueIsNull)
ExprContext * tmpcontext
Definition: execnodes.h:2159
NullableDatum args[FLEXIBLE_ARRAY_MEMBER]
Definition: fmgr.h:95
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:172
Datum value
Definition: postgres.h:378
ExprContext * curaggcontext
Definition: execnodes.h:2161
uintptr_t Datum
Definition: postgres.h:367
#define DatumGetPointer(X)
Definition: postgres.h:549
AggStatePerTrans curpertrans
Definition: execnodes.h:2164

◆ ExecAggPlainTransByVal()

static pg_attribute_always_inline void ExecAggPlainTransByVal ( AggState aggstate,
AggStatePerTrans  pertrans,
AggStatePerGroup  pergroup,
ExprContext aggcontext,
int  setno 
)
static

Definition at line 4243 of file execExprInterp.c.

References FunctionCallInfoBaseData::args, AggState::curaggcontext, AggState::curpertrans, AggState::current_set, ExprContext::ecxt_per_tuple_memory, FunctionCallInvoke, FunctionCallInfoBaseData::isnull, NullableDatum::isnull, MemoryContextSwitchTo(), pg_attribute_always_inline, AggState::tmpcontext, AggStatePerTransData::transfn_fcinfo, AggStatePerGroupData::transValue, AggStatePerGroupData::transValueIsNull, and NullableDatum::value.

Referenced by ExecInterpExpr().

4246 {
4247  FunctionCallInfo fcinfo = pertrans->transfn_fcinfo;
4248  MemoryContext oldContext;
4249  Datum newVal;
4250 
4251  /* cf. select_current_set() */
4252  aggstate->curaggcontext = aggcontext;
4253  aggstate->current_set = setno;
4254 
4255  /* set up aggstate->curpertrans for AggGetAggref() */
4256  aggstate->curpertrans = pertrans;
4257 
4258  /* invoke transition function in per-tuple context */
4259  oldContext = MemoryContextSwitchTo(aggstate->tmpcontext->ecxt_per_tuple_memory);
4260 
4261  fcinfo->args[0].value = pergroup->transValue;
4262  fcinfo->args[0].isnull = pergroup->transValueIsNull;
4263  fcinfo->isnull = false; /* just in case transfn doesn't set it */
4264 
4265  newVal = FunctionCallInvoke(fcinfo);
4266 
4267  pergroup->transValue = newVal;
4268  pergroup->transValueIsNull = fcinfo->isnull;
4269 
4270  MemoryContextSwitchTo(oldContext);
4271 }
MemoryContext ecxt_per_tuple_memory
Definition: execnodes.h:234
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
int current_set
Definition: execnodes.h:2169
FunctionCallInfo transfn_fcinfo
Definition: nodeAgg.h:162
ExprContext * tmpcontext
Definition: execnodes.h:2159
NullableDatum args[FLEXIBLE_ARRAY_MEMBER]
Definition: fmgr.h:95
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:172
Datum value
Definition: postgres.h:378
ExprContext * curaggcontext
Definition: execnodes.h:2161
uintptr_t Datum
Definition: postgres.h:367
AggStatePerTrans curpertrans
Definition: execnodes.h:2164

◆ ExecAggTransReparent()

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

Definition at line 4169 of file execExprInterp.c.

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

Referenced by advance_transition_function(), and ExecAggPlainTransByRef().

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

◆ ExecEvalAggOrderedTransDatum()

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

Definition at line 4215 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

4217 {
4218  AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
4219  int setno = op->d.agg_trans.setno;
4220 
4221  tuplesort_putdatum(pertrans->sortstates[setno],
4222  *op->resvalue, *op->resnull);
4223 }
void tuplesort_putdatum(Tuplesortstate *state, Datum val, bool isNull)
Definition: tuplesort.c:1729
Datum * resvalue
Definition: execExpr.h:253
bool * resnull
Definition: execExpr.h:254
struct ExprEvalStep::@51::@92 agg_trans
Tuplesortstate ** sortstates
Definition: nodeAgg.h:154
union ExprEvalStep::@51 d

◆ ExecEvalAggOrderedTransTuple()

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

Definition at line 4229 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

4231 {
4232  AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
4233  int setno = op->d.agg_trans.setno;
4234 
4235  ExecClearTuple(pertrans->sortslot);
4236  pertrans->sortslot->tts_nvalid = pertrans->numInputs;
4237  ExecStoreVirtualTuple(pertrans->sortslot);
4238  tuplesort_puttupleslot(pertrans->sortstates[setno], pertrans->sortslot);
4239 }
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:425
struct ExprEvalStep::@51::@92 agg_trans
Tuplesortstate ** sortstates
Definition: nodeAgg.h:154
union ExprEvalStep::@51 d
AttrNumber tts_nvalid
Definition: tuptable.h:121
TupleTableSlot * sortslot
Definition: nodeAgg.h:136
TupleTableSlot * ExecStoreVirtualTuple(TupleTableSlot *slot)
Definition: execTuples.c:1522
void tuplesort_puttupleslot(Tuplesortstate *state, TupleTableSlot *slot)
Definition: tuplesort.c:1608

◆ ExecEvalAlternativeSubPlan()

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

Definition at line 3875 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

3876 {
3877  AlternativeSubPlanState *asstate = op->d.alternative_subplan.asstate;
3878 
3879  /* could potentially be nested, so make sure there's enough stack */
3881 
3882  *op->resvalue = ExecAlternativeSubPlan(asstate, econtext, op->resnull);
3883 }
Datum * resvalue
Definition: execExpr.h:253
bool * resnull
Definition: execExpr.h:254
Datum ExecAlternativeSubPlan(AlternativeSubPlanState *node, ExprContext *econtext, bool *isNull)
Definition: nodeSubplan.c:1376
void check_stack_depth(void)
Definition: postgres.c:3312
union ExprEvalStep::@51 d
struct ExprEvalStep::@51::@88 alternative_subplan

◆ ExecEvalArrayCoerce()

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

Definition at line 2835 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

2836 {
2837  Datum arraydatum;
2838 
2839  /* NULL array -> NULL result */
2840  if (*op->resnull)
2841  return;
2842 
2843  arraydatum = *op->resvalue;
2844 
2845  /*
2846  * If it's binary-compatible, modify the element type in the array header,
2847  * but otherwise leave the array as we received it.
2848  */
2849  if (op->d.arraycoerce.elemexprstate == NULL)
2850  {
2851  /* Detoast input array if necessary, and copy in any case */
2852  ArrayType *array = DatumGetArrayTypePCopy(arraydatum);
2853 
2854  ARR_ELEMTYPE(array) = op->d.arraycoerce.resultelemtype;
2855  *op->resvalue = PointerGetDatum(array);
2856  return;
2857  }
2858 
2859  /*
2860  * Use array_map to apply the sub-expression to each array element.
2861  */
2862  *op->resvalue = array_map(arraydatum,
2863  op->d.arraycoerce.elemexprstate,
2864  econtext,
2865  op->d.arraycoerce.resultelemtype,
2866  op->d.arraycoerce.amstate);
2867 }
struct ExprEvalStep::@51::@71 arraycoerce
Datum * resvalue
Definition: execExpr.h:253
#define PointerGetDatum(X)
Definition: postgres.h:556
bool * resnull
Definition: execExpr.h:254
union ExprEvalStep::@51 d
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:3132
#define ARR_ELEMTYPE(a)
Definition: array.h:280

◆ ExecEvalArrayExpr()

void ExecEvalArrayExpr ( ExprState state,
ExprEvalStep op 
)

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

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

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

Referenced by ExecInterpExpr().

3598 {
3599  if (!*op->d.domaincheck.checknull &&
3600  !DatumGetBool(*op->d.domaincheck.checkvalue))
3601  ereport(ERROR,
3602  (errcode(ERRCODE_CHECK_VIOLATION),
3603  errmsg("value for domain %s violates check constraint \"%s\"",
3604  format_type_be(op->d.domaincheck.resulttype),
3605  op->d.domaincheck.constraintname),
3606  errdomainconstraint(op->d.domaincheck.resulttype,
3607  op->d.domaincheck.constraintname)));
3608 }
struct ExprEvalStep::@51::@80 domaincheck
int errcode(int sqlerrcode)
Definition: elog.c:610
char * format_type_be(Oid type_oid)
Definition: format_type.c:327
#define ERROR
Definition: elog.h:43
int errdomainconstraint(Oid datatypeOid, const char *conname)
Definition: domains.c:384
#define DatumGetBool(X)
Definition: postgres.h:393
union ExprEvalStep::@51 d
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824

◆ ExecEvalConstraintNotNull()

void ExecEvalConstraintNotNull ( ExprState state,
ExprEvalStep op 
)

Definition at line 3583 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

3584 {
3585  if (*op->resnull)
3586  ereport(ERROR,
3587  (errcode(ERRCODE_NOT_NULL_VIOLATION),
3588  errmsg("domain %s does not allow null values",
3589  format_type_be(op->d.domaincheck.resulttype)),
3590  errdatatype(op->d.domaincheck.resulttype)));
3591 }
struct ExprEvalStep::@51::@80 domaincheck
bool * resnull
Definition: execExpr.h:254
int errcode(int sqlerrcode)
Definition: elog.c:610
char * format_type_be(Oid type_oid)
Definition: format_type.c:327
#define ERROR
Definition: elog.h:43
union ExprEvalStep::@51 d
int errdatatype(Oid datatypeOid)
Definition: domains.c:360
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824

◆ ExecEvalConvertRowtype()

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

Definition at line 3335 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

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

◆ ExecEvalCurrentOfExpr()

void ExecEvalCurrentOfExpr ( ExprState state,
ExprEvalStep op 
)

Definition at line 2490 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

2491 {
2492  ereport(ERROR,
2493  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2494  errmsg("WHERE CURRENT OF is not supported for this table type")));
2495 }
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824

◆ ExecEvalFieldSelect()

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

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

2950 {
2951  AttrNumber fieldnum = op->d.fieldselect.fieldnum;
2952  Datum tupDatum;
2953  HeapTupleHeader tuple;
2954  Oid tupType;
2955  int32 tupTypmod;
2956  TupleDesc tupDesc;
2957  Form_pg_attribute attr;
2958  HeapTupleData tmptup;
2959 
2960  /* NULL record -> NULL result */
2961  if (*op->resnull)
2962  return;
2963 
2964  tupDatum = *op->resvalue;
2965 
2966  /* We can special-case expanded records for speed */
2968  {
2970 
2971  Assert(erh->er_magic == ER_MAGIC);
2972 
2973  /* Extract record's TupleDesc */
2974  tupDesc = expanded_record_get_tupdesc(erh);
2975 
2976  /*
2977  * Find field's attr record. Note we don't support system columns
2978  * here: a datum tuple doesn't have valid values for most of the
2979  * interesting system columns anyway.
2980  */
2981  if (fieldnum <= 0) /* should never happen */
2982  elog(ERROR, "unsupported reference to system column %d in FieldSelect",
2983  fieldnum);
2984  if (fieldnum > tupDesc->natts) /* should never happen */
2985  elog(ERROR, "attribute number %d exceeds number of columns %d",
2986  fieldnum, tupDesc->natts);
2987  attr = TupleDescAttr(tupDesc, fieldnum - 1);
2988 
2989  /* Check for dropped column, and force a NULL result if so */
2990  if (attr->attisdropped)
2991  {
2992  *op->resnull = true;
2993  return;
2994  }
2995 
2996  /* Check for type mismatch --- possible after ALTER COLUMN TYPE? */
2997  /* As in CheckVarSlotCompatibility, we should but can't check typmod */
2998  if (op->d.fieldselect.resulttype != attr->atttypid)
2999  ereport(ERROR,
3000  (errcode(ERRCODE_DATATYPE_MISMATCH),
3001  errmsg("attribute %d has wrong type", fieldnum),
3002  errdetail("Table has type %s, but query expects %s.",
3003  format_type_be(attr->atttypid),
3004  format_type_be(op->d.fieldselect.resulttype))));
3005 
3006  /* extract the field */
3007  *op->resvalue = expanded_record_get_field(erh, fieldnum,
3008  op->resnull);
3009  }
3010  else
3011  {
3012  /* Get the composite datum and extract its type fields */
3013  tuple = DatumGetHeapTupleHeader(tupDatum);
3014 
3015  tupType = HeapTupleHeaderGetTypeId(tuple);
3016  tupTypmod = HeapTupleHeaderGetTypMod(tuple);
3017 
3018  /* Lookup tupdesc if first time through or if type changes */
3019  tupDesc = get_cached_rowtype(tupType, tupTypmod,
3020  &op->d.fieldselect.argdesc,
3021  econtext);
3022 
3023  /*
3024  * Find field's attr record. Note we don't support system columns
3025  * here: a datum tuple doesn't have valid values for most of the
3026  * interesting system columns anyway.
3027  */
3028  if (fieldnum <= 0) /* should never happen */
3029  elog(ERROR, "unsupported reference to system column %d in FieldSelect",
3030  fieldnum);
3031  if (fieldnum > tupDesc->natts) /* should never happen */
3032  elog(ERROR, "attribute number %d exceeds number of columns %d",
3033  fieldnum, tupDesc->natts);
3034  attr = TupleDescAttr(tupDesc, fieldnum - 1);
3035 
3036  /* Check for dropped column, and force a NULL result if so */
3037  if (attr->attisdropped)
3038  {
3039  *op->resnull = true;
3040  return;
3041  }
3042 
3043  /* Check for type mismatch --- possible after ALTER COLUMN TYPE? */
3044  /* As in CheckVarSlotCompatibility, we should but can't check typmod */
3045  if (op->d.fieldselect.resulttype != attr->atttypid)
3046  ereport(ERROR,
3047  (errcode(ERRCODE_DATATYPE_MISMATCH),
3048  errmsg("attribute %d has wrong type", fieldnum),
3049  errdetail("Table has type %s, but query expects %s.",
3050  format_type_be(attr->atttypid),
3051  format_type_be(op->d.fieldselect.resulttype))));
3052 
3053  /* heap_getattr needs a HeapTuple not a bare HeapTupleHeader */
3054  tmptup.t_len = HeapTupleHeaderGetDatumLength(tuple);
3055  tmptup.t_data = tuple;
3056 
3057  /* extract the field */
3058  *op->resvalue = heap_getattr(&tmptup,
3059  fieldnum,
3060  tupDesc,
3061  op->resnull);
3062  }
3063 }
#define VARATT_IS_EXTERNAL_EXPANDED(PTR)
Definition: postgres.h:322
Datum * resvalue
Definition: execExpr.h:253
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:254
int errcode(int sqlerrcode)
Definition: elog.c:610
char * format_type_be(Oid type_oid)
Definition: format_type.c:327
unsigned int Oid
Definition: postgres_ext.h:31
#define DatumGetHeapTupleHeader(X)
Definition: fmgr.h:294
signed int int32
Definition: c.h:355
HeapTupleHeader t_data
Definition: htup.h:68
#define HeapTupleHeaderGetTypMod(tup)
Definition: htup_details.h:468
#define ERROR
Definition: elog.h:43
uint32 t_len
Definition: htup.h:64
int errdetail(const char *fmt,...)
Definition: elog.c:957
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:193
struct ExprEvalStep::@51::@76 fieldselect
static TupleDesc expanded_record_get_tupdesc(ExpandedRecordHeader *erh)
union ExprEvalStep::@51 d
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 ereport(elevel,...)
Definition: elog.h:144
#define Assert(condition)
Definition: c.h:738
#define DatumGetPointer(X)
Definition: postgres.h:549
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define elog(elevel,...)
Definition: elog.h:214
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 3075 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().

3076 {
3077  TupleDesc tupDesc;
3078 
3079  /* Lookup tupdesc if first time through or after rescan */
3080  tupDesc = get_cached_rowtype(op->d.fieldstore.fstore->resulttype, -1,
3081  op->d.fieldstore.argdesc, econtext);
3082 
3083  /* Check that current tupdesc doesn't have more fields than we allocated */
3084  if (unlikely(tupDesc->natts > op->d.fieldstore.ncolumns))
3085  elog(ERROR, "too many columns in composite type %u",
3086  op->d.fieldstore.fstore->resulttype);
3087 
3088  if (*op->resnull)
3089  {
3090  /* Convert null input tuple into an all-nulls row */
3091  memset(op->d.fieldstore.nulls, true,
3092  op->d.fieldstore.ncolumns * sizeof(bool));
3093  }
3094  else
3095  {
3096  /*
3097  * heap_deform_tuple needs a HeapTuple not a bare HeapTupleHeader. We
3098  * set all the fields in the struct just in case.
3099  */
3100  Datum tupDatum = *op->resvalue;
3101  HeapTupleHeader tuphdr;
3102  HeapTupleData tmptup;
3103 
3104  tuphdr = DatumGetHeapTupleHeader(tupDatum);
3105  tmptup.t_len = HeapTupleHeaderGetDatumLength(tuphdr);
3106  ItemPointerSetInvalid(&(tmptup.t_self));
3107  tmptup.t_tableOid = InvalidOid;
3108  tmptup.t_data = tuphdr;
3109 
3110  heap_deform_tuple(&tmptup, tupDesc,
3111  op->d.fieldstore.values,
3112  op->d.fieldstore.nulls);
3113  }
3114 }
Datum * resvalue
Definition: execExpr.h:253
bool * resnull
Definition: execExpr.h:254
struct ExprEvalStep::@51::@77 fieldstore
#define DatumGetHeapTupleHeader(X)
Definition: fmgr.h:294
HeapTupleHeader t_data
Definition: htup.h:68
#define ERROR
Definition: elog.h:43
ItemPointerData t_self
Definition: htup.h:65
uint32 t_len
Definition: htup.h:64
Oid t_tableOid
Definition: htup.h:66
union ExprEvalStep::@51 d
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:214
#define unlikely(x)
Definition: c.h:206
#define HeapTupleHeaderGetDatumLength(tup)
Definition: htup_details.h:452

◆ ExecEvalFieldStoreForm()

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

Definition at line 3121 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

3122 {
3123  HeapTuple tuple;
3124 
3125  /* argdesc should already be valid from the DeForm step */
3126  tuple = heap_form_tuple(*op->d.fieldstore.argdesc,
3127  op->d.fieldstore.values,
3128  op->d.fieldstore.nulls);
3129 
3130  *op->resvalue = HeapTupleGetDatum(tuple);
3131  *op->resnull = false;
3132 }
Datum * resvalue
Definition: execExpr.h:253
bool * resnull
Definition: execExpr.h:254
struct ExprEvalStep::@51::@77 fieldstore
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1020
union ExprEvalStep::@51 d
#define HeapTupleGetDatum(tuple)
Definition: funcapi.h:220

◆ ExecEvalFuncExprFusage()

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

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

2303 {
2304  FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
2305  PgStat_FunctionCallUsage fcusage;
2306  Datum d;
2307 
2308  pgstat_init_function_usage(fcinfo, &fcusage);
2309 
2310  fcinfo->isnull = false;
2311  d = op->d.func.fn_addr(fcinfo);
2312  *op->resvalue = d;
2313  *op->resnull = fcinfo->isnull;
2314 
2315  pgstat_end_function_usage(&fcusage, true);
2316 }
Datum * resvalue
Definition: execExpr.h:253
bool * resnull
Definition: execExpr.h:254
struct ExprEvalStep::@51::@58 func
void pgstat_init_function_usage(FunctionCallInfo fcinfo, PgStat_FunctionCallUsage *fcu)
Definition: pgstat.c:1675
union ExprEvalStep::@51 d
uintptr_t Datum
Definition: postgres.h:367
void pgstat_end_function_usage(PgStat_FunctionCallUsage *fcu, bool finalize)
Definition: pgstat.c:1747

◆ ExecEvalFuncExprStrictFusage()

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

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

2324 {
2325 
2326  FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
2327  PgStat_FunctionCallUsage fcusage;
2328  NullableDatum *args = fcinfo->args;
2329  int nargs = op->d.func.nargs;
2330  Datum d;
2331 
2332  /* strict function, so check for NULL args */
2333  for (int argno = 0; argno < nargs; argno++)
2334  {
2335  if (args[argno].isnull)
2336  {
2337  *op->resnull = true;
2338  return;
2339  }
2340  }
2341 
2342  pgstat_init_function_usage(fcinfo, &fcusage);
2343 
2344  fcinfo->isnull = false;
2345  d = op->d.func.fn_addr(fcinfo);
2346  *op->resvalue = d;
2347  *op->resnull = fcinfo->isnull;
2348 
2349  pgstat_end_function_usage(&fcusage, true);
2350 }
Datum * resvalue
Definition: execExpr.h:253
bool * resnull
Definition: execExpr.h:254
struct ExprEvalStep::@51::@58 func
void pgstat_init_function_usage(FunctionCallInfo fcinfo, PgStat_FunctionCallUsage *fcu)
Definition: pgstat.c:1675
NullableDatum args[FLEXIBLE_ARRAY_MEMBER]
Definition: fmgr.h:95
union ExprEvalStep::@51 d
uintptr_t Datum
Definition: postgres.h:367
void pgstat_end_function_usage(PgStat_FunctionCallUsage *fcu, bool finalize)
Definition: pgstat.c:1747

◆ ExecEvalGroupingFunc()

void ExecEvalGroupingFunc ( ExprState state,
ExprEvalStep op 
)

Definition at line 3836 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

3837 {
3838  AggState *aggstate = castNode(AggState, state->parent);
3839  int result = 0;
3840  Bitmapset *grouped_cols = aggstate->grouped_cols;
3841  ListCell *lc;
3842 
3843  foreach(lc, op->d.grouping_func.clauses)
3844  {
3845  int attnum = lfirst_int(lc);
3846 
3847  result <<= 1;
3848 
3849  if (!bms_is_member(attnum, grouped_cols))
3850  result |= 1;
3851  }
3852 
3853  *op->resvalue = Int32GetDatum(result);
3854  *op->resnull = false;
3855 }
struct PlanState * parent
Definition: execnodes.h:108
Datum * resvalue
Definition: execExpr.h:253
#define castNode(_type_, nodeptr)
Definition: nodes.h:598
struct ExprEvalStep::@51::@85 grouping_func
bool * resnull
Definition: execExpr.h:254
#define lfirst_int(lc)
Definition: pg_list.h:191
Bitmapset * grouped_cols
Definition: execnodes.h:2170
union ExprEvalStep::@51 d
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 2896 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().

2897 {
2898  Datum *values = op->d.minmax.values;
2899  bool *nulls = op->d.minmax.nulls;
2900  FunctionCallInfo fcinfo = op->d.minmax.fcinfo_data;
2901  MinMaxOp operator = op->d.minmax.op;
2902 
2903  /* set at initialization */
2904  Assert(fcinfo->args[0].isnull == false);
2905  Assert(fcinfo->args[1].isnull == false);
2906 
2907  /* default to null result */
2908  *op->resnull = true;
2909 
2910  for (int off = 0; off < op->d.minmax.nelems; off++)
2911  {
2912  /* ignore NULL inputs */
2913  if (nulls[off])
2914  continue;
2915 
2916  if (*op->resnull)
2917  {
2918  /* first nonnull input, adopt value */
2919  *op->resvalue = values[off];
2920  *op->resnull = false;
2921  }
2922  else
2923  {
2924  int cmpresult;
2925 
2926  /* apply comparison function */
2927  fcinfo->args[0].value = *op->resvalue;
2928  fcinfo->args[1].value = values[off];
2929 
2930  fcinfo->isnull = false;
2931  cmpresult = DatumGetInt32(FunctionCallInvoke(fcinfo));
2932  if (fcinfo->isnull) /* probably should not happen */
2933  continue;
2934 
2935  if (cmpresult > 0 && operator == IS_LEAST)
2936  *op->resvalue = values[off];
2937  else if (cmpresult < 0 && operator == IS_GREATEST)
2938  *op->resvalue = values[off];
2939  }
2940  }
2941 }
Datum * resvalue
Definition: execExpr.h:253
#define DatumGetInt32(X)
Definition: postgres.h:472
bool * resnull
Definition: execExpr.h:254
MinMaxOp
Definition: primnodes.h:1093
NullableDatum args[FLEXIBLE_ARRAY_MEMBER]
Definition: fmgr.h:95
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:172
Datum value
Definition: postgres.h:378
union ExprEvalStep::@51 d
uintptr_t Datum
Definition: postgres.h:367
#define Assert(condition)
Definition: c.h:738
static Datum values[MAXATTR]
Definition: bootstrap.c:167
struct ExprEvalStep::@51::@75 minmax

◆ ExecEvalNextValueExpr()

void ExecEvalNextValueExpr ( ExprState state,
ExprEvalStep op 
)

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

2502 {
2503  int64 newval = nextval_internal(op->d.nextvalueexpr.seqid, false);
2504 
2505  switch (op->d.nextvalueexpr.seqtypid)
2506  {
2507  case INT2OID:
2508  *op->resvalue = Int16GetDatum((int16) newval);
2509  break;
2510  case INT4OID:
2511  *op->resvalue = Int32GetDatum((int32) newval);
2512  break;
2513  case INT8OID:
2514  *op->resvalue = Int64GetDatum((int64) newval);
2515  break;
2516  default:
2517  elog(ERROR, "unsupported sequence type %u",
2518  op->d.nextvalueexpr.seqtypid);
2519  }
2520  *op->resnull = false;
2521 }
signed short int16
Definition: c.h:354
Datum * resvalue
Definition: execExpr.h:253
int64 nextval_internal(Oid relid, bool check_permissions)
Definition: sequence.c:579
bool * resnull
Definition: execExpr.h:254
#define Int16GetDatum(X)
Definition: postgres.h:451
signed int int32
Definition: c.h:355
#define ERROR
Definition: elog.h:43
Datum Int64GetDatum(int64 X)
Definition: fmgr.c:1701
union ExprEvalStep::@51 d
struct ExprEvalStep::@51::@69 nextvalueexpr
#define newval
#define Int32GetDatum(X)
Definition: postgres.h:479
#define elog(elevel,...)
Definition: elog.h:214

◆ ExecEvalParamExec()

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

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

2360 {
2361  ParamExecData *prm;
2362 
2363  prm = &(econtext->ecxt_param_exec_vals[op->d.param.paramid]);
2364  if (unlikely(prm->execPlan != NULL))
2365  {
2366  /* Parameter not evaluated yet, so go do it */
2367  ExecSetParamPlan(prm->execPlan, econtext);
2368  /* ExecSetParamPlan should have processed this param... */
2369  Assert(prm->execPlan == NULL);
2370  }
2371  *op->resvalue = prm->value;
2372  *op->resnull = prm->isnull;
2373 }
struct ExprEvalStep::@51::@63 param
void * execPlan
Definition: params.h:148
Datum * resvalue
Definition: execExpr.h:253
bool * resnull
Definition: execExpr.h:254
void ExecSetParamPlan(SubPlanState *node, ExprContext *econtext)
Definition: nodeSubplan.c:1050
bool isnull
Definition: params.h:150
ParamExecData * ecxt_param_exec_vals
Definition: execnodes.h:237
union ExprEvalStep::@51 d
#define Assert(condition)
Definition: c.h:738
Datum value
Definition: params.h:149
#define unlikely(x)
Definition: c.h:206

◆ ExecEvalParamExtern()

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

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

2382 {
2383  ParamListInfo paramInfo = econtext->ecxt_param_list_info;
2384  int paramId = op->d.param.paramid;
2385 
2386  if (likely(paramInfo &&
2387  paramId > 0 && paramId <= paramInfo->numParams))
2388  {
2389  ParamExternData *prm;
2390  ParamExternData prmdata;
2391 
2392  /* give hook a chance in case parameter is dynamic */
2393  if (paramInfo->paramFetch != NULL)
2394  prm = paramInfo->paramFetch(paramInfo, paramId, false, &prmdata);
2395  else
2396  prm = &paramInfo->params[paramId - 1];
2397 
2398  if (likely(OidIsValid(prm->ptype)))
2399  {
2400  /* safety check in case hook did something unexpected */
2401  if (unlikely(prm->ptype != op->d.param.paramtype))
2402  ereport(ERROR,
2403  (errcode(ERRCODE_DATATYPE_MISMATCH),
2404  errmsg("type of parameter %d (%s) does not match that when preparing the plan (%s)",
2405  paramId,
2406  format_type_be(prm->ptype),
2407  format_type_be(op->d.param.paramtype))));
2408  *op->resvalue = prm->value;
2409  *op->resnull = prm->isnull;
2410  return;
2411  }
2412  }
2413 
2414  ereport(ERROR,
2415  (errcode(ERRCODE_UNDEFINED_OBJECT),
2416  errmsg("no value found for parameter %d", paramId)));
2417 }
struct ExprEvalStep::@51::@63 param
ParamExternData params[FLEXIBLE_ARRAY_MEMBER]
Definition: params.h:125
Datum value
Definition: params.h:92
#define likely(x)
Definition: c.h:205
Datum * resvalue
Definition: execExpr.h:253
bool * resnull
Definition: execExpr.h:254
int errcode(int sqlerrcode)
Definition: elog.c:610
char * format_type_be(Oid type_oid)
Definition: format_type.c:327
#define OidIsValid(objectId)
Definition: c.h:644
ParamFetchHook paramFetch
Definition: params.h:112
#define ERROR
Definition: elog.h:43
union ExprEvalStep::@51 d
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define unlikely(x)
Definition: c.h:206
ParamListInfo ecxt_param_list_info
Definition: execnodes.h:238
bool isnull
Definition: params.h:93

◆ ExecEvalRow()

void ExecEvalRow ( ExprState state,
ExprEvalStep op 
)

Definition at line 2876 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

2877 {
2878  HeapTuple tuple;
2879 
2880  /* build tuple from evaluated field values */
2881  tuple = heap_form_tuple(op->d.row.tupdesc,
2882  op->d.row.elemvalues,
2883  op->d.row.elemnulls);
2884 
2885  *op->resvalue = HeapTupleGetDatum(tuple);
2886  *op->resnull = false;
2887 }
Datum * resvalue
Definition: execExpr.h:253
bool * resnull
Definition: execExpr.h:254
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1020
struct ExprEvalStep::@51::@72 row
union ExprEvalStep::@51 d
#define HeapTupleGetDatum(tuple)
Definition: funcapi.h:220

◆ ExecEvalRowNotNull()

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

Definition at line 2536 of file execExprInterp.c.

References ExecEvalRowNullInt().

Referenced by ExecInterpExpr().

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

◆ ExecEvalRowNull()

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

Definition at line 2527 of file execExprInterp.c.

References ExecEvalRowNullInt().

Referenced by ExecInterpExpr().

2528 {
2529  ExecEvalRowNullInt(state, op, econtext, true);
2530 }
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 2543 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().

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

◆ ExecEvalScalarArrayOp()

void ExecEvalScalarArrayOp ( ExprState state,
ExprEvalStep op 
)

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

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

2424 {
2425  LOCAL_FCINFO(fcinfo, 0);
2426  SQLValueFunction *svf = op->d.sqlvaluefunction.svf;
2427 
2428  *op->resnull = false;
2429 
2430  /*
2431  * Note: current_schema() can return NULL. current_user() etc currently
2432  * cannot, but might as well code those cases the same way for safety.
2433  */
2434  switch (svf->op)
2435  {
2436  case SVFOP_CURRENT_DATE:
2438  break;
2439  case SVFOP_CURRENT_TIME:
2440  case SVFOP_CURRENT_TIME_N:
2442  break;
2446  break;
2447  case SVFOP_LOCALTIME:
2448  case SVFOP_LOCALTIME_N:
2450  break;
2451  case SVFOP_LOCALTIMESTAMP:
2454  break;
2455  case SVFOP_CURRENT_ROLE:
2456  case SVFOP_CURRENT_USER:
2457  case SVFOP_USER:
2458  InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
2459  *op->resvalue = current_user(fcinfo);
2460  *op->resnull = fcinfo->isnull;
2461  break;
2462  case SVFOP_SESSION_USER:
2463  InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
2464  *op->resvalue = session_user(fcinfo);
2465  *op->resnull = fcinfo->isnull;
2466  break;
2467  case SVFOP_CURRENT_CATALOG:
2468  InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
2469  *op->resvalue = current_database(fcinfo);
2470  *op->resnull = fcinfo->isnull;
2471  break;
2472  case SVFOP_CURRENT_SCHEMA:
2473  InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
2474  *op->resvalue = current_schema(fcinfo);
2475  *op->resnull = fcinfo->isnull;
2476  break;
2477  }
2478 }
Datum current_schema(PG_FUNCTION_ARGS)
Definition: name.c:319
Datum * resvalue
Definition: execExpr.h:253
bool * resnull
Definition: execExpr.h:254
#define TimeTzADTPGetDatum(X)
Definition: date.h:59
TimestampTz GetSQLCurrentTimestamp(int32 typmod)
Definition: timestamp.c:1592
#define DateADTGetDatum(X)
Definition: date.h:57
DateADT GetSQLCurrentDate(void)
Definition: date.c:300
SQLValueFunctionOp op
Definition: primnodes.h:1143
Datum current_database(PG_FUNCTION_ARGS)
Definition: misc.c:169
#define TimestampTzGetDatum(X)
Definition: timestamp.h:32
TimeTzADT * GetSQLCurrentTime(int32 typmod)
Definition: date.c:322
Datum current_user(PG_FUNCTION_ARGS)
Definition: name.c:303
struct ExprEvalStep::@51::@68 sqlvaluefunction
#define TimestampGetDatum(X)
Definition: timestamp.h:31
TimeADT GetSQLLocalTime(int32 typmod)
Definition: date.c:348
union ExprEvalStep::@51 d
Datum session_user(PG_FUNCTION_ARGS)
Definition: name.c:309
#define TimeADTGetDatum(X)
Definition: date.h:58
Timestamp GetSQLLocalTimestamp(int32 typmod)
Definition: timestamp.c:1606
#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

◆ ExecEvalStepOp()

ExprEvalOp ExecEvalStepOp ( ExprState state,
ExprEvalStep op 
)

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

2272 {
2273 #if defined(EEO_USE_COMPUTED_GOTO)
2274  if (state->flags & EEO_FLAG_DIRECT_THREADED)
2275  {
2276  ExprEvalOpLookup key;
2277  ExprEvalOpLookup *res;
2278 
2279  key.opcode = (void *) op->opcode;
2280  res = bsearch(&key,
2281  reverse_dispatch_table,
2282  EEOP_LAST /* nmembers */ ,
2283  sizeof(ExprEvalOpLookup),
2284  dispatch_compare_ptr);
2285  Assert(res); /* unknown ops shouldn't get looked up */
2286  return res->op;
2287  }
2288 #endif
2289  return (ExprEvalOp) op->opcode;
2290 }
ExprEvalOp
Definition: execExpr.h:44
#define Assert(condition)
Definition: c.h:738
intptr_t opcode
Definition: execExpr.h:250
uint8 flags
Definition: execnodes.h:65
#define EEO_FLAG_DIRECT_THREADED
Definition: execExpr.h:28

◆ ExecEvalSubPlan()

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

Definition at line 3861 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

3862 {
3863  SubPlanState *sstate = op->d.subplan.sstate;
3864 
3865  /* could potentially be nested, so make sure there's enough stack */
3867 
3868  *op->resvalue = ExecSubPlan(sstate, econtext, op->resnull);
3869 }
Datum * resvalue
Definition: execExpr.h:253
bool * resnull
Definition: execExpr.h:254
struct ExprEvalStep::@51::@87 subplan
void check_stack_depth(void)
Definition: postgres.c:3312
union ExprEvalStep::@51 d
Datum ExecSubPlan(SubPlanState *node, ExprContext *econtext, bool *isNull)
Definition: nodeSubplan.c:62

◆ ExecEvalSubscriptingRef()

bool ExecEvalSubscriptingRef ( ExprState state,
ExprEvalStep op 
)

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

3147 {
3148  SubscriptingRefState *sbsrefstate = op->d.sbsref_subscript.state;
3149  int *indexes;
3150  int off;
3151 
3152  /* If any index expr yields NULL, result is NULL or error */
3153  if (sbsrefstate->subscriptnull)
3154  {
3155  if (sbsrefstate->isassignment)
3156  ereport(ERROR,
3157  (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
3158  errmsg("array subscript in assignment must not be null")));
3159  *op->resnull = true;
3160  return false;
3161  }
3162 
3163  /* Convert datum to int, save in appropriate place */
3164  if (op->d.sbsref_subscript.isupper)
3165  indexes = sbsrefstate->upperindex;
3166  else
3167  indexes = sbsrefstate->lowerindex;
3168  off = op->d.sbsref_subscript.off;
3169 
3170  indexes[off] = DatumGetInt32(sbsrefstate->subscriptvalue);
3171 
3172  return true;
3173 }
#define DatumGetInt32(X)
Definition: postgres.h:472
struct ExprEvalStep::@51::@78 sbsref_subscript
bool * resnull
Definition: execExpr.h:254
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
union ExprEvalStep::@51 d
#define ereport(elevel,...)
Definition: elog.h:144
int lowerindex[MAXDIM]
Definition: execExpr.h:667
int upperindex[MAXDIM]
Definition: execExpr.h:662
int errmsg(const char *fmt,...)
Definition: elog.c:824

◆ ExecEvalSubscriptingRefAssign()

void ExecEvalSubscriptingRefAssign ( ExprState state,
ExprEvalStep op 
)

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

3271 {
3272  SubscriptingRefState *sbsrefstate = op->d.sbsref_subscript.state;
3273 
3274  /*
3275  * For an assignment to a fixed-length container type, both the original
3276  * container and the value to be assigned into it must be non-NULL, else
3277  * we punt and return the original container.
3278  */
3279  if (sbsrefstate->refattrlength > 0)
3280  {
3281  if (*op->resnull || sbsrefstate->replacenull)
3282  return;
3283  }
3284 
3285  /*
3286  * For assignment to varlena arrays, we handle a NULL original array by
3287  * substituting an empty (zero-dimensional) array; insertion of the new
3288  * element will result in a singleton array value. It does not matter
3289  * whether the new element is NULL.
3290  */
3291  if (*op->resnull)
3292  {
3294  *op->resnull = false;
3295  }
3296 
3297  if (sbsrefstate->numlower == 0)
3298  {
3299  /* Scalar case */
3300  *op->resvalue = array_set_element(*op->resvalue,
3301  sbsrefstate->numupper,
3302  sbsrefstate->upperindex,
3303  sbsrefstate->replacevalue,
3304  sbsrefstate->replacenull,
3305  sbsrefstate->refattrlength,
3306  sbsrefstate->refelemlength,
3307  sbsrefstate->refelembyval,
3308  sbsrefstate->refelemalign);
3309  }
3310  else
3311  {
3312  /* Slice case */
3313  *op->resvalue = array_set_slice(*op->resvalue,
3314  sbsrefstate->numupper,
3315  sbsrefstate->upperindex,
3316  sbsrefstate->lowerindex,
3317  sbsrefstate->upperprovided,
3318  sbsrefstate->lowerprovided,
3319  sbsrefstate->replacevalue,
3320  sbsrefstate->replacenull,
3321  sbsrefstate->refattrlength,
3322  sbsrefstate->refelemlength,
3323  sbsrefstate->refelembyval,
3324  sbsrefstate->refelemalign);
3325  }
3326 }
Datum * resvalue
Definition: execExpr.h:253
struct ExprEvalStep::@51::@78 sbsref_subscript
#define PointerGetDatum(X)
Definition: postgres.h:556
bool * resnull
Definition: execExpr.h:254
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:2200
ArrayType * construct_empty_array(Oid elmtype)
Definition: arrayfuncs.c:3411
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:2760
bool upperprovided[MAXDIM]
Definition: execExpr.h:661
union ExprEvalStep::@51 d
bool lowerprovided[MAXDIM]
Definition: execExpr.h:666
int lowerindex[MAXDIM]
Definition: execExpr.h:667
int upperindex[MAXDIM]
Definition: execExpr.h:662

◆ ExecEvalSubscriptingRefFetch()

void ExecEvalSubscriptingRefFetch ( ExprState state,
ExprEvalStep op 
)

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

3182 {
3183  SubscriptingRefState *sbsrefstate = op->d.sbsref.state;
3184 
3185  /* Should not get here if source container (or any subscript) is null */
3186  Assert(!(*op->resnull));
3187 
3188  if (sbsrefstate->numlower == 0)
3189  {
3190  /* Scalar case */
3191  *op->resvalue = array_get_element(*op->resvalue,
3192  sbsrefstate->numupper,
3193  sbsrefstate->upperindex,
3194  sbsrefstate->refattrlength,
3195  sbsrefstate->refelemlength,
3196  sbsrefstate->refelembyval,
3197  sbsrefstate->refelemalign,
3198  op->resnull);
3199  }
3200  else
3201  {
3202  /* Slice case */
3203  *op->resvalue = array_get_slice(*op->resvalue,
3204  sbsrefstate->numupper,
3205  sbsrefstate->upperindex,
3206  sbsrefstate->lowerindex,
3207  sbsrefstate->upperprovided,
3208  sbsrefstate->lowerprovided,
3209  sbsrefstate->refattrlength,
3210  sbsrefstate->refelemlength,
3211  sbsrefstate->refelembyval,
3212  sbsrefstate->refelemalign);
3213  }
3214 }
struct ExprEvalStep::@51::@79 sbsref
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:2029
Datum * resvalue
Definition: execExpr.h:253
bool * resnull
Definition: execExpr.h:254
bool upperprovided[MAXDIM]
Definition: execExpr.h:661
union ExprEvalStep::@51 d
bool lowerprovided[MAXDIM]
Definition: execExpr.h:666
Datum array_get_element(Datum arraydatum, int nSubscripts, int *indx, int arraytyplen, int elmlen, bool elmbyval, char elmalign, bool *isNull)
Definition: arrayfuncs.c:1820
#define Assert(condition)
Definition: c.h:738
int lowerindex[MAXDIM]
Definition: execExpr.h:667
int upperindex[MAXDIM]
Definition: execExpr.h:662

◆ ExecEvalSubscriptingRefOld()

void ExecEvalSubscriptingRefOld ( ExprState state,
ExprEvalStep op 
)

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

3224 {
3225  SubscriptingRefState *sbsrefstate = op->d.sbsref.state;
3226 
3227  if (*op->resnull)
3228  {
3229  /* whole array is null, so any element or slice is too */
3230  sbsrefstate->prevvalue = (Datum) 0;
3231  sbsrefstate->prevnull = true;
3232  }
3233  else if (sbsrefstate->numlower == 0)
3234  {
3235  /* Scalar case */
3236  sbsrefstate->prevvalue = array_get_element(*op->resvalue,
3237  sbsrefstate->numupper,
3238  sbsrefstate->upperindex,
3239  sbsrefstate->refattrlength,
3240  sbsrefstate->refelemlength,
3241  sbsrefstate->refelembyval,
3242  sbsrefstate->refelemalign,
3243  &sbsrefstate->prevnull);
3244  }
3245  else
3246  {
3247  /* Slice case */
3248  /* this is currently unreachable */
3249  sbsrefstate->prevvalue = array_get_slice(*op->resvalue,
3250  sbsrefstate->numupper,
3251  sbsrefstate->upperindex,
3252  sbsrefstate->lowerindex,
3253  sbsrefstate->upperprovided,
3254  sbsrefstate->lowerprovided,
3255  sbsrefstate->refattrlength,
3256  sbsrefstate->refelemlength,
3257  sbsrefstate->refelembyval,
3258  sbsrefstate->refelemalign);
3259  sbsrefstate->prevnull = false;
3260  }
3261 }
struct ExprEvalStep::@51::@79 sbsref
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:2029
Datum * resvalue
Definition: execExpr.h:253
bool * resnull
Definition: execExpr.h:254
bool upperprovided[MAXDIM]
Definition: execExpr.h:661
union ExprEvalStep::@51 d
uintptr_t Datum
Definition: postgres.h:367
bool lowerprovided[MAXDIM]
Definition: execExpr.h:666
Datum array_get_element(Datum arraydatum, int nSubscripts, int *indx, int arraytyplen, int elmlen, bool elmbyval, char elmalign, bool *isNull)
Definition: arrayfuncs.c:1820
int lowerindex[MAXDIM]
Definition: execExpr.h:667
int upperindex[MAXDIM]
Definition: execExpr.h:662

◆ ExecEvalSysVar()

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

Definition at line 4121 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

4123 {
4124  Datum d;
4125 
4126  /* slot_getsysattr has sufficient defenses against bad attnums */
4127  d = slot_getsysattr(slot,
4128  op->d.var.attnum,
4129  op->resnull);
4130  *op->resvalue = d;
4131  /* this ought to be unreachable, but it's cheap enough to check */
4132  if (unlikely(*op->resnull))
4133  elog(ERROR, "failed to fetch attribute from slot");
4134 }
Datum * resvalue
Definition: execExpr.h:253
bool * resnull
Definition: execExpr.h:254
#define ERROR
Definition: elog.h:43
union ExprEvalStep::@51 d
uintptr_t Datum
Definition: postgres.h:367
struct ExprEvalStep::@51::@53 var
#define elog(elevel,...)
Definition: elog.h:214
#define unlikely(x)
Definition: c.h:206
static Datum slot_getsysattr(TupleTableSlot *slot, int attnum, bool *isnull)
Definition: tuptable.h:402

◆ ExecEvalWholeRowVar()

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

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

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

◆ ExecEvalXmlExpr()

void ExecEvalXmlExpr ( ExprState state,
ExprEvalStep op 
)

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

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

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

Referenced by ExecReadyInterpretedExpr().

2240 {
2241 #if defined(EEO_USE_COMPUTED_GOTO)
2242  /* Set up externally-visible pointer to dispatch table */
2243  if (dispatch_table == NULL)
2244  {
2245  dispatch_table = (const void **)
2246  DatumGetPointer(ExecInterpExpr(NULL, NULL, NULL));
2247 
2248  /* build reverse lookup table */
2249  for (int i = 0; i < EEOP_LAST; i++)
2250  {
2251  reverse_dispatch_table[i].opcode = dispatch_table[i];
2252  reverse_dispatch_table[i].op = (ExprEvalOp) i;
2253  }
2254 
2255  /* make it bsearch()able */
2256  qsort(reverse_dispatch_table,
2257  EEOP_LAST /* nmembers */ ,
2258  sizeof(ExprEvalOpLookup),
2259  dispatch_compare_ptr);
2260  }
2261 #endif
2262 }
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:479

◆ ExecInterpExpr()

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

Definition at line 345 of file execExprInterp.c.

References ExprEvalStep::agg_deserialize, ExprEvalStep::agg_plain_pergroup_nullcheck, ExprEvalStep::agg_strict_input_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, castNode, CheckOpSlotCompatibility(), ExprEvalStep::constval, ExprEvalStep::cparam, ExprEvalStep::d, DatumGetBool, DatumGetCString, DatumGetInt32, 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_ORDERED_TRANS_DATUM, EEOP_AGG_ORDERED_TRANS_TUPLE, EEOP_AGG_PLAIN_PERGROUP_NULLCHECK, EEOP_AGG_PLAIN_TRANS_BYREF, EEOP_AGG_PLAIN_TRANS_BYVAL, EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYREF, EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYVAL, EEOP_AGG_PLAIN_TRANS_STRICT_BYREF, EEOP_AGG_PLAIN_TRANS_STRICT_BYVAL, EEOP_AGG_STRICT_DESERIALIZE, EEOP_AGG_STRICT_INPUT_CHECK_ARGS, EEOP_AGG_STRICT_INPUT_CHECK_NULLS, 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(), ExecAggPlainTransByRef(), ExecAggPlainTransByVal(), 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, likely, ExprEvalStep::make_readonly, MakeExpandedObjectReadOnlyInternal(), MemoryContextSwitchTo(), AggStatePerGroupData::noTransValue, ExprState::parent, 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::transtypeByVal, AggStatePerGroupData::transValueIsNull, TupleTableSlot::tts_isnull, TupleTableSlot::tts_values, unlikely, NullableDatum::value, ExprEvalStep::var, WindowFuncExprState::wfuncno, and ExprEvalStep::window_func.

Referenced by ExecInitInterpreter(), and ExecReadyInterpretedExpr().

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