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/json.h"
#include "utils/jsonb.h"
#include "utils/lsyscache.h"
#include "utils/memutils.h"
#include "utils/timestamp.h"
#include "utils/typcache.h"
#include "utils/xml.h"
#include "lib/simplehash.h"
Include dependency graph for execExprInterp.c:

Go to the source code of this file.

Data Structures

struct  ScalarArrayOpExprHashEntry
 
struct  ScalarArrayOpExprHashTable
 

Macros

#define EEO_SWITCH()   starteval: switch ((ExprEvalOp) op->opcode)
 
#define EEO_CASE(name)   case name:
 
#define EEO_DISPATCH()   goto starteval
 
#define EEO_OPCODE(opcode)   (opcode)
 
#define EEO_NEXT()
 
#define EEO_JUMP(stepno)
 
#define SH_PREFIX   saophash
 
#define SH_ELEMENT_TYPE   ScalarArrayOpExprHashEntry
 
#define SH_KEY_TYPE   Datum
 
#define SH_SCOPE   static inline
 
#define SH_DECLARE
 
#define SH_PREFIX   saophash
 
#define SH_ELEMENT_TYPE   ScalarArrayOpExprHashEntry
 
#define SH_KEY_TYPE   Datum
 
#define SH_KEY   key
 
#define SH_HASH_KEY(tb, key)   saop_element_hash(tb, key)
 
#define SH_EQUAL(tb, a, b)   saop_hash_element_match(tb, a, b)
 
#define SH_SCOPE   static inline
 
#define SH_STORE_HASH
 
#define SH_GET_HASH(tb, a)   a->hash
 
#define SH_DEFINE
 

Typedefs

typedef struct ScalarArrayOpExprHashEntry ScalarArrayOpExprHashEntry
 
typedef struct ScalarArrayOpExprHashTable ScalarArrayOpExprHashTable
 

Functions

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

Macro Definition Documentation

◆ EEO_CASE

#define EEO_CASE (   name)    case name:

Definition at line 124 of file execExprInterp.c.

◆ EEO_DISPATCH

#define EEO_DISPATCH ( )    goto starteval

Definition at line 125 of file execExprInterp.c.

◆ EEO_JUMP

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

Definition at line 136 of file execExprInterp.c.

◆ EEO_NEXT

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

Definition at line 130 of file execExprInterp.c.

◆ EEO_OPCODE

#define EEO_OPCODE (   opcode)    (opcode)

Definition at line 126 of file execExprInterp.c.

◆ EEO_SWITCH

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

Definition at line 123 of file execExprInterp.c.

◆ SH_DECLARE

#define SH_DECLARE

Definition at line 198 of file execExprInterp.c.

◆ SH_DEFINE

#define SH_DEFINE

Definition at line 227 of file execExprInterp.c.

◆ SH_ELEMENT_TYPE [1/2]

#define SH_ELEMENT_TYPE   ScalarArrayOpExprHashEntry

Definition at line 219 of file execExprInterp.c.

◆ SH_ELEMENT_TYPE [2/2]

#define SH_ELEMENT_TYPE   ScalarArrayOpExprHashEntry

Definition at line 219 of file execExprInterp.c.

◆ SH_EQUAL

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

Definition at line 223 of file execExprInterp.c.

◆ SH_GET_HASH

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

Definition at line 226 of file execExprInterp.c.

◆ SH_HASH_KEY

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

Definition at line 222 of file execExprInterp.c.

◆ SH_KEY

#define SH_KEY   key

Definition at line 221 of file execExprInterp.c.

◆ SH_KEY_TYPE [1/2]

#define SH_KEY_TYPE   Datum

Definition at line 220 of file execExprInterp.c.

◆ SH_KEY_TYPE [2/2]

#define SH_KEY_TYPE   Datum

Definition at line 220 of file execExprInterp.c.

◆ SH_PREFIX [1/2]

#define SH_PREFIX   saophash

Definition at line 218 of file execExprInterp.c.

◆ SH_PREFIX [2/2]

#define SH_PREFIX   saophash

Definition at line 218 of file execExprInterp.c.

◆ SH_SCOPE [1/2]

#define SH_SCOPE   static inline

Definition at line 224 of file execExprInterp.c.

◆ SH_SCOPE [2/2]

#define SH_SCOPE   static inline

Definition at line 224 of file execExprInterp.c.

◆ SH_STORE_HASH

#define SH_STORE_HASH

Definition at line 225 of file execExprInterp.c.

Typedef Documentation

◆ ScalarArrayOpExprHashEntry

◆ ScalarArrayOpExprHashTable

Function Documentation

◆ CheckExprStillValid()

void CheckExprStillValid ( ExprState state,
ExprContext econtext 
)

Definition at line 1856 of file execExprInterp.c.

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

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

Referenced by ExecInterpExprStillValid(), and ExecRunCompiledExpr().

◆ CheckOpSlotCompatibility()

static void CheckOpSlotCompatibility ( ExprEvalStep op,
TupleTableSlot slot 
)
static

Definition at line 1958 of file execExprInterp.c.

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

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

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

◆ CheckVarSlotCompatibility()

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

Definition at line 1907 of file execExprInterp.c.

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

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

Referenced by CheckExprStillValid().

◆ ExecAggInitGroup()

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

Definition at line 4186 of file execExprInterp.c.

4188 {
4189  FunctionCallInfo fcinfo = pertrans->transfn_fcinfo;
4190  MemoryContext oldContext;
4191 
4192  /*
4193  * We must copy the datum into aggcontext if it is pass-by-ref. We do not
4194  * need to pfree the old transValue, since it's NULL. (We already checked
4195  * that the agg's input type is binary-compatible with its transtype, so
4196  * straight copy here is OK.)
4197  */
4198  oldContext = MemoryContextSwitchTo(aggcontext->ecxt_per_tuple_memory);
4199  pergroup->transValue = datumCopy(fcinfo->args[1].value,
4200  pertrans->transtypeByVal,
4201  pertrans->transtypeLen);
4202  pergroup->transValueIsNull = false;
4203  pergroup->noTransValue = false;
4204  MemoryContextSwitchTo(oldContext);
4205 }
Datum datumCopy(Datum value, bool typByVal, int typLen)
Definition: datum.c:132
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:138
FunctionCallInfo transfn_fcinfo
Definition: nodeAgg.h:170
MemoryContext ecxt_per_tuple_memory
Definition: execnodes.h:257
NullableDatum args[FLEXIBLE_ARRAY_MEMBER]
Definition: fmgr.h:95
Datum value
Definition: postgres.h:75

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

Referenced by ExecInterpExpr().

◆ ExecAggPlainTransByRef()

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

Definition at line 4399 of file execExprInterp.c.

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

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

Referenced by ExecInterpExpr().

◆ ExecAggPlainTransByVal()

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

Definition at line 4367 of file execExprInterp.c.

4370 {
4371  FunctionCallInfo fcinfo = pertrans->transfn_fcinfo;
4372  MemoryContext oldContext;
4373  Datum newVal;
4374 
4375  /* cf. select_current_set() */
4376  aggstate->curaggcontext = aggcontext;
4377  aggstate->current_set = setno;
4378 
4379  /* set up aggstate->curpertrans for AggGetAggref() */
4380  aggstate->curpertrans = pertrans;
4381 
4382  /* invoke transition function in per-tuple context */
4383  oldContext = MemoryContextSwitchTo(aggstate->tmpcontext->ecxt_per_tuple_memory);
4384 
4385  fcinfo->args[0].value = pergroup->transValue;
4386  fcinfo->args[0].isnull = pergroup->transValueIsNull;
4387  fcinfo->isnull = false; /* just in case transfn doesn't set it */
4388 
4389  newVal = FunctionCallInvoke(fcinfo);
4390 
4391  pergroup->transValue = newVal;
4392  pergroup->transValueIsNull = fcinfo->isnull;
4393 
4394  MemoryContextSwitchTo(oldContext);
4395 }

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

Referenced by ExecInterpExpr().

◆ ExecAggTransReparent()

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

Definition at line 4214 of file execExprInterp.c.

4217 {
4218  Assert(newValue != oldValue);
4219 
4220  if (!newValueIsNull)
4221  {
4223  if (DatumIsReadWriteExpandedObject(newValue,
4224  false,
4225  pertrans->transtypeLen) &&
4226  MemoryContextGetParent(DatumGetEOHP(newValue)->eoh_context) == CurrentMemoryContext)
4227  /* do nothing */ ;
4228  else
4229  newValue = datumCopy(newValue,
4230  pertrans->transtypeByVal,
4231  pertrans->transtypeLen);
4232  }
4233  else
4234  {
4235  /*
4236  * Ensure that AggStatePerGroup->transValue ends up being 0, so
4237  * callers can safely compare newValue/oldValue without having to
4238  * check their respective nullness.
4239  */
4240  newValue = (Datum) 0;
4241  }
4242 
4243  if (!oldValueIsNull)
4244  {
4245  if (DatumIsReadWriteExpandedObject(oldValue,
4246  false,
4247  pertrans->transtypeLen))
4248  DeleteExpandedObject(oldValue);
4249  else
4250  pfree(DatumGetPointer(oldValue));
4251  }
4252 
4253  return newValue;
4254 }
ExpandedObjectHeader * DatumGetEOHP(Datum d)
Definition: expandeddatum.c:29
void DeleteExpandedObject(Datum d)
#define DatumIsReadWriteExpandedObject(d, isnull, typlen)
void pfree(void *pointer)
Definition: mcxt.c:1436
MemoryContext CurrentMemoryContext
Definition: mcxt.c:135
MemoryContext MemoryContextGetParent(MemoryContext context)
Definition: mcxt.c:624

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

Referenced by advance_transition_function(), and ExecAggPlainTransByRef().

◆ ExecEvalAggOrderedTransDatum()

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

Definition at line 4339 of file execExprInterp.c.

4341 {
4342  AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
4343  int setno = op->d.agg_trans.setno;
4344 
4345  tuplesort_putdatum(pertrans->sortstates[setno],
4346  *op->resvalue, *op->resnull);
4347 }
Tuplesortstate ** sortstates
Definition: nodeAgg.h:162
struct ExprEvalStep::@50::@92 agg_trans
Datum * resvalue
Definition: execExpr.h:276
bool * resnull
Definition: execExpr.h:277
void tuplesort_putdatum(Tuplesortstate *state, Datum val, bool isNull)

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

Referenced by ExecInterpExpr().

◆ ExecEvalAggOrderedTransTuple()

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

Definition at line 4353 of file execExprInterp.c.

4355 {
4356  AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
4357  int setno = op->d.agg_trans.setno;
4358 
4359  ExecClearTuple(pertrans->sortslot);
4360  pertrans->sortslot->tts_nvalid = pertrans->numInputs;
4361  ExecStoreVirtualTuple(pertrans->sortslot);
4362  tuplesort_puttupleslot(pertrans->sortstates[setno], pertrans->sortslot);
4363 }
TupleTableSlot * ExecStoreVirtualTuple(TupleTableSlot *slot)
Definition: execTuples.c:1552
TupleTableSlot * sortslot
Definition: nodeAgg.h:141
AttrNumber tts_nvalid
Definition: tuptable.h:121
void tuplesort_puttupleslot(Tuplesortstate *state, TupleTableSlot *slot)
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:471

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

Referenced by ExecInterpExpr().

◆ ExecEvalArrayCoerce()

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

Definition at line 2853 of file execExprInterp.c.

2854 {
2855  Datum arraydatum;
2856 
2857  /* NULL array -> NULL result */
2858  if (*op->resnull)
2859  return;
2860 
2861  arraydatum = *op->resvalue;
2862 
2863  /*
2864  * If it's binary-compatible, modify the element type in the array header,
2865  * but otherwise leave the array as we received it.
2866  */
2867  if (op->d.arraycoerce.elemexprstate == NULL)
2868  {
2869  /* Detoast input array if necessary, and copy in any case */
2870  ArrayType *array = DatumGetArrayTypePCopy(arraydatum);
2871 
2872  ARR_ELEMTYPE(array) = op->d.arraycoerce.resultelemtype;
2873  *op->resvalue = PointerGetDatum(array);
2874  return;
2875  }
2876 
2877  /*
2878  * Use array_map to apply the sub-expression to each array element.
2879  */
2880  *op->resvalue = array_map(arraydatum,
2881  op->d.arraycoerce.elemexprstate,
2882  econtext,
2883  op->d.arraycoerce.resultelemtype,
2884  op->d.arraycoerce.amstate);
2885 }
#define DatumGetArrayTypePCopy(X)
Definition: array.h:255
#define ARR_ELEMTYPE(a)
Definition: array.h:285
Datum array_map(Datum arrayd, ExprState *exprstate, ExprContext *econtext, Oid retType, ArrayMapState *amstate)
Definition: arrayfuncs.c:3181
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:322
struct ExprEvalStep::@50::@69 arraycoerce

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

Referenced by ExecInterpExpr().

◆ ExecEvalArrayExpr()

void ExecEvalArrayExpr ( ExprState state,
ExprEvalStep op 
)

Definition at line 2639 of file execExprInterp.c.

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

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

Referenced by ExecInterpExpr().

◆ ExecEvalConstraintCheck()

void ExecEvalConstraintCheck ( ExprState state,
ExprEvalStep op 
)

Definition at line 3656 of file execExprInterp.c.

3657 {
3658  if (!*op->d.domaincheck.checknull &&
3659  !DatumGetBool(*op->d.domaincheck.checkvalue))
3660  ereport(ERROR,
3661  (errcode(ERRCODE_CHECK_VIOLATION),
3662  errmsg("value for domain %s violates check constraint \"%s\"",
3663  format_type_be(op->d.domaincheck.resulttype),
3664  op->d.domaincheck.constraintname),
3665  errdomainconstraint(op->d.domaincheck.resulttype,
3666  op->d.domaincheck.constraintname)));
3667 }
int errdomainconstraint(Oid datatypeOid, const char *conname)
Definition: domains.c:400
static bool DatumGetBool(Datum X)
Definition: postgres.h:90
struct ExprEvalStep::@50::@78 domaincheck

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

Referenced by ExecInterpExpr().

◆ ExecEvalConstraintNotNull()

void ExecEvalConstraintNotNull ( ExprState state,
ExprEvalStep op 
)

Definition at line 3642 of file execExprInterp.c.

3643 {
3644  if (*op->resnull)
3645  ereport(ERROR,
3646  (errcode(ERRCODE_NOT_NULL_VIOLATION),
3647  errmsg("domain %s does not allow null values",
3648  format_type_be(op->d.domaincheck.resulttype)),
3649  errdatatype(op->d.domaincheck.resulttype)));
3650 }
int errdatatype(Oid datatypeOid)
Definition: domains.c:376

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

Referenced by ExecInterpExpr().

◆ ExecEvalConvertRowtype()

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

Definition at line 3162 of file execExprInterp.c.

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

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

Referenced by ExecInterpExpr().

◆ ExecEvalCurrentOfExpr()

void ExecEvalCurrentOfExpr ( ExprState state,
ExprEvalStep op 
)

Definition at line 2500 of file execExprInterp.c.

2501 {
2502  ereport(ERROR,
2503  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2504  errmsg("WHERE CURRENT OF is not supported for this table type")));
2505 }

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

Referenced by ExecInterpExpr().

◆ ExecEvalFieldSelect()

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

Definition at line 2967 of file execExprInterp.c.

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

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

Referenced by ExecInterpExpr().

◆ ExecEvalFieldStoreDeForm()

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

Definition at line 3092 of file execExprInterp.c.

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

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

Referenced by ExecInterpExpr().

◆ ExecEvalFieldStoreForm()

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

Definition at line 3138 of file execExprInterp.c.

3139 {
3140  TupleDesc tupDesc;
3141  HeapTuple tuple;
3142 
3143  /* Lookup tupdesc (should be valid already) */
3144  tupDesc = get_cached_rowtype(op->d.fieldstore.fstore->resulttype, -1,
3145  op->d.fieldstore.rowcache, NULL);
3146 
3147  tuple = heap_form_tuple(tupDesc,
3148  op->d.fieldstore.values,
3149  op->d.fieldstore.nulls);
3150 
3151  *op->resvalue = HeapTupleGetDatum(tuple);
3152  *op->resnull = false;
3153 }
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1020

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

Referenced by ExecInterpExpr().

◆ ExecEvalFuncExprFusage()

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

Definition at line 2372 of file execExprInterp.c.

2374 {
2375  FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
2376  PgStat_FunctionCallUsage fcusage;
2377  Datum d;
2378 
2379  pgstat_init_function_usage(fcinfo, &fcusage);
2380 
2381  fcinfo->isnull = false;
2382  d = op->d.func.fn_addr(fcinfo);
2383  *op->resvalue = d;
2384  *op->resnull = fcinfo->isnull;
2385 
2386  pgstat_end_function_usage(&fcusage, true);
2387 }
void pgstat_init_function_usage(FunctionCallInfo fcinfo, PgStat_FunctionCallUsage *fcu)
void pgstat_end_function_usage(PgStat_FunctionCallUsage *fcu, bool finalize)
struct ExprEvalStep::@50::@57 func

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

Referenced by ExecInterpExpr().

◆ ExecEvalFuncExprStrictFusage()

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

Definition at line 2393 of file execExprInterp.c.

2395 {
2396 
2397  FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
2398  PgStat_FunctionCallUsage fcusage;
2399  NullableDatum *args = fcinfo->args;
2400  int nargs = op->d.func.nargs;
2401  Datum d;
2402 
2403  /* strict function, so check for NULL args */
2404  for (int argno = 0; argno < nargs; argno++)
2405  {
2406  if (args[argno].isnull)
2407  {
2408  *op->resnull = true;
2409  return;
2410  }
2411  }
2412 
2413  pgstat_init_function_usage(fcinfo, &fcusage);
2414 
2415  fcinfo->isnull = false;
2416  d = op->d.func.fn_addr(fcinfo);
2417  *op->resvalue = d;
2418  *op->resnull = fcinfo->isnull;
2419 
2420  pgstat_end_function_usage(&fcusage, true);
2421 }

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

Referenced by ExecInterpExpr().

◆ ExecEvalGroupingFunc()

void ExecEvalGroupingFunc ( ExprState state,
ExprEvalStep op 
)

Definition at line 3897 of file execExprInterp.c.

3898 {
3899  AggState *aggstate = castNode(AggState, state->parent);
3900  int result = 0;
3901  Bitmapset *grouped_cols = aggstate->grouped_cols;
3902  ListCell *lc;
3903 
3904  foreach(lc, op->d.grouping_func.clauses)
3905  {
3906  int attnum = lfirst_int(lc);
3907 
3908  result <<= 1;
3909 
3910  if (!bms_is_member(attnum, grouped_cols))
3911  result |= 1;
3912  }
3913 
3914  *op->resvalue = Int32GetDatum(result);
3915  *op->resnull = false;
3916 }
bool bms_is_member(int x, const Bitmapset *a)
Definition: bitmapset.c:444
#define castNode(_type_, nodeptr)
Definition: nodes.h:197
#define lfirst_int(lc)
Definition: pg_list.h:173
static Datum Int32GetDatum(int32 X)
Definition: postgres.h:212
Bitmapset * grouped_cols
Definition: execnodes.h:2389
struct ExprEvalStep::@50::@85 grouping_func

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

Referenced by ExecInterpExpr().

◆ ExecEvalHashedScalarArrayOp()

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

Definition at line 3460 of file execExprInterp.c.

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

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

Referenced by ExecInterpExpr().

◆ ExecEvalJsonConstructor()

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

Definition at line 4455 of file execExprInterp.c.

4457 {
4458  Datum res;
4459  JsonConstructorExprState *jcstate = op->d.json_constructor.jcstate;
4460  JsonConstructorExpr *ctor = jcstate->constructor;
4461  bool is_jsonb = ctor->returning->format->format_type == JS_FORMAT_JSONB;
4462  bool isnull = false;
4463 
4464  if (ctor->type == JSCTOR_JSON_ARRAY)
4465  res = (is_jsonb ?
4467  json_build_array_worker) (jcstate->nargs,
4468  jcstate->arg_values,
4469  jcstate->arg_nulls,
4470  jcstate->arg_types,
4471  jcstate->constructor->absent_on_null);
4472  else if (ctor->type == JSCTOR_JSON_OBJECT)
4473  res = (is_jsonb ?
4475  json_build_object_worker) (jcstate->nargs,
4476  jcstate->arg_values,
4477  jcstate->arg_nulls,
4478  jcstate->arg_types,
4479  jcstate->constructor->absent_on_null,
4480  jcstate->constructor->unique);
4481  else
4482  {
4483  res = (Datum) 0;
4484  elog(ERROR, "invalid JsonConstructorExpr type %d", ctor->type);
4485  }
4486 
4487  *op->resvalue = res;
4488  *op->resnull = isnull;
4489 }
Datum json_build_array_worker(int nargs, Datum *args, bool *nulls, Oid *types, bool absent_on_null)
Definition: json.c:1382
Datum json_build_object_worker(int nargs, Datum *args, bool *nulls, Oid *types, bool absent_on_null, bool unique_keys)
Definition: json.c:1269
Datum jsonb_build_array_worker(int nargs, Datum *args, bool *nulls, Oid *types, bool absent_on_null)
Definition: jsonb.c:1309
Datum jsonb_build_object_worker(int nargs, Datum *args, bool *nulls, Oid *types, bool absent_on_null, bool unique_keys)
Definition: jsonb.c:1224
@ JS_FORMAT_JSONB
Definition: primnodes.h:1521
@ JSCTOR_JSON_OBJECT
Definition: primnodes.h:1563
@ JSCTOR_JSON_ARRAY
Definition: primnodes.h:1564
struct ExprEvalStep::@50::@83 json_constructor
JsonConstructorExpr * constructor
Definition: execExpr.h:729
JsonReturning * returning
Definition: primnodes.h:1580
JsonConstructorType type
Definition: primnodes.h:1576
JsonFormatType format_type
Definition: primnodes.h:1532
JsonFormat * format
Definition: primnodes.h:1544

References JsonConstructorExpr::absent_on_null, JsonConstructorExprState::arg_nulls, JsonConstructorExprState::arg_types, JsonConstructorExprState::arg_values, JsonConstructorExprState::constructor, elog(), ERROR, JsonReturning::format, JsonFormat::format_type, ExprEvalStep::isnull, ExprEvalStep::jcstate, JS_FORMAT_JSONB, JSCTOR_JSON_ARRAY, JSCTOR_JSON_OBJECT, json_build_array_worker(), json_build_object_worker(), jsonb_build_array_worker(), jsonb_build_object_worker(), JsonConstructorExprState::nargs, ExprEvalStep::op, res, JsonConstructorExpr::returning, JsonConstructorExpr::type, and JsonConstructorExpr::unique.

Referenced by ExecInterpExpr().

◆ ExecEvalMinMax()

void ExecEvalMinMax ( ExprState state,
ExprEvalStep op 
)

Definition at line 2914 of file execExprInterp.c.

2915 {
2916  Datum *values = op->d.minmax.values;
2917  bool *nulls = op->d.minmax.nulls;
2918  FunctionCallInfo fcinfo = op->d.minmax.fcinfo_data;
2919  MinMaxOp operator = op->d.minmax.op;
2920 
2921  /* set at initialization */
2922  Assert(fcinfo->args[0].isnull == false);
2923  Assert(fcinfo->args[1].isnull == false);
2924 
2925  /* default to null result */
2926  *op->resnull = true;
2927 
2928  for (int off = 0; off < op->d.minmax.nelems; off++)
2929  {
2930  /* ignore NULL inputs */
2931  if (nulls[off])
2932  continue;
2933 
2934  if (*op->resnull)
2935  {
2936  /* first nonnull input, adopt value */
2937  *op->resvalue = values[off];
2938  *op->resnull = false;
2939  }
2940  else
2941  {
2942  int cmpresult;
2943 
2944  /* apply comparison function */
2945  fcinfo->args[0].value = *op->resvalue;
2946  fcinfo->args[1].value = values[off];
2947 
2948  fcinfo->isnull = false;
2949  cmpresult = DatumGetInt32(FunctionCallInvoke(fcinfo));
2950  if (fcinfo->isnull) /* probably should not happen */
2951  continue;
2952 
2953  if (cmpresult > 0 && operator == IS_LEAST)
2954  *op->resvalue = values[off];
2955  else if (cmpresult < 0 && operator == IS_GREATEST)
2956  *op->resvalue = values[off];
2957  }
2958  }
2959 }
static Datum values[MAXATTR]
Definition: bootstrap.c:156
static int32 DatumGetInt32(Datum X)
Definition: postgres.h:202
MinMaxOp
Definition: primnodes.h:1426
@ IS_LEAST
Definition: primnodes.h:1428
@ IS_GREATEST
Definition: primnodes.h:1427
struct ExprEvalStep::@50::@73 minmax

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

Referenced by ExecInterpExpr().

◆ ExecEvalNextValueExpr()

void ExecEvalNextValueExpr ( ExprState state,
ExprEvalStep op 
)

Definition at line 2511 of file execExprInterp.c.

2512 {
2513  int64 newval = nextval_internal(op->d.nextvalueexpr.seqid, false);
2514 
2515  switch (op->d.nextvalueexpr.seqtypid)
2516  {
2517  case INT2OID:
2518  *op->resvalue = Int16GetDatum((int16) newval);
2519  break;
2520  case INT4OID:
2521  *op->resvalue = Int32GetDatum((int32) newval);
2522  break;
2523  case INT8OID:
2524  *op->resvalue = Int64GetDatum((int64) newval);
2525  break;
2526  default:
2527  elog(ERROR, "unsupported sequence type %u",
2528  op->d.nextvalueexpr.seqtypid);
2529  }
2530  *op->resnull = false;
2531 }
Datum Int64GetDatum(int64 X)
Definition: fmgr.c:1779
#define newval
static Datum Int16GetDatum(int16 X)
Definition: postgres.h:172
int64 nextval_internal(Oid relid, bool check_permissions)
Definition: sequence.c:629
struct ExprEvalStep::@50::@67 nextvalueexpr

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

Referenced by ExecInterpExpr().

◆ ExecEvalParamExec()

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

Definition at line 2430 of file execExprInterp.c.

2431 {
2432  ParamExecData *prm;
2433 
2434  prm = &(econtext->ecxt_param_exec_vals[op->d.param.paramid]);
2435  if (unlikely(prm->execPlan != NULL))
2436  {
2437  /* Parameter not evaluated yet, so go do it */
2438  ExecSetParamPlan(prm->execPlan, econtext);
2439  /* ExecSetParamPlan should have processed this param... */
2440  Assert(prm->execPlan == NULL);
2441  }
2442  *op->resvalue = prm->value;
2443  *op->resnull = prm->isnull;
2444 }
void ExecSetParamPlan(SubPlanState *node, ExprContext *econtext)
Definition: nodeSubplan.c:1092
ParamExecData * ecxt_param_exec_vals
Definition: execnodes.h:260
struct ExprEvalStep::@50::@62 param
bool isnull
Definition: params.h:150
Datum value
Definition: params.h:149
void * execPlan
Definition: params.h:148

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

Referenced by ExecInterpExpr().

◆ ExecEvalParamExtern()

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

Definition at line 2452 of file execExprInterp.c.

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

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

Referenced by ExecInterpExpr().

◆ ExecEvalPreOrderedDistinctMulti()

bool ExecEvalPreOrderedDistinctMulti ( AggState aggstate,
AggStatePerTrans  pertrans 
)

Definition at line 4305 of file execExprInterp.c.

4306 {
4307  ExprContext *tmpcontext = aggstate->tmpcontext;
4308 
4309  for (int i = 0; i < pertrans->numTransInputs; i++)
4310  {
4311  pertrans->sortslot->tts_values[i] = pertrans->transfn_fcinfo->args[i + 1].value;
4312  pertrans->sortslot->tts_isnull[i] = pertrans->transfn_fcinfo->args[i + 1].isnull;
4313  }
4314 
4315  ExecClearTuple(pertrans->sortslot);
4316  pertrans->sortslot->tts_nvalid = pertrans->numInputs;
4317  ExecStoreVirtualTuple(pertrans->sortslot);
4318 
4319  tmpcontext->ecxt_outertuple = pertrans->sortslot;
4320  tmpcontext->ecxt_innertuple = pertrans->uniqslot;
4321 
4322  if (!pertrans->haslast ||
4323  !ExecQual(pertrans->equalfnMulti, tmpcontext))
4324  {
4325  if (pertrans->haslast)
4326  ExecClearTuple(pertrans->uniqslot);
4327 
4328  pertrans->haslast = true;
4329  ExecCopySlot(pertrans->uniqslot, pertrans->sortslot);
4330  return true;
4331  }
4332  return false;
4333 }
static bool ExecQual(ExprState *state, ExprContext *econtext)
Definition: executor.h:411
ExprState * equalfnMulti
Definition: nodeAgg.h:116
TupleTableSlot * uniqslot
Definition: nodeAgg.h:142
bool * tts_isnull
Definition: tuptable.h:128
Datum * tts_values
Definition: tuptable.h:126
static TupleTableSlot * ExecCopySlot(TupleTableSlot *dstslot, TupleTableSlot *srcslot)
Definition: tuptable.h:521

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

Referenced by ExecInterpExpr().

◆ ExecEvalPreOrderedDistinctSingle()

bool ExecEvalPreOrderedDistinctSingle ( AggState aggstate,
AggStatePerTrans  pertrans 
)

Definition at line 4263 of file execExprInterp.c.

4264 {
4265  Datum value = pertrans->transfn_fcinfo->args[1].value;
4266  bool isnull = pertrans->transfn_fcinfo->args[1].isnull;
4267 
4268  if (!pertrans->haslast ||
4269  pertrans->lastisnull != isnull ||
4270  (!isnull && !DatumGetBool(FunctionCall2Coll(&pertrans->equalfnOne,
4271  pertrans->aggCollation,
4272  pertrans->lastdatum, value))))
4273  {
4274  if (pertrans->haslast && !pertrans->inputtypeByVal &&
4275  !pertrans->lastisnull)
4276  pfree(DatumGetPointer(pertrans->lastdatum));
4277 
4278  pertrans->haslast = true;
4279  if (!isnull)
4280  {
4281  MemoryContext oldContext;
4282 
4284 
4285  pertrans->lastdatum = datumCopy(value, pertrans->inputtypeByVal,
4286  pertrans->inputtypeLen);
4287 
4288  MemoryContextSwitchTo(oldContext);
4289  }
4290  else
4291  pertrans->lastdatum = (Datum) 0;
4292  pertrans->lastisnull = isnull;
4293  return true;
4294  }
4295 
4296  return false;
4297 }
Datum FunctionCall2Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2)
Definition: fmgr.c:1121
static struct @145 value
FmgrInfo equalfnOne
Definition: nodeAgg.h:115

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

Referenced by ExecInterpExpr().

◆ ExecEvalRow()

void ExecEvalRow ( ExprState state,
ExprEvalStep op 
)

Definition at line 2894 of file execExprInterp.c.

2895 {
2896  HeapTuple tuple;
2897 
2898  /* build tuple from evaluated field values */
2899  tuple = heap_form_tuple(op->d.row.tupdesc,
2900  op->d.row.elemvalues,
2901  op->d.row.elemnulls);
2902 
2903  *op->resvalue = HeapTupleGetDatum(tuple);
2904  *op->resnull = false;
2905 }
struct ExprEvalStep::@50::@70 row

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

Referenced by ExecInterpExpr().

◆ ExecEvalRowNotNull()

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

Definition at line 2546 of file execExprInterp.c.

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

References ExecEvalRowNullInt(), and ExprEvalStep::op.

Referenced by ExecInterpExpr().

◆ ExecEvalRowNull()

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

Definition at line 2537 of file execExprInterp.c.

2538 {
2539  ExecEvalRowNullInt(state, op, econtext, true);
2540 }

References ExecEvalRowNullInt(), and ExprEvalStep::op.

Referenced by ExecInterpExpr().

◆ ExecEvalRowNullInt()

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

Definition at line 2553 of file execExprInterp.c.

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

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

Referenced by ExecEvalRowNotNull(), and ExecEvalRowNull().

◆ ExecEvalScalarArrayOp()

void ExecEvalScalarArrayOp ( ExprState state,
ExprEvalStep op 
)

Definition at line 3257 of file execExprInterp.c.

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

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

Referenced by ExecInterpExpr().

◆ ExecEvalStepOp()

ExprEvalOp ExecEvalStepOp ( ExprState state,
ExprEvalStep op 
)

Definition at line 2342 of file execExprInterp.c.

2343 {
2344 #if defined(EEO_USE_COMPUTED_GOTO)
2345  if (state->flags & EEO_FLAG_DIRECT_THREADED)
2346  {
2347  ExprEvalOpLookup key;
2348  ExprEvalOpLookup *res;
2349 
2350  key.opcode = (void *) op->opcode;
2351  res = bsearch(&key,
2352  reverse_dispatch_table,
2353  EEOP_LAST /* nmembers */ ,
2354  sizeof(ExprEvalOpLookup),
2355  dispatch_compare_ptr);
2356  Assert(res); /* unknown ops shouldn't get looked up */
2357  return res->op;
2358  }
2359 #endif
2360  return (ExprEvalOp) op->opcode;
2361 }
#define EEO_FLAG_DIRECT_THREADED
Definition: execExpr.h:30
ExprEvalOp
Definition: execExpr.h:66
@ EEOP_LAST
Definition: execExpr.h:262
intptr_t opcode
Definition: execExpr.h:273

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

Referenced by CheckExprStillValid().

◆ ExecEvalSubPlan()

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

Definition at line 3922 of file execExprInterp.c.

3923 {
3924  SubPlanState *sstate = op->d.subplan.sstate;
3925 
3926  /* could potentially be nested, so make sure there's enough stack */
3928 
3929  *op->resvalue = ExecSubPlan(sstate, econtext, op->resnull);
3930 }
Datum ExecSubPlan(SubPlanState *node, ExprContext *econtext, bool *isNull)
Definition: nodeSubplan.c:62
void check_stack_depth(void)
Definition: postgres.c:3461
struct ExprEvalStep::@50::@87 subplan

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

Referenced by ExecInterpExpr().

◆ ExecEvalSysVar()

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

Definition at line 4166 of file execExprInterp.c.

4168 {
4169  Datum d;
4170 
4171  /* slot_getsysattr has sufficient defenses against bad attnums */
4172  d = slot_getsysattr(slot,
4173  op->d.var.attnum,
4174  op->resnull);
4175  *op->resvalue = d;
4176  /* this ought to be unreachable, but it's cheap enough to check */
4177  if (unlikely(*op->resnull))
4178  elog(ERROR, "failed to fetch attribute from slot");
4179 }
static Datum slot_getsysattr(TupleTableSlot *slot, int attnum, bool *isnull)
Definition: tuptable.h:448

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

Referenced by ExecInterpExpr().

◆ ExecEvalWholeRowVar()

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

Definition at line 3939 of file execExprInterp.c.

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

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

Referenced by ExecInterpExpr().

◆ ExecEvalXmlExpr()

void ExecEvalXmlExpr ( ExprState state,
ExprEvalStep op 
)

Definition at line 3676 of file execExprInterp.c.

3677 {
3678  XmlExpr *xexpr = op->d.xmlexpr.xexpr;
3679  Datum value;
3680 
3681  *op->resnull = true; /* until we get a result */
3682  *op->resvalue = (Datum) 0;
3683 
3684  switch (xexpr->op)
3685  {
3686  case IS_XMLCONCAT:
3687  {
3688  Datum *argvalue = op->d.xmlexpr.argvalue;
3689  bool *argnull = op->d.xmlexpr.argnull;
3690  List *values = NIL;
3691 
3692  for (int i = 0; i < list_length(xexpr->args); i++)
3693  {
3694  if (!argnull[i])
3695  values = lappend(values, DatumGetPointer(argvalue[i]));
3696  }
3697 
3698  if (values != NIL)
3699  {
3701  *op->resnull = false;
3702  }
3703  }
3704  break;
3705 
3706  case IS_XMLFOREST:
3707  {
3708  Datum *argvalue = op->d.xmlexpr.named_argvalue;
3709  bool *argnull = op->d.xmlexpr.named_argnull;
3711  ListCell *lc;
3712  ListCell *lc2;
3713  int i;
3714 
3715  initStringInfo(&buf);
3716 
3717  i = 0;
3718  forboth(lc, xexpr->named_args, lc2, xexpr->arg_names)
3719  {
3720  Expr *e = (Expr *) lfirst(lc);
3721  char *argname = strVal(lfirst(lc2));
3722 
3723  if (!argnull[i])
3724  {
3725  value = argvalue[i];
3726  appendStringInfo(&buf, "<%s>%s</%s>",
3727  argname,
3729  exprType((Node *) e), true),
3730  argname);
3731  *op->resnull = false;
3732  }
3733  i++;
3734  }
3735 
3736  if (!*op->resnull)
3737  {
3738  text *result;
3739 
3740  result = cstring_to_text_with_len(buf.data, buf.len);
3741  *op->resvalue = PointerGetDatum(result);
3742  }
3743 
3744  pfree(buf.data);
3745  }
3746  break;
3747 
3748  case IS_XMLELEMENT:
3749  *op->resvalue = PointerGetDatum(xmlelement(xexpr,
3750  op->d.xmlexpr.named_argvalue,
3751  op->d.xmlexpr.named_argnull,
3752  op->d.xmlexpr.argvalue,
3753  op->d.xmlexpr.argnull));
3754  *op->resnull = false;
3755  break;
3756 
3757  case IS_XMLPARSE:
3758  {
3759  Datum *argvalue = op->d.xmlexpr.argvalue;
3760  bool *argnull = op->d.xmlexpr.argnull;
3761  text *data;
3762  bool preserve_whitespace;
3763 
3764  /* arguments are known to be text, bool */
3765  Assert(list_length(xexpr->args) == 2);
3766 
3767  if (argnull[0])
3768  return;
3769  value = argvalue[0];
3771 
3772  if (argnull[1]) /* probably can't happen */
3773  return;
3774  value = argvalue[1];
3775  preserve_whitespace = DatumGetBool(value);
3776 
3778  xexpr->xmloption,
3779  preserve_whitespace));
3780  *op->resnull = false;
3781  }
3782  break;
3783 
3784  case IS_XMLPI:
3785  {
3786  text *arg;
3787  bool isnull;
3788 
3789  /* optional argument is known to be text */
3790  Assert(list_length(xexpr->args) <= 1);
3791 
3792  if (xexpr->args)
3793  {
3794  isnull = op->d.xmlexpr.argnull[0];
3795  if (isnull)
3796  arg = NULL;
3797  else
3798  arg = DatumGetTextPP(op->d.xmlexpr.argvalue[0]);
3799  }
3800  else
3801  {
3802  arg = NULL;
3803  isnull = false;
3804  }
3805 
3806  *op->resvalue = PointerGetDatum(xmlpi(xexpr->name,
3807  arg,
3808  isnull,
3809  op->resnull));
3810  }
3811  break;
3812 
3813  case IS_XMLROOT:
3814  {
3815  Datum *argvalue = op->d.xmlexpr.argvalue;
3816  bool *argnull = op->d.xmlexpr.argnull;
3817  xmltype *data;
3818  text *version;
3819  int standalone;
3820 
3821  /* arguments are known to be xml, text, int */
3822  Assert(list_length(xexpr->args) == 3);
3823 
3824  if (argnull[0])
3825  return;
3826  data = DatumGetXmlP(argvalue[0]);
3827 
3828  if (argnull[1])
3829  version = NULL;
3830  else
3831  version = DatumGetTextPP(argvalue[1]);
3832 
3833  Assert(!argnull[2]); /* always present */
3834  standalone = DatumGetInt32(argvalue[2]);
3835 
3837  version,
3838  standalone));
3839  *op->resnull = false;
3840  }
3841  break;
3842 
3843  case IS_XMLSERIALIZE:
3844  {
3845  Datum *argvalue = op->d.xmlexpr.argvalue;
3846  bool *argnull = op->d.xmlexpr.argnull;
3847 
3848  /* argument type is known to be xml */
3849  Assert(list_length(xexpr->args) == 1);
3850 
3851  if (argnull[0])
3852  return;
3853  value = argvalue[0];
3854 
3855  *op->resvalue =
3857  xexpr->xmloption,
3858  xexpr->indent));
3859  *op->resnull = false;
3860  }
3861  break;
3862 
3863  case IS_DOCUMENT:
3864  {
3865  Datum *argvalue = op->d.xmlexpr.argvalue;
3866  bool *argnull = op->d.xmlexpr.argnull;
3867 
3868  /* optional argument is known to be xml */
3869  Assert(list_length(xexpr->args) == 1);
3870 
3871  if (argnull[0])
3872  return;
3873  value = argvalue[0];
3874 
3875  *op->resvalue =
3877  *op->resnull = false;
3878  }
3879  break;
3880 
3881  default:
3882  elog(ERROR, "unrecognized XML operation");
3883  break;
3884  }
3885 }
#define DatumGetTextPP(X)
Definition: fmgr.h:292
List * lappend(List *list, void *datum)
Definition: list.c:338
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:43
void * arg
const void * data
#define lfirst(lc)
Definition: pg_list.h:172
static int list_length(const List *l)
Definition: pg_list.h:152
#define NIL
Definition: pg_list.h:68
#define forboth(cell1, list1, cell2, list2)
Definition: pg_list.h:467
static char * buf
Definition: pg_test_fsync.c:67
e
Definition: preproc-init.c:82
@ IS_DOCUMENT
Definition: primnodes.h:1468
@ IS_XMLFOREST
Definition: primnodes.h:1463
@ IS_XMLCONCAT
Definition: primnodes.h:1461
@ IS_XMLPI
Definition: primnodes.h:1465
@ IS_XMLPARSE
Definition: primnodes.h:1464
@ IS_XMLSERIALIZE
Definition: primnodes.h:1467
@ IS_XMLROOT
Definition: primnodes.h:1466
@ IS_XMLELEMENT
Definition: primnodes.h:1462
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:91
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
struct ExprEvalStep::@50::@82 xmlexpr
Definition: pg_list.h:54
List * args
Definition: primnodes.h:1489
bool indent
Definition: primnodes.h:1493
List * named_args
Definition: primnodes.h:1485
XmlExprOp op
Definition: primnodes.h:1481
Definition: c.h:671
#define strVal(v)
Definition: value.h:82
text * cstring_to_text_with_len(const char *s, int len)
Definition: varlena.c:194
xmltype * xmlconcat(List *args)
Definition: xml.c:522
text * xmltotext_with_options(xmltype *data, XmlOptionType xmloption_arg, bool indent)
Definition: xml.c:625
xmltype * xmlparse(text *data, XmlOptionType xmloption_arg, bool preserve_whitespace)
Definition: xml.c:929
bool xml_is_document(xmltype *arg)
Definition: xml.c:1065
xmltype * xmlpi(const char *target, text *arg, bool arg_is_null, bool *result_is_null)
Definition: xml.c:947
char * map_sql_value_to_xml_value(Datum value, Oid type, bool xml_escape_strings)
Definition: xml.c:2384
xmltype * xmlelement(XmlExpr *xexpr, Datum *named_argvalue, bool *named_argnull, Datum *argvalue, bool *argnull)
Definition: xml.c:805
xmltype * xmlroot(xmltype *data, text *version, int standalone)
Definition: xml.c:999
static xmltype * DatumGetXmlP(Datum X)
Definition: xml.h:51

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

Referenced by ExecInterpExpr().

◆ ExecInitInterpreter()

static void ExecInitInterpreter ( void  )
static

Definition at line 2310 of file execExprInterp.c.

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

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

Referenced by ExecReadyInterpretedExpr().

◆ ExecInterpExpr()

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

Definition at line 394 of file execExprInterp.c.

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

References ExprEvalStep::aggno, AggState::all_pergroups, generate_unaccent_rules::args, FunctionCallInfoBaseData::args, Assert(), attnum, BoolGetDatum(), ExprContext::caseValue_datum, ExprContext::caseValue_isNull, castNode, CheckOpSlotCompatibility(), ExprEvalStep::d, DatumGetBool(), DatumGetCString(), DatumGetInt32(), ExprContext::domainValue_datum, ExprContext::domainValue_isNull, ExprContext::ecxt_aggnulls, ExprContext::ecxt_aggvalues, ExprContext::ecxt_innertuple, ExprContext::ecxt_outertuple, ExprContext::ecxt_per_tuple_memory, ExprContext::ecxt_scantuple, EEO_CASE, EEO_DISPATCH, EEO_JUMP, EEO_NEXT, EEO_SWITCH, EEOP_AGG_DESERIALIZE, EEOP_AGG_ORDERED_TRANS_DATUM, EEOP_AGG_ORDERED_TRANS_TUPLE, EEOP_AGG_PLAIN_PERGROUP_NULLCHECK, EEOP_AGG_PLAIN_TRANS_BYREF, EEOP_AGG_PLAIN_TRANS_BYVAL, EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYREF, EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYVAL, EEOP_AGG_PLAIN_TRANS_STRICT_BYREF, EEOP_AGG_PLAIN_TRANS_STRICT_BYVAL, EEOP_AGG_PRESORTED_DISTINCT_MULTI, EEOP_AGG_PRESORTED_DISTINCT_SINGLE, EEOP_AGG_STRICT_DESERIALIZE, EEOP_AGG_STRICT_INPUT_CHECK_ARGS, EEOP_AGG_STRICT_INPUT_CHECK_NULLS, EEOP_AGGREF, EEOP_ARRAYCOERCE, EEOP_ARRAYEXPR, EEOP_ASSIGN_INNER_VAR, EEOP_ASSIGN_OUTER_VAR, EEOP_ASSIGN_SCAN_VAR, EEOP_ASSIGN_TMP, EEOP_ASSIGN_TMP_MAKE_RO, EEOP_BOOL_AND_STEP, EEOP_BOOL_AND_STEP_FIRST, EEOP_BOOL_AND_STEP_LAST, EEOP_BOOL_NOT_STEP, EEOP_BOOL_OR_STEP, EEOP_BOOL_OR_STEP_FIRST, EEOP_BOOL_OR_STEP_LAST, EEOP_BOOLTEST_IS_FALSE, EEOP_BOOLTEST_IS_NOT_FALSE, EEOP_BOOLTEST_IS_NOT_TRUE, EEOP_BOOLTEST_IS_TRUE, EEOP_CASE_TESTVAL, EEOP_CONST, EEOP_CONVERT_ROWTYPE, EEOP_CURRENTOFEXPR, EEOP_DISTINCT, EEOP_DOMAIN_CHECK, EEOP_DOMAIN_NOTNULL, EEOP_DOMAIN_TESTVAL, EEOP_DONE, EEOP_FIELDSELECT, EEOP_FIELDSTORE_DEFORM, EEOP_FIELDSTORE_FORM, EEOP_FUNCEXPR, EEOP_FUNCEXPR_FUSAGE, EEOP_FUNCEXPR_STRICT, EEOP_FUNCEXPR_STRICT_FUSAGE, EEOP_GROUPING_FUNC, EEOP_HASHED_SCALARARRAYOP, EEOP_INNER_FETCHSOME, EEOP_INNER_SYSVAR, EEOP_INNER_VAR, EEOP_IOCOERCE, EEOP_JSON_CONSTRUCTOR, EEOP_JUMP, EEOP_JUMP_IF_NOT_NULL, EEOP_JUMP_IF_NOT_TRUE, EEOP_JUMP_IF_NULL, EEOP_LAST, EEOP_MAKE_READONLY, EEOP_MINMAX, EEOP_NEXTVALUEEXPR, EEOP_NOT_DISTINCT, EEOP_NULLIF, EEOP_NULLTEST_ISNOTNULL, EEOP_NULLTEST_ISNULL, EEOP_NULLTEST_ROWISNOTNULL, EEOP_NULLTEST_ROWISNULL, EEOP_OUTER_FETCHSOME, EEOP_OUTER_SYSVAR, EEOP_OUTER_VAR, EEOP_PARAM_CALLBACK, EEOP_PARAM_EXEC, EEOP_PARAM_EXTERN, EEOP_QUAL, EEOP_ROW, EEOP_ROWCOMPARE_FINAL, EEOP_ROWCOMPARE_STEP, EEOP_SBSREF_ASSIGN, EEOP_SBSREF_FETCH, EEOP_SBSREF_OLD, EEOP_SBSREF_SUBSCRIPTS, EEOP_SCALARARRAYOP, EEOP_SCAN_FETCHSOME, EEOP_SCAN_SYSVAR, EEOP_SCAN_VAR, EEOP_SUBPLAN, EEOP_WHOLEROW, EEOP_WINDOW_FUNC, EEOP_XMLEXPR, ExecAggInitGroup(), ExecAggPlainTransByRef(), ExecAggPlainTransByVal(), ExecEvalAggOrderedTransDatum(), ExecEvalAggOrderedTransTuple(), ExecEvalArrayCoerce(), ExecEvalArrayExpr(), ExecEvalConstraintCheck(), ExecEvalConstraintNotNull(), ExecEvalConvertRowtype(), ExecEvalCurrentOfExpr(), ExecEvalFieldSelect(), ExecEvalFieldStoreDeForm(), ExecEvalFieldStoreForm(), ExecEvalFuncExprFusage(), ExecEvalFuncExprStrictFusage(), ExecEvalGroupingFunc(), ExecEvalHashedScalarArrayOp(), ExecEvalJsonConstructor(), ExecEvalMinMax(), ExecEvalNextValueExpr(), ExecEvalParamExec(), ExecEvalParamExtern(), ExecEvalPreOrderedDistinctMulti(), ExecEvalPreOrderedDistinctSingle(), ExecEvalRow(), ExecEvalRowNotNull(), ExecEvalRowNull(), ExecEvalScalarArrayOp(), ExecEvalSubPlan(), ExecEvalSysVar(), ExecEvalWholeRowVar(), ExecEvalXmlExpr(), FunctionCallInvoke, ExprEvalStep::isnull, FunctionCallInfoBaseData::isnull, NullableDatum::isnull, lengthof, likely, MakeExpandedObjectReadOnlyInternal(), MemoryContextSwitchTo(), ExprEvalStep::nargs, AggStatePerGroupData::noTransValue, ExprEvalStep::nulls, ExprEvalStep::op, ExprEvalStep::pertrans, PointerGetDatum(), ExprEvalStep::rctype, ExprEvalStep::resultnum, ROWCOMPARE_GE, ROWCOMPARE_GT, ROWCOMPARE_LE, ROWCOMPARE_LT, slot_getsomeattrs(), StaticAssertDecl, generate_unaccent_rules::str, AggState::tmpcontext, AggStatePerTransData::transtypeByVal, AggStatePerGroupData::transValueIsNull, TupleTableSlot::tts_isnull, TupleTableSlot::tts_values, unlikely, NullableDatum::value, and WindowFuncExprState::wfuncno.

Referenced by ExecInitInterpreter(), and ExecReadyInterpretedExpr().

◆ ExecInterpExprStillValid()

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

Definition at line 1836 of file execExprInterp.c.

1837 {
1838  /*
1839  * First time through, check whether attribute matches Var. Might not be
1840  * ok anymore, due to schema changes.
1841  */
1842  CheckExprStillValid(state, econtext);
1843 
1844  /* skip the check during further executions */
1845  state->evalfunc = (ExprStateEvalFunc) state->evalfunc_private;
1846 
1847  /* and actually execute */
1848  return state->evalfunc(state, econtext, isNull);
1849 }
void CheckExprStillValid(ExprState *state, ExprContext *econtext)
Datum(* ExprStateEvalFunc)(struct ExprState *expression, struct ExprContext *econtext, bool *isNull)
Definition: execnodes.h:69

References CheckExprStillValid().

Referenced by ExecReadyInterpretedExpr().

◆ ExecJustApplyFuncToCase()

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

Definition at line 2155 of file execExprInterp.c.

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

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

Referenced by ExecReadyInterpretedExpr().

◆ ExecJustAssignInnerVar()

static Datum ExecJustAssignInnerVar ( ExprState state,