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 "lib/simplehash.h"
Include dependency graph for execExprInterp.c:

Go to the source code of this file.

Data Structures

struct  ScalarArrayOpExprHashEntry
 
struct  ScalarArrayOpExprHashTable
 

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)
 
#define SH_PREFIX   saophash
 
#define SH_ELEMENT_TYPE   ScalarArrayOpExprHashEntry
 
#define SH_KEY_TYPE   Datum
 
#define SH_SCOPE   static inline
 
#define SH_DECLARE
 
#define SH_PREFIX   saophash
 
#define SH_ELEMENT_TYPE   ScalarArrayOpExprHashEntry
 
#define SH_KEY_TYPE   Datum
 
#define SH_KEY   key
 
#define SH_HASH_KEY(tb, key)   saop_element_hash(tb, key)
 
#define SH_EQUAL(tb, a, b)   saop_hash_element_match(tb, a, b)
 
#define SH_SCOPE   static inline
 
#define SH_STORE_HASH
 
#define SH_GET_HASH(tb, a)   a->hash
 
#define SH_DEFINE
 

Typedefs

typedef struct ScalarArrayOpExprHashEntry ScalarArrayOpExprHashEntry
 
typedef struct ScalarArrayOpExprHashTable ScalarArrayOpExprHashTable
 

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, ExprEvalRowtypeCache *rowcache, bool *changed)
 
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)
 
static bool saop_hash_element_match (struct saophash_hash *tb, Datum key1, Datum key2)
 
static uint32 saop_element_hash (struct saophash_hash *tb, Datum key)
 
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 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)
 
void ExecEvalConvertRowtype (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalScalarArrayOp (ExprState *state, ExprEvalStep *op)
 
void ExecEvalHashedScalarArrayOp (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
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 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)
 
bool ExecEvalPreOrderedDistinctSingle (AggState *aggstate, AggStatePerTrans pertrans)
 
bool ExecEvalPreOrderedDistinctMulti (AggState *aggstate, AggStatePerTrans pertrans)
 
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.

◆ EEO_DISPATCH

#define EEO_DISPATCH ( )    goto starteval

Definition at line 123 of file execExprInterp.c.

◆ EEO_JUMP

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

Definition at line 134 of file execExprInterp.c.

◆ EEO_NEXT

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

Definition at line 128 of file execExprInterp.c.

◆ EEO_OPCODE

#define EEO_OPCODE (   opcode)    (opcode)

Definition at line 124 of file execExprInterp.c.

◆ EEO_SWITCH

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

Definition at line 121 of file execExprInterp.c.

◆ SH_DECLARE

#define SH_DECLARE

Definition at line 196 of file execExprInterp.c.

◆ SH_DEFINE

#define SH_DEFINE

Definition at line 225 of file execExprInterp.c.

◆ SH_ELEMENT_TYPE [1/2]

#define SH_ELEMENT_TYPE   ScalarArrayOpExprHashEntry

Definition at line 217 of file execExprInterp.c.

◆ SH_ELEMENT_TYPE [2/2]

#define SH_ELEMENT_TYPE   ScalarArrayOpExprHashEntry

Definition at line 217 of file execExprInterp.c.

◆ SH_EQUAL

#define SH_EQUAL (   tb,
  a,
  b 
)    saop_hash_element_match(tb, a, b)

Definition at line 221 of file execExprInterp.c.

◆ SH_GET_HASH

#define SH_GET_HASH (   tb,
  a 
)    a->hash

Definition at line 224 of file execExprInterp.c.

◆ SH_HASH_KEY

#define SH_HASH_KEY (   tb,
  key 
)    saop_element_hash(tb, key)

Definition at line 220 of file execExprInterp.c.

◆ SH_KEY

#define SH_KEY   key

Definition at line 219 of file execExprInterp.c.

◆ SH_KEY_TYPE [1/2]

#define SH_KEY_TYPE   Datum

Definition at line 218 of file execExprInterp.c.

◆ SH_KEY_TYPE [2/2]

#define SH_KEY_TYPE   Datum

Definition at line 218 of file execExprInterp.c.

◆ SH_PREFIX [1/2]

#define SH_PREFIX   saophash

Definition at line 216 of file execExprInterp.c.

◆ SH_PREFIX [2/2]

#define SH_PREFIX   saophash

Definition at line 216 of file execExprInterp.c.

◆ SH_SCOPE [1/2]

#define SH_SCOPE   static inline

Definition at line 222 of file execExprInterp.c.

◆ SH_SCOPE [2/2]

#define SH_SCOPE   static inline

Definition at line 222 of file execExprInterp.c.

◆ SH_STORE_HASH

#define SH_STORE_HASH

Definition at line 223 of file execExprInterp.c.

Typedef Documentation

◆ ScalarArrayOpExprHashEntry

◆ ScalarArrayOpExprHashTable

Function Documentation

◆ CheckExprStillValid()

void CheckExprStillValid ( ExprState state,
ExprContext econtext 
)

Definition at line 1846 of file execExprInterp.c.

1847 {
1848  TupleTableSlot *innerslot;
1849  TupleTableSlot *outerslot;
1850  TupleTableSlot *scanslot;
1851 
1852  innerslot = econtext->ecxt_innertuple;
1853  outerslot = econtext->ecxt_outertuple;
1854  scanslot = econtext->ecxt_scantuple;
1855 
1856  for (int i = 0; i < state->steps_len; i++)
1857  {
1858  ExprEvalStep *op = &state->steps[i];
1859 
1860  switch (ExecEvalStepOp(state, op))
1861  {
1862  case EEOP_INNER_VAR:
1863  {
1864  int attnum = op->d.var.attnum;
1865 
1866  CheckVarSlotCompatibility(innerslot, attnum + 1, op->d.var.vartype);
1867  break;
1868  }
1869 
1870  case EEOP_OUTER_VAR:
1871  {
1872  int attnum = op->d.var.attnum;
1873 
1874  CheckVarSlotCompatibility(outerslot, attnum + 1, op->d.var.vartype);
1875  break;
1876  }
1877 
1878  case EEOP_SCAN_VAR:
1879  {
1880  int attnum = op->d.var.attnum;
1881 
1882  CheckVarSlotCompatibility(scanslot, attnum + 1, op->d.var.vartype);
1883  break;
1884  }
1885  default:
1886  break;
1887  }
1888  }
1889 }
static void CheckVarSlotCompatibility(TupleTableSlot *slot, int attnum, Oid vartype)
ExprEvalOp ExecEvalStepOp(ExprState *state, ExprEvalStep *op)
@ EEOP_INNER_VAR
Definition: execExpr.h:75
@ EEOP_SCAN_VAR
Definition: execExpr.h:77
@ EEOP_OUTER_VAR
Definition: execExpr.h:76
int i
Definition: isn.c:73
int16 attnum
Definition: pg_attribute.h:83
TupleTableSlot * ecxt_innertuple
Definition: execnodes.h:249
TupleTableSlot * ecxt_scantuple
Definition: execnodes.h:247
TupleTableSlot * ecxt_outertuple
Definition: execnodes.h:251
struct ExprEvalStep::@50::@52 var
union ExprEvalStep::@50 d

References attnum, CheckVarSlotCompatibility(), ExprContext::ecxt_innertuple, ExprContext::ecxt_outertuple, ExprContext::ecxt_scantuple, EEOP_INNER_VAR, EEOP_OUTER_VAR, EEOP_SCAN_VAR, ExecEvalStepOp(), i, and ExprEvalStep::op.

Referenced by ExecInterpExprStillValid(), and ExecRunCompiledExpr().

◆ CheckOpSlotCompatibility()

static void CheckOpSlotCompatibility ( ExprEvalStep op,
TupleTableSlot slot 
)
static

Definition at line 1948 of file execExprInterp.c.

1949 {
1950 #ifdef USE_ASSERT_CHECKING
1951  /* there's nothing to check */
1952  if (!op->d.fetch.fixed)
1953  return;
1954 
1955  /*
1956  * Should probably fixed at some point, but for now it's easier to allow
1957  * buffer and heap tuples to be used interchangeably.
1958  */
1959  if (slot->tts_ops == &TTSOpsBufferHeapTuple &&
1960  op->d.fetch.kind == &TTSOpsHeapTuple)
1961  return;
1962  if (slot->tts_ops == &TTSOpsHeapTuple &&
1963  op->d.fetch.kind == &TTSOpsBufferHeapTuple)
1964  return;
1965 
1966  /*
1967  * At the moment we consider it OK if a virtual slot is used instead of a
1968  * specific type of slot, as a virtual slot never needs to be deformed.
1969  */
1970  if (slot->tts_ops == &TTSOpsVirtual)
1971  return;
1972 
1973  Assert(op->d.fetch.kind == slot->tts_ops);
1974 #endif
1975 }
const TupleTableSlotOps TTSOpsVirtual
Definition: execTuples.c:83
const TupleTableSlotOps TTSOpsBufferHeapTuple
Definition: execTuples.c:86
const TupleTableSlotOps TTSOpsHeapTuple
Definition: execTuples.c:84
Assert(fmt[strlen(fmt) - 1] !='\n')
struct ExprEvalStep::@50::@51 fetch
const TupleTableSlotOps *const tts_ops
Definition: tuptable.h:122

References Assert(), ExprEvalStep::op, TupleTableSlot::tts_ops, TTSOpsBufferHeapTuple, TTSOpsHeapTuple, and TTSOpsVirtual.

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

◆ CheckVarSlotCompatibility()

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

Definition at line 1897 of file execExprInterp.c.

1898 {
1899  /*
1900  * What we have to check for here is the possibility of an attribute
1901  * having been dropped or changed in type since the plan tree was created.
1902  * Ideally the plan will get invalidated and not re-used, but just in
1903  * case, we keep these defenses. Fortunately it's sufficient to check
1904  * once on the first time through.
1905  *
1906  * Note: ideally we'd check typmod as well as typid, but that seems
1907  * impractical at the moment: in many cases the tupdesc will have been
1908  * generated by ExecTypeFromTL(), and that can't guarantee to generate an
1909  * accurate typmod in all cases, because some expression node types don't
1910  * carry typmod. Fortunately, for precisely that reason, there should be
1911  * no places with a critical dependency on the typmod of a value.
1912  *
1913  * System attributes don't require checking since their types never
1914  * change.
1915  */
1916  if (attnum > 0)
1917  {
1918  TupleDesc slot_tupdesc = slot->tts_tupleDescriptor;
1919  Form_pg_attribute attr;
1920 
1921  if (attnum > slot_tupdesc->natts) /* should never happen */
1922  elog(ERROR, "attribute number %d exceeds number of columns %d",
1923  attnum, slot_tupdesc->natts);
1924 
1925  attr = TupleDescAttr(slot_tupdesc, attnum - 1);
1926 
1927  if (attr->attisdropped)
1928  ereport(ERROR,
1929  (errcode(ERRCODE_UNDEFINED_COLUMN),
1930  errmsg("attribute %d of type %s has been dropped",
1931  attnum, format_type_be(slot_tupdesc->tdtypeid))));
1932 
1933  if (vartype != attr->atttypid)
1934  ereport(ERROR,
1935  (errcode(ERRCODE_DATATYPE_MISMATCH),
1936  errmsg("attribute %d of type %s has wrong type",
1937  attnum, format_type_be(slot_tupdesc->tdtypeid)),
1938  errdetail("Table has type %s, but query expects %s.",
1939  format_type_be(attr->atttypid),
1940  format_type_be(vartype))));
1941  }
1942 }
int errdetail(const char *fmt,...)
Definition: elog.c:1039
int errcode(int sqlerrcode)
Definition: elog.c:695
int errmsg(const char *fmt,...)
Definition: elog.c:906
#define ERROR
Definition: elog.h:35
#define ereport(elevel,...)
Definition: elog.h:145
char * format_type_be(Oid type_oid)
Definition: format_type.c:339
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:207
Oid tdtypeid
Definition: tupdesc.h:82
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92

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

Referenced by CheckExprStillValid().

◆ ExecAggInitGroup()

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

Definition at line 4169 of file execExprInterp.c.

4171 {
4172  FunctionCallInfo fcinfo = pertrans->transfn_fcinfo;
4173  MemoryContext oldContext;
4174 
4175  /*
4176  * We must copy the datum into aggcontext if it is pass-by-ref. We do not
4177  * need to pfree the old transValue, since it's NULL. (We already checked
4178  * that the agg's input type is binary-compatible with its transtype, so
4179  * straight copy here is OK.)
4180  */
4181  oldContext = MemoryContextSwitchTo(aggcontext->ecxt_per_tuple_memory);
4182  pergroup->transValue = datumCopy(fcinfo->args[1].value,
4183  pertrans->transtypeByVal,
4184  pertrans->transtypeLen);
4185  pergroup->transValueIsNull = false;
4186  pergroup->noTransValue = false;
4187  MemoryContextSwitchTo(oldContext);
4188 }
Datum datumCopy(Datum value, bool typByVal, int typLen)
Definition: datum.c:132
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:135
FunctionCallInfo transfn_fcinfo
Definition: nodeAgg.h:170
MemoryContext ecxt_per_tuple_memory
Definition: execnodes.h:255
NullableDatum args[FLEXIBLE_ARRAY_MEMBER]
Definition: fmgr.h:95
Datum value
Definition: postgres.h:423

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

Referenced by ExecInterpExpr().

◆ ExecAggPlainTransByRef()

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

Definition at line 4381 of file execExprInterp.c.

4384 {
4385  FunctionCallInfo fcinfo = pertrans->transfn_fcinfo;
4386  MemoryContext oldContext;
4387  Datum newVal;
4388 
4389  /* cf. select_current_set() */
4390  aggstate->curaggcontext = aggcontext;
4391  aggstate->current_set = setno;
4392 
4393  /* set up aggstate->curpertrans for AggGetAggref() */
4394  aggstate->curpertrans = pertrans;
4395 
4396  /* invoke transition function in per-tuple context */
4397  oldContext = MemoryContextSwitchTo(aggstate->tmpcontext->ecxt_per_tuple_memory);
4398 
4399  fcinfo->args[0].value = pergroup->transValue;
4400  fcinfo->args[0].isnull = pergroup->transValueIsNull;
4401  fcinfo->isnull = false; /* just in case transfn doesn't set it */
4402 
4403  newVal = FunctionCallInvoke(fcinfo);
4404 
4405  /*
4406  * For pass-by-ref datatype, must copy the new value into aggcontext and
4407  * free the prior transValue. But if transfn returned a pointer to its
4408  * first input, we don't need to do anything. Also, if transfn returned a
4409  * pointer to a R/W expanded object that is already a child of the
4410  * aggcontext, assume we can adopt that value without copying it.
4411  *
4412  * It's safe to compare newVal with pergroup->transValue without regard
4413  * for either being NULL, because ExecAggTransReparent() takes care to set
4414  * transValue to 0 when NULL. Otherwise we could end up accidentally not
4415  * reparenting, when the transValue has the same numerical value as
4416  * newValue, despite being NULL. This is a somewhat hot path, making it
4417  * undesirable to instead solve this with another branch for the common
4418  * case of the transition function returning its (modified) input
4419  * argument.
4420  */
4421  if (DatumGetPointer(newVal) != DatumGetPointer(pergroup->transValue))
4422  newVal = ExecAggTransReparent(aggstate, pertrans,
4423  newVal, fcinfo->isnull,
4424  pergroup->transValue,
4425  pergroup->transValueIsNull);
4426 
4427  pergroup->transValue = newVal;
4428  pergroup->transValueIsNull = fcinfo->isnull;
4429 
4430  MemoryContextSwitchTo(oldContext);
4431 }
Datum ExecAggTransReparent(AggState *aggstate, AggStatePerTrans pertrans, Datum newValue, bool newValueIsNull, Datum oldValue, bool oldValueIsNull)
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:172
uintptr_t Datum
Definition: postgres.h:412
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:660
ExprContext * tmpcontext
Definition: execnodes.h:2371
ExprContext * curaggcontext
Definition: execnodes.h:2373
AggStatePerTrans curpertrans
Definition: execnodes.h:2376
int current_set
Definition: execnodes.h:2381

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

Referenced by ExecInterpExpr().

◆ ExecAggPlainTransByVal()

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

Definition at line 4349 of file execExprInterp.c.

4352 {
4353  FunctionCallInfo fcinfo = pertrans->transfn_fcinfo;
4354  MemoryContext oldContext;
4355  Datum newVal;
4356 
4357  /* cf. select_current_set() */
4358  aggstate->curaggcontext = aggcontext;
4359  aggstate->current_set = setno;
4360 
4361  /* set up aggstate->curpertrans for AggGetAggref() */
4362  aggstate->curpertrans = pertrans;
4363 
4364  /* invoke transition function in per-tuple context */
4365  oldContext = MemoryContextSwitchTo(aggstate->tmpcontext->ecxt_per_tuple_memory);
4366 
4367  fcinfo->args[0].value = pergroup->transValue;
4368  fcinfo->args[0].isnull = pergroup->transValueIsNull;
4369  fcinfo->isnull = false; /* just in case transfn doesn't set it */
4370 
4371  newVal = FunctionCallInvoke(fcinfo);
4372 
4373  pergroup->transValue = newVal;
4374  pergroup->transValueIsNull = fcinfo->isnull;
4375 
4376  MemoryContextSwitchTo(oldContext);
4377 }

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

Referenced by ExecInterpExpr().

◆ ExecAggTransReparent()

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

Definition at line 4197 of file execExprInterp.c.

4200 {
4201  Assert(newValue != oldValue);
4202 
4203  if (!newValueIsNull)
4204  {
4206  if (DatumIsReadWriteExpandedObject(newValue,
4207  false,
4208  pertrans->transtypeLen) &&
4209  MemoryContextGetParent(DatumGetEOHP(newValue)->eoh_context) == CurrentMemoryContext)
4210  /* do nothing */ ;
4211  else
4212  newValue = datumCopy(newValue,
4213  pertrans->transtypeByVal,
4214  pertrans->transtypeLen);
4215  }
4216  else
4217  {
4218  /*
4219  * Ensure that AggStatePerGroup->transValue ends up being 0, so
4220  * callers can safely compare newValue/oldValue without having to
4221  * check their respective nullness.
4222  */
4223  newValue = (Datum) 0;
4224  }
4225 
4226  if (!oldValueIsNull)
4227  {
4228  if (DatumIsReadWriteExpandedObject(oldValue,
4229  false,
4230  pertrans->transtypeLen))
4231  DeleteExpandedObject(oldValue);
4232  else
4233  pfree(DatumGetPointer(oldValue));
4234  }
4235 
4236  return newValue;
4237 }
ExpandedObjectHeader * DatumGetEOHP(Datum d)
Definition: expandeddatum.c:29
void DeleteExpandedObject(Datum d)
#define DatumIsReadWriteExpandedObject(d, isnull, typlen)
void pfree(void *pointer)
Definition: mcxt.c:1306
MemoryContext CurrentMemoryContext
Definition: mcxt.c:124
MemoryContext MemoryContextGetParent(MemoryContext context)
Definition: mcxt.c:613

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

Referenced by advance_transition_function(), and ExecAggPlainTransByRef().

◆ ExecEvalAggOrderedTransDatum()

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

Definition at line 4321 of file execExprInterp.c.

4323 {
4324  AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
4325  int setno = op->d.agg_trans.setno;
4326 
4327  tuplesort_putdatum(pertrans->sortstates[setno],
4328  *op->resvalue, *op->resnull);
4329 }
Tuplesortstate ** sortstates
Definition: nodeAgg.h:162
Datum * resvalue
Definition: execExpr.h:274
struct ExprEvalStep::@50::@91 agg_trans
bool * resnull
Definition: execExpr.h:275
void tuplesort_putdatum(Tuplesortstate *state, Datum val, bool isNull)

References ExprEvalStep::op, ExprEvalStep::pertrans, ExprEvalStep::setno, AggStatePerTransData::sortstates, and tuplesort_putdatum().

Referenced by ExecInterpExpr().

◆ ExecEvalAggOrderedTransTuple()

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

Definition at line 4335 of file execExprInterp.c.

4337 {
4338  AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
4339  int setno = op->d.agg_trans.setno;
4340 
4341  ExecClearTuple(pertrans->sortslot);
4342  pertrans->sortslot->tts_nvalid = pertrans->numInputs;
4343  ExecStoreVirtualTuple(pertrans->sortslot);
4344  tuplesort_puttupleslot(pertrans->sortstates[setno], pertrans->sortslot);
4345 }
TupleTableSlot * ExecStoreVirtualTuple(TupleTableSlot *slot)
Definition: execTuples.c:1552
TupleTableSlot * sortslot
Definition: nodeAgg.h:141
AttrNumber tts_nvalid
Definition: tuptable.h:121
void tuplesort_puttupleslot(Tuplesortstate *state, TupleTableSlot *slot)
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:433

References ExecClearTuple(), ExecStoreVirtualTuple(), AggStatePerTransData::numInputs, ExprEvalStep::op, ExprEvalStep::pertrans, ExprEvalStep::setno, AggStatePerTransData::sortslot, AggStatePerTransData::sortstates, TupleTableSlot::tts_nvalid, and tuplesort_puttupleslot().

Referenced by ExecInterpExpr().

◆ ExecEvalArrayCoerce()

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

Definition at line 2838 of file execExprInterp.c.

2839 {
2840  Datum arraydatum;
2841 
2842  /* NULL array -> NULL result */
2843  if (*op->resnull)
2844  return;
2845 
2846  arraydatum = *op->resvalue;
2847 
2848  /*
2849  * If it's binary-compatible, modify the element type in the array header,
2850  * but otherwise leave the array as we received it.
2851  */
2852  if (op->d.arraycoerce.elemexprstate == NULL)
2853  {
2854  /* Detoast input array if necessary, and copy in any case */
2855  ArrayType *array = DatumGetArrayTypePCopy(arraydatum);
2856 
2857  ARR_ELEMTYPE(array) = op->d.arraycoerce.resultelemtype;
2858  *op->resvalue = PointerGetDatum(array);
2859  return;
2860  }
2861 
2862  /*
2863  * Use array_map to apply the sub-expression to each array element.
2864  */
2865  *op->resvalue = array_map(arraydatum,
2866  op->d.arraycoerce.elemexprstate,
2867  econtext,
2868  op->d.arraycoerce.resultelemtype,
2869  op->d.arraycoerce.amstate);
2870 }
#define DatumGetArrayTypePCopy(X)
Definition: array.h:255
#define ARR_ELEMTYPE(a)
Definition: array.h:285
Datum array_map(Datum arrayd, ExprState *exprstate, ExprContext *econtext, Oid retType, ArrayMapState *amstate)
Definition: arrayfuncs.c:3158
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:670
struct ExprEvalStep::@50::@69 arraycoerce

References ARR_ELEMTYPE, array_map(), DatumGetArrayTypePCopy, ExprEvalStep::op, and PointerGetDatum().

Referenced by ExecInterpExpr().

◆ ExecEvalArrayExpr()

void ExecEvalArrayExpr ( ExprState state,
ExprEvalStep op 
)

Definition at line 2629 of file execExprInterp.c.

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

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(), ArrayCheckBounds(), ArrayGetNItems(), construct_empty_array(), construct_md_array(), ArrayType::dataoffset, DatumGetArrayTypeP, ExprEvalStep::element_type, ArrayType::elemtype, ereport, errcode(), errdetail(), errmsg(), ERROR, format_type_be(), i, MAXDIM, ArrayType::ndim, ExprEvalStep::nelems, ExprEvalStep::op, palloc(), PointerGetDatum(), and SET_VARSIZE.

Referenced by ExecInterpExpr().

◆ ExecEvalConstraintCheck()

void ExecEvalConstraintCheck ( ExprState state,
ExprEvalStep op 
)

Definition at line 3641 of file execExprInterp.c.

3642 {
3643  if (!*op->d.domaincheck.checknull &&
3644  !DatumGetBool(*op->d.domaincheck.checkvalue))
3645  ereport(ERROR,
3646  (errcode(ERRCODE_CHECK_VIOLATION),
3647  errmsg("value for domain %s violates check constraint \"%s\"",
3648  format_type_be(op->d.domaincheck.resulttype),
3649  op->d.domaincheck.constraintname),
3650  errdomainconstraint(op->d.domaincheck.resulttype,
3651  op->d.domaincheck.constraintname)));
3652 }
int errdomainconstraint(Oid datatypeOid, const char *conname)
Definition: domains.c:384
static bool DatumGetBool(Datum X)
Definition: postgres.h:438
struct ExprEvalStep::@50::@78 domaincheck

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

Referenced by ExecInterpExpr().

◆ ExecEvalConstraintNotNull()

void ExecEvalConstraintNotNull ( ExprState state,
ExprEvalStep op 
)

Definition at line 3627 of file execExprInterp.c.

3628 {
3629  if (*op->resnull)
3630  ereport(ERROR,
3631  (errcode(ERRCODE_NOT_NULL_VIOLATION),
3632  errmsg("domain %s does not allow null values",
3633  format_type_be(op->d.domaincheck.resulttype)),
3634  errdatatype(op->d.domaincheck.resulttype)));
3635 }
int errdatatype(Oid datatypeOid)
Definition: domains.c:360

References ereport, errcode(), errdatatype(), errmsg(), ERROR, format_type_be(), and ExprEvalStep::op.

Referenced by ExecInterpExpr().

◆ ExecEvalConvertRowtype()

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

Definition at line 3147 of file execExprInterp.c.

3148 {
3149  HeapTuple result;
3150  Datum tupDatum;
3151  HeapTupleHeader tuple;
3152  HeapTupleData tmptup;
3153  TupleDesc indesc,
3154  outdesc;
3155  bool changed = false;
3156 
3157  /* NULL in -> NULL out */
3158  if (*op->resnull)
3159  return;
3160 
3161  tupDatum = *op->resvalue;
3162  tuple = DatumGetHeapTupleHeader(tupDatum);
3163 
3164  /*
3165  * Lookup tupdescs if first time through or if type changes. We'd better
3166  * pin them since type conversion functions could do catalog lookups and
3167  * hence cause cache invalidation.
3168  */
3169  indesc = get_cached_rowtype(op->d.convert_rowtype.inputtype, -1,
3170  op->d.convert_rowtype.incache,
3171  &changed);
3172  IncrTupleDescRefCount(indesc);
3173  outdesc = get_cached_rowtype(op->d.convert_rowtype.outputtype, -1,
3174  op->d.convert_rowtype.outcache,
3175  &changed);
3176  IncrTupleDescRefCount(outdesc);
3177 
3178  /*
3179  * We used to be able to assert that incoming tuples are marked with
3180  * exactly the rowtype of indesc. However, now that ExecEvalWholeRowVar
3181  * might change the tuples' marking to plain RECORD due to inserting
3182  * aliases, we can only make this weak test:
3183  */
3184  Assert(HeapTupleHeaderGetTypeId(tuple) == indesc->tdtypeid ||
3185  HeapTupleHeaderGetTypeId(tuple) == RECORDOID);
3186 
3187  /* if first time through, or after change, initialize conversion map */
3188  if (changed)
3189  {
3190  MemoryContext old_cxt;
3191 
3192  /* allocate map in long-lived memory context */
3193  old_cxt = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
3194 
3195  /* prepare map from old to new attribute numbers */
3196  op->d.convert_rowtype.map = convert_tuples_by_name(indesc, outdesc);
3197 
3198  MemoryContextSwitchTo(old_cxt);
3199  }
3200 
3201  /* Following steps need a HeapTuple not a bare HeapTupleHeader */
3202  tmptup.t_len = HeapTupleHeaderGetDatumLength(tuple);
3203  tmptup.t_data = tuple;
3204 
3205  if (op->d.convert_rowtype.map != NULL)
3206  {
3207  /* Full conversion with attribute rearrangement needed */
3208  result = execute_attr_map_tuple(&tmptup, op->d.convert_rowtype.map);
3209  /* Result already has appropriate composite-datum header fields */
3210  *op->resvalue = HeapTupleGetDatum(result);
3211  }
3212  else
3213  {
3214  /*
3215  * The tuple is physically compatible as-is, but we need to insert the
3216  * destination rowtype OID in its composite-datum header field, so we
3217  * have to copy it anyway. heap_copy_tuple_as_datum() is convenient
3218  * for this since it will both make the physical copy and insert the
3219  * correct composite header fields. Note that we aren't expecting to
3220  * have to flatten any toasted fields: the input was a composite
3221  * datum, so it shouldn't contain any. So heap_copy_tuple_as_datum()
3222  * is overkill here, but its check for external fields is cheap.
3223  */
3224  *op->resvalue = heap_copy_tuple_as_datum(&tmptup, outdesc);
3225  }
3226 
3227  DecrTupleDescRefCount(indesc);
3228  DecrTupleDescRefCount(outdesc);
3229 }
static TupleDesc get_cached_rowtype(Oid type_id, int32 typmod, ExprEvalRowtypeCache *rowcache, bool *changed)
#define DatumGetHeapTupleHeader(X)
Definition: fmgr.h:295
static Datum HeapTupleGetDatum(const HeapTupleData *tuple)
Definition: funcapi.h:230
Datum heap_copy_tuple_as_datum(HeapTuple tuple, TupleDesc tupleDesc)
Definition: heaptuple.c:984
#define HeapTupleHeaderGetTypeId(tup)
Definition: htup_details.h:452
#define HeapTupleHeaderGetDatumLength(tup)
Definition: htup_details.h:446
MemoryContext ecxt_per_query_memory
Definition: execnodes.h:254
struct ExprEvalStep::@50::@79 convert_rowtype
uint32 t_len
Definition: htup.h:64
HeapTupleHeader t_data
Definition: htup.h:68
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:154
void DecrTupleDescRefCount(TupleDesc tupdesc)
Definition: tupdesc.c:384
void IncrTupleDescRefCount(TupleDesc tupdesc)
Definition: tupdesc.c:366

References Assert(), convert_tuples_by_name(), DatumGetHeapTupleHeader, DecrTupleDescRefCount(), ExprContext::ecxt_per_query_memory, execute_attr_map_tuple(), get_cached_rowtype(), heap_copy_tuple_as_datum(), HeapTupleGetDatum(), HeapTupleHeaderGetDatumLength, HeapTupleHeaderGetTypeId, IncrTupleDescRefCount(), MemoryContextSwitchTo(), ExprEvalStep::op, HeapTupleData::t_data, HeapTupleData::t_len, and TupleDescData::tdtypeid.

Referenced by ExecInterpExpr().

◆ ExecEvalCurrentOfExpr()

void ExecEvalCurrentOfExpr ( ExprState state,
ExprEvalStep op 
)

Definition at line 2490 of file execExprInterp.c.

2491 {
2492  ereport(ERROR,
2493  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2494  errmsg("WHERE CURRENT OF is not supported for this table type")));
2495 }

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

Referenced by ExecInterpExpr().

◆ ExecEvalFieldSelect()

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

Definition at line 2952 of file execExprInterp.c.

2953 {
2954  AttrNumber fieldnum = op->d.fieldselect.fieldnum;
2955  Datum tupDatum;
2956  HeapTupleHeader tuple;
2957  Oid tupType;
2958  int32 tupTypmod;
2959  TupleDesc tupDesc;
2960  Form_pg_attribute attr;
2961  HeapTupleData tmptup;
2962 
2963  /* NULL record -> NULL result */
2964  if (*op->resnull)
2965  return;
2966 
2967  tupDatum = *op->resvalue;
2968 
2969  /* We can special-case expanded records for speed */
2971  {
2973 
2974  Assert(erh->er_magic == ER_MAGIC);
2975 
2976  /* Extract record's TupleDesc */
2977  tupDesc = expanded_record_get_tupdesc(erh);
2978 
2979  /*
2980  * Find field's attr record. Note we don't support system columns
2981  * here: a datum tuple doesn't have valid values for most of the
2982  * interesting system columns anyway.
2983  */
2984  if (fieldnum <= 0) /* should never happen */
2985  elog(ERROR, "unsupported reference to system column %d in FieldSelect",
2986  fieldnum);
2987  if (fieldnum > tupDesc->natts) /* should never happen */
2988  elog(ERROR, "attribute number %d exceeds number of columns %d",
2989  fieldnum, tupDesc->natts);
2990  attr = TupleDescAttr(tupDesc, fieldnum - 1);
2991 
2992  /* Check for dropped column, and force a NULL result if so */
2993  if (attr->attisdropped)
2994  {
2995  *op->resnull = true;
2996  return;
2997  }
2998 
2999  /* Check for type mismatch --- possible after ALTER COLUMN TYPE? */
3000  /* As in CheckVarSlotCompatibility, we should but can't check typmod */
3001  if (op->d.fieldselect.resulttype != attr->atttypid)
3002  ereport(ERROR,
3003  (errcode(ERRCODE_DATATYPE_MISMATCH),
3004  errmsg("attribute %d has wrong type", fieldnum),
3005  errdetail("Table has type %s, but query expects %s.",
3006  format_type_be(attr->atttypid),
3007  format_type_be(op->d.fieldselect.resulttype))));
3008 
3009  /* extract the field */
3010  *op->resvalue = expanded_record_get_field(erh, fieldnum,
3011  op->resnull);
3012  }
3013  else
3014  {
3015  /* Get the composite datum and extract its type fields */
3016  tuple = DatumGetHeapTupleHeader(tupDatum);
3017 
3018  tupType = HeapTupleHeaderGetTypeId(tuple);
3019  tupTypmod = HeapTupleHeaderGetTypMod(tuple);
3020 
3021  /* Lookup tupdesc if first time through or if type changes */
3022  tupDesc = get_cached_rowtype(tupType, tupTypmod,
3023  &op->d.fieldselect.rowcache, NULL);
3024 
3025  /*
3026  * Find field's attr record. Note we don't support system columns
3027  * here: a datum tuple doesn't have valid values for most of the
3028  * interesting system columns anyway.
3029  */
3030  if (fieldnum <= 0) /* should never happen */
3031  elog(ERROR, "unsupported reference to system column %d in FieldSelect",
3032  fieldnum);
3033  if (fieldnum > tupDesc->natts) /* should never happen */
3034  elog(ERROR, "attribute number %d exceeds number of columns %d",
3035  fieldnum, tupDesc->natts);
3036  attr = TupleDescAttr(tupDesc, fieldnum - 1);
3037 
3038  /* Check for dropped column, and force a NULL result if so */
3039  if (attr->attisdropped)
3040  {
3041  *op->resnull = true;
3042  return;
3043  }
3044 
3045  /* Check for type mismatch --- possible after ALTER COLUMN TYPE? */
3046  /* As in CheckVarSlotCompatibility, we should but can't check typmod */
3047  if (op->d.fieldselect.resulttype != attr->atttypid)
3048  ereport(ERROR,
3049  (errcode(ERRCODE_DATATYPE_MISMATCH),
3050  errmsg("attribute %d has wrong type", fieldnum),
3051  errdetail("Table has type %s, but query expects %s.",
3052  format_type_be(attr->atttypid),
3053  format_type_be(op->d.fieldselect.resulttype))));
3054 
3055  /* heap_getattr needs a HeapTuple not a bare HeapTupleHeader */
3056  tmptup.t_len = HeapTupleHeaderGetDatumLength(tuple);
3057  tmptup.t_data = tuple;
3058 
3059  /* extract the field */
3060  *op->resvalue = heap_getattr(&tmptup,
3061  fieldnum,
3062  tupDesc,
3063  op->resnull);
3064  }
3065 }
int16 AttrNumber
Definition: attnum.h:21
static Datum expanded_record_get_field(ExpandedRecordHeader *erh, int fnumber, bool *isnull)
#define ER_MAGIC
static TupleDesc expanded_record_get_tupdesc(ExpandedRecordHeader *erh)
static Datum heap_getattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
Definition: htup_details.h:788
#define HeapTupleHeaderGetTypMod(tup)
Definition: htup_details.h:462
#define VARATT_IS_EXTERNAL_EXPANDED(PTR)
Definition: postgres.h:336
struct ExprEvalStep::@50::@74 fieldselect

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

Referenced by ExecInterpExpr().

◆ ExecEvalFieldStoreDeForm()

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

Definition at line 3077 of file execExprInterp.c.

3078 {
3079  TupleDesc tupDesc;
3080 
3081  /* Lookup tupdesc if first time through or if type changes */
3082  tupDesc = get_cached_rowtype(op->d.fieldstore.fstore->resulttype, -1,
3083  op->d.fieldstore.rowcache, NULL);
3084 
3085  /* Check that current tupdesc doesn't have more fields than we allocated */
3086  if (unlikely(tupDesc->natts > op->d.fieldstore.ncolumns))
3087  elog(ERROR, "too many columns in composite type %u",
3088  op->d.fieldstore.fstore->resulttype);
3089 
3090  if (*op->resnull)
3091  {
3092  /* Convert null input tuple into an all-nulls row */
3093  memset(op->d.fieldstore.nulls, true,
3094  op->d.fieldstore.ncolumns * sizeof(bool));
3095  }
3096  else
3097  {
3098  /*
3099  * heap_deform_tuple needs a HeapTuple not a bare HeapTupleHeader. We
3100  * set all the fields in the struct just in case.
3101  */
3102  Datum tupDatum = *op->resvalue;
3103  HeapTupleHeader tuphdr;
3104  HeapTupleData tmptup;
3105 
3106  tuphdr = DatumGetHeapTupleHeader(tupDatum);
3107  tmptup.t_len = HeapTupleHeaderGetDatumLength(tuphdr);
3108  ItemPointerSetInvalid(&(tmptup.t_self));
3109  tmptup.t_tableOid = InvalidOid;
3110  tmptup.t_data = tuphdr;
3111 
3112  heap_deform_tuple(&tmptup, tupDesc,
3113  op->d.fieldstore.values,
3114  op->d.fieldstore.nulls);
3115  }
3116 }
#define unlikely(x)
Definition: c.h:295
void heap_deform_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *values, bool *isnull)
Definition: heaptuple.c:1249
static void ItemPointerSetInvalid(ItemPointerData *pointer)
Definition: itemptr.h:184
#define InvalidOid
Definition: postgres_ext.h:36
struct ExprEvalStep::@50::@75 fieldstore
ItemPointerData t_self
Definition: htup.h:65
Oid t_tableOid
Definition: htup.h:66

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

Referenced by ExecInterpExpr().

◆ ExecEvalFieldStoreForm()

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

Definition at line 3123 of file execExprInterp.c.

3124 {
3125  TupleDesc tupDesc;
3126  HeapTuple tuple;
3127 
3128  /* Lookup tupdesc (should be valid already) */
3129  tupDesc = get_cached_rowtype(op->d.fieldstore.fstore->resulttype, -1,
3130  op->d.fieldstore.rowcache, NULL);
3131 
3132  tuple = heap_form_tuple(tupDesc,
3133  op->d.fieldstore.values,
3134  op->d.fieldstore.nulls);
3135 
3136  *op->resvalue = HeapTupleGetDatum(tuple);
3137  *op->resnull = false;
3138 }
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1020

References get_cached_rowtype(), heap_form_tuple(), HeapTupleGetDatum(), and ExprEvalStep::op.

Referenced by ExecInterpExpr().

◆ ExecEvalFuncExprFusage()

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

Definition at line 2362 of file execExprInterp.c.

2364 {
2365  FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
2366  PgStat_FunctionCallUsage fcusage;
2367  Datum d;
2368 
2369  pgstat_init_function_usage(fcinfo, &fcusage);
2370 
2371  fcinfo->isnull = false;
2372  d = op->d.func.fn_addr(fcinfo);
2373  *op->resvalue = d;
2374  *op->resnull = fcinfo->isnull;
2375 
2376  pgstat_end_function_usage(&fcusage, true);
2377 }
void pgstat_init_function_usage(FunctionCallInfo fcinfo, PgStat_FunctionCallUsage *fcu)
void pgstat_end_function_usage(PgStat_FunctionCallUsage *fcu, bool finalize)
struct ExprEvalStep::@50::@57 func

References ExprEvalStep::d, FunctionCallInfoBaseData::isnull, ExprEvalStep::op, pgstat_end_function_usage(), and pgstat_init_function_usage().

Referenced by ExecInterpExpr().

◆ ExecEvalFuncExprStrictFusage()

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

Definition at line 2383 of file execExprInterp.c.

2385 {
2386 
2387  FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
2388  PgStat_FunctionCallUsage fcusage;
2389  NullableDatum *args = fcinfo->args;
2390  int nargs = op->d.func.nargs;
2391  Datum d;
2392 
2393  /* strict function, so check for NULL args */
2394  for (int argno = 0; argno < nargs; argno++)
2395  {
2396  if (args[argno].isnull)
2397  {
2398  *op->resnull = true;
2399  return;
2400  }
2401  }
2402 
2403  pgstat_init_function_usage(fcinfo, &fcusage);
2404 
2405  fcinfo->isnull = false;
2406  d = op->d.func.fn_addr(fcinfo);
2407  *op->resvalue = d;
2408  *op->resnull = fcinfo->isnull;
2409 
2410  pgstat_end_function_usage(&fcusage, true);
2411 }

References generate_unaccent_rules::args, FunctionCallInfoBaseData::args, ExprEvalStep::d, ExprEvalStep::isnull, FunctionCallInfoBaseData::isnull, ExprEvalStep::nargs, ExprEvalStep::op, pgstat_end_function_usage(), and pgstat_init_function_usage().

Referenced by ExecInterpExpr().

◆ ExecEvalGroupingFunc()

void ExecEvalGroupingFunc ( ExprState state,
ExprEvalStep op 
)

Definition at line 3880 of file execExprInterp.c.

3881 {
3882  AggState *aggstate = castNode(AggState, state->parent);
3883  int result = 0;
3884  Bitmapset *grouped_cols = aggstate->grouped_cols;
3885  ListCell *lc;
3886 
3887  foreach(lc, op->d.grouping_func.clauses)
3888  {
3889  int attnum = lfirst_int(lc);
3890 
3891  result <<= 1;
3892 
3893  if (!bms_is_member(attnum, grouped_cols))
3894  result |= 1;
3895  }
3896 
3897  *op->resvalue = Int32GetDatum(result);
3898  *op->resnull = false;
3899 }
bool bms_is_member(int x, const Bitmapset *a)
Definition: bitmapset.c:428
#define castNode(_type_, nodeptr)
Definition: nodes.h:186
#define lfirst_int(lc)
Definition: pg_list.h:171
static Datum Int32GetDatum(int32 X)
Definition: postgres.h:560
Bitmapset * grouped_cols
Definition: execnodes.h:2382
struct ExprEvalStep::@50::@84 grouping_func

References attnum, bms_is_member(), castNode, AggState::grouped_cols, Int32GetDatum(), lfirst_int, and ExprEvalStep::op.

Referenced by ExecInterpExpr().

◆ ExecEvalHashedScalarArrayOp()

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

Definition at line 3445 of file execExprInterp.c.

3446 {
3447  ScalarArrayOpExprHashTable *elements_tab = op->d.hashedscalararrayop.elements_tab;
3448  FunctionCallInfo fcinfo = op->d.hashedscalararrayop.fcinfo_data;
3449  bool inclause = op->d.hashedscalararrayop.inclause;
3450  bool strictfunc = op->d.hashedscalararrayop.finfo->fn_strict;
3451  Datum scalar = fcinfo->args[0].value;
3452  bool scalar_isnull = fcinfo->args[0].isnull;
3453  Datum result;
3454  bool resultnull;
3455  bool hashfound;
3456 
3457  /* We don't setup a hashed scalar array op if the array const is null. */
3458  Assert(!*op->resnull);
3459 
3460  /*
3461  * If the scalar is NULL, and the function is strict, return NULL; no
3462  * point in executing the search.
3463  */
3464  if (fcinfo->args[0].isnull && strictfunc)
3465  {
3466  *op->resnull = true;
3467  return;
3468  }
3469 
3470  /* Build the hash table on first evaluation */
3471  if (elements_tab == NULL)
3472  {
3473  ScalarArrayOpExpr *saop;
3474  int16 typlen;
3475  bool typbyval;
3476  char typalign;
3477  int nitems;
3478  bool has_nulls = false;
3479  char *s;
3480  bits8 *bitmap;
3481  int bitmask;
3482  MemoryContext oldcontext;
3483  ArrayType *arr;
3484 
3485  saop = op->d.hashedscalararrayop.saop;
3486 
3487  arr = DatumGetArrayTypeP(*op->resvalue);
3488  nitems = ArrayGetNItems(ARR_NDIM(arr), ARR_DIMS(arr));
3489 
3491  &typlen,
3492  &typbyval,
3493  &typalign);
3494 
3495  oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
3496 
3497  elements_tab = (ScalarArrayOpExprHashTable *)
3498  palloc0(offsetof(ScalarArrayOpExprHashTable, hash_fcinfo_data) +
3500  op->d.hashedscalararrayop.elements_tab = elements_tab;
3501  elements_tab->op = op;
3502 
3503  fmgr_info(saop->hashfuncid, &elements_tab->hash_finfo);
3504  fmgr_info_set_expr((Node *) saop, &elements_tab->hash_finfo);
3505 
3507  &elements_tab->hash_finfo,
3508  1,
3509  saop->inputcollid,
3510  NULL,
3511  NULL);
3512 
3513  /*
3514  * Create the hash table sizing it according to the number of elements
3515  * in the array. This does assume that the array has no duplicates.
3516  * If the array happens to contain many duplicate values then it'll
3517  * just mean that we sized the table a bit on the large side.
3518  */
3519  elements_tab->hashtab = saophash_create(CurrentMemoryContext, nitems,
3520  elements_tab);
3521 
3522  MemoryContextSwitchTo(oldcontext);
3523 
3524  s = (char *) ARR_DATA_PTR(arr);
3525  bitmap = ARR_NULLBITMAP(arr);
3526  bitmask = 1;
3527  for (int i = 0; i < nitems; i++)
3528  {
3529  /* Get array element, checking for NULL. */
3530  if (bitmap && (*bitmap & bitmask) == 0)
3531  {
3532  has_nulls = true;
3533  }
3534  else
3535  {
3536  Datum element;
3537 
3538  element = fetch_att(s, typbyval, typlen);
3539  s = att_addlength_pointer(s, typlen, s);
3540  s = (char *) att_align_nominal(s, typalign);
3541 
3542  saophash_insert(elements_tab->hashtab, element, &hashfound);
3543  }
3544 
3545  /* Advance bitmap pointer if any. */
3546  if (bitmap)
3547  {
3548  bitmask <<= 1;
3549  if (bitmask == 0x100)
3550  {
3551  bitmap++;
3552  bitmask = 1;
3553  }
3554  }
3555  }
3556 
3557  /*
3558  * Remember if we had any nulls so that we know if we need to execute
3559  * non-strict functions with a null lhs value if no match is found.
3560  */
3561  op->d.hashedscalararrayop.has_nulls = has_nulls;
3562  }
3563 
3564  /* Check the hash to see if we have a match. */
3565  hashfound = NULL != saophash_lookup(elements_tab->hashtab, scalar);
3566 
3567  /* the result depends on if the clause is an IN or NOT IN clause */
3568  if (inclause)
3569  result = BoolGetDatum(hashfound); /* IN */
3570  else
3571  result = BoolGetDatum(!hashfound); /* NOT IN */
3572 
3573  resultnull = false;
3574 
3575  /*
3576  * If we didn't find a match in the array, we still might need to handle
3577  * the possibility of null values. We didn't put any NULLs into the
3578  * hashtable, but instead marked if we found any when building the table
3579  * in has_nulls.
3580  */
3581  if (!hashfound && op->d.hashedscalararrayop.has_nulls)
3582  {
3583  if (strictfunc)
3584  {
3585 
3586  /*
3587  * We have nulls in the array so a non-null lhs and no match must
3588  * yield NULL.
3589  */
3590  result = (Datum) 0;
3591  resultnull = true;
3592  }
3593  else
3594  {
3595  /*
3596  * Execute function will null rhs just once.
3597  *
3598  * The hash lookup path will have scribbled on the lhs argument so
3599  * we need to set it up also (even though we entered this function
3600  * with it already set).
3601  */
3602  fcinfo->args[0].value = scalar;
3603  fcinfo->args[0].isnull = scalar_isnull;
3604  fcinfo->args[1].value = (Datum) 0;
3605  fcinfo->args[1].isnull = true;
3606 
3607  result = op->d.hashedscalararrayop.finfo->fn_addr(fcinfo);
3608  resultnull = fcinfo->isnull;
3609 
3610  /*
3611  * Reverse the result for NOT IN clauses since the above function
3612  * is the equality function and we need not-equals.
3613  */
3614  if (!inclause)
3615  result = !result;
3616  }
3617  }
3618 
3619  *op->resvalue = result;
3620  *op->resnull = resultnull;
3621 }
signed short int16
Definition: c.h:429
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:126
#define SizeForFunctionCallInfo(nargs)
Definition: fmgr.h:102
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#define fmgr_info_set_expr(expr, finfo)
Definition: fmgr.h:135
void get_typlenbyvalalign(Oid typid, int16 *typlen, bool *typbyval, char *typalign)
Definition: lsyscache.c:2229
void * palloc0(Size size)
Definition: mcxt.c:1230
char typalign
Definition: pg_type.h:176
static Datum BoolGetDatum(bool X)
Definition: postgres.h:450
static chr element(struct vars *v, const chr *startp, const chr *endp)
Definition: regc_locale.c:376
struct ExprEvalStep::@50::@81 hashedscalararrayop
Definition: nodes.h:118
FunctionCallInfoBaseData hash_fcinfo_data
struct ExprEvalStep * op
#define att_align_nominal(cur_offset, attalign)
Definition: tupmacs.h:129
#define att_addlength_pointer(cur_offset, attlen, attptr)
Definition: tupmacs.h:157
static Datum fetch_att(const void *T, bool attbyval, int attlen)
Definition: tupmacs.h:52

References FunctionCallInfoBaseData::args, ARR_DATA_PTR, ARR_DIMS, ARR_ELEMTYPE, ARR_NDIM, ARR_NULLBITMAP, ArrayGetNItems(), Assert(), att_addlength_pointer, att_align_nominal, BoolGetDatum(), CurrentMemoryContext, DatumGetArrayTypeP, ExprContext::ecxt_per_query_memory, element(), ExprEvalStep::elements_tab, fetch_att(), fmgr_info(), fmgr_info_set_expr, get_typlenbyvalalign(), ExprEvalStep::has_nulls, ScalarArrayOpExprHashTable::hash_fcinfo_data, ScalarArrayOpExprHashTable::hash_finfo, ScalarArrayOpExprHashTable::hashtab, i, ExprEvalStep::inclause, InitFunctionCallInfoData, ScalarArrayOpExpr::inputcollid, FunctionCallInfoBaseData::isnull, NullableDatum::isnull, MemoryContextSwitchTo(), ScalarArrayOpExprHashTable::op, ExprEvalStep::op, palloc0(), ExprEvalStep::saop, SizeForFunctionCallInfo, typalign, ExprEvalStep::typbyval, ExprEvalStep::typlen, and NullableDatum::value.

Referenced by ExecInterpExpr().

◆ ExecEvalMinMax()

void ExecEvalMinMax ( ExprState state,
ExprEvalStep op 
)

Definition at line 2899 of file execExprInterp.c.

2900 {
2901  Datum *values = op->d.minmax.values;
2902  bool *nulls = op->d.minmax.nulls;
2903  FunctionCallInfo fcinfo = op->d.minmax.fcinfo_data;
2904  MinMaxOp operator = op->d.minmax.op;
2905 
2906  /* set at initialization */
2907  Assert(fcinfo->args[0].isnull == false);
2908  Assert(fcinfo->args[1].isnull == false);
2909 
2910  /* default to null result */
2911  *op->resnull = true;
2912 
2913  for (int off = 0; off < op->d.minmax.nelems; off++)
2914  {
2915  /* ignore NULL inputs */
2916  if (nulls[off])
2917  continue;
2918 
2919  if (*op->resnull)
2920  {
2921  /* first nonnull input, adopt value */
2922  *op->resvalue = values[off];
2923  *op->resnull = false;
2924  }
2925  else
2926  {
2927  int cmpresult;
2928 
2929  /* apply comparison function */
2930  fcinfo->args[0].value = *op->resvalue;
2931  fcinfo->args[1].value = values[off];
2932 
2933  fcinfo->isnull = false;
2934  cmpresult = DatumGetInt32(FunctionCallInvoke(fcinfo));
2935  if (fcinfo->isnull) /* probably should not happen */
2936  continue;
2937 
2938  if (cmpresult > 0 && operator == IS_LEAST)
2939  *op->resvalue = values[off];
2940  else if (cmpresult < 0 && operator == IS_GREATEST)
2941  *op->resvalue = values[off];
2942  }
2943  }
2944 }
static Datum values[MAXATTR]
Definition: bootstrap.c:156
static int32 DatumGetInt32(Datum X)
Definition: postgres.h:550
MinMaxOp
Definition: primnodes.h:1279
@ IS_LEAST
Definition: primnodes.h:1281
@ IS_GREATEST
Definition: primnodes.h:1280
struct ExprEvalStep::@50::@73 minmax

References FunctionCallInfoBaseData::args, Assert(), DatumGetInt32(), FunctionCallInvoke, IS_GREATEST, IS_LEAST, FunctionCallInfoBaseData::isnull, NullableDatum::isnull, ExprEvalStep::nulls, ExprEvalStep::op, NullableDatum::value, and values.

Referenced by ExecInterpExpr().

◆ ExecEvalNextValueExpr()

void ExecEvalNextValueExpr ( ExprState state,
ExprEvalStep op 
)

Definition at line 2501 of file execExprInterp.c.

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 }
Datum Int64GetDatum(int64 X)
Definition: fmgr.c:1683
#define newval
static Datum Int16GetDatum(int16 X)
Definition: postgres.h:520
int64 nextval_internal(Oid relid, bool check_permissions)
Definition: sequence.c:629
struct ExprEvalStep::@50::@67 nextvalueexpr

References elog(), ERROR, Int16GetDatum(), Int32GetDatum(), Int64GetDatum(), newval, nextval_internal(), and ExprEvalStep::op.

Referenced by ExecInterpExpr().

◆ ExecEvalParamExec()

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

Definition at line 2420 of file execExprInterp.c.

2421 {
2422  ParamExecData *prm;
2423 
2424  prm = &(econtext->ecxt_param_exec_vals[op->d.param.paramid]);
2425  if (unlikely(prm->execPlan != NULL))
2426  {
2427  /* Parameter not evaluated yet, so go do it */
2428  ExecSetParamPlan(prm->execPlan, econtext);
2429  /* ExecSetParamPlan should have processed this param... */
2430  Assert(prm->execPlan == NULL);
2431  }
2432  *op->resvalue = prm->value;
2433  *op->resnull = prm->isnull;
2434 }
void ExecSetParamPlan(SubPlanState *node, ExprContext *econtext)
Definition: nodeSubplan.c:1073
ParamExecData * ecxt_param_exec_vals
Definition: execnodes.h:258
struct ExprEvalStep::@50::@62 param
bool isnull
Definition: params.h:150
Datum value
Definition: params.h:149
void * execPlan
Definition: params.h:148

References Assert(), ExprContext::ecxt_param_exec_vals, ParamExecData::execPlan, ExecSetParamPlan(), ParamExecData::isnull, ExprEvalStep::op, unlikely, and ParamExecData::value.

Referenced by ExecInterpExpr().

◆ ExecEvalParamExtern()

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

Definition at line 2442 of file execExprInterp.c.

2443 {
2444  ParamListInfo paramInfo = econtext->ecxt_param_list_info;
2445  int paramId = op->d.param.paramid;
2446 
2447  if (likely(paramInfo &&
2448  paramId > 0 && paramId <= paramInfo->numParams))
2449  {
2450  ParamExternData *prm;
2451  ParamExternData prmdata;
2452 
2453  /* give hook a chance in case parameter is dynamic */
2454  if (paramInfo->paramFetch != NULL)
2455  prm = paramInfo->paramFetch(paramInfo, paramId, false, &prmdata);
2456  else
2457  prm = &paramInfo->params[paramId - 1];
2458 
2459  if (likely(OidIsValid(prm->ptype)))
2460  {
2461  /* safety check in case hook did something unexpected */
2462  if (unlikely(prm->ptype != op->d.param.paramtype))
2463  ereport(ERROR,
2464  (errcode(ERRCODE_DATATYPE_MISMATCH),
2465  errmsg("type of parameter %d (%s) does not match that when preparing the plan (%s)",
2466  paramId,
2467  format_type_be(prm->ptype),
2468  format_type_be(op->d.param.paramtype))));
2469  *op->resvalue = prm->value;
2470  *op->resnull = prm->isnull;
2471  return;
2472  }
2473  }
2474 
2475  ereport(ERROR,
2476  (errcode(ERRCODE_UNDEFINED_OBJECT),
2477  errmsg("no value found for parameter %d", paramId)));
2478 }
#define likely(x)
Definition: c.h:294
#define OidIsValid(objectId)
Definition: c.h:711
ParamListInfo ecxt_param_list_info
Definition: execnodes.h:259
bool isnull
Definition: params.h:93
Datum value
Definition: params.h:92
ParamExternData params[FLEXIBLE_ARRAY_MEMBER]
Definition: params.h:125
ParamFetchHook paramFetch
Definition: params.h:112

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

Referenced by ExecInterpExpr().

◆ ExecEvalPreOrderedDistinctMulti()

bool ExecEvalPreOrderedDistinctMulti ( AggState aggstate,
AggStatePerTrans  pertrans 
)

Definition at line 4287 of file execExprInterp.c.

4288 {
4289  ExprContext *tmpcontext = aggstate->tmpcontext;
4290 
4291  for (int i = 0; i < pertrans->numTransInputs; i++)
4292  {
4293  pertrans->sortslot->tts_values[i] = pertrans->transfn_fcinfo->args[i + 1].value;
4294  pertrans->sortslot->tts_isnull[i] = pertrans->transfn_fcinfo->args[i + 1].isnull;
4295  }
4296 
4297  ExecClearTuple(pertrans->sortslot);
4298  pertrans->sortslot->tts_nvalid = pertrans->numInputs;
4299  ExecStoreVirtualTuple(pertrans->sortslot);
4300 
4301  tmpcontext->ecxt_outertuple = pertrans->sortslot;
4302  tmpcontext->ecxt_innertuple = pertrans->uniqslot;
4303 
4304  if (!pertrans->haslast ||
4305  !ExecQual(pertrans->equalfnMulti, tmpcontext))
4306  {
4307  if (pertrans->haslast)
4308  ExecClearTuple(pertrans->uniqslot);
4309 
4310  pertrans->haslast = true;
4311  ExecCopySlot(pertrans->uniqslot, pertrans->sortslot);
4312  return true;
4313  }
4314  return false;
4315 }
static bool ExecQual(ExprState *state, ExprContext *econtext)
Definition: executor.h:398
ExprState * equalfnMulti
Definition: nodeAgg.h:116
TupleTableSlot * uniqslot
Definition: nodeAgg.h:142
bool * tts_isnull
Definition: tuptable.h:128
Datum * tts_values
Definition: tuptable.h:126
static TupleTableSlot * ExecCopySlot(TupleTableSlot *dstslot, TupleTableSlot *srcslot)
Definition: tuptable.h:483

References FunctionCallInfoBaseData::args, ExprContext::ecxt_innertuple, ExprContext::ecxt_outertuple, AggStatePerTransData::equalfnMulti, ExecClearTuple(), ExecCopySlot(), ExecQual(), ExecStoreVirtualTuple(), AggStatePerTransData::haslast, i, NullableDatum::isnull, AggStatePerTransData::numInputs, AggStatePerTransData::numTransInputs, ExprEvalStep::pertrans, AggStatePerTransData::sortslot, AggState::tmpcontext, AggStatePerTransData::transfn_fcinfo, TupleTableSlot::tts_isnull, TupleTableSlot::tts_nvalid, TupleTableSlot::tts_values, AggStatePerTransData::uniqslot, and NullableDatum::value.

Referenced by ExecInterpExpr().

◆ ExecEvalPreOrderedDistinctSingle()

bool ExecEvalPreOrderedDistinctSingle ( AggState aggstate,
AggStatePerTrans  pertrans 
)

Definition at line 4246 of file execExprInterp.c.

4247 {
4248  Datum value = pertrans->transfn_fcinfo->args[1].value;
4249  bool isnull = pertrans->transfn_fcinfo->args[1].isnull;
4250 
4251  if (!pertrans->haslast ||
4252  pertrans->lastisnull != isnull ||
4254  pertrans->aggCollation,
4255  pertrans->lastdatum, value)))
4256  {
4257  if (pertrans->haslast && !pertrans->inputtypeByVal)
4258  pfree(DatumGetPointer(pertrans->lastdatum));
4259 
4260  pertrans->haslast = true;
4261  if (!isnull)
4262  {
4263  MemoryContext oldContext;
4264 
4266 
4267  pertrans->lastdatum = datumCopy(value, pertrans->inputtypeByVal,
4268  pertrans->inputtypeLen);
4269 
4270  MemoryContextSwitchTo(oldContext);
4271  }
4272  else
4273  pertrans->lastdatum = (Datum) 0;
4274  pertrans->lastisnull = isnull;
4275  return true;
4276  }
4277 
4278  return false;
4279 }
Datum FunctionCall2Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2)
Definition: fmgr.c:1134
static struct @143 value
FmgrInfo equalfnOne
Definition: nodeAgg.h:115

References AggStatePerTransData::aggCollation, FunctionCallInfoBaseData::args, AggState::curaggcontext, datumCopy(), DatumGetBool(), DatumGetPointer(), ExprContext::ecxt_per_tuple_memory, AggStatePerTransData::equalfnOne, FunctionCall2Coll(), AggStatePerTransData::haslast, AggStatePerTransData::inputtypeByVal, AggStatePerTransData::inputtypeLen, ExprEvalStep::isnull, NullableDatum::isnull, AggStatePerTransData::lastdatum, AggStatePerTransData::lastisnull, MemoryContextSwitchTo(), ExprEvalStep::pertrans, pfree(), AggStatePerTransData::transfn_fcinfo, NullableDatum::value, and value.

Referenced by ExecInterpExpr().

◆ ExecEvalRow()

void ExecEvalRow ( ExprState state,
ExprEvalStep op 
)

Definition at line 2879 of file execExprInterp.c.

2880 {
2881  HeapTuple tuple;
2882 
2883  /* build tuple from evaluated field values */
2884  tuple = heap_form_tuple(op->d.row.tupdesc,
2885  op->d.row.elemvalues,
2886  op->d.row.elemnulls);
2887 
2888  *op->resvalue = HeapTupleGetDatum(tuple);
2889  *op->resnull = false;
2890 }
struct ExprEvalStep::@50::@70 row

References heap_form_tuple(), HeapTupleGetDatum(), and ExprEvalStep::op.

Referenced by ExecInterpExpr().

◆ ExecEvalRowNotNull()

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

Definition at line 2536 of file execExprInterp.c.

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

References ExecEvalRowNullInt(), and ExprEvalStep::op.

Referenced by ExecInterpExpr().

◆ ExecEvalRowNull()

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

Definition at line 2527 of file execExprInterp.c.

2528 {
2529  ExecEvalRowNullInt(state, op, econtext, true);
2530 }

References ExecEvalRowNullInt(), and ExprEvalStep::op.

Referenced by ExecInterpExpr().

◆ ExecEvalRowNullInt()

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

Definition at line 2543 of file execExprInterp.c.

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.rowcache, NULL);
2587 
2588  /*
2589  * heap_attisnull needs a HeapTuple not a bare HeapTupleHeader.
2590  */
2591  tmptup.t_len = HeapTupleHeaderGetDatumLength(tuple);
2592  tmptup.t_data = tuple;
2593 
2594  for (int att = 1; att <= tupDesc->natts; att++)
2595  {
2596  /* ignore dropped columns */
2597  if (TupleDescAttr(tupDesc, att - 1)->attisdropped)
2598  continue;
2599  if (heap_attisnull(&tmptup, att, tupDesc))
2600  {
2601  /* null field disproves IS NOT NULL */
2602  if (!checkisnull)
2603  {
2604  *op->resvalue = BoolGetDatum(false);
2605  return;
2606  }
2607  }
2608  else
2609  {
2610  /* non-null field disproves IS NULL */
2611  if (checkisnull)
2612  {
2613  *op->resvalue = BoolGetDatum(false);
2614  return;
2615  }
2616  }
2617  }
2618 
2619  *op->resvalue = BoolGetDatum(true);
2620 }
bool heap_attisnull(HeapTuple tup, int attnum, TupleDesc tupleDesc)
Definition: heaptuple.c:359
struct ExprEvalStep::@50::@61 nulltest_row

References BoolGetDatum(), DatumGetHeapTupleHeader, get_cached_rowtype(), heap_attisnull(), HeapTupleHeaderGetDatumLength, HeapTupleHeaderGetTypeId, HeapTupleHeaderGetTypMod, ExprEvalStep::isnull, TupleDescData::natts, ExprEvalStep::op, HeapTupleData::t_data, HeapTupleData::t_len, TupleDescAttr, and value.

Referenced by ExecEvalRowNotNull(), and ExecEvalRowNull().

◆ ExecEvalScalarArrayOp()

void ExecEvalScalarArrayOp ( ExprState state,
ExprEvalStep op 
)

Definition at line 3242 of file execExprInterp.c.

3243 {
3244  FunctionCallInfo fcinfo = op->d.scalararrayop.fcinfo_data;
3245  bool useOr = op->d.scalararrayop.useOr;
3246  bool strictfunc = op->d.scalararrayop.finfo->fn_strict;
3247  ArrayType *arr;
3248  int nitems;
3249  Datum result;
3250  bool resultnull;
3251  int16 typlen;
3252  bool typbyval;
3253  char typalign;
3254  char *s;
3255  bits8 *bitmap;
3256  int bitmask;
3257 
3258  /*
3259  * If the array is NULL then we return NULL --- it's not very meaningful
3260  * to do anything else, even if the operator isn't strict.
3261  */
3262  if (*op->resnull)
3263  return;
3264 
3265  /* Else okay to fetch and detoast the array */
3266  arr = DatumGetArrayTypeP(*op->resvalue);
3267 
3268  /*
3269  * If the array is empty, we return either FALSE or TRUE per the useOr
3270  * flag. This is correct even if the scalar is NULL; since we would
3271  * evaluate the operator zero times, it matters not whether it would want
3272  * to return NULL.
3273  */
3274  nitems = ArrayGetNItems(ARR_NDIM(arr), ARR_DIMS(arr));
3275  if (nitems <= 0)
3276  {
3277  *op->resvalue = BoolGetDatum(!useOr);
3278  *op->resnull = false;
3279  return;
3280  }
3281 
3282  /*
3283  * If the scalar is NULL, and the function is strict, return NULL; no
3284  * point in iterating the loop.
3285  */
3286  if (fcinfo->args[0].isnull && strictfunc)
3287  {
3288  *op->resnull = true;
3289  return;
3290  }
3291 
3292  /*
3293  * We arrange to look up info about the element type only once per series
3294  * of calls, assuming the element type doesn't change underneath us.
3295  */
3296  if (op->d.scalararrayop.element_type != ARR_ELEMTYPE(arr))
3297  {
3299  &op->d.scalararrayop.typlen,
3300  &op->d.scalararrayop.typbyval,
3301  &op->d.scalararrayop.typalign);
3302  op->d.scalararrayop.element_type = ARR_ELEMTYPE(arr);
3303  }
3304 
3305  typlen = op->d.scalararrayop.typlen;
3306  typbyval = op->d.scalararrayop.typbyval;
3307  typalign = op->d.scalararrayop.typalign;
3308 
3309  /* Initialize result appropriately depending on useOr */
3310  result = BoolGetDatum(!useOr);
3311  resultnull = false;
3312 
3313  /* Loop over the array elements */
3314  s = (char *) ARR_DATA_PTR(arr);
3315  bitmap = ARR_NULLBITMAP(arr);
3316  bitmask = 1;
3317 
3318  for (int i = 0; i < nitems; i++)
3319  {
3320  Datum elt;
3321  Datum thisresult;
3322 
3323  /* Get array element, checking for NULL */
3324  if (bitmap && (*bitmap & bitmask) == 0)
3325  {
3326  fcinfo->args[1].value = (Datum) 0;
3327  fcinfo->args[1].isnull = true;
3328  }
3329  else
3330  {
3331  elt = fetch_att(s, typbyval, typlen);
3332  s = att_addlength_pointer(s, typlen, s);
3333  s = (char *) att_align_nominal(s, typalign);
3334  fcinfo->args[1].value = elt;
3335  fcinfo->args[1].isnull = false;
3336  }
3337 
3338  /* Call comparison function */
3339  if (fcinfo->args[1].isnull && strictfunc)
3340  {
3341  fcinfo->isnull = true;
3342  thisresult = (Datum) 0;
3343  }
3344  else
3345  {
3346  fcinfo->isnull = false;
3347  thisresult = op->d.scalararrayop.fn_addr(fcinfo);
3348  }
3349 
3350  /* Combine results per OR or AND semantics */
3351  if (fcinfo->isnull)
3352  resultnull = true;
3353  else if (useOr)
3354  {
3355  if (DatumGetBool(thisresult))
3356  {
3357  result = BoolGetDatum(true);
3358  resultnull = false;
3359  break; /* needn't look at any more elements */
3360  }
3361  }
3362  else
3363  {
3364  if (!DatumGetBool(thisresult))
3365  {
3366  result = BoolGetDatum(false);
3367  resultnull = false;
3368  break; /* needn't look at any more elements */
3369  }
3370  }
3371 
3372  /* advance bitmap pointer if any */
3373  if (bitmap)
3374  {
3375  bitmask <<= 1;
3376  if (bitmask == 0x100)
3377  {
3378  bitmap++;
3379  bitmask = 1;
3380  }
3381  }
3382  }
3383 
3384  *op->resvalue = result;
3385  *op->resnull = resultnull;
3386 }
struct ExprEvalStep::@50::@80 scalararrayop

References FunctionCallInfoBaseData::args, ARR_DATA_PTR, ARR_DIMS, ARR_ELEMTYPE, ARR_NDIM, ARR_NULLBITMAP, ArrayGetNItems(), att_addlength_pointer, att_align_nominal, BoolGetDatum(), DatumGetArrayTypeP, DatumGetBool(), fetch_att(), get_typlenbyvalalign(), i, FunctionCallInfoBaseData::isnull, NullableDatum::isnull, ExprEvalStep::op, typalign, ExprEvalStep::typbyval, ExprEvalStep::typlen, ExprEvalStep::useOr, and NullableDatum::value.

Referenced by ExecInterpExpr().

◆ ExecEvalStepOp()

ExprEvalOp ExecEvalStepOp ( ExprState state,
ExprEvalStep op 
)

Definition at line 2332 of file execExprInterp.c.

2333 {
2334 #if defined(EEO_USE_COMPUTED_GOTO)
2335  if (state->flags & EEO_FLAG_DIRECT_THREADED)
2336  {
2337  ExprEvalOpLookup key;
2338  ExprEvalOpLookup *res;
2339 
2340  key.opcode = (void *) op->opcode;
2341  res = bsearch(&key,
2342  reverse_dispatch_table,
2343  EEOP_LAST /* nmembers */ ,
2344  sizeof(ExprEvalOpLookup),
2345  dispatch_compare_ptr);
2346  Assert(res); /* unknown ops shouldn't get looked up */
2347  return res->op;
2348  }
2349 #endif
2350  return (ExprEvalOp) op->opcode;
2351 }
#define EEO_FLAG_DIRECT_THREADED
Definition: execExpr.h:29
ExprEvalOp
Definition: execExpr.h:65
@ EEOP_LAST
Definition: execExpr.h:260
intptr_t opcode
Definition: execExpr.h:271

References Assert(), EEO_FLAG_DIRECT_THREADED, EEOP_LAST, sort-test::key, ExprEvalStep::op, and res.

Referenced by CheckExprStillValid().

◆ ExecEvalSubPlan()

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

Definition at line 3905 of file execExprInterp.c.

3906 {
3907  SubPlanState *sstate = op->d.subplan.sstate;
3908 
3909  /* could potentially be nested, so make sure there's enough stack */
3911 
3912  *op->resvalue = ExecSubPlan(sstate, econtext, op->resnull);
3913 }
Datum ExecSubPlan(SubPlanState *node, ExprContext *econtext, bool *isNull)
Definition: nodeSubplan.c:62
void check_stack_depth(void)
Definition: postgres.c:3440
struct ExprEvalStep::@50::@86 subplan

References check_stack_depth(), ExecSubPlan(), ExprEvalStep::op, and ExprEvalStep::sstate.

Referenced by ExecInterpExpr().

◆ ExecEvalSysVar()

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

Definition at line 4149 of file execExprInterp.c.

4151 {
4152  Datum d;
4153 
4154  /* slot_getsysattr has sufficient defenses against bad attnums */
4155  d = slot_getsysattr(slot,
4156  op->d.var.attnum,
4157  op->resnull);
4158  *op->resvalue = d;
4159  /* this ought to be unreachable, but it's cheap enough to check */
4160  if (unlikely(*op->resnull))
4161  elog(ERROR, "failed to fetch attribute from slot");
4162 }
static Datum slot_getsysattr(TupleTableSlot *slot, int attnum, bool *isnull)
Definition: tuptable.h:410

References ExprEvalStep::d, elog(), ERROR, ExprEvalStep::op, slot_getsysattr(), and unlikely.

Referenced by ExecInterpExpr().

◆ ExecEvalWholeRowVar()

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

Definition at line 3922 of file execExprInterp.c.

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

References Assert(), BlessTupleDesc(), Alias::colnames, CreateTupleDescCopy(), 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, ExprEvalStep::op, OUTER_VAR, PointerGetDatum(), ReleaseTupleDesc, slot_getallattrs(), HeapTupleData::t_data, TupleDescData::tdtypeid, TupleDescData::tdtypmod, toast_build_flattened_tuple(), TupleTableSlot::tts_isnull, TupleTableSlot::tts_tupleDescriptor, TupleTableSlot::tts_values, and TupleDescAttr.

Referenced by ExecInterpExpr().

◆ ExecEvalXmlExpr()

void ExecEvalXmlExpr ( ExprState state,
ExprEvalStep op 
)

Definition at line 3661 of file execExprInterp.c.

3662 {
3663  XmlExpr *xexpr = op->d.xmlexpr.xexpr;
3664  Datum value;
3665 
3666  *op->resnull = true; /* until we get a result */
3667  *op->resvalue = (Datum) 0;
3668 
3669  switch (xexpr->op)
3670  {
3671  case IS_XMLCONCAT:
3672  {
3673  Datum *argvalue = op->d.xmlexpr.argvalue;
3674  bool *argnull = op->d.xmlexpr.argnull;
3675  List *values = NIL;
3676 
3677  for (int i = 0; i < list_length(xexpr->args); i++)
3678  {
3679  if (!argnull[i])
3680  values = lappend(values, DatumGetPointer(argvalue[i]));
3681  }
3682 
3683  if (values != NIL)
3684  {
3686  *op->resnull = false;
3687  }
3688  }
3689  break;
3690 
3691  case IS_XMLFOREST:
3692  {
3693  Datum *argvalue = op->d.xmlexpr.named_argvalue;
3694  bool *argnull = op->d.xmlexpr.named_argnull;
3696  ListCell *lc;
3697  ListCell *lc2;
3698  int i;
3699 
3700  initStringInfo(&buf);
3701 
3702  i = 0;
3703  forboth(lc, xexpr->named_args, lc2, xexpr->arg_names)
3704  {
3705  Expr *e = (Expr *) lfirst(lc);
3706  char *argname = strVal(lfirst(lc2));
3707 
3708  if (!argnull[i])
3709  {
3710  value = argvalue[i];
3711  appendStringInfo(&buf, "<%s>%s</%s>",
3712  argname,
3714  exprType((Node *) e), true),
3715  argname);
3716  *op->resnull = false;
3717  }
3718  i++;
3719  }
3720 
3721  if (!*op->resnull)
3722  {
3723  text *result;
3724 
3725  result = cstring_to_text_with_len(buf.data, buf.len);
3726  *op->resvalue = PointerGetDatum(result);
3727  }
3728 
3729  pfree(buf.data);
3730  }
3731  break;
3732 
3733  case IS_XMLELEMENT:
3734  *op->resvalue = PointerGetDatum(xmlelement(xexpr,
3735  op->d.xmlexpr.named_argvalue,
3736  op->d.xmlexpr.named_argnull,
3737  op->d.xmlexpr.argvalue,
3738  op->d.xmlexpr.argnull));
3739  *op->resnull = false;
3740  break;
3741 
3742  case IS_XMLPARSE:
3743  {
3744  Datum *argvalue = op->d.xmlexpr.argvalue;
3745  bool *argnull = op->d.xmlexpr.argnull;
3746  text *data;
3747  bool preserve_whitespace;
3748 
3749  /* arguments are known to be text, bool */
3750  Assert(list_length(xexpr->args) == 2);
3751 
3752  if (argnull[0])
3753  return;
3754  value = argvalue[0];
3756 
3757  if (argnull[1]) /* probably can't happen */
3758  return;
3759  value = argvalue[1];
3760  preserve_whitespace = DatumGetBool(value);
3761 
3763  xexpr->xmloption,
3764  preserve_whitespace));
3765  *op->resnull = false;
3766  }
3767  break;
3768 
3769  case IS_XMLPI:
3770  {
3771  text *arg;
3772  bool isnull;
3773 
3774  /* optional argument is known to be text */
3775  Assert(list_length(xexpr->args) <= 1);
3776 
3777  if (xexpr->args)
3778  {
3779  isnull = op->d.xmlexpr.argnull[0];
3780  if (isnull)
3781  arg = NULL;
3782  else
3783  arg = DatumGetTextPP(op->d.xmlexpr.argvalue[0]);
3784  }
3785  else
3786  {
3787  arg = NULL;
3788  isnull = false;
3789  }
3790 
3791  *op->resvalue = PointerGetDatum(xmlpi(xexpr->name,
3792  arg,
3793  isnull,
3794  op->resnull));
3795  }
3796  break;
3797 
3798  case IS_XMLROOT:
3799  {
3800  Datum *argvalue = op->d.xmlexpr.argvalue;
3801  bool *argnull = op->d.xmlexpr.argnull;
3802  xmltype *data;
3803  text *version;
3804  int standalone;
3805 
3806  /* arguments are known to be xml, text, int */
3807  Assert(list_length(xexpr->args) == 3);
3808 
3809  if (argnull[0])
3810  return;
3811  data = DatumGetXmlP(argvalue[0]);
3812 
3813  if (argnull[1])
3814  version = NULL;
3815  else
3816  version = DatumGetTextPP(argvalue[1]);
3817 
3818  Assert(!argnull[2]); /* always present */
3819  standalone = DatumGetInt32(argvalue[2]);
3820 
3822  version,
3823  standalone));
3824  *op->resnull = false;
3825  }
3826  break;
3827 
3828  case IS_XMLSERIALIZE:
3829  {
3830  Datum *argvalue = op->d.xmlexpr.argvalue;
3831  bool *argnull = op->d.xmlexpr.argnull;
3832 
3833  /* argument type is known to be xml */
3834  Assert(list_length(xexpr->args) == 1);
3835 
3836  if (argnull[0])
3837  return;
3838  value = argvalue[0];
3839 
3841  xexpr->xmloption));
3842  *op->resnull = false;
3843  }
3844  break;
3845 
3846  case IS_DOCUMENT:
3847  {
3848  Datum *argvalue = op->d.xmlexpr.argvalue;
3849  bool *argnull = op->d.xmlexpr.argnull;
3850 
3851  /* optional argument is known to be xml */
3852  Assert(list_length(xexpr->args) == 1);
3853 
3854  if (argnull[0])
3855  return;
3856  value = argvalue[0];
3857 
3858  *op->resvalue =
3860  *op->resnull = false;
3861  }
3862  break;
3863 
3864  default:
3865  elog(ERROR, "unrecognized XML operation");
3866  break;
3867  }
3868 }
#define DatumGetTextPP(X)
Definition: fmgr.h:292
List * lappend(List *list, void *datum)
Definition: list.c:338
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:43
void * arg
const void * data
#define lfirst(lc)
Definition: pg_list.h:170
static int list_length(const List *l)
Definition: pg_list.h:150
#define NIL
Definition: pg_list.h:66
#define forboth(cell1, list1, cell2, list2)
Definition: pg_list.h:465
static char * buf
Definition: pg_test_fsync.c:67
e
Definition: preproc-init.c:82
@ IS_DOCUMENT
Definition: primnodes.h:1315
@ IS_XMLFOREST
Definition: primnodes.h:1310
@ IS_XMLCONCAT
Definition: primnodes.h:1308
@ IS_XMLPI
Definition: primnodes.h:1312
@ IS_XMLPARSE
Definition: primnodes.h:1311
@ IS_XMLSERIALIZE
Definition: primnodes.h:1314
@ IS_XMLROOT
Definition: primnodes.h:1313
@ IS_XMLELEMENT
Definition: primnodes.h:1309
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:91
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
struct ExprEvalStep::@50::@82 xmlexpr
Definition: pg_list.h:52
List * args
Definition: primnodes.h:1331
char * name
Definition: primnodes.h:1328
List * arg_names
Definition: primnodes.h:1330
List * named_args
Definition: primnodes.h:1329
XmlExprOp op
Definition: primnodes.h:1327
XmlOptionType xmloption
Definition: primnodes.h:1332
Definition: c.h:623
#define strVal(v)
Definition: value.h:82
text * cstring_to_text_with_len(const char *s, int len)
Definition: varlena.c:201
xmltype * xmlconcat(List *args)
Definition: xml.c:511
xmltype * xmlparse(text *data, XmlOptionType xmloption_arg, bool preserve_whitespace)
Definition: xml.c:751
text * xmltotext_with_xmloption(xmltype *data, XmlOptionType xmloption_arg)
Definition: xml.c:614
bool xml_is_document(xmltype *arg)
Definition: xml.c:887
xmltype * xmlpi(const char *target, text *arg, bool arg_is_null, bool *result_is_null)
Definition: xml.c:769
char * map_sql_value_to_xml_value(Datum value, Oid type, bool xml_escape_strings)
Definition: xml.c:2133
xmltype * xmlelement(XmlExpr *xexpr, Datum *named_argvalue, bool *named_argnull, Datum *argvalue, bool *argnull)
Definition: xml.c:627
xmltype * xmlroot(xmltype *data, text *version, int standalone)
Definition: xml.c:821
static xmltype * DatumGetXmlP(Datum X)
Definition: xml.h:51

References appendStringInfo(), arg, XmlExpr::arg_names, ExprEvalStep::argnull, XmlExpr::args, ExprEvalStep::argvalue, Assert(), BoolGetDatum(), buf, cstring_to_text_with_len(), 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, ExprEvalStep::isnull, lappend(), lfirst, list_length(), map_sql_value_to_xml_value(), XmlExpr::name, XmlExpr::named_args, NIL, ExprEvalStep::op, XmlExpr::op, pfree(), PointerGetDatum(), strVal, value, values, ExprEvalStep::xexpr, xml_is_document(), xmlconcat(), xmlelement(), XmlExpr::xmloption, xmlparse(), xmlpi(), xmlroot(), and xmltotext_with_xmloption().

Referenced by ExecInterpExpr().

◆ ExecInitInterpreter()

static void ExecInitInterpreter ( void  )
static

Definition at line 2300 of file execExprInterp.c.

2301 {
2302 #if defined(EEO_USE_COMPUTED_GOTO)
2303  /* Set up externally-visible pointer to dispatch table */
2304  if (dispatch_table == NULL)
2305  {
2306  dispatch_table = (const void **)
2307  DatumGetPointer(ExecInterpExpr(NULL, NULL, NULL));
2308 
2309  /* build reverse lookup table */
2310  for (int i = 0; i < EEOP_LAST; i++)
2311  {
2312  reverse_dispatch_table[i].opcode = dispatch_table[i];
2313  reverse_dispatch_table[i].op = (ExprEvalOp) i;
2314  }
2315 
2316  /* make it bsearch()able */
2317  qsort(reverse_dispatch_table,
2318  EEOP_LAST /* nmembers */ ,
2319  sizeof(ExprEvalOpLookup),
2320  dispatch_compare_ptr);
2321  }
2322 #endif
2323 }
static Datum ExecInterpExpr(ExprState *state, ExprContext *econtext, bool *isnull)
#define qsort(a, b, c, d)
Definition: port.h:445

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

Referenced by ExecReadyInterpretedExpr().

◆ ExecInterpExpr()

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

Definition at line 392 of file execExprInterp.c.

393 {
394  ExprEvalStep *op;
395  TupleTableSlot *resultslot;
396  TupleTableSlot *innerslot;
397  TupleTableSlot *outerslot;
398  TupleTableSlot *scanslot;
399 
400  /*
401  * This array has to be in the same order as enum ExprEvalOp.
402  */
403 #if defined(EEO_USE_COMPUTED_GOTO)
404  static const void *const dispatch_table[] = {
405  &&CASE_EEOP_DONE,
406  &&CASE_EEOP_INNER_FETCHSOME,
407  &&CASE_EEOP_OUTER_FETCHSOME,
408  &&CASE_EEOP_SCAN_FETCHSOME,
409  &&CASE_EEOP_INNER_VAR,
410  &&CASE_EEOP_OUTER_VAR,
411  &&CASE_EEOP_SCAN_VAR,
412  &&CASE_EEOP_INNER_SYSVAR,
413  &&CASE_EEOP_OUTER_SYSVAR,
414  &&CASE_EEOP_SCAN_SYSVAR,
415  &&CASE_EEOP_WHOLEROW,
416  &&CASE_EEOP_ASSIGN_INNER_VAR,
417  &&CASE_EEOP_ASSIGN_OUTER_VAR,
418  &&CASE_EEOP_ASSIGN_SCAN_VAR,
419  &&CASE_EEOP_ASSIGN_TMP,
420  &&CASE_EEOP_ASSIGN_TMP_MAKE_RO,
421  &&CASE_EEOP_CONST,
422  &&CASE_EEOP_FUNCEXPR,
423  &&CASE_EEOP_FUNCEXPR_STRICT,
424  &&CASE_EEOP_FUNCEXPR_FUSAGE,
425  &&CASE_EEOP_FUNCEXPR_STRICT_FUSAGE,
426  &&CASE_EEOP_BOOL_AND_STEP_FIRST,
427  &&CASE_EEOP_BOOL_AND_STEP,
428  &&CASE_EEOP_BOOL_AND_STEP_LAST,
429  &&CASE_EEOP_BOOL_OR_STEP_FIRST,
430  &&CASE_EEOP_BOOL_OR_STEP,
431  &&CASE_EEOP_BOOL_OR_STEP_LAST,
432  &&CASE_EEOP_BOOL_NOT_STEP,
433  &&CASE_EEOP_QUAL,
434  &&CASE_EEOP_JUMP,
435  &&CASE_EEOP_JUMP_IF_NULL,
436  &&CASE_EEOP_JUMP_IF_NOT_NULL,
437  &&CASE_EEOP_JUMP_IF_NOT_TRUE,
438  &&CASE_EEOP_NULLTEST_ISNULL,
439  &&CASE_EEOP_NULLTEST_ISNOTNULL,
440  &&CASE_EEOP_NULLTEST_ROWISNULL,
441  &&CASE_EEOP_NULLTEST_ROWISNOTNULL,
442  &&CASE_EEOP_BOOLTEST_IS_TRUE,
443  &&CASE_EEOP_BOOLTEST_IS_NOT_TRUE,
444  &&CASE_EEOP_BOOLTEST_IS_FALSE,
445  &&CASE_EEOP_BOOLTEST_IS_NOT_FALSE,
446  &&CASE_EEOP_PARAM_EXEC,
447  &&CASE_EEOP_PARAM_EXTERN,
448  &&CASE_EEOP_PARAM_CALLBACK,
449  &&CASE_EEOP_CASE_TESTVAL,
450  &&CASE_EEOP_MAKE_READONLY,
451  &&CASE_EEOP_IOCOERCE,
452  &&CASE_EEOP_DISTINCT,
453  &&CASE_EEOP_NOT_DISTINCT,
454  &&CASE_EEOP_NULLIF,
455  &&CASE_EEOP_CURRENTOFEXPR,
456  &&CASE_EEOP_NEXTVALUEEXPR,
457  &&CASE_EEOP_ARRAYEXPR,
458  &&CASE_EEOP_ARRAYCOERCE,
459  &&CASE_EEOP_ROW,
460  &&CASE_EEOP_ROWCOMPARE_STEP,
461  &&CASE_EEOP_ROWCOMPARE_FINAL,
462  &&CASE_EEOP_MINMAX,
463  &&CASE_EEOP_FIELDSELECT,
464  &&CASE_EEOP_FIELDSTORE_DEFORM,
465  &&CASE_EEOP_FIELDSTORE_FORM,
466  &&CASE_EEOP_SBSREF_SUBSCRIPTS,
467  &&CASE_EEOP_SBSREF_OLD,
468  &&CASE_EEOP_SBSREF_ASSIGN,
469  &&CASE_EEOP_SBSREF_FETCH,
470  &&CASE_EEOP_DOMAIN_TESTVAL,
471  &&CASE_EEOP_DOMAIN_NOTNULL,
472  &&CASE_EEOP_DOMAIN_CHECK,
473  &&CASE_EEOP_CONVERT_ROWTYPE,
474  &&CASE_EEOP_SCALARARRAYOP,
475  &&CASE_EEOP_HASHED_SCALARARRAYOP,
476  &&CASE_EEOP_XMLEXPR,
477  &&CASE_EEOP_AGGREF,
478  &&CASE_EEOP_GROUPING_FUNC,
479  &&CASE_EEOP_WINDOW_FUNC,
480  &&CASE_EEOP_SUBPLAN,
481  &&CASE_EEOP_AGG_STRICT_DESERIALIZE,
482  &&CASE_EEOP_AGG_DESERIALIZE,
483  &&CASE_EEOP_AGG_STRICT_INPUT_CHECK_ARGS,
484  &&CASE_EEOP_AGG_STRICT_INPUT_CHECK_NULLS,
485  &&CASE_EEOP_AGG_PLAIN_PERGROUP_NULLCHECK,
486  &&CASE_EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYVAL,
487  &&CASE_EEOP_AGG_PLAIN_TRANS_STRICT_BYVAL,
488  &&CASE_EEOP_AGG_PLAIN_TRANS_BYVAL,
489  &&CASE_EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYREF,
490  &&CASE_EEOP_AGG_PLAIN_TRANS_STRICT_BYREF,
491  &&CASE_EEOP_AGG_PLAIN_TRANS_BYREF,
492  &&CASE_EEOP_AGG_PRESORTED_DISTINCT_SINGLE,
493  &&CASE_EEOP_AGG_PRESORTED_DISTINCT_MULTI,
494  &&CASE_EEOP_AGG_ORDERED_TRANS_DATUM,
495  &&CASE_EEOP_AGG_ORDERED_TRANS_TUPLE,
496  &&CASE_EEOP_LAST
497  };
498 
499  StaticAssertStmt(EEOP_LAST + 1 == lengthof(dispatch_table),
500  "dispatch_table out of whack with ExprEvalOp");
501 
502  if (unlikely(state == NULL))
503  return PointerGetDatum(dispatch_table);
504 #else
505  Assert(state != NULL);
506 #endif /* EEO_USE_COMPUTED_GOTO */
507 
508  /* setup state */
509  op = state->steps;
510  resultslot = state->resultslot;
511  innerslot = econtext->ecxt_innertuple;
512  outerslot = econtext->ecxt_outertuple;
513  scanslot = econtext->ecxt_scantuple;
514 
515 #if defined(EEO_USE_COMPUTED_GOTO)
516  EEO_DISPATCH();
517 #endif
518 
519  EEO_SWITCH()
520  {
522  {
523  goto out;
524  }
525 
527  {
528  CheckOpSlotCompatibility(op, innerslot);
529 
530  slot_getsomeattrs(innerslot, op->d.fetch.last_var);
531 
532  EEO_NEXT();
533  }
534 
536  {
537  CheckOpSlotCompatibility(op, outerslot);
538 
539  slot_getsomeattrs(outerslot, op->d.fetch.last_var);
540 
541  EEO_NEXT();
542  }
543 
545  {
546  CheckOpSlotCompatibility(op, scanslot);
547 
548  slot_getsomeattrs(scanslot, op->d.fetch.last_var);
549 
550  EEO_NEXT();
551  }
552 
554  {
555  int attnum = op->d.var.attnum;
556 
557  /*
558  * Since we already extracted all referenced columns from the
559  * tuple with a FETCHSOME step, we can just grab the value
560  * directly out of the slot's decomposed-data arrays. But let's
561  * have an Assert to check that that did happen.
562  */
563  Assert(attnum >= 0 && attnum < innerslot->tts_nvalid);
564  *op->resvalue = innerslot->tts_values[attnum];
565  *op->resnull = innerslot->tts_isnull[attnum];
566 
567  EEO_NEXT();
568  }
569 
571  {
572  int attnum = op->d.var.attnum;
573 
574  /* See EEOP_INNER_VAR comments */
575 
576  Assert(attnum >= 0 && attnum < outerslot->tts_nvalid);
577  *op->resvalue = outerslot->tts_values[attnum];
578  *op->resnull = outerslot->tts_isnull[attnum];
579 
580  EEO_NEXT();
581  }
582 
584  {
585  int attnum = op->d.var.attnum;
586 
587  /* See EEOP_INNER_VAR comments */
588 
589  Assert(attnum >= 0 && attnum < scanslot->tts_nvalid);
590  *op->resvalue = scanslot->tts_values[attnum];
591  *op->resnull = scanslot->tts_isnull[attnum];
592 
593  EEO_NEXT();
594  }
595 
597  {
598  ExecEvalSysVar(state, op, econtext, innerslot);
599  EEO_NEXT();
600  }
601 
603  {
604  ExecEvalSysVar(state, op, econtext, outerslot);
605  EEO_NEXT();
606  }
607 
609  {
610  ExecEvalSysVar(state, op, econtext, scanslot);
611  EEO_NEXT();
612  }
613 
615  {
616  /* too complex for an inline implementation */
617  ExecEvalWholeRowVar(state, op, econtext);
618 
619  EEO_NEXT();
620  }
621 
623  {
624  int resultnum = op->d.assign_var.resultnum;
625  int attnum = op->d.assign_var.attnum;
626 
627  /*
628  * We do not need CheckVarSlotCompatibility here; that was taken
629  * care of at compilation time. But see EEOP_INNER_VAR comments.
630  */
631  Assert(attnum >= 0 && attnum < innerslot->tts_nvalid);
632  Assert(resultnum >= 0 && resultnum < resultslot->tts_tupleDescriptor->natts);
633  resultslot->tts_values[resultnum] = innerslot->tts_values[attnum];
634  resultslot->tts_isnull[resultnum] = innerslot->tts_isnull[attnum];
635 
636  EEO_NEXT();
637  }
638 
640  {
641  int resultnum = op->d.assign_var.resultnum;
642  int attnum = op->d.assign_var.attnum;
643 
644  /*
645  * We do not need CheckVarSlotCompatibility here; that was taken
646  * care of at compilation time. But see EEOP_INNER_VAR comments.
647  */
648  Assert(attnum >= 0 && attnum < outerslot->tts_nvalid);
649  Assert(resultnum >= 0 && resultnum < resultslot->tts_tupleDescriptor->natts);
650  resultslot->tts_values[resultnum] = outerslot->tts_values[attnum];
651  resultslot->tts_isnull[resultnum] = outerslot->tts_isnull[attnum];
652 
653  EEO_NEXT();
654  }
655 
657  {
658  int resultnum = op->d.assign_var.resultnum;
659  int attnum = op->d.assign_var.attnum;
660 
661  /*
662  * We do not need CheckVarSlotCompatibility here; that was taken
663  * care of at compilation time. But see EEOP_INNER_VAR comments.
664  */
665  Assert(attnum >= 0 && attnum < scanslot->tts_nvalid);
666  Assert(resultnum >= 0 && resultnum < resultslot->tts_tupleDescriptor->natts);
667  resultslot->tts_values[resultnum] = scanslot->tts_values[attnum];
668  resultslot->tts_isnull[resultnum] = scanslot->tts_isnull[attnum];
669 
670  EEO_NEXT();
671  }
672 
674  {
675  int resultnum = op->d.assign_tmp.resultnum;
676 
677  Assert(resultnum >= 0 && resultnum < resultslot->tts_tupleDescriptor->natts);
678  resultslot->tts_values[resultnum] = state->resvalue;
679  resultslot->tts_isnull[resultnum] = state->resnull;
680 
681  EEO_NEXT();
682  }
683 
685  {
686  int resultnum = op->d.assign_tmp.resultnum;
687 
688  Assert(resultnum >= 0 && resultnum < resultslot->tts_tupleDescriptor->natts);
689  resultslot->tts_isnull[resultnum] = state->resnull;
690  if (!resultslot->tts_isnull[resultnum])
691  resultslot->tts_values[resultnum] =
693  else
694  resultslot->tts_values[resultnum] = state->resvalue;
695 
696  EEO_NEXT();
697  }
698 
700  {
701  *op->resnull = op->d.constval.isnull;
702  *op->resvalue = op->d.constval.value;
703 
704  EEO_NEXT();
705  }
706 
707  /*
708  * Function-call implementations. Arguments have previously been
709  * evaluated directly into fcinfo->args.
710  *
711  * As both STRICT checks and function-usage are noticeable performance
712  * wise, and function calls are a very hot-path (they also back
713  * operators!), it's worth having so many separate opcodes.
714  *
715  * Note: the reason for using a temporary variable "d", here and in
716  * other places, is that some compilers think "*op->resvalue = f();"
717  * requires them to evaluate op->resvalue into a register before
718  * calling f(), just in case f() is able to modify op->resvalue
719  * somehow. The extra line of code can save a useless register spill
720  * and reload across the function call.
721  */
723  {
724  FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
725  Datum d;
726 
727  fcinfo->isnull = false;
728  d = op->d.func.fn_addr(fcinfo);
729  *op->resvalue = d;
730  *op->resnull = fcinfo->isnull;
731 
732  EEO_NEXT();
733  }
734 
736  {
737  FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
738  NullableDatum *args = fcinfo->args;
739  int nargs = op->d.func.nargs;
740  Datum d;
741 
742  /* strict function, so check for NULL args */
743  for (int argno = 0; argno < nargs; argno++)
744  {
745  if (args[argno].isnull)
746  {
747  *op->resnull = true;
748  goto strictfail;
749  }
750  }
751  fcinfo->isnull = false;
752  d = op->d.func.fn_addr(fcinfo);
753  *op->resvalue = d;
754  *op->resnull = fcinfo->isnull;
755 
756  strictfail:
757  EEO_NEXT();
758  }
759 
761  {
762  /* not common enough to inline */
763  ExecEvalFuncExprFusage(state, op, econtext);
764 
765  EEO_NEXT();
766  }
767 
769  {
770  /* not common enough to inline */
771  ExecEvalFuncExprStrictFusage(state, op, econtext);
772 
773  EEO_NEXT();
774  }
775 
776  /*
777  * If any of its clauses is FALSE, an AND's result is FALSE regardless
778  * of the states of the rest of the clauses, so we can stop evaluating
779  * and return FALSE immediately. If none are FALSE and one or more is
780  * NULL, we return NULL; otherwise we return TRUE. This makes sense
781  * when you interpret NULL as "don't know": perhaps one of the "don't
782  * knows" would have been FALSE if we'd known its value. Only when
783  * all the inputs are known to be TRUE can we state confidently that
784  * the AND's result is TRUE.
785  */
787  {
788  *op->d.boolexpr.anynull = false;
789 
790  /*
791  * EEOP_BOOL_AND_STEP_FIRST resets anynull, otherwise it's the
792  * same as EEOP_BOOL_AND_STEP - so fall through to that.
793  */
794 
795  /* FALL THROUGH */
796  }
797 
799  {
800  if (*op->resnull)
801  {
802  *op->d.boolexpr.anynull = true;
803  }
804  else if (!DatumGetBool(*op->resvalue))
805  {
806  /* result is already set to FALSE, need not change it */
807  /* bail out early */
808  EEO_JUMP(op->d.boolexpr.jumpdone);
809  }
810 
811  EEO_NEXT();
812  }
813 
815  {
816  if (*op->resnull)
817  {
818  /* result is already set to NULL, need not change it */
819  }
820  else if (!DatumGetBool(*op->resvalue))
821  {
822  /* result is already set to FALSE, need not change it */
823 
824  /*
825  * No point jumping early to jumpdone - would be same target
826  * (as this is the last argument to the AND expression),
827  * except more expensive.
828  */
829  }
830  else if (*op->d.boolexpr.anynull)
831  {
832  *op->resvalue = (Datum) 0;
833  *op->resnull = true;
834  }
835  else
836  {
837  /* result is already set to TRUE, need not change it */
838  }
839 
840  EEO_NEXT();
841  }
842 
843  /*
844  * If any of its clauses is TRUE, an OR's result is TRUE regardless of
845  * the states of the rest of the clauses, so we can stop evaluating
846  * and return TRUE immediately. If none are TRUE and one or more is
847  * NULL, we return NULL; otherwise we return FALSE. This makes sense
848  * when you interpret NULL as "don't know": perhaps one of the "don't
849  * knows" would have been TRUE if we'd known its value. Only when all
850  * the inputs are known to be FALSE can we state confidently that the
851  * OR's result is FALSE.
852  */
854  {
855  *op->d.boolexpr.anynull = false;
856 
857  /*
858  * EEOP_BOOL_OR_STEP_FIRST resets anynull, otherwise it's the same
859  * as EEOP_BOOL_OR_STEP - so fall through to that.
860  */
861 
862  /* FALL THROUGH */
863  }
864 
866  {
867  if (*op->resnull)
868  {
869  *op->d.boolexpr.anynull = true;
870  }
871  else if (DatumGetBool(*op->resvalue))
872  {
873  /* result is already set to TRUE, need not change it */
874  /* bail out early */
875  EEO_JUMP(op->d.boolexpr.jumpdone);
876  }
877 
878  EEO_NEXT();
879  }
880 
882  {
883  if (*op->resnull)
884  {
885  /* result is already set to NULL, need not change it */
886  }
887  else if (DatumGetBool(*op->resvalue))
888  {
889  /* result is already set to TRUE, need not change it */
890 
891  /*
892  * No point jumping to jumpdone - would be same target (as
893  * this is the last argument to the AND expression), except
894  * more expensive.
895  */
896  }
897  else if (*op->d.boolexpr.anynull)
898  {
899  *op->resvalue = (Datum) 0;
900  *op->resnull = true;
901  }
902  else
903  {
904  /* result is already set to FALSE, need not change it */
905  }
906 
907  EEO_NEXT();
908  }
909 
911  {
912  /*
913  * Evaluation of 'not' is simple... if expr is false, then return
914  * 'true' and vice versa. It's safe to do this even on a
915  * nominally null value, so we ignore resnull; that means that
916  * NULL in produces NULL out, which is what we want.
917  */
919 
920  EEO_NEXT();
921  }
922 
924  {
925  /* simplified version of BOOL_AND_STEP for use by ExecQual() */
926 
927  /* If argument (also result) is false or null ... */
928  if (*op->resnull ||
929  !DatumGetBool(*op->resvalue))
930  {
931  /* ... bail out early, returning FALSE */
932  *op->resnull = false;
933  *op->resvalue = BoolGetDatum(false);
934  EEO_JUMP(op->d.qualexpr.jumpdone);
935  }
936 
937  /*
938  * Otherwise, leave the TRUE value in place, in case this is the
939  * last qual. Then, TRUE is the correct answer.
940  */
941 
942  EEO_NEXT();
943  }
944 
946  {
947  /* Unconditionally jump to target step */
948  EEO_JUMP(op->d.jump.jumpdone);
949  }
950 
952  {
953  /* Transfer control if current result is null */
954  if (*op->resnull)
955  EEO_JUMP(op->d.jump.jumpdone);
956 
957  EEO_NEXT();
958  }
959 
961  {
962  /* Transfer control if current result is non-null */
963  if (!*op->resnull)
964  EEO_JUMP(op->d.jump.jumpdone);
965 
966  EEO_NEXT();
967  }
968 
970  {
971  /* Transfer control if current result is null or false */
972  if (*op->resnull || !DatumGetBool(*op->resvalue))
973  EEO_JUMP(op->d.jump.jumpdone);
974 
975  EEO_NEXT();
976  }
977 
979  {
980  *op->resvalue = BoolGetDatum(*op->resnull);
981  *op->resnull = false;
982 
983  EEO_NEXT();
984  }
985 
987  {
988  *op->resvalue = BoolGetDatum(!*op->resnull);
989  *op->resnull = false;
990 
991  EEO_NEXT();
992  }
993 
995  {
996  /* out of line implementation: too large */
997  ExecEvalRowNull(state, op, econtext);
998 
999  EEO_NEXT();
1000  }
1001 
1003  {
1004  /* out of line implementation: too large */
1005  ExecEvalRowNotNull(state, op, econtext);
1006 
1007  EEO_NEXT();
1008  }
1009 
1010  /* BooleanTest implementations for all booltesttypes */
1011 
1013  {
1014  if (*op->resnull)
1015  {
1016  *op->resvalue = BoolGetDatum(false);
1017  *op->resnull = false;
1018  }
1019  /* else, input value is the correct output as well */
1020 
1021  EEO_NEXT();
1022  }
1023 
1025  {
1026  if (*op->resnull)
1027  {
1028  *op->resvalue = BoolGetDatum(true);
1029  *op->resnull = false;
1030  }
1031  else
1032  *op->resvalue = BoolGetDatum(!DatumGetBool(*op->resvalue));
1033 
1034  EEO_NEXT();
1035  }
1036 
1038  {
1039  if (*op->resnull)
1040  {
1041  *op->resvalue = BoolGetDatum(false);
1042  *op->resnull = false;
1043  }
1044  else
1045  *op->resvalue = BoolGetDatum(!DatumGetBool(*op->resvalue));
1046 
1047  EEO_NEXT();
1048  }
1049 
1051  {
1052  if (*op->resnull)
1053  {
1054  *op->resvalue = BoolGetDatum(true);
1055  *op->resnull = false;
1056  }
1057  /* else, input value is the correct output as well */
1058 
1059  EEO_NEXT();
1060  }
1061 
1063  {
1064  /* out of line implementation: too large */
1065  ExecEvalParamExec(state, op, econtext);
1066 
1067  EEO_NEXT();
1068  }
1069 
1071  {
1072  /* out of line implementation: too large */
1073  ExecEvalParamExtern(state, op, econtext);
1074  EEO_NEXT();
1075  }
1076 
1078  {
1079  /* allow an extension module to supply a PARAM_EXTERN value */
1080  op->d.cparam.paramfunc(state, op, econtext);
1081  EEO_NEXT();
1082  }
1083 
1085  {
1086  /*
1087  * Normally upper parts of the expression tree have setup the
1088  * values to be returned here, but some parts of the system
1089  * currently misuse {caseValue,domainValue}_{datum,isNull} to set
1090  * run-time data. So if no values have been set-up, use
1091  * ExprContext's. This isn't pretty, but also not *that* ugly,
1092  * and this is unlikely to be performance sensitive enough to
1093  * worry about an extra branch.
1094  */
1095  if (op->d.casetest.value)
1096  {
1097  *op->resvalue = *op->d.casetest.value;
1098  *op->resnull = *op->d.casetest.isnull;
1099  }
1100  else
1101  {
1102  *op->resvalue = econtext->caseValue_datum;
1103  *op->resnull = econtext->caseValue_isNull;
1104  }
1105 
1106  EEO_NEXT();
1107  }
1108 
1110  {
1111  /*
1112  * See EEOP_CASE_TESTVAL comment.
1113  */
1114  if (op->d.casetest.value)
1115  {
1116  *op->resvalue = *op->d.casetest.value;
1117  *op->resnull = *op->d.casetest.isnull;
1118  }
1119  else
1120  {
1121  *op->resvalue = econtext->domainValue_datum;
1122  *op->resnull = econtext->domainValue_isNull;
1123  }
1124 
1125  EEO_NEXT();
1126  }
1127 
1129  {
1130  /*
1131  * Force a varlena value that might be read multiple times to R/O
1132  */
1133  if (!*op->d.make_readonly.isnull)
1134  *op->resvalue =
1136  *op->resnull = *op->d.make_readonly.isnull;
1137 
1138  EEO_NEXT();
1139  }
1140 
1142  {
1143  /*
1144  * Evaluate a CoerceViaIO node. This can be quite a hot path, so
1145  * inline as much work as possible. The source value is in our
1146  * result variable.
1147  */
1148  char *str;
1149 
1150  /* call output function (similar to OutputFunctionCall) */
1151  if (*op->resnull)
1152  {
1153  /* output functions are not called on nulls */
1154  str = NULL;
1155  }
1156  else
1157  {
1158  FunctionCallInfo fcinfo_out;
1159 
1160  fcinfo_out = op->d.iocoerce.fcinfo_data_out;
1161  fcinfo_out->args[0].value = *op->resvalue;
1162  fcinfo_out->args[0].isnull = false;
1163 
1164  fcinfo_out->isnull = false;
1165  str = DatumGetCString(FunctionCallInvoke(fcinfo_out));
1166 
1167  /* OutputFunctionCall assumes result isn't null */
1168  Assert(!fcinfo_out->isnull);
1169  }
1170 
1171  /* call input function (similar to InputFunctionCall) */
1172  if (!op->d.iocoerce.finfo_in->fn_strict || str != NULL)
1173  {
1174  FunctionCallInfo fcinfo_in;
1175  Datum d;
1176 
1177  fcinfo_in = op->d.iocoerce.fcinfo_data_in;
1178  fcinfo_in->args[0].value = PointerGetDatum(str);
1179  fcinfo_in->args[0].isnull = *op->resnull;
1180  /* second and third arguments are already set up */
1181 
1182  fcinfo_in->isnull = false;
1183  d = FunctionCallInvoke(fcinfo_in);
1184  *op->resvalue = d;
1185 
1186  /* Should get null result if and only if str is NULL */
1187  if (str == NULL)
1188  {
1189  Assert(*op->resnull);
1190  Assert(fcinfo_in->isnull);
1191  }
1192  else
1193  {
1194  Assert(!*op->resnull);
1195  Assert(!fcinfo_in->isnull);
1196  }
1197  }
1198 
1199  EEO_NEXT();
1200  }
1201 
1203  {
1204  /*
1205  * IS DISTINCT FROM must evaluate arguments (already done into
1206  * fcinfo->args) to determine whether they are NULL; if either is
1207  * NULL then the result is determined. If neither is NULL, then
1208  * proceed to evaluate the comparison function, which is just the
1209  * type's standard equality operator. We need not care whether
1210  * that function is strict. Because the handling of nulls is
1211  * different, we can't just reuse EEOP_FUNCEXPR.
1212  */
1213  FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
1214 
1215  /* check function arguments for NULLness */
1216  if (fcinfo->args[0].isnull && fcinfo->args[1].isnull)
1217  {
1218  /* Both NULL? Then is not distinct... */
1219  *op->resvalue = BoolGetDatum(false);
1220  *op->resnull = false;
1221  }
1222  else if (fcinfo->args[0].isnull || fcinfo->args[1].isnull)
1223  {
1224  /* Only one is NULL? Then is distinct... */
1225  *op->resvalue = BoolGetDatum(true);
1226  *op->resnull = false;
1227  }
1228  else
1229  {
1230  /* Neither null, so apply the equality function */
1231  Datum eqresult;
1232 
1233  fcinfo->isnull = false;
1234  eqresult = op->d.func.fn_addr(fcinfo);
1235  /* Must invert result of "="; safe to do even if null */
1236  *op->resvalue = BoolGetDatum(!DatumGetBool(eqresult));
1237  *op->resnull = fcinfo->isnull;
1238  }
1239 
1240  EEO_NEXT();
1241  }
1242 
1243  /* see EEOP_DISTINCT for comments, this is just inverted */
1245  {
1246  FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
1247 
1248  if (fcinfo->args[0].isnull && fcinfo->args[1].isnull)
1249  {
1250  *op->resvalue = BoolGetDatum(true);
1251  *op->resnull = false;
1252  }
1253  else if (fcinfo->args[0].isnull || fcinfo->args[1].isnull)
1254  {
1255  *op->resvalue = BoolGetDatum(false);
1256  *op->resnull = false;
1257  }
1258  else
1259  {
1260  Datum eqresult;
1261 
1262  fcinfo->isnull = false;
1263  eqresult = op->d.func.fn_addr(fcinfo);
1264  *op->resvalue = eqresult;
1265  *op->resnull = fcinfo->isnull;
1266  }
1267 
1268  EEO_NEXT();
1269  }
1270 
1272  {
1273  /*
1274  * The arguments are already evaluated into fcinfo->args.
1275  */
1276  FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
1277 
1278  /* if either argument is NULL they can't be equal */
1279  if (!fcinfo->args[0].isnull && !fcinfo->args[1].isnull)
1280  {
1281  Datum result;
1282 
1283  fcinfo->isnull = false;
1284  result = op->d.func.fn_addr(fcinfo);
1285 
1286  /* if the arguments are equal return null */
1287  if (!fcinfo->isnull && DatumGetBool(result))
1288  {
1289  *op->resvalue = (Datum) 0;
1290  *op->resnull = true;
1291 
1292  EEO_NEXT();
1293  }
1294  }
1295 
1296  /* Arguments aren't equal, so return the first one */
1297  *op->resvalue = fcinfo->args[0].value;
1298  *op->resnull = fcinfo->args[0].isnull;
1299 
1300  EEO_NEXT();
1301  }
1302 
1304  {
1305  /* error invocation uses space, and shouldn't ever occur */
1307 
1308  EEO_NEXT();
1309  }
1310 
1312  {
1313  /*
1314  * Doesn't seem worthwhile to have an inline implementation
1315  * efficiency-wise.
1316  */
1318 
1319  EEO_NEXT();
1320  }
1321 
1323  {
1324  /* too complex for an inline implementation */
1325  ExecEvalArrayExpr(state, op);
1326 
1327  EEO_NEXT();
1328  }
1329 
1331  {
1332  /* too complex for an inline implementation */
1333  ExecEvalArrayCoerce(state, op, econtext);
1334 
1335  EEO_NEXT();
1336  }
1337 
1339  {
1340  /* too complex for an inline implementation */
1341  ExecEvalRow(state, op);
1342 
1343  EEO_NEXT();
1344  }
1345 
1347  {
1348  FunctionCallInfo fcinfo = op->d.rowcompare_step.fcinfo_data;
1349  Datum d;
1350 
1351  /* force NULL result if strict fn and NULL input */
1352  if (op->d.rowcompare_step.finfo->fn_strict &&
1353  (fcinfo->args[0].isnull || fcinfo->args[1].isnull))
1354  {
1355  *op->resnull = true;
1356  EEO_JUMP(op->d.rowcompare_step.jumpnull);
1357  }
1358 
1359  /* Apply comparison function */
1360  fcinfo->isnull = false;
1361  d = op->d.rowcompare_step.fn_addr(fcinfo);
1362  *op->resvalue = d;
1363 
1364  /* force NULL result if NULL function result */
1365  if (fcinfo->isnull)
1366  {
1367  *op->resnull = true;
1368  EEO_JUMP(op->d.rowcompare_step.jumpnull);
1369  }
1370  *op->resnull = false;
1371 
1372  /* If unequal, no need to compare remaining columns */
1373  if (DatumGetInt32(*op->resvalue) != 0)
1374  {
1375  EEO_JUMP(op->d.rowcompare_step.jumpdone);
1376  }
1377 
1378  EEO_NEXT();
1379  }
1380 
1382  {
1383  int32 cmpresult = DatumGetInt32(*op->resvalue);
1384  RowCompareType rctype = op->d.rowcompare_final.rctype;
1385 
1386  *op->resnull = false;
1387  switch (rctype)
1388  {
1389  /* EQ and NE cases aren't allowed here */
1390  case ROWCOMPARE_LT:
1391  *op->resvalue = BoolGetDatum(cmpresult < 0);
1392  break;
1393  case ROWCOMPARE_LE:
1394  *op->resvalue = BoolGetDatum(cmpresult <= 0);
1395  break;
1396  case ROWCOMPARE_GE:
1397  *op->resvalue = BoolGetDatum(cmpresult >= 0);
1398  break;
1399  case ROWCOMPARE_GT:
1400  *op->resvalue = BoolGetDatum(cmpresult > 0);
1401  break;
1402  default:
1403  Assert(false);
1404  break;
1405  }
1406 
1407  EEO_NEXT();
1408  }
1409 
1411  {
1412  /* too complex for an inline implementation */
1413  ExecEvalMinMax(state, op);
1414 
1415  EEO_NEXT();
1416  }
1417 
1419  {
1420  /* too complex for an inline implementation */
1421  ExecEvalFieldSelect(state, op, econtext);
1422 
1423  EEO_NEXT();
1424  }
1425 
1427  {
1428  /* too complex for an inline implementation */
1429  ExecEvalFieldStoreDeForm(state, op, econtext);
1430 
1431  EEO_NEXT();
1432  }
1433 
1435  {
1436  /* too complex for an inline implementation */
1437  ExecEvalFieldStoreForm(state, op, econtext);
1438 
1439  EEO_NEXT();
1440  }
1441 
1443  {
1444  /* Precheck SubscriptingRef subscript(s) */
1445  if (op->d.sbsref_subscript.subscriptfunc(state, op, econtext))
1446  {
1447  EEO_NEXT();
1448  }
1449  else
1450  {
1451  /* Subscript is null, short-circuit SubscriptingRef to NULL */
1452  EEO_JUMP(op->d.sbsref_subscript.jumpdone);
1453  }
1454  }
1455 
1459  {
1460  /* Perform a SubscriptingRef fetch or assignment */
1461  op->d.sbsref.subscriptfunc(state, op, econtext);
1462 
1463  EEO_NEXT();
1464  }
1465 
1467  {
1468  /* too complex for an inline implementation */
1469  ExecEvalConvertRowtype(state, op, econtext);
1470 
1471  EEO_NEXT();
1472  }
1473 
1475  {
1476  /* too complex for an inline implementation */
1478 
1479  EEO_NEXT();
1480  }
1481 
1483  {
1484  /* too complex for an inline implementation */
1485  ExecEvalHashedScalarArrayOp(state, op, econtext);
1486 
1487  EEO_NEXT();
1488  }
1489 
1491  {
1492  /* too complex for an inline implementation */
1494 
1495  EEO_NEXT();
1496  }
1497 
1499  {
1500  /* too complex for an inline implementation */
1502 
1503  EEO_NEXT();
1504  }
1505 
1507  {
1508  /* too complex for an inline implementation */
1509  ExecEvalXmlExpr(state, op);
1510 
1511  EEO_NEXT();
1512  }
1513 
1515  {
1516  /*
1517  * Returns a Datum whose value is the precomputed aggregate value
1518  * found in the given expression context.
1519  */
1520  int aggno = op->d.aggref.aggno;
1521 
1522  Assert(econtext->ecxt_aggvalues != NULL);
1523 
1524  *op->resvalue = econtext->ecxt_aggvalues[aggno];
1525  *op->resnull = econtext->ecxt_aggnulls[aggno];
1526 
1527  EEO_NEXT();
1528  }
1529 
1531  {
1532  /* too complex/uncommon for an inline implementation */
1534 
1535  EEO_NEXT();
1536  }
1537 
1539  {
1540  /*
1541  * Like Aggref, just return a precomputed value from the econtext.
1542  */
1543  WindowFuncExprState *wfunc = op->d.window_func.wfstate;
1544 
1545  Assert(econtext->ecxt_aggvalues != NULL);
1546 
1547  *op->resvalue = econtext->ecxt_aggvalues[wfunc->wfuncno];
1548  *op->resnull = econtext->ecxt_aggnulls[wfunc->wfuncno];
1549 
1550  EEO_NEXT();
1551  }
1552 
1554  {
1555  /* too complex for an inline implementation */
1556  ExecEvalSubPlan(state, op, econtext);
1557 
1558  EEO_NEXT();
1559  }
1560 
1561  /* evaluate a strict aggregate deserialization function */
1563  {
1564  /* Don't call a strict deserialization function with NULL input */
1565  if (op->d.agg_deserialize.fcinfo_data->args[0].isnull)
1566  EEO_JUMP(op->d.agg_deserialize.jumpnull);
1567 
1568  /* fallthrough */
1569  }
1570 
1571  /* evaluate aggregate deserialization function (non-strict portion) */
1573  {
1574  FunctionCallInfo fcinfo = op->d.agg_deserialize.fcinfo_data;
1575  AggState *aggstate = castNode(AggState, state->parent);
1576  MemoryContext oldContext;
1577 
1578  /*
1579  * We run the deserialization functions in per-input-tuple memory
1580  * context.
1581  */
1582  oldContext = MemoryContextSwitchTo(aggstate->tmpcontext->ecxt_per_tuple_memory);
1583  fcinfo->isnull = false;
1584  *op->resvalue = FunctionCallInvoke(fcinfo);
1585  *op->resnull = fcinfo->isnull;
1586  MemoryContextSwitchTo(oldContext);
1587 
1588  EEO_NEXT();
1589  }
1590 
1591  /*
1592  * Check that a strict aggregate transition / combination function's
1593  * input is not NULL.
1594  */
1595 
1597  {
1599  int nargs = op->d.agg_strict_input_check.nargs;
1600 
1601  for (int argno = 0; argno < nargs; argno++)
1602  {
1603  if (args[argno].isnull)
1604  EEO_JUMP(op->d.agg_strict_input_check.jumpnull);
1605  }
1606  EEO_NEXT();
1607  }
1608 
1610  {
1611  bool *nulls = op->d.agg_strict_input_check.nulls;
1612  int nargs = op->d.agg_strict_input_check.nargs;
1613 
1614  for (int argno = 0; argno < nargs; argno++)
1615  {
1616  if (nulls[argno])
1617  EEO_JUMP(op->d.agg_strict_input_check.jumpnull);
1618  }
1619  EEO_NEXT();
1620  }
1621 
1622  /*
1623  * Check for a NULL pointer to the per-group states.
1624  */
1625 
1627  {
1628  AggState *aggstate = castNode(AggState, state->parent);
1629  AggStatePerGroup pergroup_allaggs =
1630  aggstate->all_pergroups[op->d.agg_plain_pergroup_nullcheck.setoff];
1631 
1632  if (pergroup_allaggs == NULL)
1633  EEO_JUMP(op->d.agg_plain_pergroup_nullcheck.jumpnull);
1634 
1635  EEO_NEXT();
1636  }
1637 
1638  /*
1639  * Different types of aggregate transition functions are implemented
1640  * as different types of steps, to avoid incurring unnecessary
1641  * overhead. There's a step type for each valid combination of having
1642  * a by value / by reference transition type, [not] needing to the
1643  * initialize the transition value for the first row in a group from
1644  * input, and [not] strict transition function.
1645  *
1646  * Could optimize further by splitting off by-reference for
1647  * fixed-length types, but currently that doesn't seem worth it.
1648  */
1649 
1651  {
1652  AggState *aggstate = castNode(AggState, state->parent);
1653  AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
1654  AggStatePerGroup pergroup =
1655  &aggstate->all_pergroups[op->d.agg_trans.setoff][op->d.agg_trans.transno];
1656 
1657  Assert(pertrans->transtypeByVal);
1658 
1659  if (pergroup->noTransValue)
1660  {
1661  /* If transValue has not yet been initialized, do so now. */
1662  ExecAggInitGroup(aggstate, pertrans, pergroup,
1663  op->d.agg_trans.aggcontext);
1664  /* copied trans value from input, done this round */
1665  }
1666  else if (likely(!pergroup->transValueIsNull))
1667  {
1668  /* invoke transition function, unless prevented by strictness */
1669  ExecAggPlainTransByVal(aggstate, pertrans, pergroup,
1670  op->d.agg_trans.aggcontext,
1671  op->d.agg_trans.setno);
1672  }
1673 
1674  EEO_NEXT();
1675  }
1676 
1677  /* see comments above EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYVAL */
1679  {
1680  AggState *aggstate = castNode(AggState, state->parent);
1681  AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
1682  AggStatePerGroup pergroup =
1683  &aggstate->all_pergroups[op->d.agg_trans.setoff][op->d.agg_trans.transno];
1684 
1685  Assert(pertrans->transtypeByVal);
1686 
1687  if (likely(!pergroup->transValueIsNull))
1688  ExecAggPlainTransByVal(aggstate, pertrans, pergroup,
1689  op->d.agg_trans.aggcontext,
1690  op->d.agg_trans.setno);
1691 
1692  EEO_NEXT();
1693  }
1694 
1695  /* see comments above EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYVAL */
1697  {
1698  AggState *aggstate = castNode(AggState, state->parent);
1699  AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
1700  AggStatePerGroup pergroup =
1701  &aggstate->all_pergroups[op->d.agg_trans.setoff][op->d.agg_trans.transno];
1702 
1703  Assert(pertrans->transtypeByVal);
1704 
1705  ExecAggPlainTransByVal(aggstate, pertrans, pergroup,
1706  op->d.agg_trans.aggcontext,
1707  op->d.agg_trans.setno);
1708 
1709  EEO_NEXT();
1710  }
1711 
1712  /* see comments above EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYVAL */
1714  {
1715  AggState *aggstate = castNode(AggState, state->parent);
1716  AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
1717  AggStatePerGroup pergroup =
1718  &aggstate->all_pergroups[op->d.agg_trans.setoff][op->d.agg_trans.transno];
1719 
1720  Assert(!pertrans->transtypeByVal);
1721 
1722  if (pergroup->noTransValue)
1723  ExecAggInitGroup(aggstate, pertrans, pergroup,
1724  op->d.agg_trans.aggcontext);
1725  else if (likely(!pergroup->transValueIsNull))
1726  ExecAggPlainTransByRef(aggstate, pertrans, pergroup,
1727  op->d.agg_trans.aggcontext,
1728  op->d.agg_trans.setno);
1729 
1730  EEO_NEXT();
1731  }
1732 
1733  /* see comments above EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYVAL */
1735  {
1736  AggState *aggstate = castNode(AggState, state->parent);
1737  AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
1738  AggStatePerGroup pergroup =
1739  &aggstate->all_pergroups[op->d.agg_trans.setoff][op->d.agg_trans.transno];
1740 
1741  Assert(!pertrans->transtypeByVal);
1742 
1743  if (likely(!pergroup->transValueIsNull))
1744  ExecAggPlainTransByRef(aggstate, pertrans, pergroup,
1745  op->d.agg_trans.aggcontext,
1746  op->d.agg_trans.setno);
1747  EEO_NEXT();
1748  }
1749 
1750  /* see comments above EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYVAL */
1752  {
1753  AggState *aggstate = castNode(AggState, state->parent);
1754  AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
1755  AggStatePerGroup pergroup =
1756  &aggstate->all_pergroups[op->d.agg_trans.setoff][op->d.agg_trans.transno];
1757 
1758  Assert(!pertrans->transtypeByVal);
1759 
1760  ExecAggPlainTransByRef(aggstate, pertrans, pergroup,
1761  op->d.agg_trans.aggcontext,
1762  op->d.agg_trans.setno);
1763 
1764  EEO_NEXT();
1765  }
1766 
1768  {
1769  AggStatePerTrans pertrans = op->d.agg_presorted_distinctcheck.pertrans;
1770  AggState *aggstate = castNode(AggState, state->parent);
1771 
1772  if (ExecEvalPreOrderedDistinctSingle(aggstate, pertrans))
1773  EEO_NEXT();
1774  else
1775  EEO_JUMP(op->d.agg_presorted_distinctcheck.jumpdistinct);
1776  }
1777 
1779  {
1780  AggState *aggstate = castNode(AggState, state->parent);
1781  AggStatePerTrans pertrans = op->d.agg_presorted_distinctcheck.pertrans;
1782 
1783  if (ExecEvalPreOrderedDistinctMulti(aggstate, pertrans))
1784  EEO_NEXT();
1785  else
1786  EEO_JUMP(op->d.agg_presorted_distinctcheck.jumpdistinct);
1787  }
1788 
1789  /* process single-column ordered aggregate datum */
1791  {
1792  /* too complex for an inline implementation */
1793  ExecEvalAggOrderedTransDatum(state, op, econtext);
1794 
1795  EEO_NEXT();
1796  }
1797 
1798  /* process multi-column ordered aggregate tuple */
1800  {
1801  /* too complex for an inline implementation */
1802  ExecEvalAggOrderedTransTuple(state, op, econtext);
1803 
1804  EEO_NEXT();
1805  }
1806 
1808  {
1809  /* unreachable */
1810  Assert(false);
1811  goto out;
1812  }
1813  }
1814 
1815 out:
1816  *isnull = state->resnull;
1817  return state->resvalue;
1818 }
#define lengthof(array)
Definition: c.h:724
#define StaticAssertStmt(condition, errmessage)
Definition: c.h:869
void ExecEvalParamExtern(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
void ExecEvalFieldStoreForm(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
void ExecEvalGroupingFunc(ExprState *state, ExprEvalStep *op)
void ExecEvalRow(ExprState *state, ExprEvalStep *op)
void ExecEvalFieldStoreDeForm(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
void ExecEvalCurrentOfExpr(ExprState *state, ExprEvalStep *op)
#define EEO_SWITCH()
void ExecEvalRowNull(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
#define EEO_DISPATCH()
void ExecEvalArrayExpr(ExprState *state, ExprEvalStep *op)
static pg_attribute_always_inline void ExecAggPlainTransByVal(AggState *aggstate, AggStatePerTrans pertrans, AggStatePerGroup pergroup, ExprContext *aggcontext, int setno)
void ExecEvalConvertRowtype(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
bool ExecEvalPreOrderedDistinctMulti(AggState *aggstate, AggStatePerTrans pertrans)
void ExecEvalFieldSelect(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
void ExecEvalConstraintNotNull(ExprState *state, ExprEvalStep *op)
#define EEO_NEXT()
void ExecEvalScalarArrayOp(ExprState *state, ExprEvalStep *op)
void ExecEvalAggOrderedTransDatum(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
void ExecEvalParamExec(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
void ExecAggInitGroup(AggState *aggstate, AggStatePerTrans pertrans, AggStatePerGroup pergroup, ExprContext *aggcontext)
void ExecEvalNextValueExpr(ExprState *state, ExprEvalStep *op)
void ExecEvalSysVar(ExprState *state, ExprEvalStep *op, ExprContext *econtext, TupleTableSlot *slot)
void ExecEvalMinMax(ExprState *state, ExprEvalStep *op)
void ExecEvalSubPlan(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
void ExecEvalWholeRowVar(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
void ExecEvalHashedScalarArrayOp(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
void ExecEvalRowNotNull(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
void ExecEvalConstraintCheck(ExprState *state, ExprEvalStep *op)
void ExecEvalArrayCoerce(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
static void CheckOpSlotCompatibility(ExprEvalStep *op, TupleTableSlot *slot)
void ExecEvalFuncExprStrictFusage(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
#define EEO_CASE(name)
void ExecEvalFuncExprFusage(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
void ExecEvalXmlExpr(ExprState *state, ExprEvalStep *op)
bool ExecEvalPreOrderedDistinctSingle(AggState *aggstate, AggStatePerTrans pertrans)
static pg_attribute_always_inline void ExecAggPlainTransByRef(AggState *aggstate, AggStatePerTrans pertrans, AggStatePerGroup pergroup, ExprContext *aggcontext, int setno)
void ExecEvalAggOrderedTransTuple(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
#define EEO_JUMP(stepno)
@ EEOP_ASSIGN_TMP
Definition: execExpr.h:97
@ EEOP_SUBPLAN
Definition: execExpr.h:240
@ EEOP_CONVERT_ROWTYPE
Definition: execExpr.h:233
@ EEOP_FUNCEXPR_STRICT_FUSAGE
Definition: execExpr.h:112
@ EEOP_ARRAYEXPR
Definition: execExpr.h:175
@ EEOP_NOT_DISTINCT
Definition: execExpr.h:171
@ EEOP_DOMAIN_TESTVAL
Definition: execExpr.h:224
@ EEOP_PARAM_EXTERN
Definition: execExpr.h:159
@ EEOP_BOOL_AND_STEP
Definition: execExpr.h:121
@ EEOP_WHOLEROW
Definition: execExpr.h:85
@ EEOP_AGGREF
Definition: execExpr.h:237
@ EEOP_AGG_PLAIN_PERGROUP_NULLCHECK
Definition: execExpr.h:247
@ EEOP_ROWCOMPARE_FINAL
Definition: execExpr.h:186
@ EEOP_AGG_STRICT_DESERIALIZE
Definition: execExpr.h:243
@ EEOP_IOCOERCE
Definition: execExpr.h:169
@ EEOP_GROUPING_FUNC
Definition: execExpr.h:238
@ EEOP_DOMAIN_CHECK
Definition: execExpr.h:230
@ EEOP_BOOLTEST_IS_NOT_FALSE
Definition: execExpr.h:155
@ EEOP_NEXTVALUEEXPR
Definition: execExpr.h:174
@ EEOP_DONE
Definition: execExpr.h:67
@ EEOP_AGG_PLAIN_TRANS_BYREF
Definition: execExpr.h:253
@ EEOP_QUAL
Definition: execExpr.h:133
@ EEOP_AGG_PRESORTED_DISTINCT_MULTI
Definition: execExpr.h:255
@ EEOP_AGG_PLAIN_TRANS_BYVAL
Definition: execExpr.h:250
@ EEOP_BOOL_NOT_STEP
Definition: execExpr.h:130
@ EEOP_ASSIGN_SCAN_VAR
Definition: execExpr.h:94
@ EEOP_SCAN_SYSVAR
Definition: execExpr.h:82
@ EEOP_SCALARARRAYOP
Definition: execExpr.h:234
@ EEOP_DOMAIN_NOTNULL
Definition: execExpr.h:227
@ EEOP_WINDOW_FUNC
Definition: execExpr.h:239
@ EEOP_INNER_FETCHSOME
Definition: execExpr.h:70
@ EEOP_NULLTEST_ROWISNOTNULL
Definition: execExpr.h:149
@ EEOP_ASSIGN_OUTER_VAR
Definition: execExpr.h:93
@ EEOP_ROW
Definition: execExpr.h:177
@ EEOP_MAKE_READONLY
Definition: execExpr.h:166
@ EEOP_FIELDSTORE_FORM
Definition: execExpr.h:205
@ EEOP_SBSREF_SUBSCRIPTS
Definition: execExpr.h:208
@ EEOP_SBSREF_FETCH
Definition: execExpr.h:221
@ EEOP_FUNCEXPR_STRICT
Definition: execExpr.h:110
@ EEOP_NULLIF
Definition: execExpr.h:172
@ EEOP_CURRENTOFEXPR
Definition: execExpr.h:173
@ EEOP_INNER_SYSVAR
Definition: execExpr.h:80
@ EEOP_ASSIGN_TMP_MAKE_RO
Definition: execExpr.h:99
@ EEOP_CONST
Definition: execExpr.h:102
@ EEOP_BOOL_OR_STEP_LAST
Definition: execExpr.h:127
@ EEOP_BOOL_OR_STEP_FIRST
Definition: execExpr.h:125
@ EEOP_XMLEXPR
Definition: execExpr.h:236
@ EEOP_AGG_STRICT_INPUT_CHECK_NULLS
Definition: execExpr.h:246
@ EEOP_SBSREF_ASSIGN
Definition: execExpr.h:218
@ EEOP_OUTER_SYSVAR
Definition: execExpr.h:81
@ EEOP_ASSIGN_INNER_VAR
Definition: execExpr.h:92
@ EEOP_BOOL_OR_STEP
Definition: execExpr.h:126
@ EEOP_OUTER_FETCHSOME
Definition: execExpr.h:71
@ EEOP_AGG_STRICT_INPUT_CHECK_ARGS
Definition: execExpr.h:245
@ EEOP_NULLTEST_ROWISNULL
Definition: execExpr.h:148
@ EEOP_BOOLTEST_IS_TRUE
Definition: execExpr.h:152
@ EEOP_FUNCEXPR
Definition: execExpr.h:109
@ EEOP_NULLTEST_ISNOTNULL
Definition: execExpr.h:145
@ EEOP_ROWCOMPARE_STEP
Definition: execExpr.h:183
@ EEOP_AGG_DESERIALIZE
Definition: execExpr.h:244
@ EEOP_DISTINCT
Definition: execExpr.h:170
@ EEOP_JUMP_IF_NOT_TRUE
Definition: execExpr.h:141
@ EEOP_FUNCEXPR_FUSAGE
Definition: execExpr.h:111
@ EEOP_AGG_PRESORTED_DISTINCT_SINGLE
Definition: execExpr.h:254
@ EEOP_BOOL_AND_STEP_FIRST
Definition: execExpr.h:120
@ EEOP_JUMP
Definition: execExpr.h:136
@ EEOP_PARAM_CALLBACK
Definition: execExpr.h:160
@ EEOP_BOOL_AND_STEP_LAST
Definition: execExpr.h:122
@ EEOP_AGG_ORDERED_TRANS_DATUM
Definition: execExpr.h:256
@ EEOP_SBSREF_OLD
Definition: execExpr.h:215
@ EEOP_JUMP_IF_NOT_NULL
Definition: execExpr.h:140
@ EEOP_AGG_PLAIN_TRANS_STRICT_BYREF
Definition: execExpr.h:252
@ EEOP_FIELDSTORE_DEFORM
Definition: execExpr.h:198
@ EEOP_BOOLTEST_IS_FALSE
Definition: execExpr.h:154
@ EEOP_BOOLTEST_IS_NOT_TRUE
Definition: execExpr.h:153
@ EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYVAL
Definition: execExpr.h:248
@ EEOP_PARAM_EXEC
Definition: execExpr.h:158
@ EEOP_AGG_PLAIN_TRANS_STRICT_BYVAL
Definition: execExpr.h:249
@ EEOP_NULLTEST_ISNULL
Definition: execExpr.h:144
@ EEOP_MINMAX
Definition: execExpr.h:189
@ EEOP_JUMP_IF_NULL
Definition: execExpr.h:139
@ EEOP_ARRAYCOERCE
Definition: execExpr.h:176
@ EEOP_FIELDSELECT
Definition: execExpr.h:192
@ EEOP_CASE_TESTVAL
Definition: execExpr.h:163
@ EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYREF
Definition: execExpr.h:251
@ EEOP_HASHED_SCALARARRAYOP
Definition: execExpr.h:235
@ EEOP_AGG_ORDERED_TRANS_TUPLE
Definition: execExpr.h:257
@ EEOP_SCAN_FETCHSOME
Definition: execExpr.h:72
Datum MakeExpandedObjectReadOnlyInternal(Datum d)
Definition: expandeddatum.c:95
static char * DatumGetCString(Datum X)
Definition: postgres.h:683
RowCompareType
Definition: primnodes.h:1242
@ ROWCOMPARE_GT
Definition: primnodes.h:1248
@ ROWCOMPARE_LT
Definition: primnodes.h:1244
@ ROWCOMPARE_LE
Definition: primnodes.h:1245
@ ROWCOMPARE_GE
Definition: primnodes.h:1247
AggStatePerGroup * all_pergroups
Definition: execnodes.h:2427
Datum domainValue_datum
Definition: execnodes.h:278
Datum * ecxt_aggvalues
Definition: execnodes.h:266
bool caseValue_isNull
Definition: execnodes.h:274
Datum caseValue_datum
Definition: execnodes.h:272
bool * ecxt_aggnulls
Definition: execnodes.h:268
bool domainValue_isNull
Definition: execnodes.h:280
struct ExprEvalStep::@50::@58 boolexpr
struct ExprEvalStep::@50::@71 rowcompare_step
struct ExprEvalStep::@50::@87 agg_deserialize
struct ExprEvalStep::@50::@88 agg_strict_input_check
struct ExprEvalStep::@50::@72 rowcompare_final
struct ExprEvalStep::@50::@59 qualexpr
struct ExprEvalStep::@50::@83 aggref
struct ExprEvalStep::@50::@60 jump
struct ExprEvalStep::@50::@56 constval
struct ExprEvalStep::@50::@65 make_readonly
struct ExprEvalStep::@50::@76 sbsref_subscript
struct ExprEvalStep::@50::@63 cparam
struct ExprEvalStep::@50::@54 assign_var
struct ExprEvalStep::@50::@89 agg_plain_pergroup_nullcheck
struct ExprEvalStep::@50::@66 iocoerce
struct ExprEvalStep::@50::@55 assign_tmp
struct ExprEvalStep::@50::@85 window_func
struct ExprEvalStep::@50::@64 casetest
struct ExprEvalStep::@50::@90 agg_presorted_distinctcheck
struct ExprEvalStep::@50::@77 sbsref
static void slot_getsomeattrs(TupleTableSlot *slot, int attnum)
Definition: tuptable.h:349

References ExprEvalStep::aggno, AggState::all_pergroups, generate_unaccent_rules::args, FunctionCallInfoBaseData::args, Assert(), attnum, BoolGetDatum(), ExprContext::caseValue_datum, ExprContext::caseValue_isNull, castNode, CheckOpSlotCompatibility(), 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_PRESORTED_DISTINCT_MULTI, EEOP_AGG_PRESORTED_DISTINCT_SINGLE, EEOP_AGG_STRICT_DESERIALIZE, EEOP_AGG_STRICT_INPUT_CHECK_ARGS, EEOP_AGG_STRICT_INPUT_CHECK_NULLS, EEOP_AGGREF, 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_HASHED_SCALARARRAYOP, 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_SUBSCRIPTS, EEOP_SCALARARRAYOP, EEOP_SCAN_FETCHSOME, EEOP_SCAN_SYSVAR, EEOP_SCAN_VAR, EEOP_SUBPLAN, EEOP_WHOLEROW, EEOP_WINDOW_FUNC, EEOP_XMLEXPR, ExecAggInitGroup(), ExecAggPlainTransByRef(), ExecAggPlainTransByVal(), ExecEvalAggOrderedTransDatum(), ExecEvalAggOrderedTransTuple(), ExecEvalArrayCoerce(), ExecEvalArrayExpr(), ExecEvalConstraintCheck(), ExecEvalConstraintNotNull(), ExecEvalConvertRowtype(), ExecEvalCurrentOfExpr(), ExecEvalFieldSelect(), ExecEvalFieldStoreDeForm(), ExecEvalFieldStoreForm(), ExecEvalFuncExprFusage(), ExecEvalFuncExprStrictFusage(), ExecEvalGroupingFunc(), ExecEvalHashedScalarArrayOp(), ExecEvalMinMax(), ExecEvalNextValueExpr(), ExecEvalParamExec(), ExecEvalParamExtern(), ExecEvalPreOrderedDistinctMulti(), ExecEvalPreOrderedDistinctSingle(), ExecEvalRow(), ExecEvalRowNotNull(), ExecEvalRowNull(), ExecEvalScalarArrayOp(), ExecEvalSubPlan(), ExecEvalSysVar(), ExecEvalWholeRowVar(), ExecEvalXmlExpr(), FunctionCallInvoke, ExprEvalStep::isnull, FunctionCallInfoBaseData::isnull, NullableDatum::isnull, lengthof, likely, MakeExpandedObjectReadOnlyInternal(), MemoryContextSwitchTo(), ExprEvalStep::nargs, AggStatePerGroupData::noTransValue, ExprEvalStep::nulls, ExprEvalStep::op, ExprEvalStep::pertrans, PointerGetDatum(), ExprEvalStep::rctype, ExprEvalStep::resultnum, ROWCOMPARE_GE, ROWCOMPARE_GT, ROWCOMPARE_LE, ROWCOMPARE_LT, slot_getsomeattrs(), StaticAssertStmt, generate_unaccent_rules::str, AggState::tmpcontext, AggStatePerTransData::transtypeByVal, AggStatePerGroupData::transValueIsNull, TupleTableSlot::tts_isnull, TupleTableSlot::tts_values, unlikely, NullableDatum::value, and WindowFuncExprState::wfuncno.

Referenced by ExecInitInterpreter(), and ExecReadyInterpretedExpr().

◆ ExecInterpExprStillValid()

Datum ExecInterpExprStillValid ( ExprState state,
ExprContext econtext,
bool isNull 
)

Definition at line 1826 of file execExprInterp.c.

1827 {
1828  /*
1829  * First time through, check whether attribute matches Var. Might not be
1830  * ok anymore, due to schema changes.
1831  */
1832  CheckExprStillValid(state, econtext);
1833 
1834  /* skip the check during further executions */
1835  state->evalfunc = (ExprStateEvalFunc) state->evalfunc_private;
1836 
1837  /* and actually execute */
1838  return state->evalfunc(state, econtext, isNull);
1839 }
void CheckExprStillValid(ExprState *state, ExprContext *econtext)
Datum(* ExprStateEvalFunc)(struct ExprState *expression, struct ExprContext *econtext, bool *isNull)
Definition: execnodes.h:69

References CheckExprStillValid().

Referenced by ExecReadyInterpretedExpr().

◆ ExecJustApplyFuncToCase()

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

Definition at line 2145 of file execExprInterp.c.

2146 {
2147  ExprEvalStep *op = &state->steps[0];
2148  FunctionCallInfo fcinfo;
2150  int nargs;
2151  Datum d;
2152 
2153  /*
2154  * XXX with some redesign of the CaseTestExpr mechanism, maybe we could
2155  * get rid of this data shuffling?
2156  */
2157  *op->resvalue = *op->d.casetest.value;
2158  *op->resnull = *op->d.casetest.isnull;
2159 
2160  op++;
2161 
2162  nargs = op->d.func.nargs;
2163  fcinfo = op->d.func.fcinfo_data;
2164  args = fcinfo->args;
2165 
2166  /* strict function, so check for NULL args */
2167  for (int argno = 0; argno < nargs; argno++)
2168  {
2169  if (args[argno].isnull)
2170  {
2171  *isnull = true;
2172  return (Datum) 0;
2173  }
2174  }
2175  fcinfo->isnull = false;
2176  d = op->d.func.fn_addr(fcinfo);
2177  *isnull = fcinfo->isnull;
2178  return d;
2179 }

References generate_unaccent_rules::args, FunctionCallInfoBaseData::args, ExprEvalStep::d, ExprEvalStep::isnull, FunctionCallInfoBaseData::isnull, ExprEvalStep::nargs, and ExprEvalStep::op.

Referenced by ExecReadyInterpretedExpr().

◆ ExecJustAssignInnerVar()

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

Definition at line 2124 of file execExprInterp.c.

2125 {
2126  return ExecJustAssignVarImpl(state, econtext->ecxt_innertuple, isnull);
2127 }
static pg_attribute_always_inline Datum ExecJustAssignVarImpl(ExprState *state, TupleTableSlot *inslot, bool *isnull)

References ExprContext::ecxt_innertuple, ExecJustAssignVarImpl(), and ExprEvalStep::isnull.

Referenced by ExecReadyInterpretedExpr().

◆ ExecJustAssignInnerVarVirt()

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

Definition at line 2258 of file execExprInterp.c.

2259 {
2260  return ExecJustAssignVarVirtImpl(state, econtext->ecxt_innertuple, isnull);
2261 }
static pg_attribute_always_inline Datum ExecJustAssignVarVirtImpl(ExprState *state, TupleTableSlot *inslot, bool *isnull)

References ExprContext::ecxt_innertuple, ExecJustAssignVarVirtImpl(), and ExprEvalStep::isnull.

Referenced by ExecReadyInterpretedExpr().

◆ ExecJustAssignOuterVar()

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

Definition at line 2131 of file execExprInterp.c.

2132 {
2133  return ExecJustAssignVarImpl(state, econtext->ecxt_outertuple, isnull);
2134 }

References ExprContext::ecxt_outertuple, ExecJustAssignVarImpl(), and ExprEvalStep::isnull.

Referenced by ExecReadyInterpretedExpr().

◆ ExecJustAssignOuterVarVirt()

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

Definition at line 2265 of file execExprInterp.c.

2266 {
2267  return ExecJustAssignVarVirtImpl(state, econtext->ecxt_outertuple, isnull);
2268 }

References ExprContext::ecxt_outertuple, ExecJustAssignVarVirtImpl(), and ExprEvalStep::isnull.

Referenced by ExecReadyInterpretedExpr().

◆ ExecJustAssignScanVar()

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

Definition at line 2138 of file execExprInterp.c.

2139 {
2140  return ExecJustAssignVarImpl(state, econtext->ecxt_scantuple, isnull);
2141 }

References ExprContext::ecxt_scantuple, ExecJustAssignVarImpl(), and ExprEvalStep::isnull.

Referenced by ExecReadyInterpretedExpr().

◆ ExecJustAssignScanVarVirt()

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

Definition at line 2272 of file execExprInterp.c.

2273 {
2274  return ExecJustAssignVarVirtImpl(state, econtext->ecxt_scantuple, isnull);
2275 }

References ExprContext::ecxt_scantuple, ExecJustAssignVarVirtImpl(), and ExprEvalStep::isnull.

Referenced by ExecReadyInterpretedExpr().

◆ ExecJustAssignVarImpl()

static pg_attribute_always_inline Datum ExecJustAssignVarImpl ( ExprState state,
TupleTableSlot inslot,
bool isnull 
)
static

Definition at line 2098 of file execExprInterp.c.

2099 {
2100  ExprEvalStep *op = &state->steps[1];
2101  int attnum = op->d.assign_var.attnum + 1;
2102  int resultnum = op->d.assign_var.resultnum;
2103  TupleTableSlot *outslot = state->resultslot;
2104 
2105  CheckOpSlotCompatibility(&state->steps[0], inslot);
2106 
2107  /*
2108  * We do not need CheckVarSlotCompatibility here; that was taken care of
2109  * at compilation time.
2110  *
2111  * Since we use slot_getattr(), we don't need to implement the FETCHSOME
2112  * step explicitly, and we also needn't Assert that the attnum is in range
2113  * --- slot_getattr() will take care of any problems. Nonetheless, check
2114  * that resultnum is in range.
2115  */
2116  Assert(resultnum >= 0 && resultnum < outslot->tts_tupleDescriptor->natts);
2117  outslot->tts_values[resultnum] =
2118  slot_getattr(inslot, attnum, &outslot->tts_isnull[resultnum]);
2119  return 0;
2120 }
static Datum slot_getattr(TupleTableSlot *slot, int attnum, bool *isnull)
Definition: tuptable.h:389

References Assert(), attnum, CheckOpSlotCompatibility(), ExprEvalStep::op, ExprEvalStep::resultnum, slot_getattr(), TupleTableSlot::tts_isnull, and TupleTableSlot::tts_values.

Referenced by ExecJustAssignInnerVar(), ExecJustAssignOuterVar(), and ExecJustAssignScanVar().

◆ ExecJustAssignVarVirtImpl()

static pg_attribute_always_inline Datum ExecJustAssignVarVirtImpl ( ExprState state,
TupleTableSlot inslot,
bool isnull 
)
static

Definition at line 2236 of file execExprInterp.c.<