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 ExecEvalSQLValueFunction (ExprState *state, ExprEvalStep *op)
 
void ExecEvalCurrentOfExpr (ExprState *state, ExprEvalStep *op)
 
void ExecEvalNextValueExpr (ExprState *state, ExprEvalStep *op)
 
void ExecEvalRowNull (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalRowNotNull (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalArrayExpr (ExprState *state, ExprEvalStep *op)
 
void ExecEvalArrayCoerce (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalRow (ExprState *state, ExprEvalStep *op)
 
void ExecEvalMinMax (ExprState *state, ExprEvalStep *op)
 
void ExecEvalFieldSelect (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalFieldStoreDeForm (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalFieldStoreForm (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
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)
 
void ExecEvalAggOrderedTransDatum (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalAggOrderedTransTuple (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 

Macro Definition Documentation

◆ EEO_CASE

#define EEO_CASE (   name)    case name:

Definition at line 122 of file execExprInterp.c.

Referenced by ExecInterpExpr().

◆ EEO_DISPATCH

#define EEO_DISPATCH ( )    goto starteval

Definition at line 123 of file execExprInterp.c.

Referenced by ExecInterpExpr().

◆ EEO_JUMP

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

Definition at line 134 of file execExprInterp.c.

Referenced by ExecInterpExpr().

◆ EEO_NEXT

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

Definition at line 128 of file execExprInterp.c.

Referenced by ExecInterpExpr().

◆ EEO_OPCODE

#define EEO_OPCODE (   opcode)    (opcode)

Definition at line 124 of file execExprInterp.c.

Referenced by ExecReadyInterpretedExpr().

◆ EEO_SWITCH

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

Definition at line 121 of file execExprInterp.c.

Referenced by ExecInterpExpr().

◆ SH_DECLARE

#define SH_DECLARE

Definition at line 196 of file execExprInterp.c.

◆ SH_DEFINE

#define SH_DEFINE

Definition at line 223 of file execExprInterp.c.

◆ SH_ELEMENT_TYPE [1/2]

#define SH_ELEMENT_TYPE   ScalarArrayOpExprHashEntry

Definition at line 215 of file execExprInterp.c.

◆ SH_ELEMENT_TYPE [2/2]

#define SH_ELEMENT_TYPE   ScalarArrayOpExprHashEntry

Definition at line 215 of file execExprInterp.c.

◆ SH_EQUAL

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

Definition at line 219 of file execExprInterp.c.

◆ SH_GET_HASH

#define SH_GET_HASH (   tb,
 
)    a->hash

Definition at line 222 of file execExprInterp.c.

◆ SH_HASH_KEY

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

Definition at line 218 of file execExprInterp.c.

◆ SH_KEY

#define SH_KEY   key

Definition at line 217 of file execExprInterp.c.

◆ SH_KEY_TYPE [1/2]

#define SH_KEY_TYPE   Datum

Definition at line 216 of file execExprInterp.c.

◆ SH_KEY_TYPE [2/2]

#define SH_KEY_TYPE   Datum

Definition at line 216 of file execExprInterp.c.

◆ SH_PREFIX [1/2]

#define SH_PREFIX   saophash

Definition at line 214 of file execExprInterp.c.

◆ SH_PREFIX [2/2]

#define SH_PREFIX   saophash

Definition at line 214 of file execExprInterp.c.

◆ SH_SCOPE [1/2]

#define SH_SCOPE   static inline

Definition at line 220 of file execExprInterp.c.

◆ SH_SCOPE [2/2]

#define SH_SCOPE   static inline

Definition at line 220 of file execExprInterp.c.

◆ SH_STORE_HASH

#define SH_STORE_HASH

Definition at line 221 of file execExprInterp.c.

Typedef Documentation

◆ ScalarArrayOpExprHashEntry

◆ ScalarArrayOpExprHashTable

Function Documentation

◆ CheckExprStillValid()

void CheckExprStillValid ( ExprState state,
ExprContext econtext 
)

Definition at line 1832 of file execExprInterp.c.

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

Referenced by ExecInterpExprStillValid(), and ExecRunCompiledExpr().

1833 {
1834  TupleTableSlot *innerslot;
1835  TupleTableSlot *outerslot;
1836  TupleTableSlot *scanslot;
1837 
1838  innerslot = econtext->ecxt_innertuple;
1839  outerslot = econtext->ecxt_outertuple;
1840  scanslot = econtext->ecxt_scantuple;
1841 
1842  for (int i = 0; i < state->steps_len; i++)
1843  {
1844  ExprEvalStep *op = &state->steps[i];
1845 
1846  switch (ExecEvalStepOp(state, op))
1847  {
1848  case EEOP_INNER_VAR:
1849  {
1850  int attnum = op->d.var.attnum;
1851 
1852  CheckVarSlotCompatibility(innerslot, attnum + 1, op->d.var.vartype);
1853  break;
1854  }
1855 
1856  case EEOP_OUTER_VAR:
1857  {
1858  int attnum = op->d.var.attnum;
1859 
1860  CheckVarSlotCompatibility(outerslot, attnum + 1, op->d.var.vartype);
1861  break;
1862  }
1863 
1864  case EEOP_SCAN_VAR:
1865  {
1866  int attnum = op->d.var.attnum;
1867 
1868  CheckVarSlotCompatibility(scanslot, attnum + 1, op->d.var.vartype);
1869  break;
1870  }
1871  default:
1872  break;
1873  }
1874  }
1875 }
struct ExprEvalStep * steps
Definition: execnodes.h:85
struct ExprEvalStep::@49::@51 var
static void CheckVarSlotCompatibility(TupleTableSlot *slot, int attnum, Oid vartype)
ExprEvalOp ExecEvalStepOp(ExprState *state, ExprEvalStep *op)
union ExprEvalStep::@49 d
TupleTableSlot * ecxt_innertuple
Definition: execnodes.h:228
int16 attnum
Definition: pg_attribute.h:83
TupleTableSlot * ecxt_outertuple
Definition: execnodes.h:230
TupleTableSlot * ecxt_scantuple
Definition: execnodes.h:226
int steps_len
Definition: execnodes.h:104
int i

◆ CheckOpSlotCompatibility()

static void CheckOpSlotCompatibility ( ExprEvalStep op,
TupleTableSlot slot 
)
static

Definition at line 1934 of file execExprInterp.c.

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

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

1935 {
1936 #ifdef USE_ASSERT_CHECKING
1937  /* there's nothing to check */
1938  if (!op->d.fetch.fixed)
1939  return;
1940 
1941  /*
1942  * Should probably fixed at some point, but for now it's easier to allow
1943  * buffer and heap tuples to be used interchangeably.
1944  */
1945  if (slot->tts_ops == &TTSOpsBufferHeapTuple &&
1946  op->d.fetch.kind == &TTSOpsHeapTuple)
1947  return;
1948  if (slot->tts_ops == &TTSOpsHeapTuple &&
1949  op->d.fetch.kind == &TTSOpsBufferHeapTuple)
1950  return;
1951 
1952  /*
1953  * At the moment we consider it OK if a virtual slot is used instead of a
1954  * specific type of slot, as a virtual slot never needs to be deformed.
1955  */
1956  if (slot->tts_ops == &TTSOpsVirtual)
1957  return;
1958 
1959  Assert(op->d.fetch.kind == slot->tts_ops);
1960 #endif
1961 }
struct ExprEvalStep::@49::@50 fetch
const TupleTableSlotOps TTSOpsBufferHeapTuple
Definition: execTuples.c:86
const TupleTableSlotOps TTSOpsVirtual
Definition: execTuples.c:83
const TupleTableSlotOps *const tts_ops
Definition: tuptable.h:122
union ExprEvalStep::@49 d
#define Assert(condition)
Definition: c.h:804
const TupleTableSlotOps TTSOpsHeapTuple
Definition: execTuples.c:84

◆ CheckVarSlotCompatibility()

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

Definition at line 1883 of file execExprInterp.c.

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

Referenced by CheckExprStillValid().

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

◆ ExecAggInitGroup()

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

Definition at line 4204 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

4206 {
4207  FunctionCallInfo fcinfo = pertrans->transfn_fcinfo;
4208  MemoryContext oldContext;
4209 
4210  /*
4211  * We must copy the datum into aggcontext if it is pass-by-ref. We do not
4212  * need to pfree the old transValue, since it's NULL. (We already checked
4213  * that the agg's input type is binary-compatible with its transtype, so
4214  * straight copy here is OK.)
4215  */
4216  oldContext = MemoryContextSwitchTo(aggcontext->ecxt_per_tuple_memory);
4217  pergroup->transValue = datumCopy(fcinfo->args[1].value,
4218  pertrans->transtypeByVal,
4219  pertrans->transtypeLen);
4220  pergroup->transValueIsNull = false;
4221  pergroup->noTransValue = false;
4222  MemoryContextSwitchTo(oldContext);
4223 }
MemoryContext ecxt_per_tuple_memory
Definition: execnodes.h:234
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
FunctionCallInfo transfn_fcinfo
Definition: nodeAgg.h:162
NullableDatum args[FLEXIBLE_ARRAY_MEMBER]
Definition: fmgr.h:95
Datum value
Definition: postgres.h:422
Datum datumCopy(Datum value, bool typByVal, int typLen)
Definition: datum.c:131

◆ ExecAggPlainTransByRef()

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

Definition at line 4338 of file execExprInterp.c.

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().

4341 {
4342  FunctionCallInfo fcinfo = pertrans->transfn_fcinfo;
4343  MemoryContext oldContext;
4344  Datum newVal;
4345 
4346  /* cf. select_current_set() */
4347  aggstate->curaggcontext = aggcontext;
4348  aggstate->current_set = setno;
4349 
4350  /* set up aggstate->curpertrans for AggGetAggref() */
4351  aggstate->curpertrans = pertrans;
4352 
4353  /* invoke transition function in per-tuple context */
4354  oldContext = MemoryContextSwitchTo(aggstate->tmpcontext->ecxt_per_tuple_memory);
4355 
4356  fcinfo->args[0].value = pergroup->transValue;
4357  fcinfo->args[0].isnull = pergroup->transValueIsNull;
4358  fcinfo->isnull = false; /* just in case transfn doesn't set it */
4359 
4360  newVal = FunctionCallInvoke(fcinfo);
4361 
4362  /*
4363  * For pass-by-ref datatype, must copy the new value into aggcontext and
4364  * free the prior transValue. But if transfn returned a pointer to its
4365  * first input, we don't need to do anything. Also, if transfn returned a
4366  * pointer to a R/W expanded object that is already a child of the
4367  * aggcontext, assume we can adopt that value without copying it.
4368  *
4369  * It's safe to compare newVal with pergroup->transValue without regard
4370  * for either being NULL, because ExecAggTransReparent() takes care to set
4371  * transValue to 0 when NULL. Otherwise we could end up accidentally not
4372  * reparenting, when the transValue has the same numerical value as
4373  * newValue, despite being NULL. This is a somewhat hot path, making it
4374  * undesirable to instead solve this with another branch for the common
4375  * case of the transition function returning its (modified) input
4376  * argument.
4377  */
4378  if (DatumGetPointer(newVal) != DatumGetPointer(pergroup->transValue))
4379  newVal = ExecAggTransReparent(aggstate, pertrans,
4380  newVal, fcinfo->isnull,
4381  pergroup->transValue,
4382  pergroup->transValueIsNull);
4383 
4384  pergroup->transValue = newVal;
4385  pergroup->transValueIsNull = fcinfo->isnull;
4386 
4387  MemoryContextSwitchTo(oldContext);
4388 }
MemoryContext ecxt_per_tuple_memory
Definition: execnodes.h:234
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
int current_set
Definition: execnodes.h:2299
FunctionCallInfo transfn_fcinfo
Definition: nodeAgg.h:162
Datum ExecAggTransReparent(AggState *aggstate, AggStatePerTrans pertrans, Datum newValue, bool newValueIsNull, Datum oldValue, bool oldValueIsNull)
ExprContext * tmpcontext
Definition: execnodes.h:2289
NullableDatum args[FLEXIBLE_ARRAY_MEMBER]
Definition: fmgr.h:95
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:172
Datum value
Definition: postgres.h:422
ExprContext * curaggcontext
Definition: execnodes.h:2291
uintptr_t Datum
Definition: postgres.h:411
#define DatumGetPointer(X)
Definition: postgres.h:593
AggStatePerTrans curpertrans
Definition: execnodes.h:2294

◆ ExecAggPlainTransByVal()

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

Definition at line 4306 of file execExprInterp.c.

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, pg_attribute_always_inline, ExprEvalStep::setno, AggState::tmpcontext, AggStatePerTransData::transfn_fcinfo, AggStatePerGroupData::transValue, AggStatePerGroupData::transValueIsNull, and NullableDatum::value.

Referenced by ExecInterpExpr().

4309 {
4310  FunctionCallInfo fcinfo = pertrans->transfn_fcinfo;
4311  MemoryContext oldContext;
4312  Datum newVal;
4313 
4314  /* cf. select_current_set() */
4315  aggstate->curaggcontext = aggcontext;
4316  aggstate->current_set = setno;
4317 
4318  /* set up aggstate->curpertrans for AggGetAggref() */
4319  aggstate->curpertrans = pertrans;
4320 
4321  /* invoke transition function in per-tuple context */
4322  oldContext = MemoryContextSwitchTo(aggstate->tmpcontext->ecxt_per_tuple_memory);
4323 
4324  fcinfo->args[0].value = pergroup->transValue;
4325  fcinfo->args[0].isnull = pergroup->transValueIsNull;
4326  fcinfo->isnull = false; /* just in case transfn doesn't set it */
4327 
4328  newVal = FunctionCallInvoke(fcinfo);
4329 
4330  pergroup->transValue = newVal;
4331  pergroup->transValueIsNull = fcinfo->isnull;
4332 
4333  MemoryContextSwitchTo(oldContext);
4334 }
MemoryContext ecxt_per_tuple_memory
Definition: execnodes.h:234
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
int current_set
Definition: execnodes.h:2299
FunctionCallInfo transfn_fcinfo
Definition: nodeAgg.h:162
ExprContext * tmpcontext
Definition: execnodes.h:2289
NullableDatum args[FLEXIBLE_ARRAY_MEMBER]
Definition: fmgr.h:95
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:172
Datum value
Definition: postgres.h:422
ExprContext * curaggcontext
Definition: execnodes.h:2291
uintptr_t Datum
Definition: postgres.h:411
AggStatePerTrans curpertrans
Definition: execnodes.h:2294

◆ ExecAggTransReparent()

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

Definition at line 4232 of file execExprInterp.c.

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

Referenced by advance_transition_function(), and ExecAggPlainTransByRef().

4235 {
4236  Assert(newValue != oldValue);
4237 
4238  if (!newValueIsNull)
4239  {
4241  if (DatumIsReadWriteExpandedObject(newValue,
4242  false,
4243  pertrans->transtypeLen) &&
4244  MemoryContextGetParent(DatumGetEOHP(newValue)->eoh_context) == CurrentMemoryContext)
4245  /* do nothing */ ;
4246  else
4247  newValue = datumCopy(newValue,
4248  pertrans->transtypeByVal,
4249  pertrans->transtypeLen);
4250  }
4251  else
4252  {
4253  /*
4254  * Ensure that AggStatePerGroup->transValue ends up being 0, so
4255  * callers can safely compare newValue/oldValue without having to
4256  * check their respective nullness.
4257  */
4258  newValue = (Datum) 0;
4259  }
4260 
4261  if (!oldValueIsNull)
4262  {
4263  if (DatumIsReadWriteExpandedObject(oldValue,
4264  false,
4265  pertrans->transtypeLen))
4266  DeleteExpandedObject(oldValue);
4267  else
4268  pfree(DatumGetPointer(oldValue));
4269  }
4270 
4271  return newValue;
4272 }
MemoryContext MemoryContextGetParent(MemoryContext context)
Definition: mcxt.c:446
MemoryContext ecxt_per_tuple_memory
Definition: execnodes.h:234
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
void pfree(void *pointer)
Definition: mcxt.c:1169
MemoryContext CurrentMemoryContext
Definition: mcxt.c:42
Datum datumCopy(Datum value, bool typByVal, int typLen)
Definition: datum.c:131
ExpandedObjectHeader * DatumGetEOHP(Datum d)
Definition: expandeddatum.c:29
ExprContext * curaggcontext
Definition: execnodes.h:2291
uintptr_t Datum
Definition: postgres.h:411
void DeleteExpandedObject(Datum d)
#define Assert(condition)
Definition: c.h:804
#define DatumIsReadWriteExpandedObject(d, isnull, typlen)
#define DatumGetPointer(X)
Definition: postgres.h:593

◆ ExecEvalAggOrderedTransDatum()

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

Definition at line 4278 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

4280 {
4281  AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
4282  int setno = op->d.agg_trans.setno;
4283 
4284  tuplesort_putdatum(pertrans->sortstates[setno],
4285  *op->resvalue, *op->resnull);
4286 }
void tuplesort_putdatum(Tuplesortstate *state, Datum val, bool isNull)
Definition: tuplesort.c:1805
Datum * resvalue
Definition: execExpr.h:273
bool * resnull
Definition: execExpr.h:274
union ExprEvalStep::@49 d
struct ExprEvalStep::@49::@90 agg_trans
Tuplesortstate ** sortstates
Definition: nodeAgg.h:154

◆ ExecEvalAggOrderedTransTuple()

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

Definition at line 4292 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

4294 {
4295  AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
4296  int setno = op->d.agg_trans.setno;
4297 
4298  ExecClearTuple(pertrans->sortslot);
4299  pertrans->sortslot->tts_nvalid = pertrans->numInputs;
4300  ExecStoreVirtualTuple(pertrans->sortslot);
4301  tuplesort_puttupleslot(pertrans->sortstates[setno], pertrans->sortslot);
4302 }
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:425
union ExprEvalStep::@49 d
struct ExprEvalStep::@49::@90 agg_trans
Tuplesortstate ** sortstates
Definition: nodeAgg.h:154
AttrNumber tts_nvalid
Definition: tuptable.h:121
TupleTableSlot * sortslot
Definition: nodeAgg.h:136
TupleTableSlot * ExecStoreVirtualTuple(TupleTableSlot *slot)
Definition: execTuples.c:1552
void tuplesort_puttupleslot(Tuplesortstate *state, TupleTableSlot *slot)
Definition: tuplesort.c:1684

◆ ExecEvalArrayCoerce()

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

Definition at line 2885 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

2886 {
2887  Datum arraydatum;
2888 
2889  /* NULL array -> NULL result */
2890  if (*op->resnull)
2891  return;
2892 
2893  arraydatum = *op->resvalue;
2894 
2895  /*
2896  * If it's binary-compatible, modify the element type in the array header,
2897  * but otherwise leave the array as we received it.
2898  */
2899  if (op->d.arraycoerce.elemexprstate == NULL)
2900  {
2901  /* Detoast input array if necessary, and copy in any case */
2902  ArrayType *array = DatumGetArrayTypePCopy(arraydatum);
2903 
2904  ARR_ELEMTYPE(array) = op->d.arraycoerce.resultelemtype;
2905  *op->resvalue = PointerGetDatum(array);
2906  return;
2907  }
2908 
2909  /*
2910  * Use array_map to apply the sub-expression to each array element.
2911  */
2912  *op->resvalue = array_map(arraydatum,
2913  op->d.arraycoerce.elemexprstate,
2914  econtext,
2915  op->d.arraycoerce.resultelemtype,
2916  op->d.arraycoerce.amstate);
2917 }
Datum * resvalue
Definition: execExpr.h:273
#define PointerGetDatum(X)
Definition: postgres.h:600
bool * resnull
Definition: execExpr.h:274
union ExprEvalStep::@49 d
struct ExprEvalStep::@49::@69 arraycoerce
uintptr_t Datum
Definition: postgres.h:411
#define DatumGetArrayTypePCopy(X)
Definition: array.h:255
Datum array_map(Datum arrayd, ExprState *exprstate, ExprContext *econtext, Oid retType, ArrayMapState *amstate)
Definition: arrayfuncs.c:3159
#define ARR_ELEMTYPE(a)
Definition: array.h:285

◆ ExecEvalArrayExpr()

void ExecEvalArrayExpr ( ExprState state,
ExprEvalStep op 
)

Definition at line 2676 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

2677 {
2678  ArrayType *result;
2679  Oid element_type = op->d.arrayexpr.elemtype;
2680  int nelems = op->d.arrayexpr.nelems;
2681  int ndims = 0;
2682  int dims[MAXDIM];
2683  int lbs[MAXDIM];
2684 
2685  /* Set non-null as default */
2686  *op->resnull = false;
2687 
2688  if (!op->d.arrayexpr.multidims)
2689  {
2690  /* Elements are presumably of scalar type */
2691  Datum *dvalues = op->d.arrayexpr.elemvalues;
2692  bool *dnulls = op->d.arrayexpr.elemnulls;
2693 
2694  /* setup for 1-D array of the given length */
2695  ndims = 1;
2696  dims[0] = nelems;
2697  lbs[0] = 1;
2698 
2699  result = construct_md_array(dvalues, dnulls, ndims, dims, lbs,
2700  element_type,
2701  op->d.arrayexpr.elemlength,
2702  op->d.arrayexpr.elembyval,
2703  op->d.arrayexpr.elemalign);
2704  }
2705  else
2706  {
2707  /* Must be nested array expressions */
2708  int nbytes = 0;
2709  int nitems = 0;
2710  int outer_nelems = 0;
2711  int elem_ndims = 0;
2712  int *elem_dims = NULL;
2713  int *elem_lbs = NULL;
2714  bool firstone = true;
2715  bool havenulls = false;
2716  bool haveempty = false;
2717  char **subdata;
2718  bits8 **subbitmaps;
2719  int *subbytes;
2720  int *subnitems;
2721  int32 dataoffset;
2722  char *dat;
2723  int iitem;
2724 
2725  subdata = (char **) palloc(nelems * sizeof(char *));
2726  subbitmaps = (bits8 **) palloc(nelems * sizeof(bits8 *));
2727  subbytes = (int *) palloc(nelems * sizeof(int));
2728  subnitems = (int *) palloc(nelems * sizeof(int));
2729 
2730  /* loop through and get data area from each element */
2731  for (int elemoff = 0; elemoff < nelems; elemoff++)
2732  {
2733  Datum arraydatum;
2734  bool eisnull;
2735  ArrayType *array;
2736  int this_ndims;
2737 
2738  arraydatum = op->d.arrayexpr.elemvalues[elemoff];
2739  eisnull = op->d.arrayexpr.elemnulls[elemoff];
2740 
2741  /* temporarily ignore null subarrays */
2742  if (eisnull)
2743  {
2744  haveempty = true;
2745  continue;
2746  }
2747 
2748  array = DatumGetArrayTypeP(arraydatum);
2749 
2750  /* run-time double-check on element type */
2751  if (element_type != ARR_ELEMTYPE(array))
2752  ereport(ERROR,
2753  (errcode(ERRCODE_DATATYPE_MISMATCH),
2754  errmsg("cannot merge incompatible arrays"),
2755  errdetail("Array with element type %s cannot be "
2756  "included in ARRAY construct with element type %s.",
2757  format_type_be(ARR_ELEMTYPE(array)),
2758  format_type_be(element_type))));
2759 
2760  this_ndims = ARR_NDIM(array);
2761  /* temporarily ignore zero-dimensional subarrays */
2762  if (this_ndims <= 0)
2763  {
2764  haveempty = true;
2765  continue;
2766  }
2767 
2768  if (firstone)
2769  {
2770  /* Get sub-array details from first member */
2771  elem_ndims = this_ndims;
2772  ndims = elem_ndims + 1;
2773  if (ndims <= 0 || ndims > MAXDIM)
2774  ereport(ERROR,
2775  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
2776  errmsg("number of array dimensions (%d) exceeds the maximum allowed (%d)",
2777  ndims, MAXDIM)));
2778 
2779  elem_dims = (int *) palloc(elem_ndims * sizeof(int));
2780  memcpy(elem_dims, ARR_DIMS(array), elem_ndims * sizeof(int));
2781  elem_lbs = (int *) palloc(elem_ndims * sizeof(int));
2782  memcpy(elem_lbs, ARR_LBOUND(array), elem_ndims * sizeof(int));
2783 
2784  firstone = false;
2785  }
2786  else
2787  {
2788  /* Check other sub-arrays are compatible */
2789  if (elem_ndims != this_ndims ||
2790  memcmp(elem_dims, ARR_DIMS(array),
2791  elem_ndims * sizeof(int)) != 0 ||
2792  memcmp(elem_lbs, ARR_LBOUND(array),
2793  elem_ndims * sizeof(int)) != 0)
2794  ereport(ERROR,
2795  (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
2796  errmsg("multidimensional arrays must have array "
2797  "expressions with matching dimensions")));
2798  }
2799 
2800  subdata[outer_nelems] = ARR_DATA_PTR(array);
2801  subbitmaps[outer_nelems] = ARR_NULLBITMAP(array);
2802  subbytes[outer_nelems] = ARR_SIZE(array) - ARR_DATA_OFFSET(array);
2803  nbytes += subbytes[outer_nelems];
2804  subnitems[outer_nelems] = ArrayGetNItems(this_ndims,
2805  ARR_DIMS(array));
2806  nitems += subnitems[outer_nelems];
2807  havenulls |= ARR_HASNULL(array);
2808  outer_nelems++;
2809  }
2810 
2811  /*
2812  * If all items were null or empty arrays, return an empty array;
2813  * otherwise, if some were and some weren't, raise error. (Note: we
2814  * must special-case this somehow to avoid trying to generate a 1-D
2815  * array formed from empty arrays. It's not ideal...)
2816  */
2817  if (haveempty)
2818  {
2819  if (ndims == 0) /* didn't find any nonempty array */
2820  {
2821  *op->resvalue = PointerGetDatum(construct_empty_array(element_type));
2822  return;
2823  }
2824  ereport(ERROR,
2825  (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
2826  errmsg("multidimensional arrays must have array "
2827  "expressions with matching dimensions")));
2828  }
2829 
2830  /* setup for multi-D array */
2831  dims[0] = outer_nelems;
2832  lbs[0] = 1;
2833  for (int i = 1; i < ndims; i++)
2834  {
2835  dims[i] = elem_dims[i - 1];
2836  lbs[i] = elem_lbs[i - 1];
2837  }
2838 
2839  /* check for subscript overflow */
2840  (void) ArrayGetNItems(ndims, dims);
2841  ArrayCheckBounds(ndims, dims, lbs);
2842 
2843  if (havenulls)
2844  {
2845  dataoffset = ARR_OVERHEAD_WITHNULLS(ndims, nitems);
2846  nbytes += dataoffset;
2847  }
2848  else
2849  {
2850  dataoffset = 0; /* marker for no null bitmap */
2851  nbytes += ARR_OVERHEAD_NONULLS(ndims);
2852  }
2853 
2854  result = (ArrayType *) palloc(nbytes);
2855  SET_VARSIZE(result, nbytes);
2856  result->ndim = ndims;
2857  result->dataoffset = dataoffset;
2858  result->elemtype = element_type;
2859  memcpy(ARR_DIMS(result), dims, ndims * sizeof(int));
2860  memcpy(ARR_LBOUND(result), lbs, ndims * sizeof(int));
2861 
2862  dat = ARR_DATA_PTR(result);
2863  iitem = 0;
2864  for (int i = 0; i < outer_nelems; i++)
2865  {
2866  memcpy(dat, subdata[i], subbytes[i]);
2867  dat += subbytes[i];
2868  if (havenulls)
2869  array_bitmap_copy(ARR_NULLBITMAP(result), iitem,
2870  subbitmaps[i], 0,
2871  subnitems[i]);
2872  iitem += subnitems[i];
2873  }
2874  }
2875 
2876  *op->resvalue = PointerGetDatum(result);
2877 }
#define ARR_OVERHEAD_NONULLS(ndims)
Definition: array.h:303
#define ARR_SIZE(a)
Definition: array.h:282
Datum * resvalue
Definition: execExpr.h:273
#define PointerGetDatum(X)
Definition: postgres.h:600
void array_bitmap_copy(bits8 *destbitmap, int destoffset, const bits8 *srcbitmap, int srcoffset, int nitems)
Definition: arrayfuncs.c:4756
int32 dataoffset
Definition: array.h:89
bool * resnull
Definition: execExpr.h:274
int ArrayGetNItems(int ndim, const int *dims)
Definition: arrayutils.c:76
int errcode(int sqlerrcode)
Definition: elog.c:698
char * format_type_be(Oid type_oid)
Definition: format_type.c:339
ArrayType * construct_empty_array(Oid elmtype)
Definition: arrayfuncs.c:3440
unsigned int Oid
Definition: postgres_ext.h:31
#define ARR_OVERHEAD_WITHNULLS(ndims, nitems)
Definition: array.h:305
signed int int32
Definition: c.h:429
#define ARR_DATA_OFFSET(a)
Definition: array.h:309
#define ARR_LBOUND(a)
Definition: array.h:289
#define ERROR
Definition: elog.h:46
union ExprEvalStep::@49 d
Oid elemtype
Definition: array.h:90
#define ARR_DIMS(a)
Definition: array.h:287
#define ARR_DATA_PTR(a)
Definition: array.h:315
#define MAXDIM
Definition: array.h:75
int errdetail(const char *fmt,...)
Definition: elog.c:1042
#define ARR_HASNULL(a)
Definition: array.h:284
void ArrayCheckBounds(int ndim, const int *dims, const int *lb)
Definition: arrayutils.c:128
uint8 bits8
Definition: c.h:448
uintptr_t Datum
Definition: postgres.h:411
#define ereport(elevel,...)
Definition: elog.h:157
#define ARR_NDIM(a)
Definition: array.h:283
struct ExprEvalStep::@49::@68 arrayexpr
void * palloc(Size size)
Definition: mcxt.c:1062
int errmsg(const char *fmt,...)
Definition: elog.c:909
int i
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:342
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:3354
#define ARR_ELEMTYPE(a)
Definition: array.h:285
#define ARR_NULLBITMAP(a)
Definition: array.h:293
int ndim
Definition: array.h:88
#define DatumGetArrayTypeP(X)
Definition: array.h:254

◆ ExecEvalConstraintCheck()

void ExecEvalConstraintCheck ( ExprState state,
ExprEvalStep op 
)

Definition at line 3674 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

3675 {
3676  if (!*op->d.domaincheck.checknull &&
3677  !DatumGetBool(*op->d.domaincheck.checkvalue))
3678  ereport(ERROR,
3679  (errcode(ERRCODE_CHECK_VIOLATION),
3680  errmsg("value for domain %s violates check constraint \"%s\"",
3681  format_type_be(op->d.domaincheck.resulttype),
3682  op->d.domaincheck.constraintname),
3683  errdomainconstraint(op->d.domaincheck.resulttype,
3684  op->d.domaincheck.constraintname)));
3685 }
int errcode(int sqlerrcode)
Definition: elog.c:698
char * format_type_be(Oid type_oid)
Definition: format_type.c:339
#define ERROR
Definition: elog.h:46
int errdomainconstraint(Oid datatypeOid, const char *conname)
Definition: domains.c:384
union ExprEvalStep::@49 d
#define DatumGetBool(X)
Definition: postgres.h:437
struct ExprEvalStep::@49::@78 domaincheck
#define ereport(elevel,...)
Definition: elog.h:157
int errmsg(const char *fmt,...)
Definition: elog.c:909

◆ ExecEvalConstraintNotNull()

void ExecEvalConstraintNotNull ( ExprState state,
ExprEvalStep op 
)

Definition at line 3660 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

3661 {
3662  if (*op->resnull)
3663  ereport(ERROR,
3664  (errcode(ERRCODE_NOT_NULL_VIOLATION),
3665  errmsg("domain %s does not allow null values",
3666  format_type_be(op->d.domaincheck.resulttype)),
3667  errdatatype(op->d.domaincheck.resulttype)));
3668 }
bool * resnull
Definition: execExpr.h:274
int errcode(int sqlerrcode)
Definition: elog.c:698
char * format_type_be(Oid type_oid)
Definition: format_type.c:339
#define ERROR
Definition: elog.h:46
union ExprEvalStep::@49 d
struct ExprEvalStep::@49::@78 domaincheck
int errdatatype(Oid datatypeOid)
Definition: domains.c:360
#define ereport(elevel,...)
Definition: elog.h:157
int errmsg(const char *fmt,...)
Definition: elog.c:909

◆ ExecEvalConvertRowtype()

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

Definition at line 3194 of file execExprInterp.c.

References Assert, ExprEvalStep::convert_rowtype, convert_tuples_by_name(), ExprEvalStep::d, 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::resnull, ExprEvalStep::resvalue, HeapTupleData::t_data, HeapTupleData::t_len, and TupleDescData::tdtypeid.

Referenced by ExecInterpExpr().

3195 {
3196  HeapTuple result;
3197  Datum tupDatum;
3198  HeapTupleHeader tuple;
3199  HeapTupleData tmptup;
3200  TupleDesc indesc,
3201  outdesc;
3202  bool changed = false;
3203 
3204  /* NULL in -> NULL out */
3205  if (*op->resnull)
3206  return;
3207 
3208  tupDatum = *op->resvalue;
3209  tuple = DatumGetHeapTupleHeader(tupDatum);
3210 
3211  /*
3212  * Lookup tupdescs if first time through or if type changes. We'd better
3213  * pin them since type conversion functions could do catalog lookups and
3214  * hence cause cache invalidation.
3215  */
3216  indesc = get_cached_rowtype(op->d.convert_rowtype.inputtype, -1,
3217  op->d.convert_rowtype.incache,
3218  &changed);
3219  IncrTupleDescRefCount(indesc);
3220  outdesc = get_cached_rowtype(op->d.convert_rowtype.outputtype, -1,
3221  op->d.convert_rowtype.outcache,
3222  &changed);
3223  IncrTupleDescRefCount(outdesc);
3224 
3225  /*
3226  * We used to be able to assert that incoming tuples are marked with
3227  * exactly the rowtype of indesc. However, now that ExecEvalWholeRowVar
3228  * might change the tuples' marking to plain RECORD due to inserting
3229  * aliases, we can only make this weak test:
3230  */
3231  Assert(HeapTupleHeaderGetTypeId(tuple) == indesc->tdtypeid ||
3232  HeapTupleHeaderGetTypeId(tuple) == RECORDOID);
3233 
3234  /* if first time through, or after change, initialize conversion map */
3235  if (changed)
3236  {
3237  MemoryContext old_cxt;
3238 
3239  /* allocate map in long-lived memory context */
3240  old_cxt = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
3241 
3242  /* prepare map from old to new attribute numbers */
3243  op->d.convert_rowtype.map = convert_tuples_by_name(indesc, outdesc);
3244 
3245  MemoryContextSwitchTo(old_cxt);
3246  }
3247 
3248  /* Following steps need a HeapTuple not a bare HeapTupleHeader */
3249  tmptup.t_len = HeapTupleHeaderGetDatumLength(tuple);
3250  tmptup.t_data = tuple;
3251 
3252  if (op->d.convert_rowtype.map != NULL)
3253  {
3254  /* Full conversion with attribute rearrangement needed */
3255  result = execute_attr_map_tuple(&tmptup, op->d.convert_rowtype.map);
3256  /* Result already has appropriate composite-datum header fields */
3257  *op->resvalue = HeapTupleGetDatum(result);
3258  }
3259  else
3260  {
3261  /*
3262  * The tuple is physically compatible as-is, but we need to insert the
3263  * destination rowtype OID in its composite-datum header field, so we
3264  * have to copy it anyway. heap_copy_tuple_as_datum() is convenient
3265  * for this since it will both make the physical copy and insert the
3266  * correct composite header fields. Note that we aren't expecting to
3267  * have to flatten any toasted fields: the input was a composite
3268  * datum, so it shouldn't contain any. So heap_copy_tuple_as_datum()
3269  * is overkill here, but its check for external fields is cheap.
3270  */
3271  *op->resvalue = heap_copy_tuple_as_datum(&tmptup, outdesc);
3272  }
3273 
3274  DecrTupleDescRefCount(indesc);
3275  DecrTupleDescRefCount(outdesc);
3276 }
void IncrTupleDescRefCount(TupleDesc tupdesc)
Definition: tupdesc.c:366
Datum * resvalue
Definition: execExpr.h:273
bool * resnull
Definition: execExpr.h:274
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
#define DatumGetHeapTupleHeader(X)
Definition: fmgr.h:295
HeapTupleHeader t_data
Definition: htup.h:68
union ExprEvalStep::@49 d
static TupleDesc get_cached_rowtype(Oid type_id, int32 typmod, ExprEvalRowtypeCache *rowcache, bool *changed)
uint32 t_len
Definition: htup.h:64
struct ExprEvalStep::@49::@79 convert_rowtype
TupleConversionMap * convert_tuples_by_name(TupleDesc indesc, TupleDesc outdesc)
Definition: tupconvert.c:102
HeapTuple execute_attr_map_tuple(HeapTuple tuple, TupleConversionMap *map)
Definition: tupconvert.c:139
Datum heap_copy_tuple_as_datum(HeapTuple tuple, TupleDesc tupleDesc)
Definition: heaptuple.c:984
uintptr_t Datum
Definition: postgres.h:411
#define HeapTupleHeaderGetTypeId(tup)
Definition: htup_details.h:457
#define Assert(condition)
Definition: c.h:804
void DecrTupleDescRefCount(TupleDesc tupdesc)
Definition: tupdesc.c:384
#define HeapTupleGetDatum(tuple)
Definition: funcapi.h:220
MemoryContext ecxt_per_query_memory
Definition: execnodes.h:233
Oid tdtypeid
Definition: tupdesc.h:82
#define HeapTupleHeaderGetDatumLength(tup)
Definition: htup_details.h:451

◆ ExecEvalCurrentOfExpr()

void ExecEvalCurrentOfExpr ( ExprState state,
ExprEvalStep op 
)

Definition at line 2537 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

2538 {
2539  ereport(ERROR,
2540  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2541  errmsg("WHERE CURRENT OF is not supported for this table type")));
2542 }
int errcode(int sqlerrcode)
Definition: elog.c:698
#define ERROR
Definition: elog.h:46
#define ereport(elevel,...)
Definition: elog.h:157
int errmsg(const char *fmt,...)
Definition: elog.c:909

◆ ExecEvalFieldSelect()

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

Definition at line 2999 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

3000 {
3001  AttrNumber fieldnum = op->d.fieldselect.fieldnum;
3002  Datum tupDatum;
3003  HeapTupleHeader tuple;
3004  Oid tupType;
3005  int32 tupTypmod;
3006  TupleDesc tupDesc;
3007  Form_pg_attribute attr;
3008  HeapTupleData tmptup;
3009 
3010  /* NULL record -> NULL result */
3011  if (*op->resnull)
3012  return;
3013 
3014  tupDatum = *op->resvalue;
3015 
3016  /* We can special-case expanded records for speed */
3018  {
3020 
3021  Assert(erh->er_magic == ER_MAGIC);
3022 
3023  /* Extract record's TupleDesc */
3024  tupDesc = expanded_record_get_tupdesc(erh);
3025 
3026  /*
3027  * Find field's attr record. Note we don't support system columns
3028  * here: a datum tuple doesn't have valid values for most of the
3029  * interesting system columns anyway.
3030  */
3031  if (fieldnum <= 0) /* should never happen */
3032  elog(ERROR, "unsupported reference to system column %d in FieldSelect",
3033  fieldnum);
3034  if (fieldnum > tupDesc->natts) /* should never happen */
3035  elog(ERROR, "attribute number %d exceeds number of columns %d",
3036  fieldnum, tupDesc->natts);
3037  attr = TupleDescAttr(tupDesc, fieldnum - 1);
3038 
3039  /* Check for dropped column, and force a NULL result if so */
3040  if (attr->attisdropped)
3041  {
3042  *op->resnull = true;
3043  return;
3044  }
3045 
3046  /* Check for type mismatch --- possible after ALTER COLUMN TYPE? */
3047  /* As in CheckVarSlotCompatibility, we should but can't check typmod */
3048  if (op->d.fieldselect.resulttype != attr->atttypid)
3049  ereport(ERROR,
3050  (errcode(ERRCODE_DATATYPE_MISMATCH),
3051  errmsg("attribute %d has wrong type", fieldnum),
3052  errdetail("Table has type %s, but query expects %s.",
3053  format_type_be(attr->atttypid),
3054  format_type_be(op->d.fieldselect.resulttype))));
3055 
3056  /* extract the field */
3057  *op->resvalue = expanded_record_get_field(erh, fieldnum,
3058  op->resnull);
3059  }
3060  else
3061  {
3062  /* Get the composite datum and extract its type fields */
3063  tuple = DatumGetHeapTupleHeader(tupDatum);
3064 
3065  tupType = HeapTupleHeaderGetTypeId(tuple);
3066  tupTypmod = HeapTupleHeaderGetTypMod(tuple);
3067 
3068  /* Lookup tupdesc if first time through or if type changes */
3069  tupDesc = get_cached_rowtype(tupType, tupTypmod,
3070  &op->d.fieldselect.rowcache, NULL);
3071 
3072  /*
3073  * Find field's attr record. Note we don't support system columns
3074  * here: a datum tuple doesn't have valid values for most of the
3075  * interesting system columns anyway.
3076  */
3077  if (fieldnum <= 0) /* should never happen */
3078  elog(ERROR, "unsupported reference to system column %d in FieldSelect",
3079  fieldnum);
3080  if (fieldnum > tupDesc->natts) /* should never happen */
3081  elog(ERROR, "attribute number %d exceeds number of columns %d",
3082  fieldnum, tupDesc->natts);
3083  attr = TupleDescAttr(tupDesc, fieldnum - 1);
3084 
3085  /* Check for dropped column, and force a NULL result if so */
3086  if (attr->attisdropped)
3087  {
3088  *op->resnull = true;
3089  return;
3090  }
3091 
3092  /* Check for type mismatch --- possible after ALTER COLUMN TYPE? */
3093  /* As in CheckVarSlotCompatibility, we should but can't check typmod */
3094  if (op->d.fieldselect.resulttype != attr->atttypid)
3095  ereport(ERROR,
3096  (errcode(ERRCODE_DATATYPE_MISMATCH),
3097  errmsg("attribute %d has wrong type", fieldnum),
3098  errdetail("Table has type %s, but query expects %s.",
3099  format_type_be(attr->atttypid),
3100  format_type_be(op->d.fieldselect.resulttype))));
3101 
3102  /* heap_getattr needs a HeapTuple not a bare HeapTupleHeader */
3103  tmptup.t_len = HeapTupleHeaderGetDatumLength(tuple);
3104  tmptup.t_data = tuple;
3105 
3106  /* extract the field */
3107  *op->resvalue = heap_getattr(&tmptup,
3108  fieldnum,
3109  tupDesc,
3110  op->resnull);
3111  }
3112 }
#define VARATT_IS_EXTERNAL_EXPANDED(PTR)
Definition: postgres.h:335
Datum * resvalue
Definition: execExpr.h:273
static Datum expanded_record_get_field(ExpandedRecordHeader *erh, int fnumber, bool *isnull)
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
bool * resnull
Definition: execExpr.h:274
int errcode(int sqlerrcode)
Definition: elog.c:698
struct ExprEvalStep::@49::@74 fieldselect
char * format_type_be(Oid type_oid)
Definition: format_type.c:339
unsigned int Oid
Definition: postgres_ext.h:31
#define DatumGetHeapTupleHeader(X)
Definition: fmgr.h:295
signed int int32
Definition: c.h:429
HeapTupleHeader t_data
Definition: htup.h:68
#define HeapTupleHeaderGetTypMod(tup)
Definition: htup_details.h:467
#define ERROR
Definition: elog.h:46
union ExprEvalStep::@49 d
static TupleDesc get_cached_rowtype(Oid type_id, int32 typmod, ExprEvalRowtypeCache *rowcache, bool *changed)
uint32 t_len
Definition: htup.h:64
int errdetail(const char *fmt,...)
Definition: elog.c:1042
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:207
static TupleDesc expanded_record_get_tupdesc(ExpandedRecordHeader *erh)
ExpandedObjectHeader * DatumGetEOHP(Datum d)
Definition: expandeddatum.c:29
#define heap_getattr(tup, attnum, tupleDesc, isnull)
Definition: htup_details.h:761
uintptr_t Datum
Definition: postgres.h:411
#define ER_MAGIC
#define HeapTupleHeaderGetTypeId(tup)
Definition: htup_details.h:457
#define ereport(elevel,...)
Definition: elog.h:157
#define Assert(condition)
Definition: c.h:804
#define DatumGetPointer(X)
Definition: postgres.h:593
int errmsg(const char *fmt,...)
Definition: elog.c:909
#define elog(elevel,...)
Definition: elog.h:232
int16 AttrNumber
Definition: attnum.h:21
#define HeapTupleHeaderGetDatumLength(tup)
Definition: htup_details.h:451

◆ ExecEvalFieldStoreDeForm()

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

Definition at line 3124 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

3125 {
3126  TupleDesc tupDesc;
3127 
3128  /* Lookup tupdesc if first time through or if type changes */
3129  tupDesc = get_cached_rowtype(op->d.fieldstore.fstore->resulttype, -1,
3130  op->d.fieldstore.rowcache, NULL);
3131 
3132  /* Check that current tupdesc doesn't have more fields than we allocated */
3133  if (unlikely(tupDesc->natts > op->d.fieldstore.ncolumns))
3134  elog(ERROR, "too many columns in composite type %u",
3135  op->d.fieldstore.fstore->resulttype);
3136 
3137  if (*op->resnull)
3138  {
3139  /* Convert null input tuple into an all-nulls row */
3140  memset(op->d.fieldstore.nulls, true,
3141  op->d.fieldstore.ncolumns * sizeof(bool));
3142  }
3143  else
3144  {
3145  /*
3146  * heap_deform_tuple needs a HeapTuple not a bare HeapTupleHeader. We
3147  * set all the fields in the struct just in case.
3148  */
3149  Datum tupDatum = *op->resvalue;
3150  HeapTupleHeader tuphdr;
3151  HeapTupleData tmptup;
3152 
3153  tuphdr = DatumGetHeapTupleHeader(tupDatum);
3154  tmptup.t_len = HeapTupleHeaderGetDatumLength(tuphdr);
3155  ItemPointerSetInvalid(&(tmptup.t_self));
3156  tmptup.t_tableOid = InvalidOid;
3157  tmptup.t_data = tuphdr;
3158 
3159  heap_deform_tuple(&tmptup, tupDesc,
3160  op->d.fieldstore.values,
3161  op->d.fieldstore.nulls);
3162  }
3163 }
Datum * resvalue
Definition: execExpr.h:273
bool * resnull
Definition: execExpr.h:274
#define DatumGetHeapTupleHeader(X)
Definition: fmgr.h:295
HeapTupleHeader t_data
Definition: htup.h:68
#define ERROR
Definition: elog.h:46
union ExprEvalStep::@49 d
ItemPointerData t_self
Definition: htup.h:65
static TupleDesc get_cached_rowtype(Oid type_id, int32 typmod, ExprEvalRowtypeCache *rowcache, bool *changed)
uint32 t_len
Definition: htup.h:64
Oid t_tableOid
Definition: htup.h:66
struct ExprEvalStep::@49::@75 fieldstore
uintptr_t Datum
Definition: postgres.h:411
#define InvalidOid
Definition: postgres_ext.h:36
void heap_deform_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *values, bool *isnull)
Definition: heaptuple.c:1249
#define ItemPointerSetInvalid(pointer)
Definition: itemptr.h:172
#define elog(elevel,...)
Definition: elog.h:232
#define unlikely(x)
Definition: c.h:273
#define HeapTupleHeaderGetDatumLength(tup)
Definition: htup_details.h:451

◆ ExecEvalFieldStoreForm()

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

Definition at line 3170 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

3171 {
3172  TupleDesc tupDesc;
3173  HeapTuple tuple;
3174 
3175  /* Lookup tupdesc (should be valid already) */
3176  tupDesc = get_cached_rowtype(op->d.fieldstore.fstore->resulttype, -1,
3177  op->d.fieldstore.rowcache, NULL);
3178 
3179  tuple = heap_form_tuple(tupDesc,
3180  op->d.fieldstore.values,
3181  op->d.fieldstore.nulls);
3182 
3183  *op->resvalue = HeapTupleGetDatum(tuple);
3184  *op->resnull = false;
3185 }
Datum * resvalue
Definition: execExpr.h:273
bool * resnull
Definition: execExpr.h:274
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1020
union ExprEvalStep::@49 d
static TupleDesc get_cached_rowtype(Oid type_id, int32 typmod, ExprEvalRowtypeCache *rowcache, bool *changed)
struct ExprEvalStep::@49::@75 fieldstore
#define HeapTupleGetDatum(tuple)
Definition: funcapi.h:220

◆ ExecEvalFuncExprFusage()

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

Definition at line 2348 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

2350 {
2351  FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
2352  PgStat_FunctionCallUsage fcusage;
2353  Datum d;
2354 
2355  pgstat_init_function_usage(fcinfo, &fcusage);
2356 
2357  fcinfo->isnull = false;
2358  d = op->d.func.fn_addr(fcinfo);
2359  *op->resvalue = d;
2360  *op->resnull = fcinfo->isnull;
2361 
2362  pgstat_end_function_usage(&fcusage, true);
2363 }
Datum * resvalue
Definition: execExpr.h:273
bool * resnull
Definition: execExpr.h:274
void pgstat_init_function_usage(FunctionCallInfo fcinfo, PgStat_FunctionCallUsage *fcu)
Definition: pgstat.c:1914
union ExprEvalStep::@49 d
uintptr_t Datum
Definition: postgres.h:411
struct ExprEvalStep::@49::@56 func
void pgstat_end_function_usage(PgStat_FunctionCallUsage *fcu, bool finalize)
Definition: pgstat.c:1987

◆ ExecEvalFuncExprStrictFusage()

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

Definition at line 2369 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

2371 {
2372 
2373  FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
2374  PgStat_FunctionCallUsage fcusage;
2375  NullableDatum *args = fcinfo->args;
2376  int nargs = op->d.func.nargs;
2377  Datum d;
2378 
2379  /* strict function, so check for NULL args */
2380  for (int argno = 0; argno < nargs; argno++)
2381  {
2382  if (args[argno].isnull)
2383  {
2384  *op->resnull = true;
2385  return;
2386  }
2387  }
2388 
2389  pgstat_init_function_usage(fcinfo, &fcusage);
2390 
2391  fcinfo->isnull = false;
2392  d = op->d.func.fn_addr(fcinfo);
2393  *op->resvalue = d;
2394  *op->resnull = fcinfo->isnull;
2395 
2396  pgstat_end_function_usage(&fcusage, true);
2397 }
Datum * resvalue
Definition: execExpr.h:273
bool * resnull
Definition: execExpr.h:274
void pgstat_init_function_usage(FunctionCallInfo fcinfo, PgStat_FunctionCallUsage *fcu)
Definition: pgstat.c:1914
union ExprEvalStep::@49 d
NullableDatum args[FLEXIBLE_ARRAY_MEMBER]
Definition: fmgr.h:95
uintptr_t Datum
Definition: postgres.h:411
struct ExprEvalStep::@49::@56 func
void pgstat_end_function_usage(PgStat_FunctionCallUsage *fcu, bool finalize)
Definition: pgstat.c:1987

◆ ExecEvalGroupingFunc()

void ExecEvalGroupingFunc ( ExprState state,
ExprEvalStep op 
)

Definition at line 3913 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

3914 {
3915  AggState *aggstate = castNode(AggState, state->parent);
3916  int result = 0;
3917  Bitmapset *grouped_cols = aggstate->grouped_cols;
3918  ListCell *lc;
3919 
3920  foreach(lc, op->d.grouping_func.clauses)
3921  {
3922  int attnum = lfirst_int(lc);
3923 
3924  result <<= 1;
3925 
3926  if (!bms_is_member(attnum, grouped_cols))
3927  result |= 1;
3928  }
3929 
3930  *op->resvalue = Int32GetDatum(result);
3931  *op->resnull = false;
3932 }
struct PlanState * parent
Definition: execnodes.h:108
Datum * resvalue
Definition: execExpr.h:273
#define castNode(_type_, nodeptr)
Definition: nodes.h:605
bool * resnull
Definition: execExpr.h:274
union ExprEvalStep::@49 d
#define lfirst_int(lc)
Definition: pg_list.h:170
Bitmapset * grouped_cols
Definition: execnodes.h:2300
struct ExprEvalStep::@49::@84 grouping_func
int16 attnum
Definition: pg_attribute.h:83
#define Int32GetDatum(X)
Definition: postgres.h:523
bool bms_is_member(int x, const Bitmapset *a)
Definition: bitmapset.c:427

◆ ExecEvalHashedScalarArrayOp()

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

Definition at line 3492 of file execExprInterp.c.

References FunctionCallInfoBaseData::args, ARR_DATA_PTR, ARR_DIMS, ARR_ELEMTYPE, ARR_NDIM, ARR_NULLBITMAP, ArrayGetNItems(), Assert, att_addlength_pointer, att_align_nominal, BoolGetDatum, CurrentMemoryContext, ExprEvalStep::d, DatumGetArrayTypeP, ExprContext::ecxt_per_query_memory, element(), ExprEvalStep::elements_tab, fetch_att, get_typlenbyvalalign(), ExprEvalStep::has_nulls, ExprEvalStep::hashedscalararrayop, ScalarArrayOpExprHashTable::hashtab, i, ExprEvalStep::inclause, FunctionCallInfoBaseData::isnull, NullableDatum::isnull, MemoryContextSwitchTo(), ScalarArrayOpExprHashTable::op, ExprEvalStep::op, palloc(), ExprEvalStep::resnull, ExprEvalStep::resvalue, typalign, ExprEvalStep::typbyval, ExprEvalStep::typlen, and NullableDatum::value.

Referenced by ExecInterpExpr().

3493 {
3494  ScalarArrayOpExprHashTable *elements_tab = op->d.hashedscalararrayop.elements_tab;
3495  FunctionCallInfo fcinfo = op->d.hashedscalararrayop.fcinfo_data;
3496  bool inclause = op->d.hashedscalararrayop.inclause;
3497  bool strictfunc = op->d.hashedscalararrayop.finfo->fn_strict;
3498  Datum scalar = fcinfo->args[0].value;
3499  bool scalar_isnull = fcinfo->args[0].isnull;
3500  Datum result;
3501  bool resultnull;
3502  bool hashfound;
3503 
3504  /* We don't setup a hashed scalar array op if the array const is null. */
3505  Assert(!*op->resnull);
3506 
3507  /*
3508  * If the scalar is NULL, and the function is strict, return NULL; no
3509  * point in executing the search.
3510  */
3511  if (fcinfo->args[0].isnull && strictfunc)
3512  {
3513  *op->resnull = true;
3514  return;
3515  }
3516 
3517  /* Build the hash table on first evaluation */
3518  if (elements_tab == NULL)
3519  {
3520  int16 typlen;
3521  bool typbyval;
3522  char typalign;
3523  int nitems;
3524  bool has_nulls = false;
3525  char *s;
3526  bits8 *bitmap;
3527  int bitmask;
3528  MemoryContext oldcontext;
3529  ArrayType *arr;
3530 
3531  arr = DatumGetArrayTypeP(*op->resvalue);
3532  nitems = ArrayGetNItems(ARR_NDIM(arr), ARR_DIMS(arr));
3533 
3535  &typlen,
3536  &typbyval,
3537  &typalign);
3538 
3539  oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
3540 
3541  elements_tab = (ScalarArrayOpExprHashTable *)
3543  op->d.hashedscalararrayop.elements_tab = elements_tab;
3544  elements_tab->op = op;
3545 
3546  /*
3547  * Create the hash table sizing it according to the number of elements
3548  * in the array. This does assume that the array has no duplicates.
3549  * If the array happens to contain many duplicate values then it'll
3550  * just mean that we sized the table a bit on the large side.
3551  */
3552  elements_tab->hashtab = saophash_create(CurrentMemoryContext, nitems,
3553  elements_tab);
3554 
3555  MemoryContextSwitchTo(oldcontext);
3556 
3557  s = (char *) ARR_DATA_PTR(arr);
3558  bitmap = ARR_NULLBITMAP(arr);
3559  bitmask = 1;
3560  for (int i = 0; i < nitems; i++)
3561  {
3562  /* Get array element, checking for NULL. */
3563  if (bitmap && (*bitmap & bitmask) == 0)
3564  {
3565  has_nulls = true;
3566  }
3567  else
3568  {
3569  Datum element;
3570 
3571  element = fetch_att(s, typbyval, typlen);
3572  s = att_addlength_pointer(s, typlen, s);
3573  s = (char *) att_align_nominal(s, typalign);
3574 
3575  saophash_insert(elements_tab->hashtab, element, &hashfound);
3576  }
3577 
3578  /* Advance bitmap pointer if any. */
3579  if (bitmap)
3580  {
3581  bitmask <<= 1;
3582  if (bitmask == 0x100)
3583  {
3584  bitmap++;
3585  bitmask = 1;
3586  }
3587  }
3588  }
3589 
3590  /*
3591  * Remember if we had any nulls so that we know if we need to execute
3592  * non-strict functions with a null lhs value if no match is found.
3593  */
3594  op->d.hashedscalararrayop.has_nulls = has_nulls;
3595  }
3596 
3597  /* Check the hash to see if we have a match. */
3598  hashfound = NULL != saophash_lookup(elements_tab->hashtab, scalar);
3599 
3600  /* the result depends on if the clause is an IN or NOT IN clause */
3601  if (inclause)
3602  result = BoolGetDatum(hashfound); /* IN */
3603  else
3604  result = BoolGetDatum(!hashfound); /* NOT IN */
3605 
3606  resultnull = false;
3607 
3608  /*
3609  * If we didn't find a match in the array, we still might need to handle
3610  * the possibility of null values. We didn't put any NULLs into the
3611  * hashtable, but instead marked if we found any when building the table
3612  * in has_nulls.
3613  */
3614  if (!hashfound && op->d.hashedscalararrayop.has_nulls)
3615  {
3616  if (strictfunc)
3617  {
3618 
3619  /*
3620  * We have nulls in the array so a non-null lhs and no match must
3621  * yield NULL.
3622  */
3623  result = (Datum) 0;
3624  resultnull = true;
3625  }
3626  else
3627  {
3628  /*
3629  * Execute function will null rhs just once.
3630  *
3631  * The hash lookup path will have scribbled on the lhs argument so
3632  * we need to set it up also (even though we entered this function
3633  * with it already set).
3634  */
3635  fcinfo->args[0].value = scalar;
3636  fcinfo->args[0].isnull = scalar_isnull;
3637  fcinfo->args[1].value = (Datum) 0;
3638  fcinfo->args[1].isnull = true;
3639 
3640  result = op->d.hashedscalararrayop.fn_addr(fcinfo);
3641  resultnull = fcinfo->isnull;
3642 
3643  /*
3644  * Reverse the result for NOT IN clauses since the above function
3645  * is the equality function and we need not-equals.
3646  */
3647  if (!inclause)
3648  result = !result;
3649  }
3650  }
3651 
3652  *op->resvalue = result;
3653  *op->resnull = resultnull;
3654 }
signed short int16
Definition: c.h:428
struct ExprEvalStep * op
#define att_align_nominal(cur_offset, attalign)
Definition: tupmacs.h:148
Datum * resvalue
Definition: execExpr.h:273
void get_typlenbyvalalign(Oid typid, int16 *typlen, bool *typbyval, char *typalign)
Definition: lsyscache.c:2218
bool * resnull
Definition: execExpr.h:274
int ArrayGetNItems(int ndim, const int *dims)
Definition: arrayutils.c:76
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
char typalign
Definition: pg_type.h:176
union ExprEvalStep::@49 d
NullableDatum args[FLEXIBLE_ARRAY_MEMBER]
Definition: fmgr.h:95
#define ARR_DIMS(a)
Definition: array.h:287
#define ARR_DATA_PTR(a)
Definition: array.h:315
MemoryContext CurrentMemoryContext
Definition: mcxt.c:42
#define att_addlength_pointer(cur_offset, attlen, attptr)
Definition: tupmacs.h:176
Datum value
Definition: postgres.h:422
static chr element(struct vars *v, const chr *startp, const chr *endp)
Definition: regc_locale.c:376
uint8 bits8
Definition: c.h:448
uintptr_t Datum
Definition: postgres.h:411
#define BoolGetDatum(X)
Definition: postgres.h:446
#define Assert(condition)
Definition: c.h:804
struct ExprEvalStep::@49::@81 hashedscalararrayop
MemoryContext ecxt_per_query_memory
Definition: execnodes.h:233
#define ARR_NDIM(a)
Definition: array.h:283
void * palloc(Size size)
Definition: mcxt.c:1062
#define fetch_att(T, attbyval, attlen)
Definition: tupmacs.h:75
int i
#define ARR_ELEMTYPE(a)
Definition: array.h:285
#define ARR_NULLBITMAP(a)
Definition: array.h:293
#define DatumGetArrayTypeP(X)
Definition: array.h:254

◆ ExecEvalMinMax()

void ExecEvalMinMax ( ExprState state,
ExprEvalStep op 
)

Definition at line 2946 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

2947 {
2948  Datum *values = op->d.minmax.values;
2949  bool *nulls = op->d.minmax.nulls;
2950  FunctionCallInfo fcinfo = op->d.minmax.fcinfo_data;
2951  MinMaxOp operator = op->d.minmax.op;
2952 
2953  /* set at initialization */
2954  Assert(fcinfo->args[0].isnull == false);
2955  Assert(fcinfo->args[1].isnull == false);
2956 
2957  /* default to null result */
2958  *op->resnull = true;
2959 
2960  for (int off = 0; off < op->d.minmax.nelems; off++)
2961  {
2962  /* ignore NULL inputs */
2963  if (nulls[off])
2964  continue;
2965 
2966  if (*op->resnull)
2967  {
2968  /* first nonnull input, adopt value */
2969  *op->resvalue = values[off];
2970  *op->resnull = false;
2971  }
2972  else
2973  {
2974  int cmpresult;
2975 
2976  /* apply comparison function */
2977  fcinfo->args[0].value = *op->resvalue;
2978  fcinfo->args[1].value = values[off];
2979 
2980  fcinfo->isnull = false;
2981  cmpresult = DatumGetInt32(FunctionCallInvoke(fcinfo));
2982  if (fcinfo->isnull) /* probably should not happen */
2983  continue;
2984 
2985  if (cmpresult > 0 && operator == IS_LEAST)
2986  *op->resvalue = values[off];
2987  else if (cmpresult < 0 && operator == IS_GREATEST)
2988  *op->resvalue = values[off];
2989  }
2990  }
2991 }
Datum * resvalue
Definition: execExpr.h:273
#define DatumGetInt32(X)
Definition: postgres.h:516
bool * resnull
Definition: execExpr.h:274
MinMaxOp
Definition: primnodes.h:1139
union ExprEvalStep::@49 d
NullableDatum args[FLEXIBLE_ARRAY_MEMBER]
Definition: fmgr.h:95
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:172
Datum value
Definition: postgres.h:422
uintptr_t Datum
Definition: postgres.h:411
#define Assert(condition)
Definition: c.h:804
static Datum values[MAXATTR]
Definition: bootstrap.c:156
struct ExprEvalStep::@49::@73 minmax

◆ ExecEvalNextValueExpr()

void ExecEvalNextValueExpr ( ExprState state,
ExprEvalStep op 
)

Definition at line 2548 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

2549 {
2550  int64 newval = nextval_internal(op->d.nextvalueexpr.seqid, false);
2551 
2552  switch (op->d.nextvalueexpr.seqtypid)
2553  {
2554  case INT2OID:
2555  *op->resvalue = Int16GetDatum((int16) newval);
2556  break;
2557  case INT4OID:
2558  *op->resvalue = Int32GetDatum((int32) newval);
2559  break;
2560  case INT8OID:
2561  *op->resvalue = Int64GetDatum((int64) newval);
2562  break;
2563  default:
2564  elog(ERROR, "unsupported sequence type %u",
2565  op->d.nextvalueexpr.seqtypid);
2566  }
2567  *op->resnull = false;
2568 }
signed short int16
Definition: c.h:428
Datum * resvalue
Definition: execExpr.h:273
int64 nextval_internal(Oid relid, bool check_permissions)
Definition: sequence.c:579
bool * resnull
Definition: execExpr.h:274
#define Int16GetDatum(X)
Definition: postgres.h:495
struct ExprEvalStep::@49::@67 nextvalueexpr
signed int int32
Definition: c.h:429
#define ERROR
Definition: elog.h:46
union ExprEvalStep::@49 d
Datum Int64GetDatum(int64 X)
Definition: fmgr.c:1697
#define newval
#define Int32GetDatum(X)
Definition: postgres.h:523
#define elog(elevel,...)
Definition: elog.h:232

◆ ExecEvalParamExec()

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

Definition at line 2406 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

2407 {
2408  ParamExecData *prm;
2409 
2410  prm = &(econtext->ecxt_param_exec_vals[op->d.param.paramid]);
2411  if (unlikely(prm->execPlan != NULL))
2412  {
2413  /* Parameter not evaluated yet, so go do it */
2414  ExecSetParamPlan(prm->execPlan, econtext);
2415  /* ExecSetParamPlan should have processed this param... */
2416  Assert(prm->execPlan == NULL);
2417  }
2418  *op->resvalue = prm->value;
2419  *op->resnull = prm->isnull;
2420 }
void * execPlan
Definition: params.h:148
Datum * resvalue
Definition: execExpr.h:273
bool * resnull
Definition: execExpr.h:274
union ExprEvalStep::@49 d
void ExecSetParamPlan(SubPlanState *node, ExprContext *econtext)
Definition: nodeSubplan.c:1058
bool isnull
Definition: params.h:150
struct ExprEvalStep::@49::@61 param
ParamExecData * ecxt_param_exec_vals
Definition: execnodes.h:237
#define Assert(condition)
Definition: c.h:804
Datum value
Definition: params.h:149
#define unlikely(x)
Definition: c.h:273

◆ ExecEvalParamExtern()

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

Definition at line 2428 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

2429 {
2430  ParamListInfo paramInfo = econtext->ecxt_param_list_info;
2431  int paramId = op->d.param.paramid;
2432 
2433  if (likely(paramInfo &&
2434  paramId > 0 && paramId <= paramInfo->numParams))
2435  {
2436  ParamExternData *prm;
2437  ParamExternData prmdata;
2438 
2439  /* give hook a chance in case parameter is dynamic */
2440  if (paramInfo->paramFetch != NULL)
2441  prm = paramInfo->paramFetch(paramInfo, paramId, false, &prmdata);
2442  else
2443  prm = &paramInfo->params[paramId - 1];
2444 
2445  if (likely(OidIsValid(prm->ptype)))
2446  {
2447  /* safety check in case hook did something unexpected */
2448  if (unlikely(prm->ptype != op->d.param.paramtype))
2449  ereport(ERROR,
2450  (errcode(ERRCODE_DATATYPE_MISMATCH),
2451  errmsg("type of parameter %d (%s) does not match that when preparing the plan (%s)",
2452  paramId,
2453  format_type_be(prm->ptype),
2454  format_type_be(op->d.param.paramtype))));
2455  *op->resvalue = prm->value;
2456  *op->resnull = prm->isnull;
2457  return;
2458  }
2459  }
2460 
2461  ereport(ERROR,
2462  (errcode(ERRCODE_UNDEFINED_OBJECT),
2463  errmsg("no value found for parameter %d", paramId)));
2464 }
ParamExternData params[FLEXIBLE_ARRAY_MEMBER]
Definition: params.h:125
Datum value
Definition: params.h:92
#define likely(x)
Definition: c.h:272
Datum * resvalue
Definition: execExpr.h:273
bool * resnull
Definition: execExpr.h:274
int errcode(int sqlerrcode)
Definition: elog.c:698
char * format_type_be(Oid type_oid)
Definition: format_type.c:339
#define OidIsValid(objectId)
Definition: c.h:710
ParamFetchHook paramFetch
Definition: params.h:112
#define ERROR
Definition: elog.h:46
union ExprEvalStep::@49 d
struct ExprEvalStep::@49::@61 param
#define ereport(elevel,...)
Definition: elog.h:157
int errmsg(const char *fmt,...)
Definition: elog.c:909
#define unlikely(x)
Definition: c.h:273
ParamListInfo ecxt_param_list_info
Definition: execnodes.h:238
bool isnull
Definition: params.h:93

◆ ExecEvalRow()

void ExecEvalRow ( ExprState state,
ExprEvalStep op 
)

Definition at line 2926 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

2927 {
2928  HeapTuple tuple;
2929 
2930  /* build tuple from evaluated field values */
2931  tuple = heap_form_tuple(op->d.row.tupdesc,
2932  op->d.row.elemvalues,
2933  op->d.row.elemnulls);
2934 
2935  *op->resvalue = HeapTupleGetDatum(tuple);
2936  *op->resnull = false;
2937 }
Datum * resvalue
Definition: execExpr.h:273
bool * resnull
Definition: execExpr.h:274
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1020
union ExprEvalStep::@49 d
#define HeapTupleGetDatum(tuple)
Definition: funcapi.h:220
struct ExprEvalStep::@49::@70 row

◆ ExecEvalRowNotNull()

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

Definition at line 2583 of file execExprInterp.c.

References ExecEvalRowNullInt().

Referenced by ExecInterpExpr().

2584 {
2585  ExecEvalRowNullInt(state, op, econtext, false);
2586 }
static void ExecEvalRowNullInt(ExprState *state, ExprEvalStep *op, ExprContext *econtext, bool checkisnull)

◆ ExecEvalRowNull()

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

Definition at line 2574 of file execExprInterp.c.

References ExecEvalRowNullInt().

Referenced by ExecInterpExpr().

2575 {
2576  ExecEvalRowNullInt(state, op, econtext, true);
2577 }
static void ExecEvalRowNullInt(ExprState *state, ExprEvalStep *op, ExprContext *econtext, bool checkisnull)

◆ ExecEvalRowNullInt()

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

Definition at line 2590 of file execExprInterp.c.

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

Referenced by ExecEvalRowNotNull(), and ExecEvalRowNull().

2592 {
2593  Datum value = *op->resvalue;
2594  bool isnull = *op->resnull;
2595  HeapTupleHeader tuple;
2596  Oid tupType;
2597  int32 tupTypmod;
2598  TupleDesc tupDesc;
2599  HeapTupleData tmptup;
2600 
2601  *op->resnull = false;
2602 
2603  /* NULL row variables are treated just as NULL scalar columns */
2604  if (isnull)
2605  {
2606  *op->resvalue = BoolGetDatum(checkisnull);
2607  return;
2608  }
2609 
2610  /*
2611  * The SQL standard defines IS [NOT] NULL for a non-null rowtype argument
2612  * as:
2613  *
2614  * "R IS NULL" is true if every field is the null value.
2615  *
2616  * "R IS NOT NULL" is true if no field is the null value.
2617  *
2618  * This definition is (apparently intentionally) not recursive; so our
2619  * tests on the fields are primitive attisnull tests, not recursive checks
2620  * to see if they are all-nulls or no-nulls rowtypes.
2621  *
2622  * The standard does not consider the possibility of zero-field rows, but
2623  * here we consider them to vacuously satisfy both predicates.
2624  */
2625 
2626  tuple = DatumGetHeapTupleHeader(value);
2627 
2628  tupType = HeapTupleHeaderGetTypeId(tuple);
2629  tupTypmod = HeapTupleHeaderGetTypMod(tuple);
2630 
2631  /* Lookup tupdesc if first time through or if type changes */
2632  tupDesc = get_cached_rowtype(tupType, tupTypmod,
2633  &op->d.nulltest_row.rowcache, NULL);
2634 
2635  /*
2636  * heap_attisnull needs a HeapTuple not a bare HeapTupleHeader.
2637  */
2638  tmptup.t_len = HeapTupleHeaderGetDatumLength(tuple);
2639  tmptup.t_data = tuple;
2640 
2641  for (int att = 1; att <= tupDesc->natts; att++)
2642  {
2643  /* ignore dropped columns */
2644  if (TupleDescAttr(tupDesc, att - 1)->attisdropped)
2645  continue;
2646  if (heap_attisnull(&tmptup, att, tupDesc))
2647  {
2648  /* null field disproves IS NOT NULL */
2649  if (!checkisnull)
2650  {
2651  *op->resvalue = BoolGetDatum(false);
2652  return;
2653  }
2654  }
2655  else
2656  {
2657  /* non-null field disproves IS NULL */
2658  if (checkisnull)
2659  {
2660  *op->resvalue = BoolGetDatum(false);
2661  return;
2662  }
2663  }
2664  }
2665 
2666  *op->resvalue = BoolGetDatum(true);
2667 }
Datum * resvalue
Definition: execExpr.h:273
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
bool * resnull
Definition: execExpr.h:274
bool heap_attisnull(HeapTuple tup, int attnum, TupleDesc tupleDesc)
Definition: heaptuple.c:359
unsigned int Oid
Definition: postgres_ext.h:31
#define DatumGetHeapTupleHeader(X)
Definition: fmgr.h:295
signed int int32
Definition: c.h:429
HeapTupleHeader t_data
Definition: htup.h:68
#define HeapTupleHeaderGetTypMod(tup)
Definition: htup_details.h:467
union ExprEvalStep::@49 d
static TupleDesc get_cached_rowtype(Oid type_id, int32 typmod, ExprEvalRowtypeCache *rowcache, bool *changed)
uint32 t_len
Definition: htup.h:64
uintptr_t Datum
Definition: postgres.h:411
#define HeapTupleHeaderGetTypeId(tup)
Definition: htup_details.h:457
#define BoolGetDatum(X)
Definition: postgres.h:446
static struct @143 value
struct ExprEvalStep::@49::@60 nulltest_row
#define HeapTupleHeaderGetDatumLength(tup)
Definition: htup_details.h:451

◆ ExecEvalScalarArrayOp()

void ExecEvalScalarArrayOp ( ExprState state,
ExprEvalStep op 
)

Definition at line 3289 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

3290 {
3291  FunctionCallInfo fcinfo = op->d.scalararrayop.fcinfo_data;
3292  bool useOr = op->d.scalararrayop.useOr;
3293  bool strictfunc = op->d.scalararrayop.finfo->fn_strict;
3294  ArrayType *arr;
3295  int nitems;
3296  Datum result;
3297  bool resultnull;
3298  int16 typlen;
3299  bool typbyval;
3300  char typalign;
3301  char *s;
3302  bits8 *bitmap;
3303  int bitmask;
3304 
3305  /*
3306  * If the array is NULL then we return NULL --- it's not very meaningful
3307  * to do anything else, even if the operator isn't strict.
3308  */
3309  if (*op->resnull)
3310  return;
3311 
3312  /* Else okay to fetch and detoast the array */
3313  arr = DatumGetArrayTypeP(*op->resvalue);
3314 
3315  /*
3316  * If the array is empty, we return either FALSE or TRUE per the useOr
3317  * flag. This is correct even if the scalar is NULL; since we would
3318  * evaluate the operator zero times, it matters not whether it would want
3319  * to return NULL.
3320  */
3321  nitems = ArrayGetNItems(ARR_NDIM(arr), ARR_DIMS(arr));
3322  if (nitems <= 0)
3323  {
3324  *op->resvalue = BoolGetDatum(!useOr);
3325  *op->resnull = false;
3326  return;
3327  }
3328 
3329  /*
3330  * If the scalar is NULL, and the function is strict, return NULL; no
3331  * point in iterating the loop.
3332  */
3333  if (fcinfo->args[0].isnull && strictfunc)
3334  {
3335  *op->resnull = true;
3336  return;
3337  }
3338 
3339  /*
3340  * We arrange to look up info about the element type only once per series
3341  * of calls, assuming the element type doesn't change underneath us.
3342  */
3343  if (op->d.scalararrayop.element_type != ARR_ELEMTYPE(arr))
3344  {
3346  &op->d.scalararrayop.typlen,
3347  &op->d.scalararrayop.typbyval,
3348  &op->d.scalararrayop.typalign);
3349  op->d.scalararrayop.element_type = ARR_ELEMTYPE(arr);
3350  }
3351 
3352  typlen = op->d.scalararrayop.typlen;
3353  typbyval = op->d.scalararrayop.typbyval;
3354  typalign = op->d.scalararrayop.typalign;
3355 
3356  /* Initialize result appropriately depending on useOr */
3357  result = BoolGetDatum(!useOr);
3358  resultnull = false;
3359 
3360  /* Loop over the array elements */
3361  s = (char *) ARR_DATA_PTR(arr);
3362  bitmap = ARR_NULLBITMAP(arr);
3363  bitmask = 1;
3364 
3365  for (int i = 0; i < nitems; i++)
3366  {
3367  Datum elt;
3368  Datum thisresult;
3369 
3370  /* Get array element, checking for NULL */
3371  if (bitmap && (*bitmap & bitmask) == 0)
3372  {
3373  fcinfo->args[1].value = (Datum) 0;
3374  fcinfo->args[1].isnull = true;
3375  }
3376  else
3377  {
3378  elt = fetch_att(s, typbyval, typlen);
3379  s = att_addlength_pointer(s, typlen, s);
3380  s = (char *) att_align_nominal(s, typalign);
3381  fcinfo->args[1].value = elt;
3382  fcinfo->args[1].isnull = false;
3383  }
3384 
3385  /* Call comparison function */
3386  if (fcinfo->args[1].isnull && strictfunc)
3387  {
3388  fcinfo->isnull = true;
3389  thisresult = (Datum) 0;
3390  }
3391  else
3392  {
3393  fcinfo->isnull = false;
3394  thisresult = op->d.scalararrayop.fn_addr(fcinfo);
3395  }
3396 
3397  /* Combine results per OR or AND semantics */
3398  if (fcinfo->isnull)
3399  resultnull = true;
3400  else if (useOr)
3401  {
3402  if (DatumGetBool(thisresult))
3403  {
3404  result = BoolGetDatum(true);
3405  resultnull = false;
3406  break; /* needn't look at any more elements */
3407  }
3408  }
3409  else
3410  {
3411  if (!DatumGetBool(thisresult))
3412  {
3413  result = BoolGetDatum(false);
3414  resultnull = false;
3415  break; /* needn't look at any more elements */
3416  }
3417  }
3418 
3419  /* advance bitmap pointer if any */
3420  if (bitmap)
3421  {
3422  bitmask <<= 1;
3423  if (bitmask == 0x100)
3424  {
3425  bitmap++;
3426  bitmask = 1;
3427  }
3428  }
3429  }
3430 
3431  *op->resvalue = result;
3432  *op->resnull = resultnull;
3433 }
signed short int16
Definition: c.h:428
struct ExprEvalStep::@49::@80 scalararrayop
#define att_align_nominal(cur_offset, attalign)
Definition: tupmacs.h:148
Datum * resvalue
Definition: execExpr.h:273
void get_typlenbyvalalign(Oid typid, int16 *typlen, bool *typbyval, char *typalign)
Definition: lsyscache.c:2218
bool * resnull
Definition: execExpr.h:274
int ArrayGetNItems(int ndim, const int *dims)
Definition: arrayutils.c:76
char typalign
Definition: pg_type.h:176
union ExprEvalStep::@49 d
NullableDatum args[FLEXIBLE_ARRAY_MEMBER]
Definition: fmgr.h:95
#define ARR_DIMS(a)
Definition: array.h:287
#define ARR_DATA_PTR(a)
Definition: array.h:315
#define DatumGetBool(X)
Definition: postgres.h:437
#define att_addlength_pointer(cur_offset, attlen, attptr)
Definition: tupmacs.h:176
Datum value
Definition: postgres.h:422
uint8 bits8
Definition: c.h:448
uintptr_t Datum
Definition: postgres.h:411
#define BoolGetDatum(X)
Definition: postgres.h:446
#define ARR_NDIM(a)
Definition: array.h:283
#define fetch_att(T, attbyval, attlen)
Definition: tupmacs.h:75
int i
#define ARR_ELEMTYPE(a)
Definition: array.h:285
#define ARR_NULLBITMAP(a)
Definition: array.h:293
#define DatumGetArrayTypeP(X)
Definition: array.h:254

◆ ExecEvalSQLValueFunction()

void ExecEvalSQLValueFunction ( ExprState state,
ExprEvalStep op 
)

Definition at line 2470 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

2471 {
2472  LOCAL_FCINFO(fcinfo, 0);
2473  SQLValueFunction *svf = op->d.sqlvaluefunction.svf;
2474 
2475  *op->resnull = false;
2476 
2477  /*
2478  * Note: current_schema() can return NULL. current_user() etc currently
2479  * cannot, but might as well code those cases the same way for safety.
2480  */
2481  switch (svf->op)
2482  {
2483  case SVFOP_CURRENT_DATE:
2485  break;
2486  case SVFOP_CURRENT_TIME:
2487  case SVFOP_CURRENT_TIME_N:
2489  break;
2493  break;
2494  case SVFOP_LOCALTIME:
2495  case SVFOP_LOCALTIME_N:
2497  break;
2498  case SVFOP_LOCALTIMESTAMP:
2501  break;
2502  case SVFOP_CURRENT_ROLE:
2503  case SVFOP_CURRENT_USER:
2504  case SVFOP_USER:
2505  InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
2506  *op->resvalue = current_user(fcinfo);
2507  *op->resnull = fcinfo->isnull;
2508  break;
2509  case SVFOP_SESSION_USER:
2510  InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
2511  *op->resvalue = session_user(fcinfo);
2512  *op->resnull = fcinfo->isnull;
2513  break;
2514  case SVFOP_CURRENT_CATALOG:
2515  InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
2516  *op->resvalue = current_database(fcinfo);
2517  *op->resnull = fcinfo->isnull;
2518  break;
2519  case SVFOP_CURRENT_SCHEMA:
2520  InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
2521  *op->resvalue = current_schema(fcinfo);
2522  *op->resnull = fcinfo->isnull;
2523  break;
2524  }
2525 }
Datum current_schema(PG_FUNCTION_ARGS)
Definition: name.c:279
Datum * resvalue
Definition: execExpr.h:273
bool * resnull
Definition: execExpr.h:274
#define TimeTzADTPGetDatum(X)
Definition: date.h:59
TimestampTz GetSQLCurrentTimestamp(int32 typmod)
Definition: timestamp.c:1598
#define DateADTGetDatum(X)
Definition: date.h:57
DateADT GetSQLCurrentDate(void)
Definition: date.c:301
SQLValueFunctionOp op
Definition: primnodes.h:1189
Datum current_database(PG_FUNCTION_ARGS)
Definition: misc.c:173
union ExprEvalStep::@49 d
#define TimestampTzGetDatum(X)
Definition: timestamp.h:32
TimeTzADT * GetSQLCurrentTime(int32 typmod)
Definition: date.c:334
Datum current_user(PG_FUNCTION_ARGS)
Definition: name.c:263
#define TimestampGetDatum(X)
Definition: timestamp.h:31
TimeADT GetSQLLocalTime(int32 typmod)
Definition: date.c:354
Datum session_user(PG_FUNCTION_ARGS)
Definition: name.c:269
#define TimeADTGetDatum(X)
Definition: date.h:58
Timestamp GetSQLLocalTimestamp(int32 typmod)
Definition: timestamp.c:1612
#define InvalidOid
Definition: postgres_ext.h:36
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
struct ExprEvalStep::@49::@66 sqlvaluefunction

◆ ExecEvalStepOp()

ExprEvalOp ExecEvalStepOp ( ExprState state,
ExprEvalStep op 
)

Definition at line 2318 of file execExprInterp.c.

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

Referenced by CheckExprStillValid(), and llvm_compile_expr().

2319 {
2320 #if defined(EEO_USE_COMPUTED_GOTO)
2321  if (state->flags & EEO_FLAG_DIRECT_THREADED)
2322  {
2323  ExprEvalOpLookup key;
2324  ExprEvalOpLookup *res;
2325 
2326  key.opcode = (void *) op->opcode;
2327  res = bsearch(&key,
2328  reverse_dispatch_table,
2329  EEOP_LAST /* nmembers */ ,
2330  sizeof(ExprEvalOpLookup),
2331  dispatch_compare_ptr);
2332  Assert(res); /* unknown ops shouldn't get looked up */
2333  return res->op;
2334  }
2335 #endif
2336  return (ExprEvalOp) op->opcode;
2337 }
ExprEvalOp
Definition: execExpr.h:64
#define Assert(condition)
Definition: c.h:804
intptr_t opcode
Definition: execExpr.h:270
uint8 flags
Definition: execnodes.h:65
#define EEO_FLAG_DIRECT_THREADED
Definition: execExpr.h:29

◆ ExecEvalSubPlan()

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

Definition at line 3938 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

3939 {
3940  SubPlanState *sstate = op->d.subplan.sstate;
3941 
3942  /* could potentially be nested, so make sure there's enough stack */
3944 
3945  *op->resvalue = ExecSubPlan(sstate, econtext, op->resnull);
3946 }
struct ExprEvalStep::@49::@86 subplan
Datum * resvalue
Definition: execExpr.h:273
bool * resnull
Definition: execExpr.h:274
union ExprEvalStep::@49 d
void check_stack_depth(void)
Definition: postgres.c:3469
Datum ExecSubPlan(SubPlanState *node, ExprContext *econtext, bool *isNull)
Definition: nodeSubplan.c:62

◆ ExecEvalSysVar()

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

Definition at line 4184 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

4186 {
4187  Datum d;
4188 
4189  /* slot_getsysattr has sufficient defenses against bad attnums */
4190  d = slot_getsysattr(slot,
4191  op->d.var.attnum,
4192  op->resnull);
4193  *op->resvalue = d;
4194  /* this ought to be unreachable, but it's cheap enough to check */
4195  if (unlikely(*op->resnull))
4196  elog(ERROR, "failed to fetch attribute from slot");
4197 }
Datum * resvalue
Definition: execExpr.h:273
bool * resnull
Definition: execExpr.h:274
struct ExprEvalStep::@49::@51 var
#define ERROR
Definition: elog.h:46
union ExprEvalStep::@49 d
uintptr_t Datum
Definition: postgres.h:411
#define elog(elevel,...)
Definition: elog.h:232
#define unlikely(x)
Definition: c.h:273
static Datum slot_getsysattr(TupleTableSlot *slot, int attnum, bool *isnull)
Definition: tuptable.h:402

◆ ExecEvalWholeRowVar()

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

Definition at line 3955 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

3956 {
3957  Var *variable = op->d.wholerow.var;
3958  TupleTableSlot *slot;
3959  TupleDesc output_tupdesc;
3960  MemoryContext oldcontext;
3961  HeapTupleHeader dtuple;
3962  HeapTuple tuple;
3963 
3964  /* This was checked by ExecInitExpr */
3965  Assert(variable->varattno == InvalidAttrNumber);
3966 
3967  /* Get the input slot we want */
3968  switch (variable->varno)
3969  {
3970  case INNER_VAR:
3971  /* get the tuple from the inner node */
3972  slot = econtext->ecxt_innertuple;
3973  break;
3974 
3975  case OUTER_VAR:
3976  /* get the tuple from the outer node */
3977  slot = econtext->ecxt_outertuple;
3978  break;
3979 
3980  /* INDEX_VAR is handled by default case */
3981 
3982  default:
3983  /* get the tuple from the relation being scanned */
3984  slot = econtext->ecxt_scantuple;
3985  break;
3986  }
3987 
3988  /* Apply the junkfilter if any */
3989  if (op->d.wholerow.junkFilter != NULL)
3990  slot = ExecFilterJunk(op->d.wholerow.junkFilter, slot);
3991 
3992  /*
3993  * If first time through, obtain tuple descriptor and check compatibility.
3994  *
3995  * XXX: It'd be great if this could be moved to the expression
3996  * initialization phase, but due to using slots that's currently not
3997  * feasible.
3998  */
3999  if (op->d.wholerow.first)
4000  {
4001  /* optimistically assume we don't need slow path */
4002  op->d.wholerow.slow = false;
4003 
4004  /*
4005  * If the Var identifies a named composite type, we must check that
4006  * the actual tuple type is compatible with it.
4007  */
4008  if (variable->vartype != RECORDOID)
4009  {
4010  TupleDesc var_tupdesc;
4011  TupleDesc slot_tupdesc;
4012 
4013  /*
4014  * We really only care about numbers of attributes and data types.
4015  * Also, we can ignore type mismatch on columns that are dropped
4016  * in the destination type, so long as (1) the physical storage
4017  * matches or (2) the actual column value is NULL. Case (1) is
4018  * helpful in some cases involving out-of-date cached plans, while
4019  * case (2) is expected behavior in situations such as an INSERT
4020  * into a table with dropped columns (the planner typically
4021  * generates an INT4 NULL regardless of the dropped column type).
4022  * If we find a dropped column and cannot verify that case (1)
4023  * holds, we have to use the slow path to check (2) for each row.
4024  *
4025  * If vartype is a domain over composite, just look through that
4026  * to the base composite type.
4027  */
4028  var_tupdesc = lookup_rowtype_tupdesc_domain(variable->vartype,
4029  -1, false);
4030 
4031  slot_tupdesc = slot->tts_tupleDescriptor;
4032 
4033  if (var_tupdesc->natts != slot_tupdesc->natts)
4034  ereport(ERROR,
4035  (errcode(ERRCODE_DATATYPE_MISMATCH),
4036  errmsg("table row type and query-specified row type do not match"),
4037  errdetail_plural("Table row contains %d attribute, but query expects %d.",
4038  "Table row contains %d attributes, but query expects %d.",
4039  slot_tupdesc->natts,
4040  slot_tupdesc->natts,
4041  var_tupdesc->natts)));
4042 
4043  for (int i = 0; i < var_tupdesc->natts; i++)
4044  {
4045  Form_pg_attribute vattr = TupleDescAttr(var_tupdesc, i);
4046  Form_pg_attribute sattr = TupleDescAttr(slot_tupdesc, i);
4047 
4048  if (vattr->atttypid == sattr->atttypid)
4049  continue; /* no worries */
4050  if (!vattr->attisdropped)
4051  ereport(ERROR,
4052  (errcode(ERRCODE_DATATYPE_MISMATCH),
4053  errmsg("table row type and query-specified row type do not match"),
4054  errdetail("Table has type %s at ordinal position %d, but query expects %s.",
4055  format_type_be(sattr->atttypid),
4056  i + 1,
4057  format_type_be(vattr->atttypid))));
4058 
4059  if (vattr->attlen != sattr->attlen ||
4060  vattr->attalign != sattr->attalign)
4061  op->d.wholerow.slow = true; /* need to check for nulls */
4062  }
4063 
4064  /*
4065  * Use the variable's declared rowtype as the descriptor for the
4066  * output values, modulo possibly assigning new column names
4067  * below. In particular, we *must* absorb any attisdropped
4068  * markings.
4069  */
4070  oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
4071  output_tupdesc = CreateTupleDescCopy(var_tupdesc);
4072  MemoryContextSwitchTo(oldcontext);
4073 
4074  ReleaseTupleDesc(var_tupdesc);
4075  }
4076  else
4077  {
4078  /*
4079  * In the RECORD case, we use the input slot's rowtype as the
4080  * descriptor for the output values, modulo possibly assigning new
4081  * column names below.
4082  */
4083  oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
4084  output_tupdesc = CreateTupleDescCopy(slot->tts_tupleDescriptor);
4085  MemoryContextSwitchTo(oldcontext);
4086  }
4087 
4088  /*
4089  * Construct a tuple descriptor for the composite values we'll
4090  * produce, and make sure its record type is "blessed". The main
4091  * reason to do this is to be sure that operations such as
4092  * row_to_json() will see the desired column names when they look up
4093  * the descriptor from the type information embedded in the composite
4094  * values.
4095  *
4096  * We already got the correct physical datatype info above, but now we
4097  * should try to find the source RTE and adopt its column aliases, in
4098  * case they are different from the original rowtype's names. For
4099  * example, in "SELECT foo(t) FROM tab t(x,y)", the first two columns
4100  * in the composite output should be named "x" and "y" regardless of
4101  * tab's column names.
4102  *
4103  * If we can't locate the RTE, assume the column names we've got are
4104  * OK. (As of this writing, the only cases where we can't locate the
4105  * RTE are in execution of trigger WHEN clauses, and then the Var will
4106  * have the trigger's relation's rowtype, so its names are fine.)
4107  * Also, if the creator of the RTE didn't bother to fill in an eref
4108  * field, assume our column names are OK. (This happens in COPY, and
4109  * perhaps other places.)
4110  */
4111  if (econtext->ecxt_estate &&
4112  variable->varno <= econtext->ecxt_estate->es_range_table_size)
4113  {
4114  RangeTblEntry *rte = exec_rt_fetch(variable->varno,
4115  econtext->ecxt_estate);
4116 
4117  if (rte->eref)
4118  ExecTypeSetColNames(output_tupdesc, rte->eref->colnames);
4119  }
4120 
4121  /* Bless the tupdesc if needed, and save it in the execution state */
4122  op->d.wholerow.tupdesc = BlessTupleDesc(output_tupdesc);
4123 
4124  op->d.wholerow.first = false;
4125  }
4126 
4127  /*
4128  * Make sure all columns of the slot are accessible in the slot's
4129  * Datum/isnull arrays.
4130  */
4131  slot_getallattrs(slot);
4132 
4133  if (op->d.wholerow.slow)
4134  {
4135  /* Check to see if any dropped attributes are non-null */
4136  TupleDesc tupleDesc = slot->tts_tupleDescriptor;
4137  TupleDesc var_tupdesc = op->d.wholerow.tupdesc;
4138 
4139  Assert(var_tupdesc->natts == tupleDesc->natts);
4140 
4141  for (int i = 0; i < var_tupdesc->natts; i++)
4142  {
4143  Form_pg_attribute vattr = TupleDescAttr(var_tupdesc, i);
4144  Form_pg_attribute sattr = TupleDescAttr(tupleDesc, i);
4145 
4146  if (!vattr->attisdropped)
4147  continue; /* already checked non-dropped cols */
4148  if (slot->tts_isnull[i])
4149  continue; /* null is always okay */
4150  if (vattr->attlen != sattr->attlen ||
4151  vattr->attalign != sattr->attalign)
4152  ereport(ERROR,
4153  (errcode(ERRCODE_DATATYPE_MISMATCH),
4154  errmsg("table row type and query-specified row type do not match"),
4155  errdetail("Physical storage mismatch on dropped attribute at ordinal position %d.",
4156  i + 1)));
4157  }
4158  }
4159 
4160  /*
4161  * Build a composite datum, making sure any toasted fields get detoasted.
4162  *
4163  * (Note: it is critical that we not change the slot's state here.)
4164  */
4166  slot->tts_values,
4167  slot->tts_isnull);
4168  dtuple = tuple->t_data;
4169 
4170  /*
4171  * Label the datum with the composite type info we identified before.
4172  *
4173  * (Note: we could skip doing this by passing op->d.wholerow.tupdesc to
4174  * the tuple build step; but that seems a tad risky so let's not.)
4175  */
4176  HeapTupleHeaderSetTypeId(dtuple, op->d.wholerow.tupdesc->tdtypeid);
4177  HeapTupleHeaderSetTypMod(dtuple, op->d.wholerow.tupdesc->tdtypmod);
4178 
4179  *op->resvalue = PointerGetDatum(dtuple);
4180  *op->resnull = false;
4181 }
int varno
Definition: primnodes.h:189
struct ExprEvalStep::@49::@52 wholerow
TupleDesc CreateTupleDescCopy(TupleDesc tupdesc)
Definition: tupdesc.c:111
#define HeapTupleHeaderSetTypeId(tup, typeid)
Definition: htup_details.h:462
Datum * resvalue
Definition: execExpr.h:273
List * colnames
Definition: primnodes.h:43
#define PointerGetDatum(X)
Definition: postgres.h:600
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
bool * resnull
Definition: execExpr.h:274
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
int errcode(int sqlerrcode)
Definition: elog.c:698
AttrNumber varattno
Definition: primnodes.h:191
char * format_type_be(Oid type_oid)
Definition: format_type.c:339
Datum * tts_values
Definition: tuptable.h:126
Definition: primnodes.h:186
TupleDesc lookup_rowtype_tupdesc_domain(Oid type_id, int32 typmod, bool noError)
Definition: typcache.c:1883
HeapTupleHeader t_data
Definition: htup.h:68
#define ERROR
Definition: elog.h:46
union ExprEvalStep::@49 d
Oid vartype
Definition: primnodes.h:193
static void slot_getallattrs(TupleTableSlot *slot)
Definition: tuptable.h:354
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:2082
HeapTuple toast_build_flattened_tuple(TupleDesc tupleDesc, Datum *values, bool *isnull)
Definition: heaptoast.c:563
bool * tts_isnull
Definition: tuptable.h:128
int errdetail(const char *fmt,...)
Definition: elog.c:1042
TupleTableSlot * ecxt_innertuple
Definition: execnodes.h:228
struct EState * ecxt_estate
Definition: execnodes.h:262
static RangeTblEntry * exec_rt_fetch(Index rti, EState *estate)
Definition: executor.h:571
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:207
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
TupleTableSlot * ExecFilterJunk(JunkFilter *junkfilter, TupleTableSlot *slot)
Definition: execJunk.c:247
#define HeapTupleHeaderSetTypMod(tup, typmod)
Definition: htup_details.h:472
#define ereport(elevel,...)
Definition: elog.h:157
#define INNER_VAR
Definition: primnodes.h:175
TupleTableSlot * ecxt_outertuple
Definition: execnodes.h:230
#define Assert(condition)
Definition: c.h:804
int errdetail_plural(const char *fmt_singular, const char *fmt_plural, unsigned long n,...)
Definition: elog.c:1134
TupleTableSlot * ecxt_scantuple
Definition: execnodes.h:226
Index es_range_table_size
Definition: execnodes.h:561
MemoryContext ecxt_per_query_memory
Definition: execnodes.h:233
#define InvalidAttrNumber
Definition: attnum.h:23
int errmsg(const char *fmt,...)
Definition: elog.c:909
int i
Alias * eref
Definition: parsenodes.h:1153
#define ReleaseTupleDesc(tupdesc)
Definition: tupdesc.h:122
#define OUTER_VAR
Definition: primnodes.h:176
void ExecTypeSetColNames(TupleDesc typeInfo, List *namesList)
Definition: execTuples.c:2036

◆ ExecEvalXmlExpr()

void ExecEvalXmlExpr ( ExprState state,
ExprEvalStep op 
)

Definition at line 3694 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

3695 {
3696  XmlExpr *xexpr = op->d.xmlexpr.xexpr;
3697  Datum value;
3698 
3699  *op->resnull = true; /* until we get a result */
3700  *op->resvalue = (Datum) 0;
3701 
3702  switch (xexpr->op)
3703  {
3704  case IS_XMLCONCAT:
3705  {
3706  Datum *argvalue = op->d.xmlexpr.argvalue;
3707  bool *argnull = op->d.xmlexpr.argnull;
3708  List *values = NIL;
3709 
3710  for (int i = 0; i < list_length(xexpr->args); i++)
3711  {
3712  if (!argnull[i])
3713  values = lappend(values, DatumGetPointer(argvalue[i]));
3714  }
3715 
3716  if (values != NIL)
3717  {
3718  *op->resvalue = PointerGetDatum(xmlconcat(values));
3719  *op->resnull = false;
3720  }
3721  }
3722  break;
3723 
3724  case IS_XMLFOREST:
3725  {
3726  Datum *argvalue = op->d.xmlexpr.named_argvalue;
3727  bool *argnull = op->d.xmlexpr.named_argnull;
3729  ListCell *lc;
3730  ListCell *lc2;
3731  int i;
3732 
3733  initStringInfo(&buf);
3734 
3735  i = 0;
3736  forboth(lc, xexpr->named_args, lc2, xexpr->arg_names)
3737  {
3738  Expr *e = (Expr *) lfirst(lc);
3739  char *argname = strVal(lfirst(lc2));
3740 
3741  if (!argnull[i])
3742  {
3743  value = argvalue[i];
3744  appendStringInfo(&buf, "<%s>%s</%s>",
3745  argname,
3747  exprType((Node *) e), true),
3748  argname);
3749  *op->resnull = false;
3750  }
3751  i++;
3752  }
3753 
3754  if (!*op->resnull)
3755  {
3756  text *result;
3757 
3758  result = cstring_to_text_with_len(buf.data, buf.len);
3759  *op->resvalue = PointerGetDatum(result);
3760  }
3761 
3762  pfree(buf.data);
3763  }
3764  break;
3765 
3766  case IS_XMLELEMENT:
3767  *op->resvalue = PointerGetDatum(xmlelement(xexpr,
3768  op->d.xmlexpr.named_argvalue,
3769  op->d.xmlexpr.named_argnull,
3770  op->d.xmlexpr.argvalue,
3771  op->d.xmlexpr.argnull));
3772  *op->resnull = false;
3773  break;
3774 
3775  case IS_XMLPARSE:
3776  {
3777  Datum *argvalue = op->d.xmlexpr.argvalue;
3778  bool *argnull = op->d.xmlexpr.argnull;
3779  text *data;
3780  bool preserve_whitespace;
3781 
3782  /* arguments are known to be text, bool */
3783  Assert(list_length(xexpr->args) == 2);
3784 
3785  if (argnull[0])
3786  return;
3787  value = argvalue[0];
3788  data = DatumGetTextPP(value);
3789 
3790  if (argnull[1]) /* probably can't happen */
3791  return;
3792  value = argvalue[1];
3793  preserve_whitespace = DatumGetBool(value);
3794 
3795  *op->resvalue = PointerGetDatum(xmlparse(data,
3796  xexpr->xmloption,
3797  preserve_whitespace));
3798  *op->resnull = false;
3799  }
3800  break;
3801 
3802  case IS_XMLPI:
3803  {
3804  text *arg;
3805  bool isnull;
3806 
3807  /* optional argument is known to be text */
3808  Assert(list_length(xexpr->args) <= 1);
3809 
3810  if (xexpr->args)
3811  {
3812  isnull = op->d.xmlexpr.argnull[0];
3813  if (isnull)
3814  arg = NULL;
3815  else
3816  arg = DatumGetTextPP(op->d.xmlexpr.argvalue[0]);
3817  }
3818  else
3819  {
3820  arg = NULL;
3821  isnull = false;
3822  }
3823 
3824  *op->resvalue = PointerGetDatum(xmlpi(xexpr->name,
3825  arg,
3826  isnull,
3827  op->resnull));
3828  }
3829  break;
3830 
3831  case IS_XMLROOT:
3832  {
3833  Datum *argvalue = op->d.xmlexpr.argvalue;
3834  bool *argnull = op->d.xmlexpr.argnull;
3835  xmltype *data;
3836  text *version;
3837  int standalone;
3838 
3839  /* arguments are known to be xml, text, int */
3840  Assert(list_length(xexpr->args) == 3);
3841 
3842  if (argnull[0])
3843  return;
3844  data = DatumGetXmlP(argvalue[0]);
3845 
3846  if (argnull[1])
3847  version = NULL;
3848  else
3849  version = DatumGetTextPP(argvalue[1]);
3850 
3851  Assert(!argnull[2]); /* always present */
3852  standalone = DatumGetInt32(argvalue[2]);
3853 
3854  *op->resvalue = PointerGetDatum(xmlroot(data,
3855  version,
3856  standalone));
3857  *op->resnull = false;
3858  }
3859  break;
3860 
3861  case IS_XMLSERIALIZE:
3862  {
3863  Datum *argvalue = op->d.xmlexpr.argvalue;
3864  bool *argnull = op->d.xmlexpr.argnull;
3865 
3866  /* argument type is known to be xml */
3867  Assert(list_length(xexpr->args) == 1);
3868 
3869  if (argnull[0])
3870  return;
3871  value = argvalue[0];
3872 
3874  xexpr->xmloption));
3875  *op->resnull = false;
3876  }
3877  break;
3878 
3879  case IS_DOCUMENT:
3880  {
3881  Datum *argvalue = op->d.xmlexpr.argvalue;
3882  bool *argnull = op->d.xmlexpr.argnull;
3883 
3884  /* optional argument is known to be xml */
3885  Assert(list_length(xexpr->args) == 1);
3886 
3887  if (argnull[0])
3888  return;
3889  value = argvalue[0];
3890 
3891  *op->resvalue =
3893  *op->resnull = false;
3894  }
3895  break;
3896 
3897  default:
3898  elog(ERROR, "unrecognized XML operation");
3899  break;
3900  }
3901 }
#define NIL
Definition: pg_list.h:65
#define forboth(cell1, list1, cell2, list2)
Definition: pg_list.h:446
char * name
Definition: primnodes.h:1228
Datum * resvalue
Definition: execExpr.h:273
#define DatumGetInt32(X)
Definition: postgres.h:516
#define PointerGetDatum(X)
Definition: postgres.h:600
#define DatumGetTextPP(X)
Definition: fmgr.h:292
bool * resnull
Definition: execExpr.h:274
xmltype * xmlconcat(List *args)
Definition: xml.c:512
Definition: nodes.h:536
#define strVal(v)
Definition: value.h:65
List * arg_names
Definition: primnodes.h:1230
#define DatumGetXmlP(X)
Definition: xml.h:50
xmltype * xmlpi(const char *target, text *arg, bool arg_is_null, bool *result_is_null)
Definition: xml.c:770
void pfree(void *pointer)
Definition: mcxt.c:1169
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:91
#define ERROR
Definition: elog.h:46
union ExprEvalStep::@49 d
text * xmltotext_with_xmloption(xmltype *data, XmlOptionType xmloption_arg)
Definition: xml.c:615
static char * buf
Definition: pg_test_fsync.c:68
text * cstring_to_text_with_len(const char *s, int len)
Definition: varlena.c:201
xmltype * xmlroot(xmltype *data, text *version, int standalone)
Definition: xml.c:822
#define DatumGetBool(X)
Definition: postgres.h:437
List * lappend(List *list, void *datum)
Definition: list.c:336
bool xml_is_document(xmltype *arg)
Definition: xml.c:888
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
XmlExprOp op
Definition: primnodes.h:1227
uintptr_t Datum
Definition: postgres.h:411
#define BoolGetDatum(X)
Definition: postgres.h:446
List * named_args
Definition: primnodes.h:1229
static struct @143 value
List * args
Definition: primnodes.h:1231
struct ExprEvalStep::@49::@82 xmlexpr
#define Assert(condition)
Definition: c.h:804
#define lfirst(lc)
Definition: pg_list.h:169
XmlOptionType xmloption
Definition: primnodes.h:1232
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:41
static int list_length(const List *l)
Definition: pg_list.h:149
#define DatumGetPointer(X)
Definition: postgres.h:593
static Datum values[MAXATTR]
Definition: bootstrap.c:156
e
Definition: preproc-init.c:82
#define elog(elevel,...)
Definition: elog.h:232
int i
xmltype * xmlelement(XmlExpr *xexpr, Datum *named_argvalue, bool *named_argnull, Datum *argvalue, bool *argnull)
Definition: xml.c:628
void * arg
Definition: c.h:621
char * map_sql_value_to_xml_value(Datum value, Oid type, bool xml_escape_strings)
Definition: xml.c:2134
Definition: pg_list.h:50
xmltype * xmlparse(text *data, XmlOptionType xmloption_arg, bool preserve_whitespace)
Definition: xml.c:752

◆ ExecInitInterpreter()

static void ExecInitInterpreter ( void  )
static

Definition at line 2286 of file execExprInterp.c.

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

Referenced by ExecReadyInterpretedExpr().

2287 {
2288 #if defined(EEO_USE_COMPUTED_GOTO)
2289  /* Set up externally-visible pointer to dispatch table */
2290  if (dispatch_table == NULL)
2291  {
2292  dispatch_table = (const void **)
2293  DatumGetPointer(ExecInterpExpr(NULL, NULL, NULL));
2294 
2295  /* build reverse lookup table */
2296  for (int i = 0; i < EEOP_LAST; i++)
2297  {
2298  reverse_dispatch_table[i].opcode = dispatch_table[i];
2299  reverse_dispatch_table[i].op = (ExprEvalOp) i;
2300  }
2301 
2302  /* make it bsearch()able */
2303  qsort(reverse_dispatch_table,
2304  EEOP_LAST /* nmembers */ ,
2305  sizeof(ExprEvalOpLookup),
2306  dispatch_compare_ptr);
2307  }
2308 #endif
2309 }
ExprEvalOp
Definition: execExpr.h:64
static Datum ExecInterpExpr(ExprState *state, ExprContext *econtext, bool *isnull)
#define DatumGetPointer(X)
Definition: postgres.h:593
int i
#define qsort(a, b, c, d)
Definition: port.h:505

◆ ExecInterpExpr()

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

Definition at line 390 of file execExprInterp.c.

References ExprEvalStep::agg_deserialize, ExprEvalStep::agg_plain_pergroup_nullcheck, ExprEvalStep::agg_strict_input_check, ExprEvalStep::agg_trans, ExprEvalStep::aggno, ExprEvalStep::aggref, AggState::all_pergroups, FunctionCallInfoBaseData::args, generate_unaccent_rules::args, Assert, ExprEvalStep::assign_tmp, ExprEvalStep::assign_var, attnum, ExprEvalStep::boolexpr, BoolGetDatum, ExprEvalStep::casetest, ExprContext::caseValue_datum, ExprContext::caseValue_isNull, castNode, CheckOpSlotCompatibility(), ExprEvalStep::constval, ExprEvalStep::cparam, ExprEvalStep::d, DatumGetBool, DatumGetCString, DatumGetInt32, ExprContext::domainValue_datum, ExprContext::domainValue_isNull, ExprContext::ecxt_aggnulls, ExprContext::ecxt_aggvalues, ExprContext::ecxt_innertuple, ExprContext::ecxt_outertuple, ExprContext::ecxt_per_tuple_memory, ExprContext::ecxt_scantuple, EEO_CASE, EEO_DISPATCH, EEO_JUMP, EEO_NEXT, EEO_SWITCH, EEOP_AGG_DESERIALIZE, EEOP_AGG_ORDERED_TRANS_DATUM, EEOP_AGG_ORDERED_TRANS_TUPLE, EEOP_AGG_PLAIN_PERGROUP_NULLCHECK, EEOP_AGG_PLAIN_TRANS_BYREF, EEOP_AGG_PLAIN_TRANS_BYVAL, EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYREF, EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYVAL, EEOP_AGG_PLAIN_TRANS_STRICT_BYREF, EEOP_AGG_PLAIN_TRANS_STRICT_BYVAL, EEOP_AGG_STRICT_DESERIALIZE, EEOP_AGG_STRICT_INPUT_CHECK_ARGS, EEOP_AGG_STRICT_INPUT_CHECK_NULLS, EEOP_AGGREF, EEOP_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_SQLVALUEFUNCTION, 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(), ExecEvalRow(), ExecEvalRowNotNull(), ExecEvalRowNull(), ExecEvalScalarArrayOp(), ExecEvalSQLValueFunction(), ExecEvalSubPlan(), ExecEvalSysVar(), ExecEvalWholeRowVar(), ExecEvalXmlExpr(), ExprEvalStep::fetch, ExprEvalStep::func, FunctionCallInvoke, ExprEvalStep::iocoerce, FunctionCallInfoBaseData::isnull, NullableDatum::isnull, ExprEvalStep::jump, lengthof, likely, ExprEvalStep::make_readonly, MakeExpandedObjectReadOnlyInternal(), MemoryContextSwitchTo(), ExprEvalStep::nargs, AggStatePerGroupData::noTransValue, ExprEvalStep::nulls, ExprEvalStep::op, ExprState::parent, ExprEvalStep::pertrans, PointerGetDatum, ExprEvalStep::qualexpr, ExprEvalStep::rctype, ExprState::resnull, ExprEvalStep::resnull, ExprEvalStep::resultnum, ExprState::resultslot, ExprState::resvalue, ExprEvalStep::resvalue, ExprEvalStep::rowcompare_final, ROWCOMPARE_GE, ROWCOMPARE_GT, ROWCOMPARE_LE, ROWCOMPARE_LT, ExprEvalStep::rowcompare_step, ExprEvalStep::sbsref, ExprEvalStep::sbsref_subscript, slot_getsomeattrs(), StaticAssertStmt, ExprState::steps, generate_unaccent_rules::str, AggState::tmpcontext, AggStatePerTransData::transtypeByVal, AggStatePerGroupData::transValueIsNull, TupleTableSlot::tts_isnull, TupleTableSlot::tts_values, unlikely, NullableDatum::value, ExprEvalStep::var, WindowFuncExprState::wfuncno, and ExprEvalStep::window_func.

Referenced by ExecInitInterpreter(), and ExecReadyInterpretedExpr().

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