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/miscnodes.h"
#include "nodes/nodeFuncs.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/jsonfuncs.h"
#include "utils/jsonpath.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 char * ExecGetJsonValueItemString (JsonbValue *item, bool *resnull)
 
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 ExecEvalCoerceViaIOSafe (ExprState *state, ExprEvalStep *op)
 
void ExecEvalSQLValueFunction (ExprState *state, ExprEvalStep *op)
 
void ExecEvalCurrentOfExpr (ExprState *state, ExprEvalStep *op)
 
void ExecEvalNextValueExpr (ExprState *state, ExprEvalStep *op)
 
void ExecEvalRowNull (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalRowNotNull (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalArrayExpr (ExprState *state, ExprEvalStep *op)
 
void ExecEvalArrayCoerce (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalRow (ExprState *state, ExprEvalStep *op)
 
void ExecEvalMinMax (ExprState *state, ExprEvalStep *op)
 
void ExecEvalFieldSelect (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalFieldStoreDeForm (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalFieldStoreForm (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalConvertRowtype (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalScalarArrayOp (ExprState *state, ExprEvalStep *op)
 
void ExecEvalHashedScalarArrayOp (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalConstraintNotNull (ExprState *state, ExprEvalStep *op)
 
void ExecEvalConstraintCheck (ExprState *state, ExprEvalStep *op)
 
void ExecEvalXmlExpr (ExprState *state, ExprEvalStep *op)
 
void ExecEvalJsonConstructor (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalJsonIsPredicate (ExprState *state, ExprEvalStep *op)
 
int ExecEvalJsonExprPath (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalJsonCoercion (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalJsonCoercionFinish (ExprState *state, ExprEvalStep *op)
 
void ExecEvalGroupingFunc (ExprState *state, ExprEvalStep *op)
 
void ExecEvalMergeSupportFunc (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
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 ExecAggCopyTransValue (AggState *aggstate, AggStatePerTrans pertrans, Datum newValue, bool newValueIsNull, Datum oldValue, bool oldValueIsNull)
 
bool ExecEvalPreOrderedDistinctSingle (AggState *aggstate, AggStatePerTrans pertrans)
 
bool ExecEvalPreOrderedDistinctMulti (AggState *aggstate, AggStatePerTrans pertrans)
 
void ExecEvalAggOrderedTransDatum (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
void ExecEvalAggOrderedTransTuple (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 

Macro Definition Documentation

◆ EEO_CASE

#define EEO_CASE (   name)    case name:

Definition at line 125 of file execExprInterp.c.

◆ EEO_DISPATCH

#define EEO_DISPATCH ( )    goto starteval

Definition at line 126 of file execExprInterp.c.

◆ EEO_JUMP

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

Definition at line 137 of file execExprInterp.c.

◆ EEO_NEXT

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

Definition at line 131 of file execExprInterp.c.

◆ EEO_OPCODE

#define EEO_OPCODE (   opcode)    (opcode)

Definition at line 127 of file execExprInterp.c.

◆ EEO_SWITCH

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

Definition at line 124 of file execExprInterp.c.

◆ SH_DECLARE

#define SH_DECLARE

Definition at line 200 of file execExprInterp.c.

◆ SH_DEFINE

#define SH_DEFINE

Definition at line 229 of file execExprInterp.c.

◆ SH_ELEMENT_TYPE [1/2]

#define SH_ELEMENT_TYPE   ScalarArrayOpExprHashEntry

Definition at line 221 of file execExprInterp.c.

◆ SH_ELEMENT_TYPE [2/2]

#define SH_ELEMENT_TYPE   ScalarArrayOpExprHashEntry

Definition at line 221 of file execExprInterp.c.

◆ SH_EQUAL

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

Definition at line 225 of file execExprInterp.c.

◆ SH_GET_HASH

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

Definition at line 228 of file execExprInterp.c.

◆ SH_HASH_KEY

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

Definition at line 224 of file execExprInterp.c.

◆ SH_KEY

#define SH_KEY   key

Definition at line 223 of file execExprInterp.c.

◆ SH_KEY_TYPE [1/2]

#define SH_KEY_TYPE   Datum

Definition at line 222 of file execExprInterp.c.

◆ SH_KEY_TYPE [2/2]

#define SH_KEY_TYPE   Datum

Definition at line 222 of file execExprInterp.c.

◆ SH_PREFIX [1/2]

#define SH_PREFIX   saophash

Definition at line 220 of file execExprInterp.c.

◆ SH_PREFIX [2/2]

#define SH_PREFIX   saophash

Definition at line 220 of file execExprInterp.c.

◆ SH_SCOPE [1/2]

#define SH_SCOPE   static inline

Definition at line 226 of file execExprInterp.c.

◆ SH_SCOPE [2/2]

#define SH_SCOPE   static inline

Definition at line 226 of file execExprInterp.c.

◆ SH_STORE_HASH

#define SH_STORE_HASH

Definition at line 227 of file execExprInterp.c.

Typedef Documentation

◆ ScalarArrayOpExprHashEntry

◆ ScalarArrayOpExprHashTable

Function Documentation

◆ CheckExprStillValid()

void CheckExprStillValid ( ExprState state,
ExprContext econtext 
)

Definition at line 1923 of file execExprInterp.c.

1924 {
1925  TupleTableSlot *innerslot;
1926  TupleTableSlot *outerslot;
1927  TupleTableSlot *scanslot;
1928 
1929  innerslot = econtext->ecxt_innertuple;
1930  outerslot = econtext->ecxt_outertuple;
1931  scanslot = econtext->ecxt_scantuple;
1932 
1933  for (int i = 0; i < state->steps_len; i++)
1934  {
1935  ExprEvalStep *op = &state->steps[i];
1936 
1937  switch (ExecEvalStepOp(state, op))
1938  {
1939  case EEOP_INNER_VAR:
1940  {
1941  int attnum = op->d.var.attnum;
1942 
1943  CheckVarSlotCompatibility(innerslot, attnum + 1, op->d.var.vartype);
1944  break;
1945  }
1946 
1947  case EEOP_OUTER_VAR:
1948  {
1949  int attnum = op->d.var.attnum;
1950 
1951  CheckVarSlotCompatibility(outerslot, attnum + 1, op->d.var.vartype);
1952  break;
1953  }
1954 
1955  case EEOP_SCAN_VAR:
1956  {
1957  int attnum = op->d.var.attnum;
1958 
1959  CheckVarSlotCompatibility(scanslot, attnum + 1, op->d.var.vartype);
1960  break;
1961  }
1962  default:
1963  break;
1964  }
1965  }
1966 }
static void CheckVarSlotCompatibility(TupleTableSlot *slot, int attnum, Oid vartype)
ExprEvalOp ExecEvalStepOp(ExprState *state, ExprEvalStep *op)
@ EEOP_INNER_VAR
Definition: execExpr.h:77
@ EEOP_SCAN_VAR
Definition: execExpr.h:79
@ EEOP_OUTER_VAR
Definition: execExpr.h:78
int i
Definition: isn.c:73
int16 attnum
Definition: pg_attribute.h:74
TupleTableSlot * ecxt_innertuple
Definition: execnodes.h:257
TupleTableSlot * ecxt_scantuple
Definition: execnodes.h:255
TupleTableSlot * ecxt_outertuple
Definition: execnodes.h:259
struct ExprEvalStep::@53::@55 var
union ExprEvalStep::@53 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 2025 of file execExprInterp.c.

2026 {
2027 #ifdef USE_ASSERT_CHECKING
2028  /* there's nothing to check */
2029  if (!op->d.fetch.fixed)
2030  return;
2031 
2032  /*
2033  * Should probably fixed at some point, but for now it's easier to allow
2034  * buffer and heap tuples to be used interchangeably.
2035  */
2036  if (slot->tts_ops == &TTSOpsBufferHeapTuple &&
2037  op->d.fetch.kind == &TTSOpsHeapTuple)
2038  return;
2039  if (slot->tts_ops == &TTSOpsHeapTuple &&
2040  op->d.fetch.kind == &TTSOpsBufferHeapTuple)
2041  return;
2042 
2043  /*
2044  * At the moment we consider it OK if a virtual slot is used instead of a
2045  * specific type of slot, as a virtual slot never needs to be deformed.
2046  */
2047  if (slot->tts_ops == &TTSOpsVirtual)
2048  return;
2049 
2050  Assert(op->d.fetch.kind == slot->tts_ops);
2051 #endif
2052 }
const TupleTableSlotOps TTSOpsVirtual
Definition: execTuples.c:84
const TupleTableSlotOps TTSOpsBufferHeapTuple
Definition: execTuples.c:87
const TupleTableSlotOps TTSOpsHeapTuple
Definition: execTuples.c:85
Assert(fmt[strlen(fmt) - 1] !='\n')
struct ExprEvalStep::@53::@54 fetch
const TupleTableSlotOps *const tts_ops
Definition: tuptable.h:121

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 1974 of file execExprInterp.c.

1975 {
1976  /*
1977  * What we have to check for here is the possibility of an attribute
1978  * having been dropped or changed in type since the plan tree was created.
1979  * Ideally the plan will get invalidated and not re-used, but just in
1980  * case, we keep these defenses. Fortunately it's sufficient to check
1981  * once on the first time through.
1982  *
1983  * Note: ideally we'd check typmod as well as typid, but that seems
1984  * impractical at the moment: in many cases the tupdesc will have been
1985  * generated by ExecTypeFromTL(), and that can't guarantee to generate an
1986  * accurate typmod in all cases, because some expression node types don't
1987  * carry typmod. Fortunately, for precisely that reason, there should be
1988  * no places with a critical dependency on the typmod of a value.
1989  *
1990  * System attributes don't require checking since their types never
1991  * change.
1992  */
1993  if (attnum > 0)
1994  {
1995  TupleDesc slot_tupdesc = slot->tts_tupleDescriptor;
1996  Form_pg_attribute attr;
1997 
1998  if (attnum > slot_tupdesc->natts) /* should never happen */
1999  elog(ERROR, "attribute number %d exceeds number of columns %d",
2000  attnum, slot_tupdesc->natts);
2001 
2002  attr = TupleDescAttr(slot_tupdesc, attnum - 1);
2003 
2004  if (attr->attisdropped)
2005  ereport(ERROR,
2006  (errcode(ERRCODE_UNDEFINED_COLUMN),
2007  errmsg("attribute %d of type %s has been dropped",
2008  attnum, format_type_be(slot_tupdesc->tdtypeid))));
2009 
2010  if (vartype != attr->atttypid)
2011  ereport(ERROR,
2012  (errcode(ERRCODE_DATATYPE_MISMATCH),
2013  errmsg("attribute %d of type %s has wrong type",
2014  attnum, format_type_be(slot_tupdesc->tdtypeid)),
2015  errdetail("Table has type %s, but query expects %s.",
2016  format_type_be(attr->atttypid),
2017  format_type_be(vartype))));
2018  }
2019 }
int errdetail(const char *fmt,...)
Definition: elog.c:1205
int errcode(int sqlerrcode)
Definition: elog.c:859
int errmsg(const char *fmt,...)
Definition: elog.c:1072
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:224
#define ereport(elevel,...)
Definition: elog.h:149
char * format_type_be(Oid type_oid)
Definition: format_type.c:343
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:209
Oid tdtypeid
Definition: tupdesc.h:82
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:123
#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().

◆ ExecAggCopyTransValue()

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

Definition at line 4953 of file execExprInterp.c.

4956 {
4957  Assert(newValue != oldValue);
4958 
4959  if (!newValueIsNull)
4960  {
4962  if (DatumIsReadWriteExpandedObject(newValue,
4963  false,
4964  pertrans->transtypeLen) &&
4965  MemoryContextGetParent(DatumGetEOHP(newValue)->eoh_context) == CurrentMemoryContext)
4966  /* do nothing */ ;
4967  else
4968  newValue = datumCopy(newValue,
4969  pertrans->transtypeByVal,
4970  pertrans->transtypeLen);
4971  }
4972  else
4973  {
4974  /*
4975  * Ensure that AggStatePerGroup->transValue ends up being 0, so
4976  * callers can safely compare newValue/oldValue without having to
4977  * check their respective nullness.
4978  */
4979  newValue = (Datum) 0;
4980  }
4981 
4982  if (!oldValueIsNull)
4983  {
4984  if (DatumIsReadWriteExpandedObject(oldValue,
4985  false,
4986  pertrans->transtypeLen))
4987  DeleteExpandedObject(oldValue);
4988  else
4989  pfree(DatumGetPointer(oldValue));
4990  }
4991 
4992  return newValue;
4993 }
Datum datumCopy(Datum value, bool typByVal, int typLen)
Definition: datum.c:132
ExpandedObjectHeader * DatumGetEOHP(Datum d)
Definition: expandeddatum.c:29
void DeleteExpandedObject(Datum d)
#define DatumIsReadWriteExpandedObject(d, isnull, typlen)
void pfree(void *pointer)
Definition: mcxt.c:1508
MemoryContext CurrentMemoryContext
Definition: mcxt.c:131
MemoryContext MemoryContextGetParent(MemoryContext context)
Definition: mcxt.c:719
uintptr_t Datum
Definition: postgres.h:64
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:312
MemoryContextSwitchTo(old_ctx)
ExprContext * curaggcontext
Definition: execnodes.h:2472
MemoryContext ecxt_per_tuple_memory
Definition: execnodes.h:263

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

◆ ExecAggInitGroup()

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

Definition at line 4900 of file execExprInterp.c.

4902 {
4903  FunctionCallInfo fcinfo = pertrans->transfn_fcinfo;
4904  MemoryContext oldContext;
4905 
4906  /*
4907  * We must copy the datum into aggcontext if it is pass-by-ref. We do not
4908  * need to pfree the old transValue, since it's NULL. (We already checked
4909  * that the agg's input type is binary-compatible with its transtype, so
4910  * straight copy here is OK.)
4911  */
4912  oldContext = MemoryContextSwitchTo(aggcontext->ecxt_per_tuple_memory);
4913  pergroup->transValue = datumCopy(fcinfo->args[1].value,
4914  pertrans->transtypeByVal,
4915  pertrans->transtypeLen);
4916  pergroup->transValueIsNull = false;
4917  pergroup->noTransValue = false;
4918  MemoryContextSwitchTo(oldContext);
4919 }
FunctionCallInfo transfn_fcinfo
Definition: nodeAgg.h:170
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 5152 of file execExprInterp.c.

5155 {
5156  FunctionCallInfo fcinfo = pertrans->transfn_fcinfo;
5157  MemoryContext oldContext;
5158  Datum newVal;
5159 
5160  /* cf. select_current_set() */
5161  aggstate->curaggcontext = aggcontext;
5162  aggstate->current_set = setno;
5163 
5164  /* set up aggstate->curpertrans for AggGetAggref() */
5165  aggstate->curpertrans = pertrans;
5166 
5167  /* invoke transition function in per-tuple context */
5168  oldContext = MemoryContextSwitchTo(aggstate->tmpcontext->ecxt_per_tuple_memory);
5169 
5170  fcinfo->args[0].value = pergroup->transValue;
5171  fcinfo->args[0].isnull = pergroup->transValueIsNull;
5172  fcinfo->isnull = false; /* just in case transfn doesn't set it */
5173 
5174  newVal = FunctionCallInvoke(fcinfo);
5175 
5176  /*
5177  * For pass-by-ref datatype, must copy the new value into aggcontext and
5178  * free the prior transValue. But if transfn returned a pointer to its
5179  * first input, we don't need to do anything.
5180  *
5181  * It's safe to compare newVal with pergroup->transValue without regard
5182  * for either being NULL, because ExecAggCopyTransValue takes care to set
5183  * transValue to 0 when NULL. Otherwise we could end up accidentally not
5184  * reparenting, when the transValue has the same numerical value as
5185  * newValue, despite being NULL. This is a somewhat hot path, making it
5186  * undesirable to instead solve this with another branch for the common
5187  * case of the transition function returning its (modified) input
5188  * argument.
5189  */
5190  if (DatumGetPointer(newVal) != DatumGetPointer(pergroup->transValue))
5191  newVal = ExecAggCopyTransValue(aggstate, pertrans,
5192  newVal, fcinfo->isnull,
5193  pergroup->transValue,
5194  pergroup->transValueIsNull);
5195 
5196  pergroup->transValue = newVal;
5197  pergroup->transValueIsNull = fcinfo->isnull;
5198 
5199  MemoryContextSwitchTo(oldContext);
5200 }
Datum ExecAggCopyTransValue(AggState *aggstate, AggStatePerTrans pertrans, Datum newValue, bool newValueIsNull, Datum oldValue, bool oldValueIsNull)
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:172
ExprContext * tmpcontext
Definition: execnodes.h:2470
AggStatePerTrans curpertrans
Definition: execnodes.h:2475
int current_set
Definition: execnodes.h:2480
bool isnull
Definition: postgres.h:77

References ExprEvalStep::aggcontext, FunctionCallInfoBaseData::args, AggState::curaggcontext, AggState::curpertrans, AggState::current_set, DatumGetPointer(), ExprContext::ecxt_per_tuple_memory, ExecAggCopyTransValue(), 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 5120 of file execExprInterp.c.

5123 {
5124  FunctionCallInfo fcinfo = pertrans->transfn_fcinfo;
5125  MemoryContext oldContext;
5126  Datum newVal;
5127 
5128  /* cf. select_current_set() */
5129  aggstate->curaggcontext = aggcontext;
5130  aggstate->current_set = setno;
5131 
5132  /* set up aggstate->curpertrans for AggGetAggref() */
5133  aggstate->curpertrans = pertrans;
5134 
5135  /* invoke transition function in per-tuple context */
5136  oldContext = MemoryContextSwitchTo(aggstate->tmpcontext->ecxt_per_tuple_memory);
5137 
5138  fcinfo->args[0].value = pergroup->transValue;
5139  fcinfo->args[0].isnull = pergroup->transValueIsNull;
5140  fcinfo->isnull = false; /* just in case transfn doesn't set it */
5141 
5142  newVal = FunctionCallInvoke(fcinfo);
5143 
5144  pergroup->transValue = newVal;
5145  pergroup->transValueIsNull = fcinfo->isnull;
5146 
5147  MemoryContextSwitchTo(oldContext);
5148 }

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

◆ ExecEvalAggOrderedTransDatum()

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

Definition at line 5092 of file execExprInterp.c.

5094 {
5095  AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
5096  int setno = op->d.agg_trans.setno;
5097 
5098  tuplesort_putdatum(pertrans->sortstates[setno],
5099  *op->resvalue, *op->resnull);
5100 }
Tuplesortstate ** sortstates
Definition: nodeAgg.h:162
struct ExprEvalStep::@53::@96 agg_trans
Datum * resvalue
Definition: execExpr.h:284
bool * resnull
Definition: execExpr.h:285
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 5106 of file execExprInterp.c.

5108 {
5109  AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
5110  int setno = op->d.agg_trans.setno;
5111 
5112  ExecClearTuple(pertrans->sortslot);
5113  pertrans->sortslot->tts_nvalid = pertrans->numInputs;
5114  ExecStoreVirtualTuple(pertrans->sortslot);
5115  tuplesort_puttupleslot(pertrans->sortstates[setno], pertrans->sortslot);
5116 }
TupleTableSlot * ExecStoreVirtualTuple(TupleTableSlot *slot)
Definition: execTuples.c:1639
TupleTableSlot * sortslot
Definition: nodeAgg.h:141
AttrNumber tts_nvalid
Definition: tuptable.h:120
void tuplesort_puttupleslot(Tuplesortstate *state, TupleTableSlot *slot)
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:454

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 3047 of file execExprInterp.c.

3048 {
3049  Datum arraydatum;
3050 
3051  /* NULL array -> NULL result */
3052  if (*op->resnull)
3053  return;
3054 
3055  arraydatum = *op->resvalue;
3056 
3057  /*
3058  * If it's binary-compatible, modify the element type in the array header,
3059  * but otherwise leave the array as we received it.
3060  */
3061  if (op->d.arraycoerce.elemexprstate == NULL)
3062  {
3063  /* Detoast input array if necessary, and copy in any case */
3064  ArrayType *array = DatumGetArrayTypePCopy(arraydatum);
3065 
3066  ARR_ELEMTYPE(array) = op->d.arraycoerce.resultelemtype;
3067  *op->resvalue = PointerGetDatum(array);
3068  return;
3069  }
3070 
3071  /*
3072  * Use array_map to apply the sub-expression to each array element.
3073  */
3074  *op->resvalue = array_map(arraydatum,
3075  op->d.arraycoerce.elemexprstate,
3076  econtext,
3077  op->d.arraycoerce.resultelemtype,
3078  op->d.arraycoerce.amstate);
3079 }
#define DatumGetArrayTypePCopy(X)
Definition: array.h:262
#define ARR_ELEMTYPE(a)
Definition: array.h:292
Datum array_map(Datum arrayd, ExprState *exprstate, ExprContext *econtext, Oid retType, ArrayMapState *amstate)
Definition: arrayfuncs.c:3194
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:322
struct ExprEvalStep::@53::@73 arraycoerce

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

Referenced by ExecInterpExpr().

◆ ExecEvalArrayExpr()

void ExecEvalArrayExpr ( ExprState state,
ExprEvalStep op 
)

Definition at line 2833 of file execExprInterp.c.

2834 {
2835  ArrayType *result;
2836  Oid element_type = op->d.arrayexpr.elemtype;
2837  int nelems = op->d.arrayexpr.nelems;
2838  int ndims = 0;
2839  int dims[MAXDIM];
2840  int lbs[MAXDIM];
2841 
2842  /* Set non-null as default */
2843  *op->resnull = false;
2844 
2845  if (!op->d.arrayexpr.multidims)
2846  {
2847  /* Elements are presumably of scalar type */
2848  Datum *dvalues = op->d.arrayexpr.elemvalues;
2849  bool *dnulls = op->d.arrayexpr.elemnulls;
2850 
2851  /* setup for 1-D array of the given length */
2852  ndims = 1;
2853  dims[0] = nelems;
2854  lbs[0] = 1;
2855 
2856  result = construct_md_array(dvalues, dnulls, ndims, dims, lbs,
2857  element_type,
2858  op->d.arrayexpr.elemlength,
2859  op->d.arrayexpr.elembyval,
2860  op->d.arrayexpr.elemalign);
2861  }
2862  else
2863  {
2864  /* Must be nested array expressions */
2865  int nbytes = 0;
2866  int nitems;
2867  int outer_nelems = 0;
2868  int elem_ndims = 0;
2869  int *elem_dims = NULL;
2870  int *elem_lbs = NULL;
2871  bool firstone = true;
2872  bool havenulls = false;
2873  bool haveempty = false;
2874  char **subdata;
2875  bits8 **subbitmaps;
2876  int *subbytes;
2877  int *subnitems;
2878  int32 dataoffset;
2879  char *dat;
2880  int iitem;
2881 
2882  subdata = (char **) palloc(nelems * sizeof(char *));
2883  subbitmaps = (bits8 **) palloc(nelems * sizeof(bits8 *));
2884  subbytes = (int *) palloc(nelems * sizeof(int));
2885  subnitems = (int *) palloc(nelems * sizeof(int));
2886 
2887  /* loop through and get data area from each element */
2888  for (int elemoff = 0; elemoff < nelems; elemoff++)
2889  {
2890  Datum arraydatum;
2891  bool eisnull;
2892  ArrayType *array;
2893  int this_ndims;
2894 
2895  arraydatum = op->d.arrayexpr.elemvalues[elemoff];
2896  eisnull = op->d.arrayexpr.elemnulls[elemoff];
2897 
2898  /* temporarily ignore null subarrays */
2899  if (eisnull)
2900  {
2901  haveempty = true;
2902  continue;
2903  }
2904 
2905  array = DatumGetArrayTypeP(arraydatum);
2906 
2907  /* run-time double-check on element type */
2908  if (element_type != ARR_ELEMTYPE(array))
2909  ereport(ERROR,
2910  (errcode(ERRCODE_DATATYPE_MISMATCH),
2911  errmsg("cannot merge incompatible arrays"),
2912  errdetail("Array with element type %s cannot be "
2913  "included in ARRAY construct with element type %s.",
2914  format_type_be(ARR_ELEMTYPE(array)),
2915  format_type_be(element_type))));
2916 
2917  this_ndims = ARR_NDIM(array);
2918  /* temporarily ignore zero-dimensional subarrays */
2919  if (this_ndims <= 0)
2920  {
2921  haveempty = true;
2922  continue;
2923  }
2924 
2925  if (firstone)
2926  {
2927  /* Get sub-array details from first member */
2928  elem_ndims = this_ndims;
2929  ndims = elem_ndims + 1;
2930  if (ndims <= 0 || ndims > MAXDIM)
2931  ereport(ERROR,
2932  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
2933  errmsg("number of array dimensions (%d) exceeds the maximum allowed (%d)",
2934  ndims, MAXDIM)));
2935 
2936  elem_dims = (int *) palloc(elem_ndims * sizeof(int));
2937  memcpy(elem_dims, ARR_DIMS(array), elem_ndims * sizeof(int));
2938  elem_lbs = (int *) palloc(elem_ndims * sizeof(int));
2939  memcpy(elem_lbs, ARR_LBOUND(array), elem_ndims * sizeof(int));
2940 
2941  firstone = false;
2942  }
2943  else
2944  {
2945  /* Check other sub-arrays are compatible */
2946  if (elem_ndims != this_ndims ||
2947  memcmp(elem_dims, ARR_DIMS(array),
2948  elem_ndims * sizeof(int)) != 0 ||
2949  memcmp(elem_lbs, ARR_LBOUND(array),
2950  elem_ndims * sizeof(int)) != 0)
2951  ereport(ERROR,
2952  (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
2953  errmsg("multidimensional arrays must have array "
2954  "expressions with matching dimensions")));
2955  }
2956 
2957  subdata[outer_nelems] = ARR_DATA_PTR(array);
2958  subbitmaps[outer_nelems] = ARR_NULLBITMAP(array);
2959  subbytes[outer_nelems] = ARR_SIZE(array) - ARR_DATA_OFFSET(array);
2960  nbytes += subbytes[outer_nelems];
2961  /* check for overflow of total request */
2962  if (!AllocSizeIsValid(nbytes))
2963  ereport(ERROR,
2964  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
2965  errmsg("array size exceeds the maximum allowed (%d)",
2966  (int) MaxAllocSize)));
2967  subnitems[outer_nelems] = ArrayGetNItems(this_ndims,
2968  ARR_DIMS(array));
2969  havenulls |= ARR_HASNULL(array);
2970  outer_nelems++;
2971  }
2972 
2973  /*
2974  * If all items were null or empty arrays, return an empty array;
2975  * otherwise, if some were and some weren't, raise error. (Note: we
2976  * must special-case this somehow to avoid trying to generate a 1-D
2977  * array formed from empty arrays. It's not ideal...)
2978  */
2979  if (haveempty)
2980  {
2981  if (ndims == 0) /* didn't find any nonempty array */
2982  {
2983  *op->resvalue = PointerGetDatum(construct_empty_array(element_type));
2984  return;
2985  }
2986  ereport(ERROR,
2987  (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
2988  errmsg("multidimensional arrays must have array "
2989  "expressions with matching dimensions")));
2990  }
2991 
2992  /* setup for multi-D array */
2993  dims[0] = outer_nelems;
2994  lbs[0] = 1;
2995  for (int i = 1; i < ndims; i++)
2996  {
2997  dims[i] = elem_dims[i - 1];
2998  lbs[i] = elem_lbs[i - 1];
2999  }
3000 
3001  /* check for subscript overflow */
3002  nitems = ArrayGetNItems(ndims, dims);
3003  ArrayCheckBounds(ndims, dims, lbs);
3004 
3005  if (havenulls)
3006  {
3007  dataoffset = ARR_OVERHEAD_WITHNULLS(ndims, nitems);
3008  nbytes += dataoffset;
3009  }
3010  else
3011  {
3012  dataoffset = 0; /* marker for no null bitmap */
3013  nbytes += ARR_OVERHEAD_NONULLS(ndims);
3014  }
3015 
3016  result = (ArrayType *) palloc0(nbytes);
3017  SET_VARSIZE(result, nbytes);
3018  result->ndim = ndims;
3019  result->dataoffset = dataoffset;
3020  result->elemtype = element_type;
3021  memcpy(ARR_DIMS(result), dims, ndims * sizeof(int));
3022  memcpy(ARR_LBOUND(result), lbs, ndims * sizeof(int));
3023 
3024  dat = ARR_DATA_PTR(result);
3025  iitem = 0;
3026  for (int i = 0; i < outer_nelems; i++)
3027  {
3028  memcpy(dat, subdata[i], subbytes[i]);
3029  dat += subbytes[i];
3030  if (havenulls)
3031  array_bitmap_copy(ARR_NULLBITMAP(result), iitem,
3032  subbitmaps[i], 0,
3033  subnitems[i]);
3034  iitem += subnitems[i];
3035  }
3036  }
3037 
3038  *op->resvalue = PointerGetDatum(result);
3039 }
#define ARR_NDIM(a)
Definition: array.h:290
#define ARR_DATA_PTR(a)
Definition: array.h:322
#define MAXDIM
Definition: array.h:75
#define ARR_NULLBITMAP(a)
Definition: array.h:300
#define ARR_OVERHEAD_WITHNULLS(ndims, nitems)
Definition: array.h:312
#define DatumGetArrayTypeP(X)
Definition: array.h:261
#define ARR_SIZE(a)
Definition: array.h:289
#define ARR_OVERHEAD_NONULLS(ndims)
Definition: array.h:310
#define ARR_DATA_OFFSET(a)
Definition: array.h:316
#define ARR_DIMS(a)
Definition: array.h:294
#define ARR_HASNULL(a)
Definition: array.h:291
#define ARR_LBOUND(a)
Definition: array.h:296
ArrayType * construct_empty_array(Oid elmtype)
Definition: arrayfuncs.c:3561
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:3475
void array_bitmap_copy(bits8 *destbitmap, int destoffset, const bits8 *srcbitmap, int srcoffset, int nitems)
Definition: arrayfuncs.c:4947
int ArrayGetNItems(int ndim, const int *dims)
Definition: arrayutils.c:57
void ArrayCheckBounds(int ndim, const int *dims, const int *lb)
Definition: arrayutils.c:117
signed int int32
Definition: c.h:481
uint8 bits8
Definition: c.h:500
#define nitems(x)
Definition: indent.h:31
void * palloc0(Size size)
Definition: mcxt.c:1334
void * palloc(Size size)
Definition: mcxt.c:1304
#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:97
int ndim
Definition: array.h:95
int32 dataoffset
Definition: array.h:96
struct ExprEvalStep::@53::@72 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().

◆ ExecEvalCoerceViaIOSafe()

void ExecEvalCoerceViaIOSafe ( ExprState state,
ExprEvalStep op 
)

Definition at line 2567 of file execExprInterp.c.

2568 {
2569  char *str;
2570 
2571  /* call output function (similar to OutputFunctionCall) */
2572  if (*op->resnull)
2573  {
2574  /* output functions are not called on nulls */
2575  str = NULL;
2576  }
2577  else
2578  {
2579  FunctionCallInfo fcinfo_out;
2580 
2581  fcinfo_out = op->d.iocoerce.fcinfo_data_out;
2582  fcinfo_out->args[0].value = *op->resvalue;
2583  fcinfo_out->args[0].isnull = false;
2584 
2585  fcinfo_out->isnull = false;
2586  str = DatumGetCString(FunctionCallInvoke(fcinfo_out));
2587 
2588  /* OutputFunctionCall assumes result isn't null */
2589  Assert(!fcinfo_out->isnull);
2590  }
2591 
2592  /* call input function (similar to InputFunctionCallSafe) */
2593  if (!op->d.iocoerce.finfo_in->fn_strict || str != NULL)
2594  {
2595  FunctionCallInfo fcinfo_in;
2596 
2597  fcinfo_in = op->d.iocoerce.fcinfo_data_in;
2598  fcinfo_in->args[0].value = PointerGetDatum(str);
2599  fcinfo_in->args[0].isnull = *op->resnull;
2600  /* second and third arguments are already set up */
2601 
2602  /* ErrorSaveContext must be present. */
2603  Assert(IsA(fcinfo_in->context, ErrorSaveContext));
2604 
2605  fcinfo_in->isnull = false;
2606  *op->resvalue = FunctionCallInvoke(fcinfo_in);
2607 
2608  if (SOFT_ERROR_OCCURRED(fcinfo_in->context))
2609  {
2610  *op->resnull = true;
2611  *op->resvalue = (Datum) 0;
2612  return;
2613  }
2614 
2615  /* Should get null result if and only if str is NULL */
2616  if (str == NULL)
2617  Assert(*op->resnull);
2618  else
2619  Assert(!*op->resnull);
2620  }
2621 }
#define SOFT_ERROR_OCCURRED(escontext)
Definition: miscnodes.h:52
#define IsA(nodeptr, _type_)
Definition: nodes.h:158
static char * DatumGetCString(Datum X)
Definition: postgres.h:335
struct ExprEvalStep::@53::@69 iocoerce
fmNodePtr context
Definition: fmgr.h:88

References FunctionCallInfoBaseData::args, Assert(), FunctionCallInfoBaseData::context, DatumGetCString(), FunctionCallInvoke, IsA, FunctionCallInfoBaseData::isnull, NullableDatum::isnull, ExprEvalStep::op, PointerGetDatum(), SOFT_ERROR_OCCURRED, generate_unaccent_rules::str, and NullableDatum::value.

Referenced by ExecInterpExpr().

◆ ExecEvalConstraintCheck()

void ExecEvalConstraintCheck ( ExprState state,
ExprEvalStep op 
)

Definition at line 3854 of file execExprInterp.c.

3855 {
3856  if (!*op->d.domaincheck.checknull &&
3857  !DatumGetBool(*op->d.domaincheck.checkvalue))
3858  errsave((Node *) op->d.domaincheck.escontext,
3859  (errcode(ERRCODE_CHECK_VIOLATION),
3860  errmsg("value for domain %s violates check constraint \"%s\"",
3861  format_type_be(op->d.domaincheck.resulttype),
3862  op->d.domaincheck.constraintname),
3863  errdomainconstraint(op->d.domaincheck.resulttype,
3864  op->d.domaincheck.constraintname)));
3865 }
int errdomainconstraint(Oid datatypeOid, const char *conname)
Definition: domains.c:431
#define errsave(context,...)
Definition: elog.h:260
static bool DatumGetBool(Datum X)
Definition: postgres.h:90
struct ExprEvalStep::@53::@82 domaincheck
Definition: nodes.h:129

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

Referenced by ExecInterpExpr().

◆ ExecEvalConstraintNotNull()

void ExecEvalConstraintNotNull ( ExprState state,
ExprEvalStep op 
)

Definition at line 3840 of file execExprInterp.c.

3841 {
3842  if (*op->resnull)
3843  errsave((Node *) op->d.domaincheck.escontext,
3844  (errcode(ERRCODE_NOT_NULL_VIOLATION),
3845  errmsg("domain %s does not allow null values",
3846  format_type_be(op->d.domaincheck.resulttype)),
3847  errdatatype(op->d.domaincheck.resulttype)));
3848 }
int errdatatype(Oid datatypeOid)
Definition: domains.c:407

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

Referenced by ExecInterpExpr().

◆ ExecEvalConvertRowtype()

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

Definition at line 3360 of file execExprInterp.c.

3361 {
3362  HeapTuple result;
3363  Datum tupDatum;
3364  HeapTupleHeader tuple;
3365  HeapTupleData tmptup;
3366  TupleDesc indesc,
3367  outdesc;
3368  bool changed = false;
3369 
3370  /* NULL in -> NULL out */
3371  if (*op->resnull)
3372  return;
3373 
3374  tupDatum = *op->resvalue;
3375  tuple = DatumGetHeapTupleHeader(tupDatum);
3376 
3377  /*
3378  * Lookup tupdescs if first time through or if type changes. We'd better
3379  * pin them since type conversion functions could do catalog lookups and
3380  * hence cause cache invalidation.
3381  */
3382  indesc = get_cached_rowtype(op->d.convert_rowtype.inputtype, -1,
3383  op->d.convert_rowtype.incache,
3384  &changed);
3385  IncrTupleDescRefCount(indesc);
3386  outdesc = get_cached_rowtype(op->d.convert_rowtype.outputtype, -1,
3387  op->d.convert_rowtype.outcache,
3388  &changed);
3389  IncrTupleDescRefCount(outdesc);
3390 
3391  /*
3392  * We used to be able to assert that incoming tuples are marked with
3393  * exactly the rowtype of indesc. However, now that ExecEvalWholeRowVar
3394  * might change the tuples' marking to plain RECORD due to inserting
3395  * aliases, we can only make this weak test:
3396  */
3397  Assert(HeapTupleHeaderGetTypeId(tuple) == indesc->tdtypeid ||
3398  HeapTupleHeaderGetTypeId(tuple) == RECORDOID);
3399 
3400  /* if first time through, or after change, initialize conversion map */
3401  if (changed)
3402  {
3403  MemoryContext old_cxt;
3404 
3405  /* allocate map in long-lived memory context */
3406  old_cxt = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
3407 
3408  /* prepare map from old to new attribute numbers */
3409  op->d.convert_rowtype.map = convert_tuples_by_name(indesc, outdesc);
3410 
3411  MemoryContextSwitchTo(old_cxt);
3412  }
3413 
3414  /* Following steps need a HeapTuple not a bare HeapTupleHeader */
3415  tmptup.t_len = HeapTupleHeaderGetDatumLength(tuple);
3416  tmptup.t_data = tuple;
3417 
3418  if (op->d.convert_rowtype.map != NULL)
3419  {
3420  /* Full conversion with attribute rearrangement needed */
3421  result = execute_attr_map_tuple(&tmptup, op->d.convert_rowtype.map);
3422  /* Result already has appropriate composite-datum header fields */
3423  *op->resvalue = HeapTupleGetDatum(result);
3424  }
3425  else
3426  {
3427  /*
3428  * The tuple is physically compatible as-is, but we need to insert the
3429  * destination rowtype OID in its composite-datum header field, so we
3430  * have to copy it anyway. heap_copy_tuple_as_datum() is convenient
3431  * for this since it will both make the physical copy and insert the
3432  * correct composite header fields. Note that we aren't expecting to
3433  * have to flatten any toasted fields: the input was a composite
3434  * datum, so it shouldn't contain any. So heap_copy_tuple_as_datum()
3435  * is overkill here, but its check for external fields is cheap.
3436  */
3437  *op->resvalue = heap_copy_tuple_as_datum(&tmptup, outdesc);
3438  }
3439 
3440  DecrTupleDescRefCount(indesc);
3441  DecrTupleDescRefCount(outdesc);
3442 }
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:1080
#define HeapTupleHeaderGetTypeId(tup)
Definition: htup_details.h:456
#define HeapTupleHeaderGetDatumLength(tup)
Definition: htup_details.h:450
MemoryContext ecxt_per_query_memory
Definition: execnodes.h:262
struct ExprEvalStep::@53::@83 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:406
void IncrTupleDescRefCount(TupleDesc tupdesc)
Definition: tupdesc.c:388

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 2694 of file execExprInterp.c.

2695 {
2696  ereport(ERROR,
2697  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2698  errmsg("WHERE CURRENT OF is not supported for this table type")));
2699 }

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

Referenced by ExecInterpExpr().

◆ ExecEvalFieldSelect()

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

Definition at line 3161 of file execExprInterp.c.

3162 {
3163  AttrNumber fieldnum = op->d.fieldselect.fieldnum;
3164  Datum tupDatum;
3165  HeapTupleHeader tuple;
3166  Oid tupType;
3167  int32 tupTypmod;
3168  TupleDesc tupDesc;
3169  Form_pg_attribute attr;
3170  HeapTupleData tmptup;
3171 
3172  /* NULL record -> NULL result */
3173  if (*op->resnull)
3174  return;
3175 
3176  tupDatum = *op->resvalue;
3177 
3178  /* We can special-case expanded records for speed */
3180  {
3182 
3183  Assert(erh->er_magic == ER_MAGIC);
3184 
3185  /* Extract record's TupleDesc */
3186  tupDesc = expanded_record_get_tupdesc(erh);
3187 
3188  /*
3189  * Find field's attr record. Note we don't support system columns
3190  * here: a datum tuple doesn't have valid values for most of the
3191  * interesting system columns anyway.
3192  */
3193  if (fieldnum <= 0) /* should never happen */
3194  elog(ERROR, "unsupported reference to system column %d in FieldSelect",
3195  fieldnum);
3196  if (fieldnum > tupDesc->natts) /* should never happen */
3197  elog(ERROR, "attribute number %d exceeds number of columns %d",
3198  fieldnum, tupDesc->natts);
3199  attr = TupleDescAttr(tupDesc, fieldnum - 1);
3200 
3201  /* Check for dropped column, and force a NULL result if so */
3202  if (attr->attisdropped)
3203  {
3204  *op->resnull = true;
3205  return;
3206  }
3207 
3208  /* Check for type mismatch --- possible after ALTER COLUMN TYPE? */
3209  /* As in CheckVarSlotCompatibility, we should but can't check typmod */
3210  if (op->d.fieldselect.resulttype != attr->atttypid)
3211  ereport(ERROR,
3212  (errcode(ERRCODE_DATATYPE_MISMATCH),
3213  errmsg("attribute %d has wrong type", fieldnum),
3214  errdetail("Table has type %s, but query expects %s.",
3215  format_type_be(attr->atttypid),
3216  format_type_be(op->d.fieldselect.resulttype))));
3217 
3218  /* extract the field */
3219  *op->resvalue = expanded_record_get_field(erh, fieldnum,
3220  op->resnull);
3221  }
3222  else
3223  {
3224  /* Get the composite datum and extract its type fields */
3225  tuple = DatumGetHeapTupleHeader(tupDatum);
3226 
3227  tupType = HeapTupleHeaderGetTypeId(tuple);
3228  tupTypmod = HeapTupleHeaderGetTypMod(tuple);
3229 
3230  /* Lookup tupdesc if first time through or if type changes */
3231  tupDesc = get_cached_rowtype(tupType, tupTypmod,
3232  &op->d.fieldselect.rowcache, NULL);
3233 
3234  /*
3235  * Find field's attr record. Note we don't support system columns
3236  * here: a datum tuple doesn't have valid values for most of the
3237  * interesting system columns anyway.
3238  */
3239  if (fieldnum <= 0) /* should never happen */
3240  elog(ERROR, "unsupported reference to system column %d in FieldSelect",
3241  fieldnum);
3242  if (fieldnum > tupDesc->natts) /* should never happen */
3243  elog(ERROR, "attribute number %d exceeds number of columns %d",
3244  fieldnum, tupDesc->natts);
3245  attr = TupleDescAttr(tupDesc, fieldnum - 1);
3246 
3247  /* Check for dropped column, and force a NULL result if so */
3248  if (attr->attisdropped)
3249  {
3250  *op->resnull = true;
3251  return;
3252  }
3253 
3254  /* Check for type mismatch --- possible after ALTER COLUMN TYPE? */
3255  /* As in CheckVarSlotCompatibility, we should but can't check typmod */
3256  if (op->d.fieldselect.resulttype != attr->atttypid)
3257  ereport(ERROR,
3258  (errcode(ERRCODE_DATATYPE_MISMATCH),
3259  errmsg("attribute %d has wrong type", fieldnum),
3260  errdetail("Table has type %s, but query expects %s.",
3261  format_type_be(attr->atttypid),
3262  format_type_be(op->d.fieldselect.resulttype))));
3263 
3264  /* heap_getattr needs a HeapTuple not a bare HeapTupleHeader */
3265  tmptup.t_len = HeapTupleHeaderGetDatumLength(tuple);
3266  tmptup.t_data = tuple;
3267 
3268  /* extract the field */
3269  *op->resvalue = heap_getattr(&tmptup,
3270  fieldnum,
3271  tupDesc,
3272  op->resnull);
3273  }
3274 }
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::@53::@78 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 3286 of file execExprInterp.c.

3287 {
3288  if (*op->resnull)
3289  {
3290  /* Convert null input tuple into an all-nulls row */
3291  memset(op->d.fieldstore.nulls, true,
3292  op->d.fieldstore.ncolumns * sizeof(bool));
3293  }
3294  else
3295  {
3296  /*
3297  * heap_deform_tuple needs a HeapTuple not a bare HeapTupleHeader. We
3298  * set all the fields in the struct just in case.
3299  */
3300  Datum tupDatum = *op->resvalue;
3301  HeapTupleHeader tuphdr;
3302  HeapTupleData tmptup;
3303  TupleDesc tupDesc;
3304 
3305  tuphdr = DatumGetHeapTupleHeader(tupDatum);
3306  tmptup.t_len = HeapTupleHeaderGetDatumLength(tuphdr);
3307  ItemPointerSetInvalid(&(tmptup.t_self));
3308  tmptup.t_tableOid = InvalidOid;
3309  tmptup.t_data = tuphdr;
3310 
3311  /*
3312  * Lookup tupdesc if first time through or if type changes. Because
3313  * we don't pin the tupdesc, we must not do this lookup until after
3314  * doing DatumGetHeapTupleHeader: that could do database access while
3315  * detoasting the datum.
3316  */
3317  tupDesc = get_cached_rowtype(op->d.fieldstore.fstore->resulttype, -1,
3318  op->d.fieldstore.rowcache, NULL);
3319 
3320  /* Check that current tupdesc doesn't have more fields than allocated */
3321  if (unlikely(tupDesc->natts > op->d.fieldstore.ncolumns))
3322  elog(ERROR, "too many columns in composite type %u",
3323  op->d.fieldstore.fstore->resulttype);
3324 
3325  heap_deform_tuple(&tmptup, tupDesc,
3326  op->d.fieldstore.values,
3327  op->d.fieldstore.nulls);
3328  }
3329 }
#define unlikely(x)
Definition: c.h:298
void heap_deform_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *values, bool *isnull)
Definition: heaptuple.c:1345
static void ItemPointerSetInvalid(ItemPointerData *pointer)
Definition: itemptr.h:184
#define InvalidOid
Definition: postgres_ext.h:36
struct ExprEvalStep::@53::@79 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 3336 of file execExprInterp.c.

3337 {
3338  TupleDesc tupDesc;
3339  HeapTuple tuple;
3340 
3341  /* Lookup tupdesc (should be valid already) */
3342  tupDesc = get_cached_rowtype(op->d.fieldstore.fstore->resulttype, -1,
3343  op->d.fieldstore.rowcache, NULL);
3344 
3345  tuple = heap_form_tuple(tupDesc,
3346  op->d.fieldstore.values,
3347  op->d.fieldstore.nulls);
3348 
3349  *op->resvalue = HeapTupleGetDatum(tuple);
3350  *op->resnull = false;
3351 }
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
Definition: heaptuple.c:1116

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 2440 of file execExprInterp.c.

2442 {
2443  FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
2444  PgStat_FunctionCallUsage fcusage;
2445  Datum d;
2446 
2447  pgstat_init_function_usage(fcinfo, &fcusage);
2448 
2449  fcinfo->isnull = false;
2450  d = op->d.func.fn_addr(fcinfo);
2451  *op->resvalue = d;
2452  *op->resnull = fcinfo->isnull;
2453 
2454  pgstat_end_function_usage(&fcusage, true);
2455 }
void pgstat_init_function_usage(FunctionCallInfo fcinfo, PgStat_FunctionCallUsage *fcu)
void pgstat_end_function_usage(PgStat_FunctionCallUsage *fcu, bool finalize)
struct ExprEvalStep::@53::@60 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 2461 of file execExprInterp.c.

2463 {
2464 
2465  FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
2466  PgStat_FunctionCallUsage fcusage;
2467  NullableDatum *args = fcinfo->args;
2468  int nargs = op->d.func.nargs;
2469  Datum d;
2470 
2471  /* strict function, so check for NULL args */
2472  for (int argno = 0; argno < nargs; argno++)
2473  {
2474  if (args[argno].isnull)
2475  {
2476  *op->resnull = true;
2477  return;
2478  }
2479  }
2480 
2481  pgstat_init_function_usage(fcinfo, &fcusage);
2482 
2483  fcinfo->isnull = false;
2484  d = op->d.func.fn_addr(fcinfo);
2485  *op->resvalue = d;
2486  *op->resnull = fcinfo->isnull;
2487 
2488  pgstat_end_function_usage(&fcusage, true);
2489 }

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 4572 of file execExprInterp.c.

4573 {
4574  AggState *aggstate = castNode(AggState, state->parent);
4575  int result = 0;
4576  Bitmapset *grouped_cols = aggstate->grouped_cols;
4577  ListCell *lc;
4578 
4579  foreach(lc, op->d.grouping_func.clauses)
4580  {
4581  int attnum = lfirst_int(lc);
4582 
4583  result <<= 1;
4584 
4585  if (!bms_is_member(attnum, grouped_cols))
4586  result |= 1;
4587  }
4588 
4589  *op->resvalue = Int32GetDatum(result);
4590  *op->resnull = false;
4591 }
bool bms_is_member(int x, const Bitmapset *a)
Definition: bitmapset.c:510
#define castNode(_type_, nodeptr)
Definition: nodes.h:176
#define lfirst_int(lc)
Definition: pg_list.h:173
static Datum Int32GetDatum(int32 X)
Definition: postgres.h:212
Bitmapset * grouped_cols
Definition: execnodes.h:2481
struct ExprEvalStep::@53::@89 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 3658 of file execExprInterp.c.

3659 {
3660  ScalarArrayOpExprHashTable *elements_tab = op->d.hashedscalararrayop.elements_tab;
3661  FunctionCallInfo fcinfo = op->d.hashedscalararrayop.fcinfo_data;
3662  bool inclause = op->d.hashedscalararrayop.inclause;
3663  bool strictfunc = op->d.hashedscalararrayop.finfo->fn_strict;
3664  Datum scalar = fcinfo->args[0].value;
3665  bool scalar_isnull = fcinfo->args[0].isnull;
3666  Datum result;
3667  bool resultnull;
3668  bool hashfound;
3669 
3670  /* We don't setup a hashed scalar array op if the array const is null. */
3671  Assert(!*op->resnull);
3672 
3673  /*
3674  * If the scalar is NULL, and the function is strict, return NULL; no
3675  * point in executing the search.
3676  */
3677  if (fcinfo->args[0].isnull && strictfunc)
3678  {
3679  *op->resnull = true;
3680  return;
3681  }
3682 
3683  /* Build the hash table on first evaluation */
3684  if (elements_tab == NULL)
3685  {
3686  ScalarArrayOpExpr *saop;
3687  int16 typlen;
3688  bool typbyval;
3689  char typalign;
3690  int nitems;
3691  bool has_nulls = false;
3692  char *s;
3693  bits8 *bitmap;
3694  int bitmask;
3695  MemoryContext oldcontext;
3696  ArrayType *arr;
3697 
3698  saop = op->d.hashedscalararrayop.saop;
3699 
3700  arr = DatumGetArrayTypeP(*op->resvalue);
3701  nitems = ArrayGetNItems(ARR_NDIM(arr), ARR_DIMS(arr));
3702 
3704  &typlen,
3705  &typbyval,
3706  &typalign);
3707 
3708  oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
3709 
3710  elements_tab = (ScalarArrayOpExprHashTable *)
3711  palloc0(offsetof(ScalarArrayOpExprHashTable, hash_fcinfo_data) +
3713  op->d.hashedscalararrayop.elements_tab = elements_tab;
3714  elements_tab->op = op;
3715 
3716  fmgr_info(saop->hashfuncid, &elements_tab->hash_finfo);
3717  fmgr_info_set_expr((Node *) saop, &elements_tab->hash_finfo);
3718 
3720  &elements_tab->hash_finfo,
3721  1,
3722  saop->inputcollid,
3723  NULL,
3724  NULL);
3725 
3726  /*
3727  * Create the hash table sizing it according to the number of elements
3728  * in the array. This does assume that the array has no duplicates.
3729  * If the array happens to contain many duplicate values then it'll
3730  * just mean that we sized the table a bit on the large side.
3731  */
3732  elements_tab->hashtab = saophash_create(CurrentMemoryContext, nitems,
3733  elements_tab);
3734 
3735  MemoryContextSwitchTo(oldcontext);
3736 
3737  s = (char *) ARR_DATA_PTR(arr);
3738  bitmap = ARR_NULLBITMAP(arr);
3739  bitmask = 1;
3740  for (int i = 0; i < nitems; i++)
3741  {
3742  /* Get array element, checking for NULL. */
3743  if (bitmap && (*bitmap & bitmask) == 0)
3744  {
3745  has_nulls = true;
3746  }
3747  else
3748  {
3749  Datum element;
3750 
3751  element = fetch_att(s, typbyval, typlen);
3752  s = att_addlength_pointer(s, typlen, s);
3753  s = (char *) att_align_nominal(s, typalign);
3754 
3755  saophash_insert(elements_tab->hashtab, element, &hashfound);
3756  }
3757 
3758  /* Advance bitmap pointer if any. */
3759  if (bitmap)
3760  {
3761  bitmask <<= 1;
3762  if (bitmask == 0x100)
3763  {
3764  bitmap++;
3765  bitmask = 1;
3766  }
3767  }
3768  }
3769 
3770  /*
3771  * Remember if we had any nulls so that we know if we need to execute
3772  * non-strict functions with a null lhs value if no match is found.
3773  */
3774  op->d.hashedscalararrayop.has_nulls = has_nulls;
3775  }
3776 
3777  /* Check the hash to see if we have a match. */
3778  hashfound = NULL != saophash_lookup(elements_tab->hashtab, scalar);
3779 
3780  /* the result depends on if the clause is an IN or NOT IN clause */
3781  if (inclause)
3782  result = BoolGetDatum(hashfound); /* IN */
3783  else
3784  result = BoolGetDatum(!hashfound); /* NOT IN */
3785 
3786  resultnull = false;
3787 
3788  /*
3789  * If we didn't find a match in the array, we still might need to handle
3790  * the possibility of null values. We didn't put any NULLs into the
3791  * hashtable, but instead marked if we found any when building the table
3792  * in has_nulls.
3793  */
3794  if (!hashfound && op->d.hashedscalararrayop.has_nulls)
3795  {
3796  if (strictfunc)
3797  {
3798 
3799  /*
3800  * We have nulls in the array so a non-null lhs and no match must
3801  * yield NULL.
3802  */
3803  result = (Datum) 0;
3804  resultnull = true;
3805  }
3806  else
3807  {
3808  /*
3809  * Execute function will null rhs just once.
3810  *
3811  * The hash lookup path will have scribbled on the lhs argument so
3812  * we need to set it up also (even though we entered this function
3813  * with it already set).
3814  */
3815  fcinfo->args[0].value = scalar;
3816  fcinfo->args[0].isnull = scalar_isnull;
3817  fcinfo->args[1].value = (Datum) 0;
3818  fcinfo->args[1].isnull = true;
3819 
3820  result = op->d.hashedscalararrayop.finfo->fn_addr(fcinfo);
3821  resultnull = fcinfo->isnull;
3822 
3823  /*
3824  * Reverse the result for NOT IN clauses since the above function
3825  * is the equality function and we need not-equals.
3826  */
3827  if (!inclause)
3828  result = !result;
3829  }
3830  }
3831 
3832  *op->resvalue = result;
3833  *op->resnull = resultnull;
3834 }
signed short int16
Definition: c.h:480
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:2249
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::@53::@85 hashedscalararrayop
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().

◆ ExecEvalJsonCoercion()

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

Definition at line 4531 of file execExprInterp.c.

4533 {
4534  ErrorSaveContext *escontext = op->d.jsonexpr_coercion.escontext;
4535 
4536  *op->resvalue = json_populate_type(*op->resvalue, JSONBOID,
4537  op->d.jsonexpr_coercion.targettype,
4538  op->d.jsonexpr_coercion.targettypmod,
4539  &op->d.jsonexpr_coercion.json_populate_type_cache,
4540  econtext->ecxt_per_query_memory,
4541  op->resnull, (Node *) escontext);
4542 }
Datum json_populate_type(Datum json_val, Oid json_type, Oid typid, int32 typmod, void **cache, MemoryContext mcxt, bool *isnull, Node *escontext)
Definition: jsonfuncs.c:3335
struct ExprEvalStep::@53::@99 jsonexpr_coercion

References ExprContext::ecxt_per_query_memory, ExprEvalStep::escontext, json_populate_type(), and ExprEvalStep::op.

Referenced by ExecInterpExpr().

◆ ExecEvalJsonCoercionFinish()

void ExecEvalJsonCoercionFinish ( ExprState state,
ExprEvalStep op 
)

Definition at line 4550 of file execExprInterp.c.

4551 {
4552  JsonExprState *jsestate = op->d.jsonexpr.jsestate;
4553 
4554  if (SOFT_ERROR_OCCURRED(&jsestate->escontext))
4555  {
4556  *op->resvalue = (Datum) 0;
4557  *op->resnull = true;
4558  jsestate->error.value = BoolGetDatum(true);
4559  }
4560 }
struct ExprEvalStep::@53::@98 jsonexpr
NullableDatum error
Definition: execnodes.h:1039
ErrorSaveContext escontext
Definition: execnodes.h:1081

References BoolGetDatum(), JsonExprState::error, JsonExprState::escontext, ExprEvalStep::jsestate, ExprEvalStep::op, SOFT_ERROR_OCCURRED, and NullableDatum::value.

Referenced by ExecInterpExpr().

◆ ExecEvalJsonConstructor()

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

Definition at line 4089 of file execExprInterp.c.

4091 {
4092  Datum res;
4093  JsonConstructorExprState *jcstate = op->d.json_constructor.jcstate;
4094  JsonConstructorExpr *ctor = jcstate->constructor;
4095  bool is_jsonb = ctor->returning->format->format_type == JS_FORMAT_JSONB;
4096  bool isnull = false;
4097 
4098  if (ctor->type == JSCTOR_JSON_ARRAY)
4099  res = (is_jsonb ?
4101  json_build_array_worker) (jcstate->nargs,
4102  jcstate->arg_values,
4103  jcstate->arg_nulls,
4104  jcstate->arg_types,
4105  jcstate->constructor->absent_on_null);
4106  else if (ctor->type == JSCTOR_JSON_OBJECT)
4107  res = (is_jsonb ?
4109  json_build_object_worker) (jcstate->nargs,
4110  jcstate->arg_values,
4111  jcstate->arg_nulls,
4112  jcstate->arg_types,
4113  jcstate->constructor->absent_on_null,
4114  jcstate->constructor->unique);
4115  else if (ctor->type == JSCTOR_JSON_SCALAR)
4116  {
4117  if (jcstate->arg_nulls[0])
4118  {
4119  res = (Datum) 0;
4120  isnull = true;
4121  }
4122  else
4123  {
4124  Datum value = jcstate->arg_values[0];
4125  Oid outfuncid = jcstate->arg_type_cache[0].outfuncid;
4126  JsonTypeCategory category = (JsonTypeCategory)
4127  jcstate->arg_type_cache[0].category;
4128 
4129  if (is_jsonb)
4130  res = datum_to_jsonb(value, category, outfuncid);
4131  else
4132  res = datum_to_json(value, category, outfuncid);
4133  }
4134  }
4135  else if (ctor->type == JSCTOR_JSON_PARSE)
4136  {
4137  if (jcstate->arg_nulls[0])
4138  {
4139  res = (Datum) 0;
4140  isnull = true;
4141  }
4142  else
4143  {
4144  Datum value = jcstate->arg_values[0];
4145  text *js = DatumGetTextP(value);
4146 
4147  if (is_jsonb)
4148  res = jsonb_from_text(js, true);
4149  else
4150  {
4151  (void) json_validate(js, true, true);
4152  res = value;
4153  }
4154  }
4155  }
4156  else
4157  elog(ERROR, "invalid JsonConstructorExpr type %d", ctor->type);
4158 
4159  *op->resvalue = res;
4160  *op->resnull = isnull;
4161 }
#define DatumGetTextP(X)
Definition: fmgr.h:332
static struct @154 value
if(TABLE==NULL||TABLE_index==NULL)
Definition: isn.c:77
Datum json_build_array_worker(int nargs, const Datum *args, const bool *nulls, const Oid *types, bool absent_on_null)
Definition: json.c:1321
Datum json_build_object_worker(int nargs, const Datum *args, const bool *nulls, const Oid *types, bool absent_on_null, bool unique_keys)
Definition: json.c:1208
Datum datum_to_json(Datum val, JsonTypeCategory tcategory, Oid outfuncoid)
Definition: json.c:754
bool json_validate(text *json, bool check_unique_keys, bool throw_error)
Definition: json.c:1650
Datum jsonb_from_text(text *js, bool unique_keys)
Definition: jsonb.c:147
Datum jsonb_build_array_worker(int nargs, const Datum *args, const bool *nulls, const Oid *types, bool absent_on_null)
Definition: jsonb.c:1210
Datum jsonb_build_object_worker(int nargs, const Datum *args, const bool *nulls, const Oid *types, bool absent_on_null, bool unique_keys)
Definition: jsonb.c:1125
Datum datum_to_jsonb(Datum val, JsonTypeCategory tcategory, Oid outfuncoid)
Definition: jsonb.c:1112
JsonTypeCategory
Definition: jsonfuncs.h:69
@ JS_FORMAT_JSONB
Definition: primnodes.h:1596
@ JSCTOR_JSON_PARSE
Definition: primnodes.h:1646
@ JSCTOR_JSON_OBJECT
Definition: primnodes.h:1642
@ JSCTOR_JSON_SCALAR
Definition: primnodes.h:1647
@ JSCTOR_JSON_ARRAY
Definition: primnodes.h:1643
struct ExprEvalStep::@53::@87 json_constructor
JsonConstructorExpr * constructor
Definition: execExpr.h:764
struct JsonConstructorExprState::@100 * arg_type_cache
JsonReturning * returning
Definition: primnodes.h:1662
JsonConstructorType type
Definition: primnodes.h:1658
JsonFormatType format_type
Definition: primnodes.h:1607
JsonFormat * format
Definition: primnodes.h:1619
Definition: c.h:674

References JsonConstructorExpr::absent_on_null, JsonConstructorExprState::arg_nulls, JsonConstructorExprState::arg_type_cache, JsonConstructorExprState::arg_types, JsonConstructorExprState::arg_values, JsonConstructorExprState::category, JsonConstructorExprState::constructor, datum_to_json(), datum_to_jsonb(), DatumGetTextP, elog, ERROR, JsonReturning::format, JsonFormat::format_type, if(), ExprEvalStep::isnull, ExprEvalStep::jcstate, JS_FORMAT_JSONB, JSCTOR_JSON_ARRAY, JSCTOR_JSON_OBJECT, JSCTOR_JSON_PARSE, JSCTOR_JSON_SCALAR, json_build_array_worker(), json_build_object_worker(), json_validate(), jsonb_build_array_worker(), jsonb_build_object_worker(), jsonb_from_text(), JsonConstructorExprState::nargs, ExprEvalStep::op, JsonConstructorExprState::outfuncid, res, JsonConstructorExpr::returning, JsonConstructorExpr::type, JsonConstructorExpr::unique, and value.

Referenced by ExecInterpExpr().

◆ ExecEvalJsonExprPath()

int ExecEvalJsonExprPath ( ExprState state,
ExprEvalStep op,
ExprContext econtext 
)

Definition at line 4267 of file execExprInterp.c.

4269 {
4270  JsonExprState *jsestate = op->d.jsonexpr.jsestate;
4271  JsonExpr *jsexpr = jsestate->jsexpr;
4272  Datum item;
4273  JsonPath *path;
4274  bool throw_error = jsexpr->on_error->btype == JSON_BEHAVIOR_ERROR;
4275  bool error = false,
4276  empty = false;
4277  int jump_eval_coercion = jsestate->jump_eval_coercion;
4278  char *val_string = NULL;
4279 
4280  item = jsestate->formatted_expr.value;
4281  path = DatumGetJsonPathP(jsestate->pathspec.value);
4282 
4283  /* Set error/empty to false. */
4284  memset(&jsestate->error, 0, sizeof(NullableDatum));
4285  memset(&jsestate->empty, 0, sizeof(NullableDatum));
4286 
4287  /*
4288  * Also reset ErrorSaveContext contents for the next row. Since we don't
4289  * set details_wanted, we don't need to also reset error_data, which would
4290  * be NULL anyway.
4291  */
4292  Assert(!jsestate->escontext.details_wanted &&
4293  jsestate->escontext.error_data == NULL);
4294  jsestate->escontext.error_occurred = false;
4295 
4296  switch (jsexpr->op)
4297  {
4298  case JSON_EXISTS_OP:
4299  {
4300  bool exists = JsonPathExists(item, path,
4301  !throw_error ? &error : NULL,
4302  jsestate->args);
4303 
4304  if (!error)
4305  {
4306  *op->resvalue = BoolGetDatum(exists);
4307  *op->resnull = false;
4308  }
4309  }
4310  break;
4311 
4312  case JSON_QUERY_OP:
4313  *op->resvalue = JsonPathQuery(item, path, jsexpr->wrapper, &empty,
4314  !throw_error ? &error : NULL,
4315  jsestate->args);
4316 
4317  *op->resnull = (DatumGetPointer(*op->resvalue) == NULL);
4318 
4319  /* Handle OMIT QUOTES. */
4320  if (!*op->resnull && jsexpr->omit_quotes)
4321  {
4323 
4324  /*
4325  * Pass the string as a text value to the cast expression if
4326  * one present. If not, use the input function call below to
4327  * do the coercion.
4328  */
4329  if (jump_eval_coercion >= 0)
4330  *op->resvalue =
4333  }
4334  break;
4335 
4336  case JSON_VALUE_OP:
4337  {
4338  JsonbValue *jbv = JsonPathValue(item, path, &empty,
4339  !throw_error ? &error : NULL,
4340  jsestate->args);
4341 
4342  if (jbv == NULL)
4343  {
4344  /* Will be coerced with coercion_expr, if any. */
4345  *op->resvalue = (Datum) 0;
4346  *op->resnull = true;
4347  }
4348  else if (!error && !empty)
4349  {
4350  if (jsexpr->returning->typid == JSONOID ||
4351  jsexpr->returning->typid == JSONBOID)
4352  {
4355  }
4356  else
4357  {
4359 
4360  /*
4361  * Pass the string as a text value to the cast
4362  * expression if one present. If not, use the input
4363  * function call below to do the coercion.
4364  */
4366  if (jump_eval_coercion >= 0)
4368  }
4369  }
4370  break;
4371  }
4372 
4373  default:
4374  elog(ERROR, "unrecognized SQL/JSON expression op %d",
4375  (int) jsexpr->op);
4376  return false;
4377  }
4378 
4379  /*
4380  * Coerce the result value to the RETURNING type by calling its input
4381  * function.
4382  */
4383  if (!*op->resnull && jsexpr->use_io_coercion)
4384  {
4385  FunctionCallInfo fcinfo;
4386 
4387  Assert(jump_eval_coercion == -1);
4388  fcinfo = jsestate->input_fcinfo;
4389  Assert(fcinfo != NULL);
4390  Assert(val_string != NULL);
4391  fcinfo->args[0].value = PointerGetDatum(val_string);
4392  fcinfo->args[0].isnull = *op->resnull;
4393 
4394  /*
4395  * Second and third arguments are already set up in
4396  * ExecInitJsonExpr().
4397  */
4398 
4399  fcinfo->isnull = false;
4400  *op->resvalue = FunctionCallInvoke(fcinfo);
4401  if (SOFT_ERROR_OCCURRED(&jsestate->escontext))
4402  error = true;
4403  }
4404 
4405  /* Handle ON EMPTY. */
4406  if (empty)
4407  {
4408  if (jsexpr->on_empty)
4409  {
4410  if (jsexpr->on_empty->btype == JSON_BEHAVIOR_ERROR)
4411  ereport(ERROR,
4412  errcode(ERRCODE_NO_SQL_JSON_ITEM),
4413  errmsg("no SQL/JSON item"));
4414  else
4415  jsestate->empty.value = BoolGetDatum(true);
4416 
4417  Assert(jsestate->jump_empty >= 0);
4418  return jsestate->jump_empty;
4419  }
4420  else if (jsexpr->on_error->btype == JSON_BEHAVIOR_ERROR)
4421  ereport(ERROR,
4422  errcode(ERRCODE_NO_SQL_JSON_ITEM),
4423  errmsg("no SQL/JSON item"));
4424  else
4425  jsestate->error.value = BoolGetDatum(true);
4426 
4427  *op->resvalue = (Datum) 0;
4428  *op->resnull = true;
4429 
4430  Assert(!throw_error && jsestate->jump_error >= 0);
4431  return jsestate->jump_error;
4432  }
4433 
4434  /*
4435  * ON ERROR. Wouldn't get here if the behavior is ERROR, because they
4436  * would have already been thrown.
4437  */
4438  if (error)
4439  {
4440  Assert(!throw_error && jsestate->jump_error >= 0);
4441  *op->resvalue = (Datum) 0;
4442  *op->resnull = true;
4443  jsestate->error.value = BoolGetDatum(true);
4444  return jsestate->jump_error;
4445  }
4446 
4447  return jump_eval_coercion >= 0 ? jump_eval_coercion : jsestate->jump_end;
4448 }
static char * ExecGetJsonValueItemString(JsonbValue *item, bool *resnull)
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:642
char * val_string
Definition: informix.c:675
Datum jsonb_out(PG_FUNCTION_ARGS)
Definition: jsonb.c:108
char * JsonbUnquote(Jsonb *jb)
Definition: jsonb.c:2166
static Jsonb * DatumGetJsonbP(Datum d)
Definition: jsonb.h:374
static Datum JsonbPGetDatum(const Jsonb *p)
Definition: jsonb.h:386
Jsonb * JsonbValueToJsonb(JsonbValue *val)
Definition: jsonb_util.c:92
static JsonPath * DatumGetJsonPathP(Datum d)
Definition: jsonpath.h:34
bool JsonPathExists(Datum jb, JsonPath *jp, bool *error, List *vars)
Datum JsonPathQuery(Datum jb, JsonPath *jp, JsonWrapper wrapper, bool *empty, bool *error, List *vars)
JsonbValue * JsonPathValue(Datum jb, JsonPath *jp, bool *empty, bool *error, List *vars)
@ JSON_BEHAVIOR_ERROR
Definition: primnodes.h:1718
@ JSON_QUERY_OP
Definition: primnodes.h:1755
@ JSON_EXISTS_OP
Definition: primnodes.h:1754
@ JSON_VALUE_OP
Definition: primnodes.h:1756
static void error(void)
Definition: sql-dyntest.c:147
bool details_wanted
Definition: miscnodes.h:47
ErrorData * error_data
Definition: miscnodes.h:48
bool error_occurred
Definition: miscnodes.h:46
JsonBehaviorType btype
Definition: primnodes.h:1742
int jump_eval_coercion
Definition: execnodes.h:1057
NullableDatum empty
Definition: execnodes.h:1042
FunctionCallInfo input_fcinfo
Definition: execnodes.h:1072
JsonExpr * jsexpr
Definition: execnodes.h:1020
NullableDatum pathspec
Definition: execnodes.h:1026
NullableDatum formatted_expr
Definition: execnodes.h:1023
JsonBehavior * on_empty
Definition: primnodes.h:1787
bool use_io_coercion
Definition: primnodes.h:1800
JsonReturning * returning
Definition: primnodes.h:1780
JsonWrapper wrapper
Definition: primnodes.h:1804
JsonExprOp op
Definition: primnodes.h:1768
JsonBehavior * on_error
Definition: primnodes.h:1788
bool omit_quotes
Definition: primnodes.h:1807
Datum textin(PG_FUNCTION_ARGS)
Definition: varlena.c:579

References FunctionCallInfoBaseData::args, JsonExprState::args, Assert(), BoolGetDatum(), JsonBehavior::btype, DatumGetCString(), DatumGetJsonbP(), DatumGetJsonPathP(), DatumGetPointer(), ErrorSaveContext::details_wanted, DirectFunctionCall1, elog, JsonExprState::empty, ereport, errcode(), errmsg(), JsonExprState::error, ERROR, error(), ErrorSaveContext::error_data, ErrorSaveContext::error_occurred, JsonExprState::escontext, ExecGetJsonValueItemString(), JsonExprState::formatted_expr, FunctionCallInvoke, JsonExprState::input_fcinfo, FunctionCallInfoBaseData::isnull, NullableDatum::isnull, ExprEvalStep::jsestate, JsonExprState::jsexpr, JSON_BEHAVIOR_ERROR, JSON_EXISTS_OP, JSON_QUERY_OP, JSON_VALUE_OP, jsonb_out(), JsonbPGetDatum(), JsonbUnquote(), JsonbValueToJsonb(), JsonPathExists(), JsonPathQuery(), JsonPathValue(), JsonExprState::jump_empty, JsonExprState::jump_end, JsonExprState::jump_error, JsonExprState::jump_eval_coercion, JsonExpr::omit_quotes, JsonExpr::on_empty, JsonExpr::on_error, ExprEvalStep::op, JsonExpr::op, JsonExprState::pathspec, PointerGetDatum(), JsonExpr::returning, SOFT_ERROR_OCCURRED, textin(), JsonReturning::typid, JsonExpr::use_io_coercion, val_string, NullableDatum::value, and JsonExpr::wrapper.

Referenced by ExecInterpExpr().

◆ ExecEvalJsonIsPredicate()

void ExecEvalJsonIsPredicate ( ExprState state,
ExprEvalStep op 
)

Definition at line 4167 of file execExprInterp.c.

4168 {
4169  JsonIsPredicate *pred = op->d.is_json.pred;
4170  Datum js = *op->resvalue;
4171  Oid exprtype;
4172  bool res;
4173 
4174  if (*op->resnull)
4175  {
4176  *op->resvalue = BoolGetDatum(false);
4177  return;
4178  }
4179 
4180  exprtype = exprType(pred->expr);
4181 
4182  if (exprtype == TEXTOID || exprtype == JSONOID)
4183  {
4184  text *json = DatumGetTextP(js);
4185 
4186  if (pred->item_type == JS_TYPE_ANY)
4187  res = true;
4188  else
4189  {
4190  switch (json_get_first_token(json, false))
4191  {
4193  res = pred->item_type == JS_TYPE_OBJECT;
4194  break;
4196  res = pred->item_type == JS_TYPE_ARRAY;
4197  break;
4198  case JSON_TOKEN_STRING:
4199  case JSON_TOKEN_NUMBER:
4200  case JSON_TOKEN_TRUE:
4201  case JSON_TOKEN_FALSE:
4202  case JSON_TOKEN_NULL:
4203  res = pred->item_type == JS_TYPE_SCALAR;
4204  break;
4205  default:
4206  res = false;
4207  break;
4208  }
4209  }
4210 
4211  /*
4212  * Do full parsing pass only for uniqueness check or for JSON text
4213  * validation.
4214  */
4215  if (res && (pred->unique_keys || exprtype == TEXTOID))
4216  res = json_validate(json, pred->unique_keys, false);
4217  }
4218  else if (exprtype == JSONBOID)
4219  {
4220  if (pred->item_type == JS_TYPE_ANY)
4221  res = true;
4222  else
4223  {
4224  Jsonb *jb = DatumGetJsonbP(js);
4225 
4226  switch (pred->item_type)
4227  {
4228  case JS_TYPE_OBJECT:
4229  res = JB_ROOT_IS_OBJECT(jb);
4230  break;
4231  case JS_TYPE_ARRAY:
4232  res = JB_ROOT_IS_ARRAY(jb) && !JB_ROOT_IS_SCALAR(jb);
4233  break;
4234  case JS_TYPE_SCALAR:
4235  res = JB_ROOT_IS_ARRAY(jb) && JB_ROOT_IS_SCALAR(jb);
4236  break;
4237  default:
4238  res = false;
4239  break;
4240  }
4241  }
4242 
4243  /* Key uniqueness check is redundant for jsonb */
4244  }
4245  else
4246  res = false;
4247 
4248  *op->resvalue = BoolGetDatum(res);
4249 }
@ JSON_TOKEN_FALSE
Definition: jsonapi.h:31
@ JSON_TOKEN_TRUE
Definition: jsonapi.h:30
@ JSON_TOKEN_NULL
Definition: jsonapi.h:32
@ JSON_TOKEN_OBJECT_START
Definition: jsonapi.h:24
@ JSON_TOKEN_NUMBER
Definition: jsonapi.h:23
@ JSON_TOKEN_STRING
Definition: jsonapi.h:22
@ JSON_TOKEN_ARRAY_START
Definition: jsonapi.h:26
#define JB_ROOT_IS_OBJECT(jbp_)
Definition: jsonb.h:221
#define JB_ROOT_IS_ARRAY(jbp_)
Definition: jsonb.h:222
#define JB_ROOT_IS_SCALAR(jbp_)
Definition: jsonb.h:220
JsonTokenType json_get_first_token(text *json, bool throw_error)
Definition: jsonfuncs.c:5926
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:42
@ JS_TYPE_ANY
Definition: primnodes.h:1674
@ JS_TYPE_ARRAY
Definition: primnodes.h:1676
@ JS_TYPE_OBJECT
Definition: primnodes.h:1675
@ JS_TYPE_SCALAR
Definition: primnodes.h:1677
struct ExprEvalStep::@53::@97 is_json
JsonValueType item_type
Definition: primnodes.h:1689
Definition: jsonb.h:213

References BoolGetDatum(), DatumGetJsonbP(), DatumGetTextP, JsonIsPredicate::expr, exprType(), JsonIsPredicate::item_type, JB_ROOT_IS_ARRAY, JB_ROOT_IS_OBJECT, JB_ROOT_IS_SCALAR, JS_TYPE_ANY, JS_TYPE_ARRAY, JS_TYPE_OBJECT, JS_TYPE_SCALAR, json_get_first_token(), JSON_TOKEN_ARRAY_START, JSON_TOKEN_FALSE, JSON_TOKEN_NULL, JSON_TOKEN_NUMBER, JSON_TOKEN_OBJECT_START, JSON_TOKEN_STRING, JSON_TOKEN_TRUE, json_validate(), ExprEvalStep::op, ExprEvalStep::pred, res, and JsonIsPredicate::unique_keys.

Referenced by ExecInterpExpr().

◆ ExecEvalMergeSupportFunc()

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

Definition at line 4599 of file execExprInterp.c.

4601 {
4602  ModifyTableState *mtstate = castNode(ModifyTableState, state->parent);
4603  MergeActionState *relaction = mtstate->mt_merge_action;
4604 
4605  if (!relaction)
4606  elog(ERROR, "no merge action in progress");
4607 
4608  /* Return the MERGE action ("INSERT", "UPDATE", or "DELETE") */
4609  switch (relaction->mas_action->commandType)
4610  {
4611  case CMD_INSERT:
4612  *op->resvalue = PointerGetDatum(cstring_to_text_with_len("INSERT", 6));
4613  *op->resnull = false;
4614  break;
4615  case CMD_UPDATE:
4616  *op->resvalue = PointerGetDatum(cstring_to_text_with_len("UPDATE", 6));
4617  *op->resnull = false;
4618  break;
4619  case CMD_DELETE:
4620  *op->resvalue = PointerGetDatum(cstring_to_text_with_len("DELETE", 6));
4621  *op->resnull = false;
4622  break;
4623  case CMD_NOTHING:
4624  elog(ERROR, "unexpected merge action: DO NOTHING");
4625  break;
4626  default:
4627  elog(ERROR, "unrecognized commandType: %d",
4628  (int) relaction->mas_action->commandType);
4629  }
4630 }
@ CMD_INSERT
Definition: nodes.h:267
@ CMD_DELETE
Definition: nodes.h:268
@ CMD_UPDATE
Definition: nodes.h:266
@ CMD_NOTHING
Definition: nodes.h:272
MergeAction * mas_action
Definition: execnodes.h:425
CmdType commandType
Definition: primnodes.h:1882
MergeActionState * mt_merge_action
Definition: execnodes.h:1402
text * cstring_to_text_with_len(const char *s, int len)
Definition: varlena.c:196

References castNode, CMD_DELETE, CMD_INSERT, CMD_NOTHING, CMD_UPDATE, MergeAction::commandType, cstring_to_text_with_len(), elog, ERROR, MergeActionState::mas_action, ModifyTableState::mt_merge_action, ExprEvalStep::op, and PointerGetDatum().

Referenced by ExecInterpExpr().

◆ ExecEvalMinMax()

void ExecEvalMinMax ( ExprState state,
ExprEvalStep op 
)

Definition at line 3108 of file execExprInterp.c.

3109 {
3110  Datum *values = op->d.minmax.values;
3111  bool *nulls = op->d.minmax.nulls;
3112  FunctionCallInfo fcinfo = op->d.minmax.fcinfo_data;
3113  MinMaxOp operator = op->d.minmax.op;
3114 
3115  /* set at initialization */
3116  Assert(fcinfo->args[0].isnull == false);
3117  Assert(fcinfo->args[1].isnull == false);
3118 
3119  /* default to null result */
3120  *op->resnull = true;
3121 
3122  for (int off = 0; off < op->d.minmax.nelems; off++)
3123  {
3124  /* ignore NULL inputs */
3125  if (nulls[off])
3126  continue;
3127 
3128  if (*op->resnull)
3129  {
3130  /* first nonnull input, adopt value */
3131  *op->resvalue = values[off];
3132  *op->resnull = false;
3133  }
3134  else
3135  {
3136  int cmpresult;
3137 
3138  /* apply comparison function */
3139  fcinfo->args[0].value = *op->resvalue;
3140  fcinfo->args[1].value = values[off];
3141 
3142  fcinfo->isnull = false;
3143  cmpresult = DatumGetInt32(FunctionCallInvoke(fcinfo));
3144  if (fcinfo->isnull) /* probably should not happen */
3145  continue;
3146 
3147  if (cmpresult > 0 && operator == IS_LEAST)
3148  *op->resvalue = values[off];
3149  else if (cmpresult < 0 && operator == IS_GREATEST)
3150  *op->resvalue = values[off];
3151  }
3152  }
3153 }
static Datum values[MAXATTR]
Definition: bootstrap.c:152
static int32 DatumGetInt32(Datum X)
Definition: postgres.h:202
MinMaxOp
Definition: primnodes.h:1457
@ IS_LEAST
Definition: primnodes.h:1459
@ IS_GREATEST
Definition: primnodes.h:1458
struct ExprEvalStep::@53::@77 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 2705 of file execExprInterp.c.

2706 {
2707  int64 newval = nextval_internal(op->d.nextvalueexpr.seqid, false);
2708 
2709  switch (op->d.nextvalueexpr.seqtypid)
2710  {
2711  case INT2OID:
2712  *op->resvalue = Int16GetDatum((int16) newval);
2713  break;
2714  case INT4OID:
2715  *op->resvalue = Int32GetDatum((int32) newval);
2716  break;
2717  case INT8OID:
2718  *op->resvalue = Int64GetDatum((int64) newval);
2719  break;
2720  default:
2721  elog(ERROR, "unsupported sequence type %u",
2722  op->d.nextvalueexpr.seqtypid);
2723  }
2724  *op->resnull = false;
2725 }
int64 nextval_internal(Oid relid, bool check_permissions)
Definition: sequence.c:616
Datum Int64GetDatum(int64 X)
Definition: fmgr.c:1807
#define newval
static Datum Int16GetDatum(int16 X)
Definition: postgres.h:172
struct ExprEvalStep::@53::@71 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 2498 of file execExprInterp.c.

2499 {
2500  ParamExecData *prm;
2501 
2502  prm = &(econtext->ecxt_param_exec_vals[op->d.param.paramid]);
2503  if (unlikely(prm->execPlan != NULL))
2504  {
2505  /* Parameter not evaluated yet, so go do it */
2506  ExecSetParamPlan(prm->execPlan, econtext);
2507  /* ExecSetParamPlan should have processed this param... */
2508  Assert(prm->execPlan == NULL);
2509  }
2510  *op->resvalue = prm->value;
2511  *op->resnull = prm->isnull;
2512 }
void ExecSetParamPlan(SubPlanState *node, ExprContext *econtext)
Definition: nodeSubplan.c:1092
ParamExecData * ecxt_param_exec_vals
Definition: execnodes.h:266
struct ExprEvalStep::@53::@65 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 2520 of file execExprInterp.c.

2521 {
2522  ParamListInfo paramInfo = econtext->ecxt_param_list_info;
2523  int paramId = op->d.param.paramid;
2524 
2525  if (likely(paramInfo &&
2526  paramId > 0 && paramId <= paramInfo->numParams))
2527  {
2528  ParamExternData *prm;
2529  ParamExternData prmdata;
2530 
2531  /* give hook a chance in case parameter is dynamic */
2532  if (paramInfo->paramFetch != NULL)
2533  prm = paramInfo->paramFetch(paramInfo, paramId, false, &prmdata);
2534  else
2535  prm = &paramInfo->params[paramId - 1];
2536 
2537  if (likely(OidIsValid(prm->ptype)))
2538  {
2539  /* safety check in case hook did something unexpected */
2540  if (unlikely(prm->ptype != op->d.param.paramtype))
2541  ereport(ERROR,
2542  (errcode(ERRCODE_DATATYPE_MISMATCH),
2543  errmsg("type of parameter %d (%s) does not match that when preparing the plan (%s)",
2544  paramId,
2545  format_type_be(prm->ptype),
2546  format_type_be(op->d.param.paramtype))));
2547  *op->resvalue = prm->value;
2548  *op->resnull = prm->isnull;
2549  return;
2550  }
2551  }
2552 
2553  ereport(ERROR,
2554  (errcode(ERRCODE_UNDEFINED_OBJECT),
2555  errmsg("no value found for parameter %d", paramId)));
2556 }
#define likely(x)
Definition: c.h:297
#define OidIsValid(objectId)
Definition: c.h:762
ParamListInfo ecxt_param_list_info
Definition: execnodes.h:267
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 5045 of file execExprInterp.c.

5046 {
5047  ExprContext *tmpcontext = aggstate->tmpcontext;
5048  bool isdistinct = false; /* for now */
5049  TupleTableSlot *save_outer;
5050  TupleTableSlot *save_inner;
5051 
5052  for (int i = 0; i < pertrans->numTransInputs; i++)
5053  {
5054  pertrans->sortslot->tts_values[i] = pertrans->transfn_fcinfo->args[i + 1].value;
5055  pertrans->sortslot->tts_isnull[i] = pertrans->transfn_fcinfo->args[i + 1].isnull;
5056  }
5057 
5058  ExecClearTuple(pertrans->sortslot);
5059  pertrans->sortslot->tts_nvalid = pertrans->numInputs;
5060  ExecStoreVirtualTuple(pertrans->sortslot);
5061 
5062  /* save the previous slots before we overwrite them */
5063  save_outer = tmpcontext->ecxt_outertuple;
5064  save_inner = tmpcontext->ecxt_innertuple;
5065 
5066  tmpcontext->ecxt_outertuple = pertrans->sortslot;
5067  tmpcontext->ecxt_innertuple = pertrans->uniqslot;
5068 
5069  if (!pertrans->haslast ||
5070  !ExecQual(pertrans->equalfnMulti, tmpcontext))
5071  {
5072  if (pertrans->haslast)
5073  ExecClearTuple(pertrans->uniqslot);
5074 
5075  pertrans->haslast = true;
5076  ExecCopySlot(pertrans->uniqslot, pertrans->sortslot);
5077 
5078  isdistinct = true;
5079  }
5080 
5081  /* restore the original slots */
5082  tmpcontext->ecxt_outertuple = save_outer;
5083  tmpcontext->ecxt_innertuple = save_inner;
5084 
5085  return isdistinct;
5086 }
static bool ExecQual(ExprState *state, ExprContext *econtext)
Definition: executor.h:413
ExprState * equalfnMulti
Definition: nodeAgg.h:116
TupleTableSlot * uniqslot
Definition: nodeAgg.h:142
bool * tts_isnull
Definition: tuptable.h:127
Datum * tts_values
Definition: tuptable.h:125
static TupleTableSlot * ExecCopySlot(TupleTableSlot *dstslot, TupleTableSlot *srcslot)
Definition: tuptable.h:509

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 5002 of file execExprInterp.c.

5003 {
5004  Datum value = pertrans->transfn_fcinfo->args[1].value;
5005  bool isnull = pertrans->transfn_fcinfo->args[1].isnull;
5006 
5007  if (!pertrans->haslast ||
5008  pertrans->lastisnull != isnull ||
5009  (!isnull && !DatumGetBool(FunctionCall2Coll(&pertrans->equalfnOne,
5010  pertrans->aggCollation,
5011  pertrans->lastdatum, value))))
5012  {
5013  if (pertrans->haslast && !pertrans->inputtypeByVal &&
5014  !pertrans->lastisnull)
5015  pfree(DatumGetPointer(pertrans->lastdatum));
5016 
5017  pertrans->haslast = true;
5018  if (!isnull)
5019  {
5020  MemoryContext oldContext;
5021 
5023 
5024  pertrans->lastdatum = datumCopy(value, pertrans->inputtypeByVal,
5025  pertrans->inputtypeLen);
5026 
5027  MemoryContextSwitchTo(oldContext);
5028  }
5029  else
5030  pertrans->lastdatum = (Datum) 0;
5031  pertrans->lastisnull = isnull;
5032  return true;
5033  }
5034 
5035  return false;
5036 }
Datum FunctionCall2Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2)
Definition: fmgr.c:1149
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 3088 of file execExprInterp.c.

3089 {
3090  HeapTuple tuple;
3091 
3092  /* build tuple from evaluated field values */
3093  tuple = heap_form_tuple(op->d.row.tupdesc,
3094  op->d.row.elemvalues,
3095  op->d.row.elemnulls);
3096 
3097  *op->resvalue = HeapTupleGetDatum(tuple);
3098  *op->resnull = false;
3099 }
struct ExprEvalStep::@53::@74 row

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

Referenced by ExecInterpExpr().

◆ ExecEvalRowNotNull()

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

Definition at line 2740 of file execExprInterp.c.

2741 {
2742  ExecEvalRowNullInt(state, op, econtext, false);
2743 }
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 2731 of file execExprInterp.c.

2732 {
2733  ExecEvalRowNullInt(state, op, econtext, true);
2734 }

References ExecEvalRowNullInt(), and ExprEvalStep::op.

Referenced by ExecInterpExpr().

◆ ExecEvalRowNullInt()

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

Definition at line 2747 of file execExprInterp.c.

2749 {
2750  Datum value = *op->resvalue;
2751  bool isnull = *op->resnull;
2752  HeapTupleHeader tuple;
2753  Oid tupType;
2754  int32 tupTypmod;
2755  TupleDesc tupDesc;
2756  HeapTupleData tmptup;
2757 
2758  *op->resnull = false;
2759 
2760  /* NULL row variables are treated just as NULL scalar columns */
2761  if (isnull)
2762  {
2763  *op->resvalue = BoolGetDatum(checkisnull);
2764  return;
2765  }
2766 
2767  /*
2768  * The SQL standard defines IS [NOT] NULL for a non-null rowtype argument
2769  * as:
2770  *
2771  * "R IS NULL" is true if every field is the null value.
2772  *
2773  * "R IS NOT NULL" is true if no field is the null value.
2774  *
2775  * This definition is (apparently intentionally) not recursive; so our
2776  * tests on the fields are primitive attisnull tests, not recursive checks
2777  * to see if they are all-nulls or no-nulls rowtypes.
2778  *
2779  * The standard does not consider the possibility of zero-field rows, but
2780  * here we consider them to vacuously satisfy both predicates.
2781  */
2782 
2783  tuple = DatumGetHeapTupleHeader(value);
2784 
2785  tupType = HeapTupleHeaderGetTypeId(tuple);
2786  tupTypmod = HeapTupleHeaderGetTypMod(tuple);
2787 
2788  /* Lookup tupdesc if first time through or if type changes */
2789  tupDesc = get_cached_rowtype(tupType, tupTypmod,
2790  &op->d.nulltest_row.rowcache, NULL);
2791 
2792  /*
2793  * heap_attisnull needs a HeapTuple not a bare HeapTupleHeader.
2794  */
2795  tmptup.t_len = HeapTupleHeaderGetDatumLength(tuple);
2796  tmptup.t_data = tuple;
2797 
2798  for (int att = 1; att <= tupDesc->natts; att++)
2799  {
2800  /* ignore dropped columns */
2801  if (TupleDescAttr(tupDesc, att - 1)->attisdropped)
2802  continue;
2803  if (heap_attisnull(&tmptup, att, tupDesc))
2804  {
2805  /* null field disproves IS NOT NULL */
2806  if (!checkisnull)
2807  {
2808  *op->resvalue = BoolGetDatum(false);
2809  return;
2810  }
2811  }
2812  else
2813  {
2814  /* non-null field disproves IS NULL */
2815  if (checkisnull)
2816  {
2817  *op->resvalue = BoolGetDatum(false);
2818  return;
2819  }
2820  }
2821  }
2822 
2823  *op->resvalue = BoolGetDatum(true);
2824 }
bool heap_attisnull(HeapTuple tup, int attnum, TupleDesc tupleDesc)
Definition: heaptuple.c:455
struct ExprEvalStep::@53::@64 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 3455 of file execExprInterp.c.

3456 {
3457  FunctionCallInfo fcinfo = op->d.scalararrayop.fcinfo_data;
3458  bool useOr = op->d.scalararrayop.useOr;
3459  bool strictfunc = op->d.scalararrayop.finfo->fn_strict;
3460  ArrayType *arr;
3461  int nitems;
3462  Datum result;
3463  bool resultnull;
3464  int16 typlen;
3465  bool typbyval;
3466  char typalign;
3467  char *s;
3468  bits8 *bitmap;
3469  int bitmask;
3470 
3471  /*
3472  * If the array is NULL then we return NULL --- it's not very meaningful
3473  * to do anything else, even if the operator isn't strict.
3474  */
3475  if (*op->resnull)
3476  return;
3477 
3478  /* Else okay to fetch and detoast the array */
3479  arr = DatumGetArrayTypeP(*op->resvalue);
3480 
3481  /*
3482  * If the array is empty, we return either FALSE or TRUE per the useOr
3483  * flag. This is correct even if the scalar is NULL; since we would
3484  * evaluate the operator zero times, it matters not whether it would want
3485  * to return NULL.
3486  */
3487  nitems = ArrayGetNItems(ARR_NDIM(arr), ARR_DIMS(arr));
3488  if (nitems <= 0)
3489  {
3490  *op->resvalue = BoolGetDatum(!useOr);
3491  *op->resnull = false;
3492  return;
3493  }
3494 
3495  /*
3496  * If the scalar is NULL, and the function is strict, return NULL; no
3497  * point in iterating the loop.
3498  */
3499  if (fcinfo->args[0].isnull && strictfunc)
3500  {
3501  *op->resnull = true;
3502  return;
3503  }
3504 
3505  /*
3506  * We arrange to look up info about the element type only once per series
3507  * of calls, assuming the element type doesn't change underneath us.
3508  */
3509  if (op->d.scalararrayop.element_type != ARR_ELEMTYPE(arr))
3510  {
3512  &op->d.scalararrayop.typlen,
3513  &op->d.scalararrayop.typbyval,
3514  &op->d.scalararrayop.typalign);
3515  op->d.scalararrayop.element_type = ARR_ELEMTYPE(arr);
3516  }
3517 
3518  typlen = op->d.scalararrayop.typlen;
3519  typbyval = op->d.scalararrayop.typbyval;
3520  typalign = op->d.scalararrayop.typalign;
3521 
3522  /* Initialize result appropriately depending on useOr */
3523  result = BoolGetDatum(!useOr);
3524  resultnull = false;
3525 
3526  /* Loop over the array elements */
3527  s = (char *) ARR_DATA_PTR(arr);
3528  bitmap = ARR_NULLBITMAP(arr);
3529  bitmask = 1;
3530 
3531  for (int i = 0; i < nitems; i++)
3532  {
3533  Datum elt;
3534  Datum thisresult;
3535 
3536  /* Get array element, checking for NULL */
3537  if (bitmap && (*bitmap & bitmask) == 0)
3538  {
3539  fcinfo->args[1].value = (Datum) 0;
3540  fcinfo->args[1].isnull = true;
3541  }
3542  else
3543  {
3544  elt = fetch_att(s, typbyval, typlen);
3545  s = att_addlength_pointer(s, typlen, s);
3546  s = (char *) att_align_nominal(s, typalign);
3547  fcinfo->args[1].value = elt;
3548  fcinfo->args[1].isnull = false;
3549  }
3550 
3551  /* Call comparison function */
3552  if (fcinfo->args[1].isnull && strictfunc)
3553  {
3554  fcinfo->isnull = true;
3555  thisresult = (Datum) 0;
3556  }
3557  else
3558  {
3559  fcinfo->isnull = false;
3560  thisresult = op->d.scalararrayop.fn_addr(fcinfo);
3561  }
3562 
3563  /* Combine results per OR or AND semantics */
3564  if (fcinfo->isnull)
3565  resultnull = true;
3566  else if (useOr)
3567  {
3568  if (DatumGetBool(thisresult))
3569  {
3570  result = BoolGetDatum(true);
3571  resultnull = false;
3572  break; /* needn't look at any more elements */
3573  }
3574  }
3575  else
3576  {
3577  if (!DatumGetBool(thisresult))
3578  {
3579  result = BoolGetDatum(false);
3580  resultnull = false;
3581  break; /* needn't look at any more elements */
3582  }
3583  }
3584 
3585  /* advance bitmap pointer if any */
3586  if (bitmap)
3587  {
3588  bitmask <<= 1;
3589  if (bitmask == 0x100)
3590  {
3591  bitmap++;
3592  bitmask = 1;
3593  }
3594  }
3595  }
3596 
3597  *op->resvalue = result;
3598  *op->resnull = resultnull;
3599 }
struct ExprEvalStep::@53::@84 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().

◆ ExecEvalSQLValueFunction()

void ExecEvalSQLValueFunction ( ExprState state,
ExprEvalStep op 
)

Definition at line 2627 of file execExprInterp.c.

2628 {
2629  LOCAL_FCINFO(fcinfo, 0);
2630  SQLValueFunction *svf = op->d.sqlvaluefunction.svf;
2631 
2632  *op->resnull = false;
2633 
2634  /*
2635  * Note: current_schema() can return NULL. current_user() etc currently
2636  * cannot, but might as well code those cases the same way for safety.
2637  */
2638  switch (svf->op)
2639  {
2640  case SVFOP_CURRENT_DATE:
2642  break;
2643  case SVFOP_CURRENT_TIME:
2644  case SVFOP_CURRENT_TIME_N:
2646  break;
2650  break;
2651  case SVFOP_LOCALTIME:
2652  case SVFOP_LOCALTIME_N:
2654  break;
2655  case SVFOP_LOCALTIMESTAMP:
2658  break;
2659  case SVFOP_CURRENT_ROLE:
2660  case SVFOP_CURRENT_USER:
2661  case SVFOP_USER:
2662  InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
2663  *op->resvalue = current_user(fcinfo);
2664  *op->resnull = fcinfo->isnull;
2665  break;
2666  case SVFOP_SESSION_USER:
2667  InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
2668  *op->resvalue = session_user(fcinfo);
2669  *op->resnull = fcinfo->isnull;
2670  break;
2671  case SVFOP_CURRENT_CATALOG:
2672  InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
2673  *op->resvalue = current_database(fcinfo);
2674  *op->resnull = fcinfo->isnull;
2675  break;
2676  case SVFOP_CURRENT_SCHEMA:
2677  InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
2678  *op->resvalue = current_schema(fcinfo);
2679  *op->resnull = fcinfo->isnull;
2680  break;
2681  }
2682 }
Datum current_database(PG_FUNCTION_ARGS)
Definition: misc.c:194
Timestamp GetSQLLocalTimestamp(int32 typmod)
Definition: timestamp.c:1686
TimestampTz GetSQLCurrentTimestamp(int32 typmod)
Definition: timestamp.c:1672
TimeTzADT * GetSQLCurrentTime(int32 typmod)
Definition: date.c:342
TimeADT GetSQLLocalTime(int32 typmod)
Definition: date.c:362
DateADT GetSQLCurrentDate(void)
Definition: date.c:309
static Datum DateADTGetDatum(DateADT X)
Definition: date.h:72
static Datum TimeTzADTPGetDatum(const TimeTzADT *X)
Definition: date.h:84
static Datum TimeADTGetDatum(TimeADT X)
Definition: date.h:78
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
Datum current_user(PG_FUNCTION_ARGS)
Definition: name.c:263
Datum session_user(PG_FUNCTION_ARGS)
Definition: name.c:269
Datum current_schema(PG_FUNCTION_ARGS)
Definition: name.c:279
@ SVFOP_CURRENT_CATALOG
Definition: primnodes.h:1505
@ SVFOP_LOCALTIME_N
Definition: primnodes.h:1498
@ SVFOP_CURRENT_TIMESTAMP
Definition: primnodes.h:1495
@ SVFOP_LOCALTIME
Definition: primnodes.h:1497
@ SVFOP_CURRENT_TIMESTAMP_N
Definition: primnodes.h:1496
@ SVFOP_CURRENT_ROLE
Definition: primnodes.h:1501
@ SVFOP_USER
Definition: primnodes.h:1503
@ SVFOP_CURRENT_SCHEMA
Definition: primnodes.h:1506
@ SVFOP_LOCALTIMESTAMP_N
Definition: primnodes.h:1500
@ SVFOP_CURRENT_DATE
Definition: primnodes.h:1492
@ SVFOP_CURRENT_TIME_N
Definition: primnodes.h:1494
@ SVFOP_CURRENT_TIME
Definition: primnodes.h:1493
@ SVFOP_LOCALTIMESTAMP
Definition: primnodes.h:1499
@ SVFOP_CURRENT_USER
Definition: primnodes.h:1502
@ SVFOP_SESSION_USER
Definition: primnodes.h:1504
struct ExprEvalStep::@53::@70 sqlvaluefunction
SQLValueFunctionOp op
Definition: primnodes.h:1512
static Datum TimestampTzGetDatum(TimestampTz X)
Definition: timestamp.h:52
static Datum TimestampGetDatum(Timestamp X)
Definition: timestamp.h:46

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

Referenced by ExecInterpExpr().

◆ ExecEvalStepOp()

ExprEvalOp ExecEvalStepOp ( ExprState state,
ExprEvalStep op 
)

Definition at line 2410 of file execExprInterp.c.

2411 {
2412 #if defined(EEO_USE_COMPUTED_GOTO)
2413  if (state->flags & EEO_FLAG_DIRECT_THREADED)
2414  {
2415  ExprEvalOpLookup key;
2416  ExprEvalOpLookup *res;
2417 
2418  key.opcode = (void *) op->opcode;
2419  res = bsearch(&key,
2420  reverse_dispatch_table,
2421  EEOP_LAST /* nmembers */ ,
2422  sizeof(ExprEvalOpLookup),
2423  dispatch_compare_ptr);
2424  Assert(res); /* unknown ops shouldn't get looked up */
2425  return res->op;
2426  }
2427 #endif
2428  return (ExprEvalOp) op->opcode;
2429 }
#define EEO_FLAG_DIRECT_THREADED
Definition: execExpr.h:31
ExprEvalOp
Definition: execExpr.h:67
@ EEOP_LAST
Definition: execExpr.h:270
intptr_t opcode
Definition: execExpr.h:281

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 4636 of file execExprInterp.c.

4637 {
4638  SubPlanState *sstate = op->d.subplan.sstate;
4639 
4640  /* could potentially be nested, so make sure there's enough stack */
4642 
4643  *op->resvalue = ExecSubPlan(sstate, econtext, op->resnull);
4644 }
Datum ExecSubPlan(SubPlanState *node, ExprContext *econtext, bool *isNull)
Definition: nodeSubplan.c:62
void check_stack_depth(void)
Definition: postgres.c:3531
struct ExprEvalStep::@53::@91 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 4880 of file execExprInterp.c.

4882 {
4883  Datum d;
4884 
4885  /* slot_getsysattr has sufficient defenses against bad attnums */
4886  d = slot_getsysattr(slot,
4887  op->d.var.attnum,
4888  op->resnull);
4889  *op->resvalue = d;
4890  /* this ought to be unreachable, but it's cheap enough to check */
4891  if (unlikely(*op->resnull))
4892  elog(ERROR, "failed to fetch attribute from slot");
4893 }
static Datum slot_getsysattr(TupleTableSlot *slot, int attnum, bool *isnull)
Definition: tuptable.h:416

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 4653 of file execExprInterp.c.

4654 {
4655  Var *variable = op->d.wholerow.var;
4656  TupleTableSlot *slot;
4657  TupleDesc output_tupdesc;
4658  MemoryContext oldcontext;
4659  HeapTupleHeader dtuple;
4660  HeapTuple tuple;
4661 
4662  /* This was checked by ExecInitExpr */
4663  Assert(variable->varattno == InvalidAttrNumber);
4664 
4665  /* Get the input slot we want */
4666  switch (variable->varno)
4667  {
4668  case INNER_VAR:
4669  /* get the tuple from the inner node */
4670  slot = econtext->ecxt_innertuple;
4671  break;
4672 
4673  case OUTER_VAR:
4674  /* get the tuple from the outer node */
4675  slot = econtext->ecxt_outertuple;
4676  break;
4677 
4678  /* INDEX_VAR is handled by default case */
4679 
4680  default:
4681  /* get the tuple from the relation being scanned */
4682  slot = econtext->ecxt_scantuple;
4683  break;
4684  }
4685 
4686  /* Apply the junkfilter if any */
4687  if (op->d.wholerow.junkFilter != NULL)
4688  slot = ExecFilterJunk(op->d.wholerow.junkFilter, slot);
4689 
4690  /*
4691  * If first time through, obtain tuple descriptor and check compatibility.
4692  *
4693  * XXX: It'd be great if this could be moved to the expression
4694  * initialization phase, but due to using slots that's currently not
4695  * feasible.
4696  */
4697  if (op->d.wholerow.first)
4698  {
4699  /* optimistically assume we don't need slow path */
4700  op->d.wholerow.slow = false;
4701 
4702  /*
4703  * If the Var identifies a named composite type, we must check that
4704  * the actual tuple type is compatible with it.
4705  */
4706  if (variable->vartype != RECORDOID)
4707  {
4708  TupleDesc var_tupdesc;
4709  TupleDesc slot_tupdesc;
4710 
4711  /*
4712  * We really only care about numbers of attributes and data types.
4713  * Also, we can ignore type mismatch on columns that are dropped
4714  * in the destination type, so long as (1) the physical storage
4715  * matches or (2) the actual column value is NULL. Case (1) is
4716  * helpful in some cases involving out-of-date cached plans, while
4717  * case (2) is expected behavior in situations such as an INSERT
4718  * into a table with dropped columns (the planner typically
4719  * generates an INT4 NULL regardless of the dropped column type).
4720  * If we find a dropped column and cannot verify that case (1)
4721  * holds, we have to use the slow path to check (2) for each row.
4722  *
4723  * If vartype is a domain over composite, just look through that
4724  * to the base composite type.
4725  */
4726  var_tupdesc = lookup_rowtype_tupdesc_domain(variable->vartype,
4727  -1, false);
4728 
4729  slot_tupdesc = slot->tts_tupleDescriptor;
4730 
4731  if (var_tupdesc->natts != slot_tupdesc->natts)
4732  ereport(ERROR,
4733  (errcode(ERRCODE_DATATYPE_MISMATCH),
4734  errmsg("table row type and query-specified row type do not match"),
4735  errdetail_plural("Table row contains %d attribute, but query expects %d.",
4736  "Table row contains %d attributes, but query expects %d.",
4737  slot_tupdesc->natts,
4738  slot_tupdesc->natts,
4739  var_tupdesc->natts)));
4740 
4741  for (int i = 0; i < var_tupdesc->natts; i++)
4742  {
4743  Form_pg_attribute vattr = TupleDescAttr(var_tupdesc, i);
4744  Form_pg_attribute sattr = TupleDescAttr(slot_tupdesc, i);
4745 
4746  if (vattr->atttypid == sattr->atttypid)
4747  continue; /* no worries */
4748  if (!vattr->attisdropped)
4749  ereport(ERROR,
4750  (errcode(ERRCODE_DATATYPE_MISMATCH),
4751  errmsg("table row type and query-specified row type do not match"),
4752  errdetail("Table has type %s at ordinal position %d, but query expects %s.",
4753  format_type_be(sattr->atttypid),
4754  i + 1,
4755  format_type_be(vattr->atttypid))));
4756 
4757  if (vattr->attlen != sattr->attlen ||
4758  vattr->attalign != sattr->attalign)
4759  op->d.wholerow.slow = true; /* need to check for nulls */
4760  }
4761 
4762  /*
4763  * Use the variable's declared rowtype as the descriptor for the
4764  * output values. In particular, we *must* absorb any
4765  * attisdropped markings.
4766  */
4767  oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
4768  output_tupdesc = CreateTupleDescCopy(var_tupdesc);
4769  MemoryContextSwitchTo(oldcontext);
4770 
4771  ReleaseTupleDesc(var_tupdesc);
4772  }
4773  else
4774  {
4775  /*
4776  * In the RECORD case, we use the input slot's rowtype as the
4777  * descriptor for the output values, modulo possibly assigning new
4778  * column names below.
4779  */
4780  oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
4781  output_tupdesc = CreateTupleDescCopy(slot->tts_tupleDescriptor);
4782  MemoryContextSwitchTo(oldcontext);
4783 
4784  /*
4785  * It's possible that the input slot is a relation scan slot and
4786  * so is marked with that relation's rowtype. But we're supposed
4787  * to be returning RECORD, so reset to that.
4788  */
4789  output_tupdesc->tdtypeid = RECORDOID;
4790  output_tupdesc->tdtypmod = -1;
4791 
4792  /*
4793  * We already got the correct physical datatype info above, but
4794  * now we should try to find the source RTE and adopt its column
4795  * aliases, since it's unlikely that the input slot has the
4796  * desired names.
4797  *
4798  * If we can't locate the RTE, assume the column names we've got
4799  * are OK. (As of this writing, the only cases where we can't
4800  * locate the RTE are in execution of trigger WHEN clauses, and
4801  * then the Var will have the trigger's relation's rowtype, so its
4802  * names are fine.) Also, if the creator of the RTE didn't bother
4803  * to fill in an eref field, assume our column names are OK. (This
4804  * happens in COPY, and perhaps other places.)
4805  */
4806  if (econtext->ecxt_estate &&
4807  variable->varno <= econtext->ecxt_estate->es_range_table_size)
4808  {
4809  RangeTblEntry *rte = exec_rt_fetch(variable->varno,
4810  econtext->ecxt_estate);
4811 
4812  if (rte->eref)
4813  ExecTypeSetColNames(output_tupdesc, rte->eref->colnames);
4814  }
4815  }
4816 
4817  /* Bless the tupdesc if needed, and save it in the execution state */
4818  op->d.wholerow.tupdesc = BlessTupleDesc(output_tupdesc);
4819 
4820  op->d.wholerow.first = false;
4821  }
4822 
4823  /*
4824  * Make sure all columns of the slot are accessible in the slot's
4825  * Datum/isnull arrays.
4826  */
4827  slot_getallattrs(slot);
4828 
4829  if (op->d.wholerow.slow)
4830  {
4831  /* Check to see if any dropped attributes are non-null */
4832  TupleDesc tupleDesc = slot->tts_tupleDescriptor;
4833  TupleDesc var_tupdesc = op->d.wholerow.tupdesc;
4834 
4835  Assert(var_tupdesc->natts == tupleDesc->natts);
4836 
4837  for (int i = 0; i < var_tupdesc->natts; i++)
4838  {
4839  Form_pg_attribute vattr = TupleDescAttr(var_tupdesc, i);
4840  Form_pg_attribute sattr = TupleDescAttr(tupleDesc, i);
4841 
4842  if (!vattr->attisdropped)
4843  continue; /* already checked non-dropped cols */
4844  if (slot->tts_isnull[i])
4845  continue; /* null is always okay */
4846  if (vattr->attlen != sattr->attlen ||
4847  vattr->attalign != sattr->attalign)
4848  ereport(ERROR,
4849  (errcode(ERRCODE_DATATYPE_MISMATCH),
4850  errmsg("table row type and query-specified row type do not match"),
4851  errdetail("Physical storage mismatch on dropped attribute at ordinal position %d.",
4852  i + 1)));
4853  }
4854  }
4855 
4856  /*
4857  * Build a composite datum, making sure any toasted fields get detoasted.
4858  *
4859  * (Note: it is critical that we not change the slot's state here.)
4860  */
4862  slot->tts_values,
4863  slot->tts_isnull);
4864  dtuple = tuple->t_data;
4865 
4866  /*
4867  * Label the datum with the composite type info we identified before.
4868  *
4869  * (Note: we could skip doing this by passing op->d.wholerow.tupdesc to
4870  * the tuple build step; but that seems a tad risky so let's not.)
4871  */
4872  HeapTupleHeaderSetTypeId(dtuple, op->d.wholerow.tupdesc->tdtypeid);
4873  HeapTupleHeaderSetTypMod(dtuple, op->d.wholerow.tupdesc->tdtypmod);
4874 
4875  *op->resvalue = PointerGetDatum(dtuple);
4876  *op->resnull = false;
4877 }
#define InvalidAttrNumber
Definition: attnum.h:23
int errdetail_plural(const char *fmt_singular, const char *fmt_plural, unsigned long n,...)
Definition: elog.c:1297
TupleTableSlot * ExecFilterJunk(JunkFilter *junkfilter, TupleTableSlot *slot)
Definition: execJunk.c:247
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:2158
void ExecTypeSetColNames(TupleDesc typeInfo, List *namesList)
Definition: execTuples.c:2117
static RangeTblEntry * exec_rt_fetch(Index rti, EState *estate)
Definition: executor.h:587
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:223
#define INNER_VAR
Definition: primnodes.h:222
Index es_range_table_size
Definition: execnodes.h:625
struct EState * ecxt_estate
Definition: execnodes.h:291
struct ExprEvalStep::@53::@56 wholerow
int32 tdtypmod
Definition: tupdesc.h:83
Definition: primnodes.h:234
TupleDesc CreateTupleDescCopy(TupleDesc tupdesc)
Definition: tupdesc.c:133
#define ReleaseTupleDesc(tupdesc)
Definition: tupdesc.h:122
static void slot_getallattrs(TupleTableSlot *slot)
Definition: tuptable.h:368
TupleDesc lookup_rowtype_tupdesc_domain(Oid type_id, int32 typmod, bool noError)
Definition: typcache.c:1889

References Assert(), BlessTupleDesc(), CreateTupleDescCopy(), ExprContext::ecxt_estate, ExprContext::ecxt_innertuple, ExprContext::ecxt_outertuple, ExprContext::ecxt_per_query_memory, ExprContext::ecxt_scantuple, 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 3874 of file execExprInterp.c.

3875 {
3876  XmlExpr *xexpr = op->d.xmlexpr.xexpr;
3877  Datum value;
3878 
3879  *op->resnull = true; /* until we get a result */
3880  *op->resvalue = (Datum) 0;
3881 
3882  switch (xexpr->op)
3883  {
3884  case IS_XMLCONCAT:
3885  {
3886  Datum *argvalue = op->d.xmlexpr.argvalue;
3887  bool *argnull = op->d.xmlexpr.argnull;
3888  List *values = NIL;
3889 
3890  for (int i = 0; i < list_length(xexpr->args); i++)
3891  {
3892  if (!argnull[i])
3893  values = lappend(values, DatumGetPointer(argvalue[i]));
3894  }
3895 
3896  if (values != NIL)
3897  {
3899  *op->resnull = false;
3900  }
3901  }
3902  break;
3903 
3904  case IS_XMLFOREST:
3905  {
3906  Datum *argvalue = op->d.xmlexpr.named_argvalue;
3907  bool *argnull = op->d.xmlexpr.named_argnull;
3909  ListCell *lc;
3910  ListCell *lc2;
3911  int i;
3912 
3913  initStringInfo(&buf);
3914 
3915  i = 0;
3916  forboth(lc, xexpr->named_args, lc2, xexpr->arg_names)
3917  {
3918  Expr *e = (Expr *) lfirst(lc);
3919  char *argname = strVal(lfirst(lc2));
3920 
3921  if (!argnull[i])
3922  {
3923  value = argvalue[i];
3924  appendStringInfo(&buf, "<%s>%s</%s>",
3925  argname,
3927  exprType((Node *) e), true),
3928  argname);
3929  *op->resnull = false;
3930  }
3931  i++;
3932  }
3933 
3934  if (!*op->resnull)
3935  {
3936  text *result;
3937 
3938  result = cstring_to_text_with_len(buf.data, buf.len);
3939  *op->resvalue = PointerGetDatum(result);
3940  }
3941 
3942  pfree(buf.data);
3943  }
3944  break;
3945 
3946  case IS_XMLELEMENT:
3947  *op->resvalue = PointerGetDatum(xmlelement(xexpr,
3948  op->d.xmlexpr.named_argvalue,
3949  op->d.xmlexpr.named_argnull,
3950  op->d.xmlexpr.argvalue,
3951  op->d.xmlexpr.argnull));
3952  *op->resnull = false;
3953  break;
3954 
3955  case IS_XMLPARSE:
3956  {
3957  Datum *argvalue = op->d.xmlexpr.argvalue;
3958  bool *argnull = op->d.xmlexpr.argnull;
3959  text *data;
3960  bool preserve_whitespace;
3961 
3962  /* arguments are known to be text, bool */
3963  Assert(list_length(xexpr->args) == 2);
3964 
3965  if (argnull[0])
3966  return;
3967  value = argvalue[0];
3969 
3970  if (argnull[1]) /* probably can't happen */
3971  return;
3972  value = argvalue[1];
3973  preserve_whitespace = DatumGetBool(value);
3974 
3976  xexpr->xmloption,
3977  preserve_whitespace));
3978  *op->resnull = false;
3979  }
3980  break;
3981 
3982  case IS_XMLPI:
3983  {
3984  text *arg;
3985  bool isnull;
3986 
3987  /* optional argument is known to be text */
3988  Assert(list_length(xexpr->args) <= 1);
3989 
3990  if (xexpr->args)
3991  {
3992  isnull = op->d.xmlexpr.argnull[0];
3993  if (isnull)
3994  arg = NULL;
3995  else
3996  arg = DatumGetTextPP(op->d.xmlexpr.argvalue[0]);
3997  }
3998  else
3999  {
4000  arg = NULL;
4001  isnull = false;
4002  }
4003 
4004  *op->resvalue = PointerGetDatum(xmlpi(xexpr->name,
4005  arg,
4006  isnull,
4007  op->resnull));
4008  }
4009  break;
4010 
4011  case IS_XMLROOT:
4012  {
4013  Datum *argvalue = op->d.xmlexpr.argvalue;
4014  bool *argnull = op->d.xmlexpr.argnull;
4015  xmltype *data;
4016  text *version;
4017  int standalone;
4018 
4019  /* arguments are known to be xml, text, int */
4020  Assert(list_length(xexpr->args) == 3);
4021 
4022  if (argnull[0])
4023  return;
4024  data = DatumGetXmlP(argvalue[0]);
4025 
4026  if (argnull[1])
4027  version = NULL;
4028  else
4029  version = DatumGetTextPP(argvalue[1]);
4030 
4031  Assert(!argnull[2]); /* always present */
4032  standalone = DatumGetInt32(argvalue[2]);
4033 
4035  version,
4036  standalone));
4037  *op->resnull = false;
4038  }
4039  break;
4040 
4041  case IS_XMLSERIALIZE:
4042  {
4043  Datum *argvalue = op->d.xmlexpr.argvalue;
4044  bool *argnull = op->d.xmlexpr.argnull;
4045 
4046  /* argument type is known to be xml */
4047  Assert(list_length(xexpr->args) == 1);
4048 
4049  if (argnull[0])
4050  return;
4051  value = argvalue[0];
4052 
4053  *op->resvalue =
4055  xexpr->xmloption,
4056  xexpr->indent));
4057  *op->resnull = false;
4058  }
4059  break;
4060 
4061  case IS_DOCUMENT:
4062  {
4063  Datum *argvalue = op->d.xmlexpr.argvalue;
4064  bool *argnull = op->d.xmlexpr.argnull;
4065 
4066  /* optional argument is known to be xml */
4067  Assert(list_length(xexpr->args) == 1);
4068 
4069  if (argnull[0])
4070  return;
4071  value = argvalue[0];
4072 
4073  *op->resvalue =
4075  *op->resnull = false;
4076  }
4077  break;
4078 
4079  default:
4080  elog(ERROR, "unrecognized XML operation");
4081  break;
4082  }
4083 }
#define DatumGetTextPP(X)
Definition: fmgr.h:292
List * lappend(List *list, void *datum)
Definition: list.c:339
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:518
static char * buf
Definition: pg_test_fsync.c:73
e
Definition: preproc-init.c:82
@ IS_DOCUMENT
Definition: primnodes.h:1543
@ IS_XMLFOREST
Definition: primnodes.h:1538
@ IS_XMLCONCAT
Definition: primnodes.h:1536
@ IS_XMLPI
Definition: primnodes.h:1540
@ IS_XMLPARSE
Definition: primnodes.h:1539
@ IS_XMLSERIALIZE
Definition: primnodes.h:1542
@ IS_XMLROOT
Definition: primnodes.h:1541
@ IS_XMLELEMENT
Definition: primnodes.h:1537
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:97
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
struct ExprEvalStep::@53::@86 xmlexpr
Definition: pg_list.h:54
List * args
Definition: primnodes.h:1564
bool indent
Definition: primnodes.h:1568
List * named_args
Definition: primnodes.h:1560
XmlExprOp op
Definition: primnodes.h:1556
#define strVal(v)
Definition: value.h:82
xmltype * xmlconcat(List *args)
Definition: xml.c:553
text * xmltotext_with_options(xmltype *data, XmlOptionType xmloption_arg, bool indent)
Definition: xml.c:656
xmltype * xmlparse(text *data, XmlOptionType xmloption_arg, bool preserve_whitespace)
Definition: xml.c:960
bool xml_is_document(xmltype *arg)
Definition: xml.c:1096
xmltype * xmlpi(const char *target, text *arg, bool arg_is_null, bool *result_is_null)
Definition: xml.c:978
char * map_sql_value_to_xml_value(Datum value, Oid type, bool xml_escape_strings)
Definition: xml.c:2413
xmltype * xmlelement(XmlExpr *xexpr, Datum *named_argvalue, bool *named_argnull, Datum *argvalue, bool *argnull)
Definition: xml.c:836
xmltype * xmlroot(xmltype *data, text *version, int standalone)
Definition: xml.c:1030
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().

◆ ExecGetJsonValueItemString()

static char * ExecGetJsonValueItemString ( JsonbValue item,
bool resnull 
)
static

Definition at line 4456 of file execExprInterp.c.

4457 {
4458  *resnull = false;
4459 
4460  /* get coercion state reference and datum of the corresponding SQL type */
4461  switch (item->type)
4462  {
4463  case jbvNull:
4464  *resnull = true;
4465  return NULL;
4466 
4467  case jbvString:
4468  {
4469  char *str = palloc(item->val.string.len + 1);
4470 
4471  memcpy(str, item->val.string.val, item->val.string.len);
4472  str[item->val.string.len] = '\0';
4473  return str;
4474  }
4475 
4476  case jbvNumeric:
4478  NumericGetDatum(item->val.numeric)));
4479 
4480  case jbvBool:
4482  BoolGetDatum(item->val.boolean)));
4483 
4484  case jbvDatetime:
4485  switch (item->val.datetime.typid)
4486  {
4487  case DATEOID:
4489  item->val.datetime.value));
4490  case TIMEOID:
4492  item->val.datetime.value));
4493  case TIMETZOID:
4495  item->val.datetime.value));
4496  case TIMESTAMPOID:
4498  item->val.datetime.value));
4499  case TIMESTAMPTZOID:
4501  item->val.datetime.value));
4502  default:
4503  elog(ERROR, "unexpected jsonb datetime type oid %u",
4504  item->val.datetime.typid);
4505  }
4506  break;
4507 
4508  case jbvArray:
4509  case jbvObject:
4510  case jbvBinary:
4513 
4514  default:
4515  elog(ERROR, "unexpected jsonb value type %d", item->type);
4516  }
4517 
4518  Assert(false);
4519  *resnull = true;
4520  return NULL;
4521 }
Datum numeric_out(PG_FUNCTION_ARGS)
Definition: numeric.c:807
Datum timestamptz_out(PG_FUNCTION_ARGS)
Definition: timestamp.c:785
Datum timestamp_out(PG_FUNCTION_ARGS)
Definition: timestamp.c:232
Datum boolout(PG_FUNCTION_ARGS)
Definition: bool.c:157
Datum date_out(PG_FUNCTION_ARGS)
Definition: date.c:184
Datum time_out(PG_FUNCTION_ARGS)
Definition: date.c:1501
Datum timetz_out(PG_FUNCTION_ARGS)
Definition: date.c:2314
@ jbvObject
Definition: jsonb.h:234
@ jbvNumeric
Definition: jsonb.h:230
@ jbvBool
Definition: jsonb.h:231
@ jbvArray
Definition: jsonb.h:233
@ jbvBinary
Definition: jsonb.h:236
@ jbvNull
Definition: jsonb.h:228
@ jbvDatetime
Definition: jsonb.h:244
@ jbvString
Definition: jsonb.h:229
static Datum NumericGetDatum(Numeric X)
Definition: numeric.h:73
enum jbvType type
Definition: jsonb.h:255
char * val
Definition: jsonb.h:264

References Assert(), BoolGetDatum(), boolout(), date_out(), DatumGetCString(), DirectFunctionCall1, elog, ERROR, jbvArray, jbvBinary, jbvBool, jbvDatetime, jbvNull, jbvNumeric, jbvObject, jbvString, jsonb_out(), JsonbPGetDatum(), JsonbValueToJsonb(), numeric_out(), NumericGetDatum(), palloc(), ExprEvalStep::resnull, generate_unaccent_rules::str, time_out(), timestamp_out(), timestamptz_out(), timetz_out(), JsonbValue::type, and JsonbValue::val.

Referenced by ExecEvalJsonExprPath().

◆ ExecInitInterpreter()

static void ExecInitInterpreter ( void  )
static

Definition at line 2378 of file execExprInterp.c.

2379 {
2380 #if defined(EEO_USE_COMPUTED_GOTO)
2381  /* Set up externally-visible pointer to dispatch table */
2382  if (dispatch_table == NULL)
2383  {
2384  dispatch_table = (const void **)
2385  DatumGetPointer(ExecInterpExpr(NULL, NULL, NULL));
2386 
2387  /* build reverse lookup table */
2388  for (int i = 0; i < EEOP_LAST; i++)
2389  {
2390  reverse_dispatch_table[i].opcode = dispatch_table[i];
2391  reverse_dispatch_table[i].op = (ExprEvalOp) i;
2392  }
2393 
2394  /* make it bsearch()able */
2395  qsort(reverse_dispatch_table,
2396  EEOP_LAST /* nmembers */ ,
2397  sizeof(ExprEvalOpLookup),
2398  dispatch_compare_ptr);
2399  }
2400 #endif
2401 }
static Datum ExecInterpExpr(ExprState *state, ExprContext *econtext, bool *isnull)
#define qsort(a, b, c, d)
Definition: port.h:449

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 396 of file execExprInterp.c.

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

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_IOCOERCE_SAFE, EEOP_IS_JSON, EEOP_JSON_CONSTRUCTOR, EEOP_JSONEXPR_COERCION, EEOP_JSONEXPR_COERCION_FINISH, EEOP_JSONEXPR_PATH, EEOP_JUMP, EEOP_JUMP_IF_NOT_NULL, EEOP_JUMP_IF_NOT_TRUE, EEOP_JUMP_IF_NULL, EEOP_LAST, EEOP_MAKE_READONLY, EEOP_MERGE_SUPPORT_FUNC, EEOP_MINMAX, EEOP_NEXTVALUEEXPR, EEOP_NOT_DISTINCT, EEOP_NULLIF, EEOP_NULLTEST_ISNOTNULL, EEOP_NULLTEST_ISNULL, EEOP_NULLTEST_ROWISNOTNULL, EEOP_NULLTEST_ROWISNULL, EEOP_OUTER_FETCHSOME, EEOP_OUTER_SYSVAR, EEOP_OUTER_VAR, EEOP_PARAM_CALLBACK, EEOP_PARAM_EXEC, EEOP_PARAM_EXTERN, EEOP_QUAL, EEOP_ROW, EEOP_ROWCOMPARE_FINAL, EEOP_ROWCOMPARE_STEP, EEOP_SBSREF_ASSIGN, EEOP_SBSREF_FETCH, EEOP_SBSREF_OLD, EEOP_SBSREF_SUBSCRIPTS, EEOP_SCALARARRAYOP, EEOP_SCAN_FETCHSOME, EEOP_SCAN_SYSVAR, EEOP_SCAN_VAR, EEOP_SQLVALUEFUNCTION, EEOP_SUBPLAN, EEOP_WHOLEROW, EEOP_WINDOW_FUNC, EEOP_XMLEXPR, ExecAggInitGroup(), ExecAggPlainTransByRef(), ExecAggPlainTransByVal(), ExecEvalAggOrderedTransDatum(), ExecEvalAggOrderedTransTuple(), ExecEvalArrayCoerce(), ExecEvalArrayExpr(), ExecEvalCoerceViaIOSafe(), ExecEvalConstraintCheck(), ExecEvalConstraintNotNull(), ExecEvalConvertRowtype(), ExecEvalCurrentOfExpr(), ExecEvalFieldSelect(), ExecEvalFieldStoreDeForm(), ExecEvalFieldStoreForm(), ExecEvalFuncExprFusage(), ExecEvalFuncExprStrictFusage(), ExecEvalGroupingFunc(), ExecEvalHashedScalarArrayOp(), ExecEvalJsonCoercion(), ExecEvalJsonCoercionFinish(), ExecEvalJsonConstructor(), ExecEvalJsonExprPath(), ExecEvalJsonIsPredicate(), ExecEvalMergeSupportFunc(), ExecEvalMinMax(), ExecEvalNextValueExpr(), ExecEvalParamExec(), ExecEvalParamExtern(), ExecEvalPreOrderedDistinctMulti(), ExecEvalPreOrderedDistinctSingle(), ExecEvalRow(), ExecEvalRowNotNull(), ExecEvalRowNull(), ExecEvalScalarArrayOp(), ExecEvalSQLValueFunction(), 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 1903 of file execExprInterp.c.

1904 {
1905  /*
1906  * First time through, check whether attribute matches Var. Might not be
1907  * ok anymore, due to schema changes.
1908  */
1909  CheckExprStillValid(state, econtext);
1910 
1911  /* skip the check during further executions */
1912  state->evalfunc = (ExprStateEvalFunc) state->evalfunc_private;
1913 
1914  /* and actually execute */
1915  return state->evalfunc(state, econtext, isNull);
1916 }
void CheckExprStillValid(ExprState *state, ExprContext *econtext)
Datum(* ExprStateEvalFunc)(struct ExprState *expression, struct ExprContext *econtext, bool *isNull)
Definition: execnodes.h:70

References CheckExprStillValid().

Referenced by ExecReadyInterpretedExpr().

◆ ExecJustApplyFuncToCase()

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

Definition at line 2223 of file execExprInterp.c.

2224 {
2225  ExprEvalStep *op = &state->steps[0];
2226  FunctionCallInfo fcinfo;
2228  int nargs;
2229  Datum d;
2230 
2231  /*
2232  * XXX with some redesign of the CaseTestExpr mechanism, maybe we could
2233  * get rid of this data shuffling?
2234  */
2235  *op->resvalue = *op->d.casetest.value;
2236  *op->resnull = *op->d.casetest.isnull;
2237 
2238  op++;
2239 
2240  nargs = op->d.func.nargs;
2241  fcinfo = op->d.func.fcinfo_data;
2242  args = fcinfo->args;
2243 
2244  /* strict function, so check for NULL args */
2245  for (int argno = 0; argno < nargs; argno++)
2246  {
2247  if (args[argno].isnull)
2248  {
2249  *isnull = true;
2250  return (Datum) 0;
2251  }
2252  }
2253  fcinfo->isnull = false;
2254  d = op->d.func.fn_addr(fcinfo);
2255  *isnull = fcinfo->isnull;
2256  return d;
2257 }

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

Referenced by ExecReadyInterpretedExpr().

◆ ExecJustAssignInnerVar()

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

Definition at line 2202 of file execExprInterp.c.

2203 {
2204  return ExecJustAssignVarImpl(state, econtext->ecxt_innertuple, isnull);
2205 }
static pg_attribute_always_inline Datum ExecJustAssignVarImpl(ExprState *state, TupleTableSlot *inslot, bool *isnull)

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

Referenced by ExecReadyInterpretedExpr().

◆ ExecJustAssignInnerVarVirt()

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

Definition at line 2336 of file execExprInterp.c.

2337 {
2338  return ExecJustAssignVarVirtImpl(state, econtext->ecxt_innertuple, isnull);
2339 }
static pg_attribute_always_inline Datum ExecJustAssignVarVirtImpl(ExprState *state, TupleTableSlot *inslot, bool *isnull)

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

Referenced by ExecReadyInterpretedExpr().

◆ ExecJustAssignOuterVar()

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

Definition at line 2209 of file execExprInterp.c.

2210 {
2211  return ExecJustAssignVarImpl(state, econtext->ecxt_outertuple, isnull);
2212 }

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

Referenced by ExecReadyInterpretedExpr().

◆ ExecJustAssignOuterVarVirt()

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

Definition at line 2343 of file execExprInterp.c.

2344 {
2345  return ExecJustAssignVarVirtImpl(state, econtext->ecxt_outertuple, isnull);
2346 }

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

Referenced by ExecReadyInterpretedExpr().

◆ ExecJustAssignScanVar()

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

Definition at line 2216 of file execExprInterp.c.

2217 {
2218  return ExecJustAssignVarImpl(state, econtext->ecxt_scantuple, isnull);
2219 }

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

Referenced by ExecReadyInterpretedExpr().

◆ ExecJustAssignScanVarVirt()

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

Definition at line 2350 of file execExprInterp.c.

2351 {
2352  return ExecJustAssignVarVirtImpl(state, econtext->ecxt_scantuple, isnull);
2353 }

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

Referenced by ExecReadyInterpretedExpr().

◆ ExecJustAssignVarImpl()

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

Definition at line 2176 of file execExprInterp.c.

2177 {
2178  ExprEvalStep *op = &state->steps[1];
2179  int attnum = op->d.assign_var.attnum + 1;
2180  int resultnum = op->d.assign_var.resultnum;
2181  TupleTableSlot *outslot = state->resultslot;
2182 
2183  CheckOpSlotCompatibility(&state->steps[0], inslot);
2184 
2185  /*
2186  * We do not need CheckVarSlotCompatibility here; that was taken care of
2187  * at compilation time.
2188  *
2189  * Since we use slot_getattr(), we don't need to implement the FETCHSOME
2190  * step explicitly, and we also needn't Assert that the attnum is in range
2191  * --- slot_getattr() will take care of any problems. Nonetheless, check
2192  * that resultnum is in range.
2193  */
2194  Assert(resultnum >= 0 && resultnum < outslot->tts_tupleDescriptor->natts);
2195  outslot->tts_values[resultnum] =
2196  slot_getattr(inslot, attnum, &outslot->tts_isnull[resultnum]);
2197  return 0;
2198 }
static Datum slot_getattr(TupleTableSlot *slot, int attnum, bool *isnull)
Definition: tuptable.h:395

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

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

◆ ExecJustAssignVarVirtImpl()

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

Definition at line 2314 of file execExprInterp.c.

2315 {
2316  ExprEvalStep *op = &state->steps[0];
2317  int attnum = op->d.assign_var.attnum;
2318  int resultnum = op->d.assign_var.resultnum;
2319  TupleTableSlot *outslot = state->resultslot;
2320 
2321  /* see ExecJustVarVirtImpl for comments */
2322 
2323  Assert(TTS_IS_VIRTUAL(inslot));
2324  Assert(TTS_FIXED(inslot));
2325  Assert(attnum >= 0 && attnum < inslot->tts_nvalid);
2326  Assert(resultnum >= 0 && resultnum < outslot->tts_tupleDescriptor->natts);
2327 
2328  outslot->tts_values[resultnum] = inslot->tts_values[attnum];
2329  outslot->tts_isnull[resultnum] = inslot->tts_isnull[attnum];
2330 
2331  return 0;
2332 }
#define TTS_IS_VIRTUAL(slot)
Definition: tuptable.h:234
#define TTS_FIXED(slot)
Definition: tuptable.h:108

References Assert(), attnum, ExprEvalStep::op, ExprEvalStep::resultnum, TTS_FIXED, TTS_IS_VIRTUAL, TupleTableSlot::tts_isnull, and TupleTableSlot::tts_values.

Referenced by ExecJustAssignInnerVarVirt(), ExecJustAssignOuterVarVirt(), and ExecJustAssignScanVarVirt().

◆ ExecJustConst()

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

Definition at line 2261 of file execExprInterp.c.

2262 {
2263  ExprEvalStep *op = &state->steps[0];
2264 
2265  *isnull = op->d.constval.isnull;
2266  return op->d.constval.value;
2267 }

References ExprEvalStep::isnull, and ExprEvalStep::op.

Referenced by ExecReadyInterpretedExpr().

◆ ExecJustInnerVar()

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

Definition at line 2155 of file execExprInterp.c.

2156 {
2157  return ExecJustVarImpl(state, econtext->ecxt_innertuple, isnull);
2158 }
static pg_attribute_always_inline Datum ExecJustVarImpl(ExprState *state, TupleTableSlot *slot, bool *isnull)

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

Referenced by ExecReadyInterpretedExpr().

◆ ExecJustInnerVarVirt()

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

Definition at line 2293 of file execExprInterp.c.

2294 {
2295  return ExecJustVarVirtImpl(state, econtext->ecxt_innertuple, isnull);
2296 }
static pg_attribute_always_inline Datum ExecJustVarVirtImpl(ExprState *state, TupleTableSlot *slot, bool *isnull)

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

Referenced by ExecReadyInterpretedExpr().

◆ ExecJustOuterVar()

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

Definition at line 2162 of file execExprInterp.c.

2163 {
2164  return ExecJustVarImpl(state, econtext->ecxt_outertuple, isnull);
2165 }

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

Referenced by ExecReadyInterpretedExpr().

◆ ExecJustOuterVarVirt()

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

Definition at line 2300 of file execExprInterp.c.

2301 {
2302  return ExecJustVarVirtImpl(state, econtext->ecxt_outertuple, isnull);
2303 }

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

Referenced by ExecReadyInterpretedExpr().

◆ ExecJustScanVar()

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

Definition at line 2169 of file execExprInterp.c.

2170 {
2171  return ExecJustVarImpl(state, econtext->ecxt_scantuple, isnull);
2172 }

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

Referenced by ExecReadyInterpretedExpr().

◆ ExecJustScanVarVirt()

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

Definition at line 2307 of file execExprInterp.c.

2308 {
2309  return ExecJustVarVirtImpl(state, econtext->ecxt_scantuple, isnull);
2310 }

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

Referenced by ExecReadyInterpretedExpr().

◆ ExecJustVarImpl()

static pg_attribute_always_inline Datum ExecJustVarImpl ( ExprState state,
TupleTableSlot slot,
bool isnull 
)
static

Definition at line 2138 of file execExprInterp.c.

2139 {
2140  ExprEvalStep *op = &state->steps[1];
2141  int attnum = op->d.var.attnum + 1;
2142 
2143  CheckOpSlotCompatibility(&state->steps[0], slot);
2144 
2145  /*
2146  * Since we use slot_getattr(), we don't need to implement the FETCHSOME
2147  * step explicitly, and we also needn't Assert that the attnum is in range
2148  * --- slot_getattr() will take care of any problems.
2149  */
2150  return slot_getattr(slot, attnum, isnull);
2151 }

References attnum, CheckOpSlotCompatibility(), ExprEvalStep::isnull, ExprEvalStep::op, and slot_getattr().

Referenced by ExecJustInnerVar(), ExecJustOuterVar(), and ExecJustScanVar().

◆ ExecJustVarVirtImpl()

static pg_attribute_always_inline Datum ExecJustVarVirtImpl ( ExprState state,
TupleTableSlot slot,
bool isnull 
)
static

Definition at line 2271 of file execExprInterp.c.

2272 {
2273  ExprEvalStep *op = &state->steps[0];
2274  int attnum = op->d.var.attnum;
2275 
2276  /*
2277  * As it is guaranteed that a virtual slot is used, there never is a need
2278  * to perform tuple deforming (nor would it be possible). Therefore
2279  * execExpr.c has not emitted an EEOP_*_FETCHSOME step. Verify, as much as
2280  * possible, that that determination was accurate.
2281  */
2282  Assert(TTS_IS_VIRTUAL(slot));
2283  Assert(TTS_FIXED(slot));
2284  Assert(attnum >= 0 && attnum < slot->tts_nvalid);
2285 
2286  *isnull = slot->tts_isnull[attnum];
2287 
2288  return slot->tts_values[attnum];
2289 }

References Assert(), attnum, ExprEvalStep::isnull, ExprEvalStep::op, TTS_FIXED, TTS_IS_VIRTUAL, TupleTableSlot::tts_isnull, and TupleTableSlot::tts_values.

Referenced by ExecJustInnerVarVirt(), ExecJustOuterVarVirt(), and ExecJustScanVarVirt().

◆ ExecReadyInterpretedExpr()

void ExecReadyInterpretedExpr ( ExprState state)

Definition at line 236 of file execExprInterp.c.

237 {
238  /* Ensure one-time interpreter setup has been done */
240 
241  /* Simple validity checks on expression */
242  Assert(state->steps_len >= 1);
243  Assert(state->steps[state->steps_len - 1].opcode == EEOP_DONE);
244 
245  /*
246  * Don't perform redundant initialization. This is unreachable in current
247  * cases, but might be hit if there's additional expression evaluation
248  * methods that rely on interpreted execution to work.
249  */
251  return;
252 
253  /*
254  * First time through, check whether attribute matches Var. Might not be
255  * ok anymore, due to schema changes. We do that by setting up a callback
256  * that does checking on the first call, which then sets the evalfunc
257  * callback to the actual method of execution.
258  */
259  state->evalfunc = ExecInterpExprStillValid;
260 
261  /* DIRECT_THREADED should not already be set */
262  Assert((state->flags & EEO_FLAG_DIRECT_THREADED) == 0);
263 
264  /*
265  * There shouldn't be any errors before the expression is fully
266  * initialized, and even if so, it'd lead to the expression being
267  * abandoned. So we can set the flag now and save some code.
268  */
270 
271  /*
272  * Select fast-path evalfuncs for very simple expressions. "Starting up"
273  * the full interpreter is a measurable overhead for these, and these
274  * patterns occur often enough to be worth optimizing.
275  */
276  if (state->steps_len == 3)
277  {
278  ExprEvalOp step0 = state->steps[0].opcode;
279  ExprEvalOp step1 = state->steps[1].opcode;
280 
281  if (step0 == EEOP_INNER_FETCHSOME &&
282  step1 == EEOP_INNER_VAR)
283  {
284  state->evalfunc_private = (void *) ExecJustInnerVar;
285  return;
286  }
287  else if (step0 == EEOP_OUTER_FETCHSOME &&
288  step1 == EEOP_OUTER_VAR)
289  {
290  state->evalfunc_private = (void *) ExecJustOuterVar;
291  return;
292  }
293  else if (step0 == EEOP_SCAN_FETCHSOME &&
294  step1 == EEOP_SCAN_VAR)
295  {
296  state->evalfunc_private = (void *) ExecJustScanVar;
297  return;
298  }
299  else if (step0 == EEOP_INNER_FETCHSOME &&
300  step1 == EEOP_ASSIGN_INNER_VAR)
301  {
302  state->evalfunc_private = (void *) ExecJustAssignInnerVar;
303  return;
304  }
305  else if (step0 == EEOP_OUTER_FETCHSOME &&
306  step1 == EEOP_ASSIGN_OUTER_VAR)
307  {
308  state->evalfunc_private = (void *) ExecJustAssignOuterVar;
309  return;
310  }
311  else if (step0 == EEOP_SCAN_FETCHSOME &&
312  step1 == EEOP_ASSIGN_SCAN_VAR)
313  {
314  state->evalfunc_private = (void *) ExecJustAssignScanVar;
315  return;
316  }
317  else if (step0 == EEOP_CASE_TESTVAL &&
318  step1 == EEOP_FUNCEXPR_STRICT &&
319  state->steps[0].d.casetest.value)
320  {
321  state->evalfunc_private = (void *) ExecJustApplyFuncToCase;
322  return;
323  }
324  }
325  else if (state->steps_len == 2)
326  {
327  ExprEvalOp step0 = state->steps[0].opcode;
328 
329  if (step0 == EEOP_CONST)
330  {
331  state->evalfunc_private = (void *) ExecJustConst;
332  return;
333  }
334  else if (step0 == EEOP_INNER_VAR)
335  {
336  state->evalfunc_private = (void *) ExecJustInnerVarVirt;
337  return;
338  }
339  else if (step0 == EEOP_OUTER_VAR)
340  {
341  state->evalfunc_private = (void *) ExecJustOuterVarVirt;
342  return;
343  }
344  else if (step0 == EEOP_SCAN_VAR)
345  {
346  state->evalfunc_private = (void *) ExecJustScanVarVirt;
347  return;
348  }
349  else if (step0 == EEOP_ASSIGN_INNER_VAR)
350  {
351  state->evalfunc_private = (void *) ExecJustAssignInnerVarVirt;
352  return;
353  }
354  else if (step0 == EEOP_ASSIGN_OUTER_VAR)
355  {
356  state->evalfunc_private = (void *) ExecJustAssignOuterVarVirt;
357  return;
358  }
359  else if (step0 == EEOP_ASSIGN_SCAN_VAR)
360  {
361  state->evalfunc_private = (void *) ExecJustAssignScanVarVirt;
362  return;
363  }
364  }
365 
366 #if defined(EEO_USE_COMPUTED_GOTO)
367 
368  /*
369  * In the direct-threaded implementation, replace each opcode with the
370  * address to jump to. (Use ExecEvalStepOp() to get back the opcode.)
371  */
372  for (int off = 0; off < state->steps_len; off++)
373  {
374  ExprEvalStep *op = &state->steps[off];
375 
376  op->opcode = EEO_OPCODE(op->opcode);
377  }
378 
380 #endif /* EEO_USE_COMPUTED_GOTO */
381 
382  state->evalfunc_private = (void *) ExecInterpExpr;
383 }
static Datum ExecJustAssignInnerVarVirt(ExprState *state, ExprContext *econtext, bool *isnull)
static Datum ExecJustScanVarVirt(ExprState *state, ExprContext *econtext, bool *isnull)
static Datum ExecJustApplyFuncToCase(ExprState *state, ExprContext *econtext, bool *isnull)
Datum ExecInterpExprStillValid(ExprState *state, ExprContext *econtext, bool *isNull)
static Datum ExecJustAssignScanVar(ExprState *state, ExprContext *econtext, bool *isnull)
static Datum ExecJustInnerVarVirt(ExprState *state, ExprContext *econtext, bool *isnull)
static void ExecInitInterpreter(void)
static Datum ExecJustConst(ExprState *state, ExprContext *econtext, bool *isnull)
static Datum ExecJustOuterVar(ExprState *state, ExprContext *econtext, bool *isnull)
static Datum ExecJustInnerVar(ExprState *state, ExprContext *econtext, bool *isnull)
static Datum ExecJustAssignInnerVar(ExprState *state, ExprContext *econtext, bool *isnull)
static Datum ExecJustAssignScanVarVirt(ExprState *state, ExprContext *econtext, bool *isnull)
static Datum ExecJustAssignOuterVar(ExprState *state, ExprContext *econtext, bool *isnull)
static Datum ExecJustAssignOuterVarVirt(ExprState *state, ExprContext *econtext, bool *isnull)
static Datum ExecJustOuterVarVirt(ExprState *state, ExprContext *econtext, bool *isnull)
static Datum ExecJustScanVar(ExprState *state, ExprContext *econtext, bool *isnull)
#define EEO_OPCODE(opcode)
#define EEO_FLAG_INTERPRETER_INITIALIZED
Definition: execExpr.h:29

References Assert(), EEO_FLAG_DIRECT_THREADED, EEO_FLAG_INTERPRETER_INITIALIZED, EEO_OPCODE, EEOP_ASSIGN_INNER_VAR, EEOP_ASSIGN_OUTER_VAR, EEOP_ASSIGN_SCAN_VAR, EEOP_CASE_TESTVAL, EEOP_CONST, EEOP_DONE, EEOP_FUNCEXPR_STRICT, EEOP_INNER_FETCHSOME, EEOP_INNER_VAR, EEOP_OUTER_FETCHSOME, EEOP_OUTER_VAR, EEOP_SCAN_FETCHSOME, EEOP_SCAN_VAR, ExecInitInterpreter(), ExecInterpExpr(), ExecInterpExprStillValid(), ExecJustApplyFuncToCase(), ExecJustAssignInnerVar(), ExecJustAssignInnerVarVirt(), ExecJustAssignOuterVar(), ExecJustAssignOuterVarVirt(), ExecJustAssignScanVar(), ExecJustAssignScanVarVirt(), ExecJustConst(), ExecJustInnerVar(), ExecJustInnerVarVirt(), ExecJustOuterVar(), ExecJustOuterVarVirt(), ExecJustScanVar(), ExecJustScanVarVirt(), and ExprEvalStep::op.

Referenced by ExecReadyExpr().

◆ get_cached_rowtype()

static TupleDesc get_cached_rowtype ( Oid  type_id,
int32  typmod,
ExprEvalRowtypeCache rowcache,
bool changed 
)
static

Definition at line 2072 of file execExprInterp.c.

2075 {
2076  if (type_id != RECORDOID)
2077  {
2078  /*
2079  * It's a named composite type, so use the regular typcache. Do a
2080  * lookup first time through, or if the composite type changed. Note:
2081  * "tupdesc_id == 0" may look redundant, but it protects against the
2082  * admittedly-theoretical possibility that type_id was RECORDOID the
2083  * last time through, so that the cacheptr isn't TypeCacheEntry *.
2084  */
2085  TypeCacheEntry *typentry = (TypeCacheEntry *) rowcache->cacheptr;
2086 
2087  if (unlikely(typentry == NULL ||
2088  rowcache->tupdesc_id == 0 ||
2089  typentry->tupDesc_identifier != rowcache->tupdesc_id))
2090  {
2091  typentry = lookup_type_cache(type_id, TYPECACHE_TUPDESC);
2092  if (typentry->tupDesc == NULL)
2093  ereport(ERROR,
2094  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
2095  errmsg("type %s is not composite",
2096  format_type_be(type_id))));
2097  rowcache->cacheptr = (void *) typentry;
2098  rowcache->tupdesc_id = typentry->tupDesc_identifier;
2099  if (changed)
2100  *changed = true;
2101  }
2102  return typentry->tupDesc;
2103  }
2104  else
2105  {
2106  /*
2107  * A RECORD type, once registered, doesn't change for the life of the
2108  * backend. So we don't need a typcache entry as such, which is good
2109  * because there isn't one. It's possible that the caller is asking
2110  * about a different type than before, though.
2111  */
2112  TupleDesc tupDesc = (TupleDesc) rowcache->cacheptr;
2113 
2114  if (unlikely(tupDesc == NULL ||
2115  rowcache->tupdesc_id != 0 ||
2116  type_id != tupDesc->tdtypeid ||
2117  typmod != tupDesc->tdtypmod))
2118  {
2119  tupDesc = lookup_rowtype_tupdesc(type_id, typmod);
2120  /* Drop pin acquired by lookup_rowtype_tupdesc */
2121  ReleaseTupleDesc(tupDesc);
2122  rowcache->cacheptr = (void *) tupDesc;
2123  rowcache->tupdesc_id = 0; /* not a valid value for non-RECORD */
2124  if (changed)
2125  *changed = true;
2126  }
2127  return tupDesc;
2128  }
2129 }
uint64 tupDesc_identifier
Definition: typcache.h:90
TupleDesc tupDesc
Definition: typcache.h:89
struct TupleDescData * TupleDesc
Definition: tupdesc.h:89
TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod)
Definition: typcache.c:1833
TypeCacheEntry * lookup_type_cache(Oid type_id, int flags)
Definition: typcache.c:346
#define TYPECACHE_TUPDESC
Definition: typcache.h:145

References ExprEvalRowtypeCache::cacheptr, ereport, errcode(), errmsg(), ERROR, format_type_be(), if(), lookup_rowtype_tupdesc(), lookup_type_cache(), ReleaseTupleDesc, ExprEvalStep::rowcache, TupleDescData::tdtypeid, TupleDescData::tdtypmod, TypeCacheEntry::tupDesc, ExprEvalRowtypeCache::tupdesc_id, TypeCacheEntry::tupDesc_identifier, TYPECACHE_TUPDESC, and unlikely.

Referenced by ExecEvalConvertRowtype(), ExecEvalFieldSelect(), ExecEvalFieldStoreDeForm(), ExecEvalFieldStoreForm(), and ExecEvalRowNullInt().

◆ saop_element_hash()

static uint32 saop_element_hash ( struct saophash_hash *  tb,
Datum  key 
)
static

Definition at line 3608 of file execExprInterp.c.

3609 {
3610  ScalarArrayOpExprHashTable *elements_tab = (ScalarArrayOpExprHashTable *) tb->private_data;
3611  FunctionCallInfo fcinfo = &elements_tab->hash_fcinfo_data;
3612  Datum hash;
3613 
3614  fcinfo->args[0].value = key;
3615  fcinfo->args[0].isnull = false;
3616 
3617  hash = elements_tab->hash_finfo.fn_addr(fcinfo);
3618 
3619  return DatumGetUInt32(hash);
3620 }
static uint32 DatumGetUInt32(Datum X)
Definition: postgres.h:222
static unsigned hash(unsigned *uv, int n)
Definition: rege_dfa.c:715
PGFunction fn_addr
Definition: fmgr.h:58

References DatumGetUInt32(), ExprEvalStep::elements_tab, FmgrInfo::fn_addr, hash(), ScalarArrayOpExprHashTable::hash_fcinfo_data, ScalarArrayOpExprHashTable::hash_finfo, and sort-test::key.

◆ saop_hash_element_match()

static bool saop_hash_element_match ( struct saophash_hash *  tb,
Datum  key1,
Datum  key2 
)
static

Definition at line 3627 of file execExprInterp.c.

3628 {
3629  Datum result;
3630 
3631  ScalarArrayOpExprHashTable *elements_tab = (ScalarArrayOpExprHashTable *) tb->private_data;
3632  FunctionCallInfo fcinfo = elements_tab->op->d.hashedscalararrayop.fcinfo_data;
3633 
3634  fcinfo->args[0].value = key1;
3635  fcinfo->args[0].isnull = false;
3636  fcinfo->args[1].value = key2;
3637  fcinfo->args[1].isnull = false;
3638 
3639  result = elements_tab->op->d.hashedscalararrayop.finfo->fn_addr(fcinfo);
3640 
3641  return DatumGetBool(result);
3642 }

References ExprEvalStep::d, DatumGetBool(), ExprEvalStep::elements_tab, ExprEvalStep::hashedscalararrayop, and ScalarArrayOpExprHashTable::op.