PostgreSQL Source Code git master
Loading...
Searching...
No Matches
execExprInterp.c File Reference
#include "postgres.h"
#include "access/heaptoast.h"
#include "access/tupconvert.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/tuplesort.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 Datum ExecJustHashInnerVarWithIV (ExprState *state, ExprContext *econtext, bool *isnull)
 
static Datum ExecJustHashOuterVar (ExprState *state, ExprContext *econtext, bool *isnull)
 
static Datum ExecJustHashInnerVar (ExprState *state, ExprContext *econtext, bool *isnull)
 
static Datum ExecJustHashOuterVarVirt (ExprState *state, ExprContext *econtext, bool *isnull)
 
static Datum ExecJustHashInnerVarVirt (ExprState *state, ExprContext *econtext, bool *isnull)
 
static Datum ExecJustHashOuterVarStrict (ExprState *state, ExprContext *econtext, bool *isnull)
 
static pg_attribute_always_inline void ExecEvalArrayCompareInternal (FunctionCallInfo fcinfo, ArrayType *arr, int16 typlen, bool typbyval, char typalign, bool useOr, Datum *result, bool *resultnull)
 
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 charExecGetJsonValueItemString (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)
 
static pg_attribute_always_inline Datum ExecJustHashVarImpl (ExprState *state, TupleTableSlot *slot, bool *isnull)
 
static pg_attribute_always_inline Datum ExecJustHashVarVirtImpl (ExprState *state, TupleTableSlot *slot, 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 ExecEvalParamSet (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)
 
static charGetJsonBehaviorValueString (JsonBehavior *behavior)
 
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 127 of file execExprInterp.c.

◆ EEO_DISPATCH

#define EEO_DISPATCH ( )    goto starteval

Definition at line 128 of file execExprInterp.c.

◆ EEO_JUMP

#define EEO_JUMP (   stepno)
Value:
do { \
op = &state->steps[stepno]; \
} while (0)
static int fb(int x)

Definition at line 139 of file execExprInterp.c.

140 { \
141 op = &state->steps[stepno]; \
142 EEO_DISPATCH(); \
143 } while (0)

◆ EEO_NEXT

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

Definition at line 133 of file execExprInterp.c.

134 { \
135 op++; \
136 EEO_DISPATCH(); \
137 } while (0)

◆ EEO_OPCODE

#define EEO_OPCODE (   opcode)    (opcode)

Definition at line 129 of file execExprInterp.c.

◆ EEO_SWITCH

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

Definition at line 126 of file execExprInterp.c.

◆ SH_DECLARE

#define SH_DECLARE

Definition at line 216 of file execExprInterp.c.

◆ SH_DEFINE

#define SH_DEFINE

Definition at line 245 of file execExprInterp.c.

◆ SH_ELEMENT_TYPE [1/2]

#define SH_ELEMENT_TYPE   ScalarArrayOpExprHashEntry

Definition at line 213 of file execExprInterp.c.

◆ SH_ELEMENT_TYPE [2/2]

#define SH_ELEMENT_TYPE   ScalarArrayOpExprHashEntry

Definition at line 213 of file execExprInterp.c.

◆ SH_EQUAL

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

Definition at line 241 of file execExprInterp.c.

◆ SH_GET_HASH

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

Definition at line 244 of file execExprInterp.c.

◆ SH_HASH_KEY

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

Definition at line 240 of file execExprInterp.c.

◆ SH_KEY

#define SH_KEY   key

Definition at line 239 of file execExprInterp.c.

◆ SH_KEY_TYPE [1/2]

#define SH_KEY_TYPE   Datum

Definition at line 214 of file execExprInterp.c.

◆ SH_KEY_TYPE [2/2]

#define SH_KEY_TYPE   Datum

Definition at line 214 of file execExprInterp.c.

◆ SH_PREFIX [1/2]

#define SH_PREFIX   saophash

Definition at line 212 of file execExprInterp.c.

◆ SH_PREFIX [2/2]

#define SH_PREFIX   saophash

Definition at line 212 of file execExprInterp.c.

◆ SH_SCOPE [1/2]

#define SH_SCOPE   static inline

Definition at line 215 of file execExprInterp.c.

◆ SH_SCOPE [2/2]

#define SH_SCOPE   static inline

Definition at line 215 of file execExprInterp.c.

◆ SH_STORE_HASH

#define SH_STORE_HASH

Definition at line 243 of file execExprInterp.c.

Typedef Documentation

◆ ScalarArrayOpExprHashEntry

◆ ScalarArrayOpExprHashTable

Function Documentation

◆ CheckExprStillValid()

void CheckExprStillValid ( ExprState state,
ExprContext econtext 
)

Definition at line 2317 of file execExprInterp.c.

2318{
2324
2325 innerslot = econtext->ecxt_innertuple;
2326 outerslot = econtext->ecxt_outertuple;
2327 scanslot = econtext->ecxt_scantuple;
2328 oldslot = econtext->ecxt_oldtuple;
2329 newslot = econtext->ecxt_newtuple;
2330
2331 for (int i = 0; i < state->steps_len; i++)
2332 {
2333 ExprEvalStep *op = &state->steps[i];
2334
2335 switch (ExecEvalStepOp(state, op))
2336 {
2337 case EEOP_INNER_VAR:
2338 {
2339 int attnum = op->d.var.attnum;
2340
2342 break;
2343 }
2344
2345 case EEOP_OUTER_VAR:
2346 {
2347 int attnum = op->d.var.attnum;
2348
2350 break;
2351 }
2352
2353 case EEOP_SCAN_VAR:
2354 {
2355 int attnum = op->d.var.attnum;
2356
2358 break;
2359 }
2360
2361 case EEOP_OLD_VAR:
2362 {
2363 int attnum = op->d.var.attnum;
2364
2366 break;
2367 }
2368
2369 case EEOP_NEW_VAR:
2370 {
2371 int attnum = op->d.var.attnum;
2372
2374 break;
2375 }
2376 default:
2377 break;
2378 }
2379 }
2380}
static void CheckVarSlotCompatibility(TupleTableSlot *slot, int attnum, Oid vartype)
ExprEvalOp ExecEvalStepOp(ExprState *state, ExprEvalStep *op)
@ EEOP_OLD_VAR
Definition execExpr.h:85
@ EEOP_INNER_VAR
Definition execExpr.h:82
@ EEOP_SCAN_VAR
Definition execExpr.h:84
@ EEOP_NEW_VAR
Definition execExpr.h:86
@ EEOP_OUTER_VAR
Definition execExpr.h:83
int i
Definition isn.c:77
int16 attnum
TupleTableSlot * ecxt_innertuple
Definition execnodes.h:289
TupleTableSlot * ecxt_newtuple
Definition execnodes.h:326
TupleTableSlot * ecxt_scantuple
Definition execnodes.h:287
TupleTableSlot * ecxt_oldtuple
Definition execnodes.h:324
TupleTableSlot * ecxt_outertuple
Definition execnodes.h:291
struct ExprEvalStep::@63::@65 var
union ExprEvalStep::@63 d

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

Referenced by ExecInterpExprStillValid(), and ExecRunCompiledExpr().

◆ CheckOpSlotCompatibility()

static void CheckOpSlotCompatibility ( ExprEvalStep op,
TupleTableSlot slot 
)
static

Definition at line 2443 of file execExprInterp.c.

2444{
2445#ifdef USE_ASSERT_CHECKING
2446 /* there's nothing to check */
2447 if (!op->d.fetch.fixed)
2448 return;
2449
2450 /*
2451 * Should probably fixed at some point, but for now it's easier to allow
2452 * buffer and heap tuples to be used interchangeably.
2453 */
2454 if (slot->tts_ops == &TTSOpsBufferHeapTuple &&
2455 op->d.fetch.kind == &TTSOpsHeapTuple)
2456 return;
2457 if (slot->tts_ops == &TTSOpsHeapTuple &&
2459 return;
2460
2461 /*
2462 * At the moment we consider it OK if a virtual slot is used instead of a
2463 * specific type of slot, as a virtual slot never needs to be deformed.
2464 */
2465 if (slot->tts_ops == &TTSOpsVirtual)
2466 return;
2467
2468 Assert(op->d.fetch.kind == slot->tts_ops);
2469#endif
2470}
#define Assert(condition)
Definition c.h:943
const TupleTableSlotOps TTSOpsVirtual
Definition execTuples.c:84
const TupleTableSlotOps TTSOpsBufferHeapTuple
Definition execTuples.c:87
const TupleTableSlotOps TTSOpsHeapTuple
Definition execTuples.c:85
struct ExprEvalStep::@63::@64 fetch
const TupleTableSlotOps * kind
Definition execExpr.h:331
const TupleTableSlotOps *const tts_ops
Definition tuptable.h:127

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

Referenced by ExecInterpExpr(), ExecJustAssignVarImpl(), ExecJustHashInnerVarWithIV(), ExecJustHashOuterVarStrict(), ExecJustHashVarImpl(), and ExecJustVarImpl().

◆ CheckVarSlotCompatibility()

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

Definition at line 2388 of file execExprInterp.c.

2389{
2390 /*
2391 * What we have to check for here is the possibility of an attribute
2392 * having been dropped or changed in type since the plan tree was created.
2393 * Ideally the plan will get invalidated and not re-used, but just in
2394 * case, we keep these defenses. Fortunately it's sufficient to check
2395 * once on the first time through.
2396 *
2397 * Note: ideally we'd check typmod as well as typid, but that seems
2398 * impractical at the moment: in many cases the tupdesc will have been
2399 * generated by ExecTypeFromTL(), and that can't guarantee to generate an
2400 * accurate typmod in all cases, because some expression node types don't
2401 * carry typmod. Fortunately, for precisely that reason, there should be
2402 * no places with a critical dependency on the typmod of a value.
2403 *
2404 * System attributes don't require checking since their types never
2405 * change.
2406 */
2407 if (attnum > 0)
2408 {
2410 Form_pg_attribute attr;
2411
2412 if (attnum > slot_tupdesc->natts) /* should never happen */
2413 elog(ERROR, "attribute number %d exceeds number of columns %d",
2414 attnum, slot_tupdesc->natts);
2415
2416 attr = TupleDescAttr(slot_tupdesc, attnum - 1);
2417
2418 /* Internal error: somebody forgot to expand it. */
2419 if (attr->attgenerated == ATTRIBUTE_GENERATED_VIRTUAL)
2420 elog(ERROR, "unexpected virtual generated column reference");
2421
2422 if (attr->attisdropped)
2423 ereport(ERROR,
2425 errmsg("attribute %d of type %s has been dropped",
2426 attnum, format_type_be(slot_tupdesc->tdtypeid))));
2427
2428 if (vartype != attr->atttypid)
2429 ereport(ERROR,
2431 errmsg("attribute %d of type %s has wrong type",
2432 attnum, format_type_be(slot_tupdesc->tdtypeid)),
2433 errdetail("Table has type %s, but query expects %s.",
2434 format_type_be(attr->atttypid),
2435 format_type_be(vartype))));
2436 }
2437}
int errcode(int sqlerrcode)
Definition elog.c:875
int errdetail(const char *fmt,...) pg_attribute_printf(1
#define ERROR
Definition elog.h:40
#define elog(elevel,...)
Definition elog.h:228
#define ereport(elevel,...)
Definition elog.h:152
char * format_type_be(Oid type_oid)
static char * errmsg
FormData_pg_attribute * Form_pg_attribute
TupleDesc tts_tupleDescriptor
Definition tuptable.h:129
static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)
Definition tupdesc.h:178

References attnum, elog, ereport, errcode(), errdetail(), errmsg, ERROR, fb(), format_type_be(), 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 5743 of file execExprInterp.c.

5746{
5748
5749 if (!newValueIsNull)
5750 {
5751 MemoryContextSwitchTo(aggstate->curaggcontext->ecxt_per_tuple_memory);
5753 false,
5754 pertrans->transtypeLen) &&
5756 /* do nothing */ ;
5757 else
5759 pertrans->transtypeByVal,
5760 pertrans->transtypeLen);
5761 }
5762 else
5763 {
5764 /*
5765 * Ensure that AggStatePerGroup->transValue ends up being 0, so
5766 * callers can safely compare newValue/oldValue without having to
5767 * check their respective nullness.
5768 */
5769 newValue = (Datum) 0;
5770 }
5771
5772 if (!oldValueIsNull)
5773 {
5775 false,
5776 pertrans->transtypeLen))
5778 else
5780 }
5781
5782 return newValue;
5783}
Datum datumCopy(Datum value, bool typByVal, int typLen)
Definition datum.c:132
ExpandedObjectHeader * DatumGetEOHP(Datum d)
void DeleteExpandedObject(Datum d)
#define DatumIsReadWriteExpandedObject(d, isnull, typlen)
void pfree(void *pointer)
Definition mcxt.c:1616
MemoryContext CurrentMemoryContext
Definition mcxt.c:160
MemoryContext MemoryContextGetParent(MemoryContext context)
Definition mcxt.c:780
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition palloc.h:124
uint64_t Datum
Definition postgres.h:70
static Pointer DatumGetPointer(Datum X)
Definition postgres.h:332

References Assert, CurrentMemoryContext, datumCopy(), DatumGetEOHP(), DatumGetPointer(), DatumIsReadWriteExpandedObject, DeleteExpandedObject(), fb(), 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 5690 of file execExprInterp.c.

5692{
5693 FunctionCallInfo fcinfo = pertrans->transfn_fcinfo;
5695
5696 /*
5697 * We must copy the datum into aggcontext if it is pass-by-ref. We do not
5698 * need to pfree the old transValue, since it's NULL. (We already checked
5699 * that the agg's input type is binary-compatible with its transtype, so
5700 * straight copy here is OK.)
5701 */
5703 pergroup->transValue = datumCopy(fcinfo->args[1].value,
5704 pertrans->transtypeByVal,
5705 pertrans->transtypeLen);
5706 pergroup->transValueIsNull = false;
5707 pergroup->noTransValue = false;
5709}
FunctionCallInfo transfn_fcinfo
Definition nodeAgg.h:170
MemoryContext ecxt_per_tuple_memory
Definition execnodes.h:295
NullableDatum args[FLEXIBLE_ARRAY_MEMBER]
Definition fmgr.h:95
Datum value
Definition postgres.h:87

References ExprEvalStep::aggcontext, FunctionCallInfoBaseData::args, datumCopy(), ExprContext::ecxt_per_tuple_memory, fb(), MemoryContextSwitchTo(), ExprEvalStep::pertrans, AggStatePerTransData::transfn_fcinfo, AggStatePerTransData::transtypeByVal, AggStatePerTransData::transtypeLen, 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 5942 of file execExprInterp.c.

5945{
5946 FunctionCallInfo fcinfo = pertrans->transfn_fcinfo;
5948 Datum newVal;
5949
5950 /* cf. select_current_set() */
5951 aggstate->curaggcontext = aggcontext;
5952 aggstate->current_set = setno;
5953
5954 /* set up aggstate->curpertrans for AggGetAggref() */
5955 aggstate->curpertrans = pertrans;
5956
5957 /* invoke transition function in per-tuple context */
5958 oldContext = MemoryContextSwitchTo(aggstate->tmpcontext->ecxt_per_tuple_memory);
5959
5960 fcinfo->args[0].value = pergroup->transValue;
5961 fcinfo->args[0].isnull = pergroup->transValueIsNull;
5962 fcinfo->isnull = false; /* just in case transfn doesn't set it */
5963
5964 newVal = FunctionCallInvoke(fcinfo);
5965
5966 /*
5967 * For pass-by-ref datatype, must copy the new value into aggcontext and
5968 * free the prior transValue. But if transfn returned a pointer to its
5969 * first input, we don't need to do anything.
5970 *
5971 * It's safe to compare newVal with pergroup->transValue without regard
5972 * for either being NULL, because ExecAggCopyTransValue takes care to set
5973 * transValue to 0 when NULL. Otherwise we could end up accidentally not
5974 * reparenting, when the transValue has the same numerical value as
5975 * newValue, despite being NULL. This is a somewhat hot path, making it
5976 * undesirable to instead solve this with another branch for the common
5977 * case of the transition function returning its (modified) input
5978 * argument.
5979 */
5980 if (DatumGetPointer(newVal) != DatumGetPointer(pergroup->transValue))
5981 newVal = ExecAggCopyTransValue(aggstate, pertrans,
5982 newVal, fcinfo->isnull,
5983 pergroup->transValue,
5984 pergroup->transValueIsNull);
5985
5986 pergroup->transValue = newVal;
5987 pergroup->transValueIsNull = fcinfo->isnull;
5988
5990}
Datum ExecAggCopyTransValue(AggState *aggstate, AggStatePerTrans pertrans, Datum newValue, bool newValueIsNull, Datum oldValue, bool oldValueIsNull)
#define FunctionCallInvoke(fcinfo)
Definition fmgr.h:172

References ExprEvalStep::aggcontext, FunctionCallInfoBaseData::args, DatumGetPointer(), ExecAggCopyTransValue(), fb(), FunctionCallInvoke, FunctionCallInfoBaseData::isnull, NullableDatum::isnull, MemoryContextSwitchTo(), ExprEvalStep::pertrans, ExprEvalStep::setno, AggStatePerTransData::transfn_fcinfo, 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 5910 of file execExprInterp.c.

5913{
5914 FunctionCallInfo fcinfo = pertrans->transfn_fcinfo;
5916 Datum newVal;
5917
5918 /* cf. select_current_set() */
5919 aggstate->curaggcontext = aggcontext;
5920 aggstate->current_set = setno;
5921
5922 /* set up aggstate->curpertrans for AggGetAggref() */
5923 aggstate->curpertrans = pertrans;
5924
5925 /* invoke transition function in per-tuple context */
5926 oldContext = MemoryContextSwitchTo(aggstate->tmpcontext->ecxt_per_tuple_memory);
5927
5928 fcinfo->args[0].value = pergroup->transValue;
5929 fcinfo->args[0].isnull = pergroup->transValueIsNull;
5930 fcinfo->isnull = false; /* just in case transfn doesn't set it */
5931
5932 newVal = FunctionCallInvoke(fcinfo);
5933
5934 pergroup->transValue = newVal;
5935 pergroup->transValueIsNull = fcinfo->isnull;
5936
5938}

References ExprEvalStep::aggcontext, FunctionCallInfoBaseData::args, fb(), FunctionCallInvoke, FunctionCallInfoBaseData::isnull, NullableDatum::isnull, MemoryContextSwitchTo(), ExprEvalStep::pertrans, ExprEvalStep::setno, AggStatePerTransData::transfn_fcinfo, and NullableDatum::value.

Referenced by ExecInterpExpr().

◆ ExecEvalAggOrderedTransDatum()

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

Definition at line 5882 of file execExprInterp.c.

5884{
5885 AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
5886 int setno = op->d.agg_trans.setno;
5887
5888 tuplesort_putdatum(pertrans->sortstates[setno],
5889 *op->resvalue, *op->resnull);
5890}
Tuplesortstate ** sortstates
Definition nodeAgg.h:162
AggStatePerTrans pertrans
Definition execExpr.h:735
Datum * resvalue
Definition execExpr.h:310
bool * resnull
Definition execExpr.h:311
struct ExprEvalStep::@63::@109 agg_trans
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 5896 of file execExprInterp.c.

5898{
5899 AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
5900 int setno = op->d.agg_trans.setno;
5901
5902 ExecClearTuple(pertrans->sortslot);
5903 pertrans->sortslot->tts_nvalid = pertrans->numInputs;
5905 tuplesort_puttupleslot(pertrans->sortstates[setno], pertrans->sortslot);
5906}
TupleTableSlot * ExecStoreVirtualTuple(TupleTableSlot *slot)
TupleTableSlot * sortslot
Definition nodeAgg.h:141
AttrNumber tts_nvalid
Definition tuptable.h:126
void tuplesort_puttupleslot(Tuplesortstate *state, TupleTableSlot *slot)
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition tuptable.h:476

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

3626{
3628
3629 /* NULL array -> NULL result */
3630 if (*op->resnull)
3631 return;
3632
3633 arraydatum = *op->resvalue;
3634
3635 /*
3636 * If it's binary-compatible, modify the element type in the array header,
3637 * but otherwise leave the array as we received it.
3638 */
3639 if (op->d.arraycoerce.elemexprstate == NULL)
3640 {
3641 /* Detoast input array if necessary, and copy in any case */
3643
3645 *op->resvalue = PointerGetDatum(array);
3646 return;
3647 }
3648
3649 /*
3650 * Use array_map to apply the sub-expression to each array element.
3651 */
3654 econtext,
3656 op->d.arraycoerce.amstate);
3657}
#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)
#define PointerGetDatum(X)
Definition postgres.h:354
ExprState * elemexprstate
Definition execExpr.h:493
Oid resultelemtype
Definition execExpr.h:494
struct ExprEvalStep::@63::@84 arraycoerce
struct ArrayMapState * amstate
Definition execExpr.h:495

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

Referenced by ExecInterpExpr().

◆ ExecEvalArrayCompareInternal()

static pg_attribute_always_inline void ExecEvalArrayCompareInternal ( FunctionCallInfo  fcinfo,
ArrayType arr,
int16  typlen,
bool  typbyval,
char  typalign,
bool  useOr,
Datum result,
bool resultnull 
)
static

Definition at line 4111 of file execExprInterp.c.

4114{
4115 uint8 typalignby = typalign_to_alignby(typalign);
4116 int nitems;
4117 char *s;
4118 uint8 *bitmap;
4119 int bitmask;
4120 bool strictfunc = fcinfo->flinfo->fn_strict;
4121
4122 nitems = ArrayGetNItems(ARR_NDIM(arr), ARR_DIMS(arr));
4123
4124 /* Initialize result appropriately depending on useOr */
4125 *result = BoolGetDatum(!useOr);
4126 *resultnull = false;
4127
4128 /* Loop over the array elements */
4129 s = (char *) ARR_DATA_PTR(arr);
4130 bitmap = ARR_NULLBITMAP(arr);
4131 bitmask = 1;
4132
4133 for (int i = 0; i < nitems; i++)
4134 {
4135 Datum elt;
4137
4138 /* Get array element, checking for NULL */
4139 if (bitmap && (*bitmap & bitmask) == 0)
4140 {
4141 fcinfo->args[1].value = (Datum) 0;
4142 fcinfo->args[1].isnull = true;
4143 }
4144 else
4145 {
4146 elt = fetch_att(s, typbyval, typlen);
4147 s = att_addlength_pointer(s, typlen, s);
4148 s = (char *) att_nominal_alignby(s, typalignby);
4149 fcinfo->args[1].value = elt;
4150 fcinfo->args[1].isnull = false;
4151 }
4152
4153 /* Call comparison function */
4154 if (fcinfo->args[1].isnull && strictfunc)
4155 {
4156 fcinfo->isnull = true;
4157 thisresult = (Datum) 0;
4158 }
4159 else
4160 {
4161 fcinfo->isnull = false;
4162 thisresult = fcinfo->flinfo->fn_addr(fcinfo);
4163 }
4164
4165 /* Combine results per OR or AND semantics */
4166 if (fcinfo->isnull)
4167 *resultnull = true;
4168 else if (useOr)
4169 {
4171 {
4172 *result = BoolGetDatum(true);
4173 *resultnull = false;
4174 break; /* needn't look at any more elements */
4175 }
4176 }
4177 else
4178 {
4180 {
4181 *result = BoolGetDatum(false);
4182 *resultnull = false;
4183 break; /* needn't look at any more elements */
4184 }
4185 }
4186
4187 /* advance bitmap pointer if any */
4188 if (bitmap)
4189 {
4190 bitmask <<= 1;
4191 if (bitmask == 0x100)
4192 {
4193 bitmap++;
4194 bitmask = 1;
4195 }
4196 }
4197 }
4198}
#define ARR_NDIM(a)
Definition array.h:290
#define ARR_DATA_PTR(a)
Definition array.h:322
#define ARR_NULLBITMAP(a)
Definition array.h:300
#define ARR_DIMS(a)
Definition array.h:294
int ArrayGetNItems(int ndim, const int *dims)
Definition arrayutils.c:57
uint8_t uint8
Definition c.h:622
uint32 result
#define nitems(x)
Definition indent.h:31
char typalign
Definition pg_type.h:178
static bool DatumGetBool(Datum X)
Definition postgres.h:100
static Datum BoolGetDatum(bool X)
Definition postgres.h:112
PGFunction fn_addr
Definition fmgr.h:58
bool fn_strict
Definition fmgr.h:61
FmgrInfo * flinfo
Definition fmgr.h:87
#define att_nominal_alignby(cur_offset, attalignby)
Definition tupmacs.h:411
#define att_addlength_pointer(cur_offset, attlen, attptr)
Definition tupmacs.h:431
static uint8 typalign_to_alignby(char typalign)
Definition tupmacs.h:302
static Datum fetch_att(const void *T, bool attbyval, int attlen)
Definition tupmacs.h:108

References FunctionCallInfoBaseData::args, ARR_DATA_PTR, ARR_DIMS, ARR_NDIM, ARR_NULLBITMAP, ArrayGetNItems(), att_addlength_pointer, att_nominal_alignby, BoolGetDatum(), DatumGetBool(), fb(), fetch_att(), FunctionCallInfoBaseData::flinfo, FmgrInfo::fn_addr, FmgrInfo::fn_strict, i, FunctionCallInfoBaseData::isnull, NullableDatum::isnull, nitems, result, typalign, typalign_to_alignby(), ExprEvalStep::typbyval, ExprEvalStep::typlen, ExprEvalStep::useOr, and NullableDatum::value.

Referenced by ExecEvalHashedScalarArrayOp(), and ExecEvalScalarArrayOp().

◆ ExecEvalArrayExpr()

void ExecEvalArrayExpr ( ExprState state,
ExprEvalStep op 
)

Definition at line 3411 of file execExprInterp.c.

3412{
3414 Oid element_type = op->d.arrayexpr.elemtype;
3415 int nelems = op->d.arrayexpr.nelems;
3416 int ndims = 0;
3417 int dims[MAXDIM];
3418 int lbs[MAXDIM];
3419
3420 /* Set non-null as default */
3421 *op->resnull = false;
3422
3423 if (!op->d.arrayexpr.multidims)
3424 {
3425 /* Elements are presumably of scalar type */
3426 Datum *dvalues = op->d.arrayexpr.elemvalues;
3427 bool *dnulls = op->d.arrayexpr.elemnulls;
3428
3429 /* setup for 1-D array of the given length */
3430 ndims = 1;
3431 dims[0] = nelems;
3432 lbs[0] = 1;
3433
3434 result = construct_md_array(dvalues, dnulls, ndims, dims, lbs,
3435 element_type,
3437 op->d.arrayexpr.elembyval,
3438 op->d.arrayexpr.elemalign);
3439 }
3440 else
3441 {
3442 /* Must be nested array expressions */
3443 int nbytes = 0;
3444 int nitems;
3445 int outer_nelems = 0;
3446 int elem_ndims = 0;
3447 int *elem_dims = NULL;
3448 int *elem_lbs = NULL;
3449 bool firstone = true;
3450 bool havenulls = false;
3451 bool haveempty = false;
3452 char **subdata;
3453 uint8 **subbitmaps;
3454 int *subbytes;
3455 int *subnitems;
3456 int32 dataoffset;
3457 char *dat;
3458 int iitem;
3459
3460 subdata = (char **) palloc(nelems * sizeof(char *));
3461 subbitmaps = (uint8 **) palloc(nelems * sizeof(uint8 *));
3462 subbytes = (int *) palloc(nelems * sizeof(int));
3463 subnitems = (int *) palloc(nelems * sizeof(int));
3464
3465 /* loop through and get data area from each element */
3466 for (int elemoff = 0; elemoff < nelems; elemoff++)
3467 {
3469 bool eisnull;
3470 ArrayType *array;
3471 int this_ndims;
3472
3475
3476 /* temporarily ignore null subarrays */
3477 if (eisnull)
3478 {
3479 haveempty = true;
3480 continue;
3481 }
3482
3484
3485 /* run-time double-check on element type */
3486 if (element_type != ARR_ELEMTYPE(array))
3487 ereport(ERROR,
3489 errmsg("cannot merge incompatible arrays"),
3490 errdetail("Array with element type %s cannot be "
3491 "included in ARRAY construct with element type %s.",
3493 format_type_be(element_type))));
3494
3495 this_ndims = ARR_NDIM(array);
3496 /* temporarily ignore zero-dimensional subarrays */
3497 if (this_ndims <= 0)
3498 {
3499 haveempty = true;
3500 continue;
3501 }
3502
3503 if (firstone)
3504 {
3505 /* Get sub-array details from first member */
3507 ndims = elem_ndims + 1;
3509 ereport(ERROR,
3511 errmsg("number of array dimensions (%d) exceeds the maximum allowed (%d)",
3512 ndims, MAXDIM)));
3513
3514 elem_dims = (int *) palloc(elem_ndims * sizeof(int));
3515 memcpy(elem_dims, ARR_DIMS(array), elem_ndims * sizeof(int));
3516 elem_lbs = (int *) palloc(elem_ndims * sizeof(int));
3517 memcpy(elem_lbs, ARR_LBOUND(array), elem_ndims * sizeof(int));
3518
3519 firstone = false;
3520 }
3521 else
3522 {
3523 /* Check other sub-arrays are compatible */
3524 if (elem_ndims != this_ndims ||
3525 memcmp(elem_dims, ARR_DIMS(array),
3526 elem_ndims * sizeof(int)) != 0 ||
3527 memcmp(elem_lbs, ARR_LBOUND(array),
3528 elem_ndims * sizeof(int)) != 0)
3529 ereport(ERROR,
3531 errmsg("multidimensional arrays must have array "
3532 "expressions with matching dimensions")));
3533 }
3534
3537 subbytes[outer_nelems] = ARR_SIZE(array) - ARR_DATA_OFFSET(array);
3538 nbytes += subbytes[outer_nelems];
3539 /* check for overflow of total request */
3540 if (!AllocSizeIsValid(nbytes))
3541 ereport(ERROR,
3543 errmsg("array size exceeds the maximum allowed (%d)",
3544 (int) MaxAllocSize)));
3546 ARR_DIMS(array));
3547 havenulls |= ARR_HASNULL(array);
3548 outer_nelems++;
3549 }
3550
3551 /*
3552 * If all items were null or empty arrays, return an empty array;
3553 * otherwise, if some were and some weren't, raise error. (Note: we
3554 * must special-case this somehow to avoid trying to generate a 1-D
3555 * array formed from empty arrays. It's not ideal...)
3556 */
3557 if (haveempty)
3558 {
3559 if (ndims == 0) /* didn't find any nonempty array */
3560 {
3561 *op->resvalue = PointerGetDatum(construct_empty_array(element_type));
3562 return;
3563 }
3564 ereport(ERROR,
3566 errmsg("multidimensional arrays must have array "
3567 "expressions with matching dimensions")));
3568 }
3569
3570 /* setup for multi-D array */
3571 dims[0] = outer_nelems;
3572 lbs[0] = 1;
3573 for (int i = 1; i < ndims; i++)
3574 {
3575 dims[i] = elem_dims[i - 1];
3576 lbs[i] = elem_lbs[i - 1];
3577 }
3578
3579 /* check for subscript overflow */
3580 nitems = ArrayGetNItems(ndims, dims);
3581 ArrayCheckBounds(ndims, dims, lbs);
3582
3583 if (havenulls)
3584 {
3585 dataoffset = ARR_OVERHEAD_WITHNULLS(ndims, nitems);
3586 nbytes += dataoffset;
3587 }
3588 else
3589 {
3590 dataoffset = 0; /* marker for no null bitmap */
3591 nbytes += ARR_OVERHEAD_NONULLS(ndims);
3592 }
3593
3594 result = (ArrayType *) palloc0(nbytes);
3595 SET_VARSIZE(result, nbytes);
3596 result->ndim = ndims;
3597 result->dataoffset = dataoffset;
3598 result->elemtype = element_type;
3599 memcpy(ARR_DIMS(result), dims, ndims * sizeof(int));
3600 memcpy(ARR_LBOUND(result), lbs, ndims * sizeof(int));
3601
3603 iitem = 0;
3604 for (int i = 0; i < outer_nelems; i++)
3605 {
3607 dat += subbytes[i];
3608 if (havenulls)
3610 subbitmaps[i], 0,
3611 subnitems[i]);
3612 iitem += subnitems[i];
3613 }
3614 }
3615
3617}
#define MAXDIM
Definition array.h:75
#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_HASNULL(a)
Definition array.h:291
#define ARR_LBOUND(a)
Definition array.h:296
ArrayType * construct_empty_array(Oid elmtype)
void array_bitmap_copy(uint8 *destbitmap, int destoffset, const uint8 *srcbitmap, int srcoffset, int nitems)
ArrayType * construct_md_array(Datum *elems, bool *nulls, int ndims, int *dims, int *lbs, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
void ArrayCheckBounds(int ndim, const int *dims, const int *lb)
Definition arrayutils.c:117
int32_t int32
Definition c.h:620
memcpy(sums, checksumBaseOffsets, sizeof(checksumBaseOffsets))
#define MaxAllocSize
Definition fe_memutils.h:22
void * palloc0(Size size)
Definition mcxt.c:1417
void * palloc(Size size)
Definition mcxt.c:1387
#define AllocSizeIsValid(size)
Definition memutils.h:42
unsigned int Oid
struct ExprEvalStep::@63::@83 arrayexpr
char elemalign
Definition execExpr.h:486
bool * elemnulls
Definition execExpr.h:481
bool multidims
Definition execExpr.h:487
int16 elemlength
Definition execExpr.h:484
bool elembyval
Definition execExpr.h:485
Datum * elemvalues
Definition execExpr.h:480
static void SET_VARSIZE(void *PTR, Size len)
Definition varatt.h:432

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(), DatumGetArrayTypeP, ExprEvalStep::element_type, ArrayType::elemtype, ereport, errcode(), errdetail(), errmsg, ERROR, fb(), format_type_be(), i, MaxAllocSize, MAXDIM, memcpy(), ExprEvalStep::nelems, nitems, ExprEvalStep::op, palloc(), palloc0(), PointerGetDatum, result, and SET_VARSIZE().

Referenced by ExecInterpExpr().

◆ ExecEvalCoerceViaIOSafe()

void ExecEvalCoerceViaIOSafe ( ExprState state,
ExprEvalStep op 
)

Definition at line 3145 of file execExprInterp.c.

3146{
3147 char *str;
3148
3149 /* call output function (similar to OutputFunctionCall) */
3150 if (*op->resnull)
3151 {
3152 /* output functions are not called on nulls */
3153 str = NULL;
3154 }
3155 else
3156 {
3158
3160 fcinfo_out->args[0].value = *op->resvalue;
3161 fcinfo_out->args[0].isnull = false;
3162
3163 fcinfo_out->isnull = false;
3165
3166 /* OutputFunctionCall assumes result isn't null */
3167 Assert(!fcinfo_out->isnull);
3168 }
3169
3170 /* call input function (similar to InputFunctionCallSafe) */
3171 if (!op->d.iocoerce.finfo_in->fn_strict || str != NULL)
3172 {
3174
3177 fcinfo_in->args[0].isnull = *op->resnull;
3178 /* second and third arguments are already set up */
3179
3180 /* ErrorSaveContext must be present. */
3182
3183 fcinfo_in->isnull = false;
3185
3186 if (SOFT_ERROR_OCCURRED(fcinfo_in->context))
3187 {
3188 *op->resnull = true;
3189 *op->resvalue = (Datum) 0;
3190 return;
3191 }
3192
3193 /* Should get null result if and only if str is NULL */
3194 if (str == NULL)
3195 Assert(*op->resnull);
3196 else
3197 Assert(!*op->resnull);
3198 }
3199}
const char * str
#define SOFT_ERROR_OCCURRED(escontext)
Definition miscnodes.h:53
#define IsA(nodeptr, _type_)
Definition nodes.h:164
static char * DatumGetCString(Datum X)
Definition postgres.h:365
struct ExprEvalStep::@63::@80 iocoerce
FunctionCallInfo fcinfo_data_in
Definition execExpr.h:461
FmgrInfo * finfo_in
Definition execExpr.h:460
FunctionCallInfo fcinfo_data_out
Definition execExpr.h:458

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

Referenced by ExecInterpExpr().

◆ ExecEvalConstraintCheck()

void ExecEvalConstraintCheck ( ExprState state,
ExprEvalStep op 
)

Definition at line 4498 of file execExprInterp.c.

4499{
4500 if (!*op->d.domaincheck.checknull &&
4504 errmsg("value for domain %s violates check constraint \"%s\"",
4509}
int errdomainconstraint(Oid datatypeOid, const char *conname)
Definition domains.c:431
#define errsave(context,...)
Definition elog.h:264
bool * checknull
Definition execExpr.h:589
struct ExprEvalStep::@63::@93 domaincheck
Datum * checkvalue
Definition execExpr.h:588
ErrorSaveContext * escontext
Definition execExpr.h:592
char * constraintname
Definition execExpr.h:586
Definition nodes.h:135

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

Referenced by ExecInterpExpr().

◆ ExecEvalConstraintNotNull()

void ExecEvalConstraintNotNull ( ExprState state,
ExprEvalStep op 
)

Definition at line 4484 of file execExprInterp.c.

4485{
4486 if (*op->resnull)
4489 errmsg("domain %s does not allow null values",
4492}
int errdatatype(Oid datatypeOid)
Definition domains.c:407

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

Referenced by ExecInterpExpr().

◆ ExecEvalConvertRowtype()

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

Definition at line 3938 of file execExprInterp.c.

3939{
3942 HeapTupleHeader tuple;
3944 TupleDesc indesc,
3945 outdesc;
3946 bool changed = false;
3947
3948 /* NULL in -> NULL out */
3949 if (*op->resnull)
3950 return;
3951
3952 tupDatum = *op->resvalue;
3954
3955 /*
3956 * Lookup tupdescs if first time through or if type changes. We'd better
3957 * pin them since type conversion functions could do catalog lookups and
3958 * hence cause cache invalidation.
3959 */
3962 &changed);
3963 IncrTupleDescRefCount(indesc);
3966 &changed);
3967 IncrTupleDescRefCount(outdesc);
3968
3969 /*
3970 * We used to be able to assert that incoming tuples are marked with
3971 * exactly the rowtype of indesc. However, now that ExecEvalWholeRowVar
3972 * might change the tuples' marking to plain RECORD due to inserting
3973 * aliases, we can only make this weak test:
3974 */
3975 Assert(HeapTupleHeaderGetTypeId(tuple) == indesc->tdtypeid ||
3977
3978 /* if first time through, or after change, initialize conversion map */
3979 if (changed)
3980 {
3982
3983 /* allocate map in long-lived memory context */
3985
3986 /* prepare map from old to new attribute numbers */
3987 op->d.convert_rowtype.map = convert_tuples_by_name(indesc, outdesc);
3988
3990 }
3991
3992 /* Following steps need a HeapTuple not a bare HeapTupleHeader */
3994 tmptup.t_data = tuple;
3995
3996 if (op->d.convert_rowtype.map != NULL)
3997 {
3998 /* Full conversion with attribute rearrangement needed */
4000 /* Result already has appropriate composite-datum header fields */
4002 }
4003 else
4004 {
4005 /*
4006 * The tuple is physically compatible as-is, but we need to insert the
4007 * destination rowtype OID in its composite-datum header field, so we
4008 * have to copy it anyway. heap_copy_tuple_as_datum() is convenient
4009 * for this since it will both make the physical copy and insert the
4010 * correct composite header fields. Note that we aren't expecting to
4011 * have to flatten any toasted fields: the input was a composite
4012 * datum, so it shouldn't contain any. So heap_copy_tuple_as_datum()
4013 * is overkill here, but its check for external fields is cheap.
4014 */
4015 *op->resvalue = heap_copy_tuple_as_datum(&tmptup, outdesc);
4016 }
4017
4018 DecrTupleDescRefCount(indesc);
4019 DecrTupleDescRefCount(outdesc);
4020}
static TupleDesc get_cached_rowtype(Oid type_id, int32 typmod, ExprEvalRowtypeCache *rowcache, bool *changed)
#define DatumGetHeapTupleHeader(X)
Definition fmgr.h:296
static Datum HeapTupleGetDatum(const HeapTupleData *tuple)
Definition funcapi.h:230
Datum heap_copy_tuple_as_datum(HeapTuple tuple, TupleDesc tupleDesc)
Definition heaptuple.c:989
static uint32 HeapTupleHeaderGetDatumLength(const HeapTupleHeaderData *tup)
static Oid HeapTupleHeaderGetTypeId(const HeapTupleHeaderData *tup)
MemoryContext ecxt_per_query_memory
Definition execnodes.h:294
TupleConversionMap * map
Definition execExpr.h:621
ExprEvalRowtypeCache * incache
Definition execExpr.h:619
ExprEvalRowtypeCache * outcache
Definition execExpr.h:620
struct ExprEvalStep::@63::@96 convert_rowtype
TupleConversionMap * convert_tuples_by_name(TupleDesc indesc, TupleDesc outdesc)
Definition tupconvert.c:103
HeapTuple execute_attr_map_tuple(HeapTuple tuple, TupleConversionMap *map)
Definition tupconvert.c:155
void DecrTupleDescRefCount(TupleDesc tupdesc)
Definition tupdesc.c:635
void IncrTupleDescRefCount(TupleDesc tupdesc)
Definition tupdesc.c:617

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

Referenced by ExecInterpExpr().

◆ ExecEvalCurrentOfExpr()

void ExecEvalCurrentOfExpr ( ExprState state,
ExprEvalStep op 
)

Definition at line 3272 of file execExprInterp.c.

3273{
3274 ereport(ERROR,
3276 errmsg("WHERE CURRENT OF is not supported for this table type")));
3277}

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

Referenced by ExecInterpExpr().

◆ ExecEvalFieldSelect()

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

Definition at line 3739 of file execExprInterp.c.

3740{
3741 AttrNumber fieldnum = op->d.fieldselect.fieldnum;
3743 HeapTupleHeader tuple;
3744 Oid tupType;
3746 TupleDesc tupDesc;
3747 Form_pg_attribute attr;
3749
3750 /* NULL record -> NULL result */
3751 if (*op->resnull)
3752 return;
3753
3754 tupDatum = *op->resvalue;
3755
3756 /* We can special-case expanded records for speed */
3758 {
3760
3761 Assert(erh->er_magic == ER_MAGIC);
3762
3763 /* Extract record's TupleDesc */
3764 tupDesc = expanded_record_get_tupdesc(erh);
3765
3766 /*
3767 * Find field's attr record. Note we don't support system columns
3768 * here: a datum tuple doesn't have valid values for most of the
3769 * interesting system columns anyway.
3770 */
3771 if (fieldnum <= 0) /* should never happen */
3772 elog(ERROR, "unsupported reference to system column %d in FieldSelect",
3773 fieldnum);
3774 if (fieldnum > tupDesc->natts) /* should never happen */
3775 elog(ERROR, "attribute number %d exceeds number of columns %d",
3776 fieldnum, tupDesc->natts);
3777 attr = TupleDescAttr(tupDesc, fieldnum - 1);
3778
3779 /* Check for dropped column, and force a NULL result if so */
3780 if (attr->attisdropped)
3781 {
3782 *op->resnull = true;
3783 return;
3784 }
3785
3786 /* Check for type mismatch --- possible after ALTER COLUMN TYPE? */
3787 /* As in CheckVarSlotCompatibility, we should but can't check typmod */
3788 if (op->d.fieldselect.resulttype != attr->atttypid)
3789 ereport(ERROR,
3791 errmsg("attribute %d has wrong type", fieldnum),
3792 errdetail("Table has type %s, but query expects %s.",
3793 format_type_be(attr->atttypid),
3795
3796 /* extract the field */
3797 *op->resvalue = expanded_record_get_field(erh, fieldnum,
3798 op->resnull);
3799 }
3800 else
3801 {
3802 /* Get the composite datum and extract its type fields */
3804
3807
3808 /* Lookup tupdesc if first time through or if type changes */
3810 &op->d.fieldselect.rowcache, NULL);
3811
3812 /*
3813 * Find field's attr record. Note we don't support system columns
3814 * here: a datum tuple doesn't have valid values for most of the
3815 * interesting system columns anyway.
3816 */
3817 if (fieldnum <= 0) /* should never happen */
3818 elog(ERROR, "unsupported reference to system column %d in FieldSelect",
3819 fieldnum);
3820 if (fieldnum > tupDesc->natts) /* should never happen */
3821 elog(ERROR, "attribute number %d exceeds number of columns %d",
3822 fieldnum, tupDesc->natts);
3823 attr = TupleDescAttr(tupDesc, fieldnum - 1);
3824
3825 /* Check for dropped column, and force a NULL result if so */
3826 if (attr->attisdropped)
3827 {
3828 *op->resnull = true;
3829 return;
3830 }
3831
3832 /* Check for type mismatch --- possible after ALTER COLUMN TYPE? */
3833 /* As in CheckVarSlotCompatibility, we should but can't check typmod */
3834 if (op->d.fieldselect.resulttype != attr->atttypid)
3835 ereport(ERROR,
3837 errmsg("attribute %d has wrong type", fieldnum),
3838 errdetail("Table has type %s, but query expects %s.",
3839 format_type_be(attr->atttypid),
3841
3842 /* heap_getattr needs a HeapTuple not a bare HeapTupleHeader */
3844 tmptup.t_data = tuple;
3845
3846 /* extract the field */
3848 fieldnum,
3849 tupDesc,
3850 op->resnull);
3851 }
3852}
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)
static int32 HeapTupleHeaderGetTypMod(const HeapTupleHeaderData *tup)
AttrNumber fieldnum
Definition execExpr.h:543
struct ExprEvalStep::@63::@89 fieldselect
ExprEvalRowtypeCache rowcache
Definition execExpr.h:419
static bool VARATT_IS_EXTERNAL_EXPANDED(const void *PTR)
Definition varatt.h:389

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

Referenced by ExecInterpExpr().

◆ ExecEvalFieldStoreDeForm()

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

Definition at line 3864 of file execExprInterp.c.

3865{
3866 if (*op->resnull)
3867 {
3868 /* Convert null input tuple into an all-nulls row */
3869 memset(op->d.fieldstore.nulls, true,
3870 op->d.fieldstore.ncolumns * sizeof(bool));
3871 }
3872 else
3873 {
3874 /*
3875 * heap_deform_tuple needs a HeapTuple not a bare HeapTupleHeader. We
3876 * set all the fields in the struct just in case.
3877 */
3878 Datum tupDatum = *op->resvalue;
3879 HeapTupleHeader tuphdr;
3881 TupleDesc tupDesc;
3882
3884 tmptup.t_len = HeapTupleHeaderGetDatumLength(tuphdr);
3885 ItemPointerSetInvalid(&(tmptup.t_self));
3886 tmptup.t_tableOid = InvalidOid;
3887 tmptup.t_data = tuphdr;
3888
3889 /*
3890 * Lookup tupdesc if first time through or if type changes. Because
3891 * we don't pin the tupdesc, we must not do this lookup until after
3892 * doing DatumGetHeapTupleHeader: that could do database access while
3893 * detoasting the datum.
3894 */
3895 tupDesc = get_cached_rowtype(op->d.fieldstore.fstore->resulttype, -1,
3896 op->d.fieldstore.rowcache, NULL);
3897
3898 /* Check that current tupdesc doesn't have more fields than allocated */
3899 if (unlikely(tupDesc->natts > op->d.fieldstore.ncolumns))
3900 elog(ERROR, "too many columns in composite type %u",
3901 op->d.fieldstore.fstore->resulttype);
3902
3903 heap_deform_tuple(&tmptup, tupDesc,
3904 op->d.fieldstore.values,
3905 op->d.fieldstore.nulls);
3906 }
3907}
#define unlikely(x)
Definition c.h:438
void heap_deform_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *values, bool *isnull)
Definition heaptuple.c:1254
static void ItemPointerSetInvalid(ItemPointerData *pointer)
Definition itemptr.h:184
#define InvalidOid
Datum * values
Definition execExpr.h:530
bool * nulls
Definition execExpr.h:531
FieldStore * fstore
Definition execExpr.h:553
struct ExprEvalStep::@63::@90 fieldstore

References DatumGetHeapTupleHeader, elog, ERROR, fb(), get_cached_rowtype(), heap_deform_tuple(), HeapTupleHeaderGetDatumLength(), InvalidOid, ItemPointerSetInvalid(), TupleDescData::natts, ExprEvalStep::op, and unlikely.

Referenced by ExecInterpExpr().

◆ ExecEvalFieldStoreForm()

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

Definition at line 3914 of file execExprInterp.c.

3915{
3916 TupleDesc tupDesc;
3917 HeapTuple tuple;
3918
3919 /* Lookup tupdesc (should be valid already) */
3920 tupDesc = get_cached_rowtype(op->d.fieldstore.fstore->resulttype, -1,
3921 op->d.fieldstore.rowcache, NULL);
3922
3923 tuple = heap_form_tuple(tupDesc,
3924 op->d.fieldstore.values,
3925 op->d.fieldstore.nulls);
3926
3927 *op->resvalue = HeapTupleGetDatum(tuple);
3928 *op->resnull = false;
3929}
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
Definition heaptuple.c:1025

References fb(), 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 3000 of file execExprInterp.c.

3002{
3003 FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
3005 Datum d;
3006
3008
3009 fcinfo->isnull = false;
3010 d = op->d.func.fn_addr(fcinfo);
3011 *op->resvalue = d;
3012 *op->resnull = fcinfo->isnull;
3013
3015}
void pgstat_init_function_usage(FunctionCallInfo fcinfo, PgStat_FunctionCallUsage *fcu)
void pgstat_end_function_usage(PgStat_FunctionCallUsage *fcu, bool finalize)
struct ExprEvalStep::@63::@71 func
PGFunction fn_addr
Definition execExpr.h:391
FunctionCallInfo fcinfo_data
Definition execExpr.h:389

References ExprEvalStep::d, fb(), 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 3021 of file execExprInterp.c.

3023{
3024
3025 FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
3027 NullableDatum *args = fcinfo->args;
3028 int nargs = op->d.func.nargs;
3029 Datum d;
3030
3031 /* strict function, so check for NULL args */
3032 for (int argno = 0; argno < nargs; argno++)
3033 {
3034 if (args[argno].isnull)
3035 {
3036 *op->resnull = true;
3037 return;
3038 }
3039 }
3040
3042
3043 fcinfo->isnull = false;
3044 d = op->d.func.fn_addr(fcinfo);
3045 *op->resvalue = d;
3046 *op->resnull = fcinfo->isnull;
3047
3049}

References ExprEvalStep::args, FunctionCallInfoBaseData::args, ExprEvalStep::d, fb(), 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 5319 of file execExprInterp.c.

5320{
5322 int result = 0;
5323 Bitmapset *grouped_cols = aggstate->grouped_cols;
5324 ListCell *lc;
5325
5326 foreach(lc, op->d.grouping_func.clauses)
5327 {
5328 int attnum = lfirst_int(lc);
5329
5330 result <<= 1;
5331
5332 if (!bms_is_member(attnum, grouped_cols))
5333 result |= 1;
5334 }
5335
5337 *op->resnull = false;
5338}
bool bms_is_member(int x, const Bitmapset *a)
Definition bitmapset.c:510
#define castNode(_type_, nodeptr)
Definition nodes.h:182
#define lfirst_int(lc)
Definition pg_list.h:173
static Datum Int32GetDatum(int32 X)
Definition postgres.h:212
struct ExprEvalStep::@63::@102 grouping_func
List * clauses
Definition execExpr.h:681

References attnum, bms_is_member(), castNode, fb(), Int32GetDatum(), lfirst_int, ExprEvalStep::op, and result.

Referenced by ExecInterpExpr().

◆ ExecEvalHashedScalarArrayOp()

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

Definition at line 4257 of file execExprInterp.c.

4258{
4261 bool inclause = op->d.hashedscalararrayop.inclause;
4263 Datum scalar = fcinfo->args[0].value;
4264 bool scalar_isnull = fcinfo->args[0].isnull;
4265 Datum result;
4266 bool resultnull;
4267 bool hashfound;
4268
4269 /* We don't setup a hashed scalar array op if the array const is null. */
4270 Assert(!*op->resnull);
4271
4272 /*
4273 * If the scalar is NULL, and the function is strict, return NULL; no
4274 * point in executing the search.
4275 */
4277 {
4278 *op->resnull = true;
4279 return;
4280 }
4281
4282 /* Build the hash table on first evaluation */
4283 if (elements_tab == NULL)
4284 {
4285 ScalarArrayOpExpr *saop;
4286 int16 typlen;
4287 bool typbyval;
4288 char typalign;
4289 uint8 typalignby;
4290 int nitems;
4291 bool has_nulls = false;
4292 char *s;
4293 uint8 *bitmap;
4294 int bitmask;
4295 MemoryContext oldcontext;
4296 ArrayType *arr;
4297
4298 saop = op->d.hashedscalararrayop.saop;
4299
4300 arr = DatumGetArrayTypeP(*op->resvalue);
4301 nitems = ArrayGetNItems(ARR_NDIM(arr), ARR_DIMS(arr));
4302
4304 &typlen,
4305 &typbyval,
4306 &typalign);
4307 typalignby = typalign_to_alignby(typalign);
4308
4309 oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
4310
4311 elements_tab = (ScalarArrayOpExprHashTable *)
4312 palloc0(offsetof(ScalarArrayOpExprHashTable, hash_fcinfo_data) +
4314 op->d.hashedscalararrayop.elements_tab = elements_tab;
4315 elements_tab->op = op;
4316
4317 fmgr_info(saop->hashfuncid, &elements_tab->hash_finfo);
4318 fmgr_info_set_expr((Node *) saop, &elements_tab->hash_finfo);
4319
4321 &elements_tab->hash_finfo,
4322 1,
4323 saop->inputcollid,
4324 NULL,
4325 NULL);
4326
4327 /*
4328 * Create the hash table sizing it according to the number of elements
4329 * in the array. This does assume that the array has no duplicates.
4330 * If the array happens to contain many duplicate values then it'll
4331 * just mean that we sized the table a bit on the large side.
4332 */
4334 elements_tab);
4335
4336 MemoryContextSwitchTo(oldcontext);
4337
4338 s = (char *) ARR_DATA_PTR(arr);
4339 bitmap = ARR_NULLBITMAP(arr);
4340 bitmask = 1;
4341 for (int i = 0; i < nitems; i++)
4342 {
4343 /* Get array element, checking for NULL. */
4344 if (bitmap && (*bitmap & bitmask) == 0)
4345 {
4346 has_nulls = true;
4347 }
4348 else
4349 {
4350 Datum element;
4351
4352 element = fetch_att(s, typbyval, typlen);
4353 s = att_addlength_pointer(s, typlen, s);
4354 s = (char *) att_nominal_alignby(s, typalignby);
4355
4356 saophash_insert(elements_tab->hashtab, element, &hashfound);
4357 }
4358
4359 /* Advance bitmap pointer if any. */
4360 if (bitmap)
4361 {
4362 bitmask <<= 1;
4363 if (bitmask == 0x100)
4364 {
4365 bitmap++;
4366 bitmask = 1;
4367 }
4368 }
4369 }
4370
4371 /*
4372 * Remember if we had any nulls so that we know if we need to execute
4373 * non-strict functions with a null lhs value if no match is found.
4374 */
4375 op->d.hashedscalararrayop.has_nulls = has_nulls;
4376
4377 /*
4378 * When we have a non-strict equality function, check and cache the
4379 * result from looking up a NULL. Non-strict functions are free to
4380 * treat a NULL as equal to any other value, e.g. a 0 or an empty
4381 * string. Here we perform a linear search over the array and cache
4382 * the outcome so that we can use that result any time we receive a
4383 * NULL.
4384 */
4385 if (!strictfunc)
4386 {
4387 bool null_lhs_result;
4388
4389 fcinfo->args[0].value = (Datum) 0;
4390 fcinfo->args[0].isnull = true;
4391
4392 ExecEvalArrayCompareInternal(fcinfo, arr, typlen, typbyval,
4393 typalign, true, &result,
4394 &resultnull);
4395
4396 null_lhs_result = DatumGetBool(result);
4397
4398 /* invert non-NULL results for NOT IN */
4399 if (!resultnull && !inclause)
4400 null_lhs_result = !null_lhs_result;
4401
4403 op->d.hashedscalararrayop.null_lhs_result = null_lhs_result;
4404 }
4405 }
4406
4407 /*
4408 * When looking up an SQL NULL value with non-strict functions, we defer
4409 * to the value we cached when building the hash table.
4410 */
4411 if (scalar_isnull)
4412 {
4414
4417 return;
4418 }
4419
4420
4421 /* Check the hash to see if we have a match. */
4422 hashfound = NULL != saophash_lookup(elements_tab->hashtab, scalar);
4423
4424 /* the result depends on if the clause is an IN or NOT IN clause */
4425 if (inclause)
4426 result = BoolGetDatum(hashfound); /* IN */
4427 else
4428 result = BoolGetDatum(!hashfound); /* NOT IN */
4429
4430 resultnull = false;
4431
4432 /*
4433 * If we didn't find a match in the array, we still might need to handle
4434 * the possibility of null values. We didn't put any NULLs into the
4435 * hashtable, but instead marked if we found any when building the table
4436 * in has_nulls.
4437 */
4439 {
4440 if (strictfunc)
4441 {
4442
4443 /*
4444 * We have nulls in the array so a non-null lhs and no match must
4445 * yield NULL.
4446 */
4447 result = (Datum) 0;
4448 resultnull = true;
4449 }
4450 else
4451 {
4452 /*
4453 * Execute function will null rhs just once.
4454 *
4455 * The hash lookup path will have scribbled on the lhs argument so
4456 * we need to set it up also (even though we entered this function
4457 * with it already set).
4458 */
4459 fcinfo->args[0].value = scalar;
4460 fcinfo->args[0].isnull = scalar_isnull;
4461 fcinfo->args[1].value = (Datum) 0;
4462 fcinfo->args[1].isnull = true;
4463
4464 result = op->d.hashedscalararrayop.finfo->fn_addr(fcinfo);
4465 resultnull = fcinfo->isnull;
4466
4467 /*
4468 * Reverse the result for NOT IN clauses since the above function
4469 * is the equality function and we need not-equals.
4470 */
4471 if (!inclause)
4473 }
4474 }
4475
4476 *op->resvalue = result;
4477 *op->resnull = resultnull;
4478}
int16_t int16
Definition c.h:619
static pg_attribute_always_inline void ExecEvalArrayCompareInternal(FunctionCallInfo fcinfo, ArrayType *arr, int16 typlen, bool typbyval, char typalign, bool useOr, Datum *result, bool *resultnull)
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition fmgr.c:129
#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:2464
static chr element(struct vars *v, const chr *startp, const chr *endp)
bool has_nulls
Definition execExpr.h:642
bool null_lhs_isnull
Definition execExpr.h:647
struct ScalarArrayOpExprHashTable * elements_tab
Definition execExpr.h:648
bool inclause
Definition execExpr.h:643
ScalarArrayOpExpr * saop
Definition execExpr.h:651
struct ExprEvalStep::@63::@98 hashedscalararrayop
bool null_lhs_result
Definition execExpr.h:644
FmgrInfo * finfo
Definition execExpr.h:388
FunctionCallInfoBaseData hash_fcinfo_data
struct ExprEvalStep * op

References FunctionCallInfoBaseData::args, ARR_DATA_PTR, ARR_DIMS, ARR_ELEMTYPE, ARR_NDIM, ARR_NULLBITMAP, ArrayGetNItems(), Assert, att_addlength_pointer, att_nominal_alignby, BoolGetDatum(), CurrentMemoryContext, DatumGetArrayTypeP, DatumGetBool(), ExprContext::ecxt_per_query_memory, element(), ExprEvalStep::elements_tab, ExecEvalArrayCompareInternal(), fb(), 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, ExprEvalStep::null_lhs_result, ScalarArrayOpExprHashTable::op, ExprEvalStep::op, palloc0(), result, ExprEvalStep::saop, SizeForFunctionCallInfo, typalign, typalign_to_alignby(), ExprEvalStep::typbyval, ExprEvalStep::typlen, and NullableDatum::value.

Referenced by ExecInterpExpr().

◆ ExecEvalJsonCoercion()

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

Definition at line 5186 of file execExprInterp.c.

5188{
5190
5191 /*
5192 * Prepare to call json_populate_type() to coerce the boolean result of
5193 * JSON_EXISTS_OP to the target type. If the target type is integer or a
5194 * domain over integer, call the boolean-to-integer cast function instead,
5195 * because the integer's input function (which is what
5196 * json_populate_type() calls to coerce to scalar target types) doesn't
5197 * accept boolean literals as valid input. We only have a special case
5198 * for integer and domains thereof as it seems common to use those types
5199 * for EXISTS columns in JSON_TABLE().
5200 */
5202 {
5204 {
5205 /* Check domain constraints if any. */
5210 econtext->ecxt_per_query_memory,
5211 (Node *) escontext))
5212 {
5213 *op->resnull = true;
5214 *op->resvalue = (Datum) 0;
5215 }
5216 else
5218 return;
5219 }
5220
5222 DatumGetBool(*op->resvalue) ?
5223 CStringGetDatum("true") :
5224 CStringGetDatum("false"));
5225 }
5226
5231 econtext->ecxt_per_query_memory,
5232 op->resnull,
5234 (Node *) escontext);
5235}
bool domain_check_safe(Datum value, bool isnull, Oid domainType, void **extra, MemoryContext mcxt, Node *escontext)
Definition domains.c:355
#define DirectFunctionCall1(func, arg1)
Definition fmgr.h:684
Datum bool_int4(PG_FUNCTION_ARGS)
Definition int.c:401
Datum jsonb_in(PG_FUNCTION_ARGS)
Definition jsonb.c:64
Datum json_populate_type(Datum json_val, Oid json_type, Oid typid, int32 typmod, void **cache, MemoryContext mcxt, bool *isnull, bool omit_quotes, Node *escontext)
Definition jsonfuncs.c:3345
static Datum CStringGetDatum(const char *X)
Definition postgres.h:383
void * json_coercion_cache
Definition execExpr.h:773
bool exists_coerce
Definition execExpr.h:770
struct ExprEvalStep::@63::@112 jsonexpr_coercion
bool exists_cast_to_int
Definition execExpr.h:771
bool exists_check_domain
Definition execExpr.h:772
int32 targettypmod
Definition execExpr.h:767
bool omit_quotes
Definition execExpr.h:768

References bool_int4(), CStringGetDatum(), DatumGetBool(), DirectFunctionCall1, domain_check_safe(), ExprContext::ecxt_per_query_memory, ExprEvalStep::escontext, fb(), json_populate_type(), jsonb_in(), and ExprEvalStep::op.

Referenced by ExecInterpExpr().

◆ ExecEvalJsonCoercionFinish()

void ExecEvalJsonCoercionFinish ( ExprState state,
ExprEvalStep op 
)

Definition at line 5266 of file execExprInterp.c.

5267{
5268 JsonExprState *jsestate = op->d.jsonexpr.jsestate;
5269
5270 if (SOFT_ERROR_OCCURRED(&jsestate->escontext))
5271 {
5272 /*
5273 * jsestate->error or jsestate->empty being set means that the error
5274 * occurred when coercing the JsonBehavior value. Throw the error in
5275 * that case with the actual coercion error message shown in the
5276 * DETAIL part.
5277 */
5278 if (DatumGetBool(jsestate->error.value))
5279 ereport(ERROR,
5281 /*- translator: first %s is a SQL/JSON clause (e.g. ON ERROR) */
5282 errmsg("could not coerce %s expression (%s) to the RETURNING type",
5283 "ON ERROR",
5285 errdetail("%s", jsestate->escontext.error_data->message)));
5286 else if (DatumGetBool(jsestate->empty.value))
5287 ereport(ERROR,
5289 /*- translator: first %s is a SQL/JSON clause (e.g. ON ERROR) */
5290 errmsg("could not coerce %s expression (%s) to the RETURNING type",
5291 "ON EMPTY",
5293 errdetail("%s", jsestate->escontext.error_data->message)));
5294
5295 *op->resvalue = (Datum) 0;
5296 *op->resnull = true;
5297
5298 jsestate->error.value = BoolGetDatum(true);
5299
5300 /*
5301 * Reset for next use such as for catching errors when coercing a
5302 * JsonBehavior expression.
5303 */
5304 jsestate->escontext.error_occurred = false;
5305 jsestate->escontext.details_wanted = true;
5306 }
5307}
static char * GetJsonBehaviorValueString(JsonBehavior *behavior)
char * message
Definition elog.h:434
ErrorData * error_data
Definition miscnodes.h:49
struct JsonExprState * jsestate
Definition execExpr.h:760
struct ExprEvalStep::@63::@111 jsonexpr
NullableDatum empty
Definition execnodes.h:1129
JsonExpr * jsexpr
Definition execnodes.h:1107
NullableDatum error
Definition execnodes.h:1126
ErrorSaveContext escontext
Definition execnodes.h:1166
JsonBehavior * on_empty
Definition primnodes.h:1867
JsonBehavior * on_error
Definition primnodes.h:1868

References BoolGetDatum(), DatumGetBool(), ErrorSaveContext::details_wanted, JsonExprState::empty, ereport, errcode(), errdetail(), errmsg, JsonExprState::error, ERROR, ErrorSaveContext::error_data, ErrorSaveContext::error_occurred, JsonExprState::escontext, fb(), GetJsonBehaviorValueString(), ExprEvalStep::jsestate, JsonExprState::jsexpr, ErrorData::message, JsonExpr::on_empty, JsonExpr::on_error, ExprEvalStep::op, SOFT_ERROR_OCCURRED, and NullableDatum::value.

Referenced by ExecInterpExpr().

◆ ExecEvalJsonConstructor()

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

Definition at line 4733 of file execExprInterp.c.

4735{
4736 Datum res;
4740 bool isnull = false;
4741
4742 if (ctor->type == JSCTOR_JSON_ARRAY)
4743 res = (is_jsonb ?
4745 json_build_array_worker) (jcstate->nargs,
4746 jcstate->arg_values,
4747 jcstate->arg_nulls,
4748 jcstate->arg_types,
4749 jcstate->constructor->absent_on_null);
4750 else if (ctor->type == JSCTOR_JSON_OBJECT)
4751 res = (is_jsonb ?
4754 jcstate->arg_values,
4755 jcstate->arg_nulls,
4756 jcstate->arg_types,
4757 jcstate->constructor->absent_on_null,
4758 jcstate->constructor->unique);
4759 else if (ctor->type == JSCTOR_JSON_SCALAR)
4760 {
4761 if (jcstate->arg_nulls[0])
4762 {
4763 res = (Datum) 0;
4764 isnull = true;
4765 }
4766 else
4767 {
4768 Datum value = jcstate->arg_values[0];
4769 Oid outfuncid = jcstate->arg_type_cache[0].outfuncid;
4771 jcstate->arg_type_cache[0].category;
4772
4773 if (is_jsonb)
4774 res = datum_to_jsonb(value, category, outfuncid);
4775 else
4776 res = datum_to_json(value, category, outfuncid);
4777 }
4778 }
4779 else if (ctor->type == JSCTOR_JSON_PARSE)
4780 {
4781 if (jcstate->arg_nulls[0])
4782 {
4783 res = (Datum) 0;
4784 isnull = true;
4785 }
4786 else
4787 {
4788 Datum value = jcstate->arg_values[0];
4789 text *js = DatumGetTextP(value);
4790
4791 if (is_jsonb)
4792 res = jsonb_from_text(js, true);
4793 else
4794 {
4795 (void) json_validate(js, true, true);
4796 res = value;
4797 }
4798 }
4799 }
4800 else
4801 elog(ERROR, "invalid JsonConstructorExpr type %d", ctor->type);
4802
4803 *op->resvalue = res;
4804 *op->resnull = isnull;
4805}
#define DatumGetTextP(X)
Definition fmgr.h:333
static struct @177 value
Datum json_build_array_worker(int nargs, const Datum *args, const bool *nulls, const Oid *types, bool absent_on_null)
Definition json.c:1314
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:1194
Datum datum_to_json(Datum val, JsonTypeCategory tcategory, Oid outfuncoid)
Definition json.c:732
bool json_validate(text *json, bool check_unique_keys, bool throw_error)
Definition json.c:1782
Datum jsonb_from_text(text *js, bool unique_keys)
Definition jsonb.c:139
Datum jsonb_build_array_worker(int nargs, const Datum *args, const bool *nulls, const Oid *types, bool absent_on_null)
Definition jsonb.c:1215
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:1130
Datum datum_to_jsonb(Datum val, JsonTypeCategory tcategory, Oid outfuncoid)
Definition jsonb.c:1117
JsonTypeCategory
Definition jsonfuncs.h:69
@ JS_FORMAT_JSONB
Definition primnodes.h:1667
@ JSCTOR_JSON_PARSE
Definition primnodes.h:1721
@ JSCTOR_JSON_OBJECT
Definition primnodes.h:1717
@ JSCTOR_JSON_SCALAR
Definition primnodes.h:1722
@ JSCTOR_JSON_ARRAY
Definition primnodes.h:1718
struct ExprEvalStep::@63::@100 json_constructor
struct JsonConstructorExprState * jcstate
Definition execExpr.h:669
JsonConstructorExpr * constructor
Definition execExpr.h:827
struct JsonConstructorExprState::@113 * arg_type_cache
JsonReturning * returning
Definition primnodes.h:1737
JsonFormatType format_type
Definition primnodes.h:1678
JsonFormat * format
Definition primnodes.h:1690
Definition c.h:776

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, fb(), JsonReturning::format, JsonFormat::format_type, 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, JsonConstructorExpr::returning, JsonConstructorExpr::unique, and value.

Referenced by ExecInterpExpr().

◆ ExecEvalJsonExprPath()

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

Definition at line 4909 of file execExprInterp.c.

4911{
4912 JsonExprState *jsestate = op->d.jsonexpr.jsestate;
4913 JsonExpr *jsexpr = jsestate->jsexpr;
4914 Datum item;
4915 JsonPath *path;
4916 bool throw_error = jsexpr->on_error->btype == JSON_BEHAVIOR_ERROR;
4917 bool error = false,
4918 empty = false;
4919 int jump_eval_coercion = jsestate->jump_eval_coercion;
4920 char *val_string = NULL;
4921
4922 item = jsestate->formatted_expr.value;
4923 path = DatumGetJsonPathP(jsestate->pathspec.value);
4924
4925 /* Set error/empty to false. */
4926 memset(&jsestate->error, 0, sizeof(NullableDatum));
4927 memset(&jsestate->empty, 0, sizeof(NullableDatum));
4928
4929 /* Also reset ErrorSaveContext contents for the next row. */
4930 if (jsestate->escontext.details_wanted)
4931 {
4932 jsestate->escontext.error_data = NULL;
4933 jsestate->escontext.details_wanted = false;
4934 }
4935 jsestate->escontext.error_occurred = false;
4936
4937 switch (jsexpr->op)
4938 {
4939 case JSON_EXISTS_OP:
4940 {
4941 bool exists = JsonPathExists(item, path,
4942 !throw_error ? &error : NULL,
4943 jsestate->args);
4944
4945 if (!error)
4946 {
4947 *op->resnull = false;
4949 }
4950 }
4951 break;
4952
4953 case JSON_QUERY_OP:
4954 *op->resvalue = JsonPathQuery(item, path, jsexpr->wrapper, &empty,
4955 !throw_error ? &error : NULL,
4956 jsestate->args,
4957 jsexpr->column_name);
4958
4959 *op->resnull = (DatumGetPointer(*op->resvalue) == NULL);
4960 break;
4961
4962 case JSON_VALUE_OP:
4963 {
4964 JsonbValue *jbv = JsonPathValue(item, path, &empty,
4965 !throw_error ? &error : NULL,
4966 jsestate->args,
4967 jsexpr->column_name);
4968
4969 if (jbv == NULL)
4970 {
4971 /* Will be coerced with json_populate_type(), if needed. */
4972 *op->resvalue = (Datum) 0;
4973 *op->resnull = true;
4974 }
4975 else if (!error && !empty)
4976 {
4977 if (jsexpr->returning->typid == JSONOID ||
4978 jsexpr->returning->typid == JSONBOID)
4979 {
4982 }
4983 else if (jsexpr->use_json_coercion)
4984 {
4986 *op->resnull = false;
4987 }
4988 else
4989 {
4991
4992 /*
4993 * Simply convert to the default RETURNING type (text)
4994 * if no coercion needed.
4995 */
4996 if (!jsexpr->use_io_coercion)
4999 }
5000 }
5001 break;
5002 }
5003
5004 /* JSON_TABLE_OP can't happen here */
5005
5006 default:
5007 elog(ERROR, "unrecognized SQL/JSON expression op %d",
5008 (int) jsexpr->op);
5009 return false;
5010 }
5011
5012 /*
5013 * Coerce the result value to the RETURNING type by calling its input
5014 * function.
5015 */
5016 if (!*op->resnull && jsexpr->use_io_coercion)
5017 {
5018 FunctionCallInfo fcinfo;
5019
5020 Assert(jump_eval_coercion == -1);
5021 fcinfo = jsestate->input_fcinfo;
5022 Assert(fcinfo != NULL);
5024 fcinfo->args[0].value = PointerGetDatum(val_string);
5025 fcinfo->args[0].isnull = *op->resnull;
5026
5027 /*
5028 * Second and third arguments are already set up in
5029 * ExecInitJsonExpr().
5030 */
5031
5032 fcinfo->isnull = false;
5033 *op->resvalue = FunctionCallInvoke(fcinfo);
5034 if (SOFT_ERROR_OCCURRED(&jsestate->escontext))
5035 error = true;
5036 }
5037
5038 /*
5039 * When setting up the ErrorSaveContext (if needed) for capturing the
5040 * errors that occur when coercing the JsonBehavior expression, set
5041 * details_wanted to be able to show the actual error message as the
5042 * DETAIL of the error message that tells that it is the JsonBehavior
5043 * expression that caused the error; see ExecEvalJsonCoercionFinish().
5044 */
5045
5046 /* Handle ON EMPTY. */
5047 if (empty)
5048 {
5049 *op->resvalue = (Datum) 0;
5050 *op->resnull = true;
5051 if (jsexpr->on_empty)
5052 {
5053 if (jsexpr->on_empty->btype != JSON_BEHAVIOR_ERROR)
5054 {
5055 jsestate->empty.value = BoolGetDatum(true);
5056 /* Set up to catch coercion errors of the ON EMPTY value. */
5057 jsestate->escontext.error_occurred = false;
5058 jsestate->escontext.details_wanted = true;
5059 /* Jump to end if the ON EMPTY behavior is to return NULL */
5060 return jsestate->jump_empty >= 0 ? jsestate->jump_empty : jsestate->jump_end;
5061 }
5062 }
5063 else if (jsexpr->on_error->btype != JSON_BEHAVIOR_ERROR)
5064 {
5065 jsestate->error.value = BoolGetDatum(true);
5066 /* Set up to catch coercion errors of the ON ERROR value. */
5067 jsestate->escontext.error_occurred = false;
5068 jsestate->escontext.details_wanted = true;
5070 /* Jump to end if the ON ERROR behavior is to return NULL */
5071 return jsestate->jump_error >= 0 ? jsestate->jump_error : jsestate->jump_end;
5072 }
5073
5074 if (jsexpr->column_name)
5075 ereport(ERROR,
5077 errmsg("no SQL/JSON item found for specified path of column \"%s\"",
5078 jsexpr->column_name));
5079 else
5080 ereport(ERROR,
5082 errmsg("no SQL/JSON item found for specified path"));
5083 }
5084
5085 /*
5086 * ON ERROR. Wouldn't get here if the behavior is ERROR, because they
5087 * would have already been thrown.
5088 */
5089 if (error)
5090 {
5092 *op->resvalue = (Datum) 0;
5093 *op->resnull = true;
5094 jsestate->error.value = BoolGetDatum(true);
5095 /* Set up to catch coercion errors of the ON ERROR value. */
5096 jsestate->escontext.error_occurred = false;
5097 jsestate->escontext.details_wanted = true;
5098 /* Jump to end if the ON ERROR behavior is to return NULL */
5099 return jsestate->jump_error >= 0 ? jsestate->jump_error : jsestate->jump_end;
5100 }
5101
5102 return jump_eval_coercion >= 0 ? jump_eval_coercion : jsestate->jump_end;
5103}
static char * ExecGetJsonValueItemString(JsonbValue *item, bool *resnull)
char * val_string
Definition informix.c:694
Datum jsonb_out(PG_FUNCTION_ARGS)
Definition jsonb.c:99
static Datum JsonbPGetDatum(const Jsonb *p)
Definition jsonb.h:413
Jsonb * JsonbValueToJsonb(JsonbValue *val)
Definition jsonb_util.c:96
static JsonPath * DatumGetJsonPathP(Datum d)
Definition jsonpath.h:35
bool JsonPathExists(Datum jb, JsonPath *jp, bool *error, List *vars)
Datum JsonPathQuery(Datum jb, JsonPath *jp, JsonWrapper wrapper, bool *empty, bool *error, List *vars, const char *column_name)
JsonbValue * JsonPathValue(Datum jb, JsonPath *jp, bool *empty, bool *error, List *vars, const char *column_name)
@ JSON_BEHAVIOR_ERROR
Definition primnodes.h:1794
@ JSON_QUERY_OP
Definition primnodes.h:1831
@ JSON_EXISTS_OP
Definition primnodes.h:1830
@ JSON_VALUE_OP
Definition primnodes.h:1832
static void error(void)
JsonBehaviorType btype
Definition primnodes.h:1818
int jump_eval_coercion
Definition execnodes.h:1143
FunctionCallInfo input_fcinfo
Definition execnodes.h:1157
NullableDatum pathspec
Definition execnodes.h:1113
NullableDatum formatted_expr
Definition execnodes.h:1110
char * column_name
Definition primnodes.h:1847
bool use_io_coercion
Definition primnodes.h:1874
JsonReturning * returning
Definition primnodes.h:1860
bool use_json_coercion
Definition primnodes.h:1875
JsonWrapper wrapper
Definition primnodes.h:1878
JsonExprOp op
Definition primnodes.h:1845
Datum textin(PG_FUNCTION_ARGS)
Definition varlena.c:278

References FunctionCallInfoBaseData::args, JsonExprState::args, Assert, BoolGetDatum(), JsonBehavior::btype, JsonExpr::column_name, CStringGetDatum(), DatumGetCString(), 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(), fb(), 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(), JsonbValueToJsonb(), JsonPathExists(), JsonPathQuery(), JsonPathValue(), JsonExprState::jump_empty, JsonExprState::jump_end, JsonExprState::jump_error, JsonExprState::jump_eval_coercion, 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, JsonExpr::use_json_coercion, val_string, NullableDatum::value, and JsonExpr::wrapper.

Referenced by ExecInterpExpr().

◆ ExecEvalJsonIsPredicate()

void ExecEvalJsonIsPredicate ( ExprState state,
ExprEvalStep op 
)

Definition at line 4811 of file execExprInterp.c.

4812{
4813 JsonIsPredicate *pred = op->d.is_json.pred;
4814 Datum js = *op->resvalue;
4815 Oid exprtype = pred->exprBaseType;
4816 bool res;
4817
4818 if (*op->resnull)
4819 {
4820 *op->resvalue = BoolGetDatum(false);
4821 return;
4822 }
4823
4824 if (exprtype == TEXTOID || exprtype == JSONOID)
4825 {
4826 text *json = DatumGetTextP(js);
4827
4828 if (pred->item_type == JS_TYPE_ANY)
4829 res = true;
4830 else
4831 {
4832 switch (json_get_first_token(json, false))
4833 {
4835 res = pred->item_type == JS_TYPE_OBJECT;
4836 break;
4838 res = pred->item_type == JS_TYPE_ARRAY;
4839 break;
4840 case JSON_TOKEN_STRING:
4841 case JSON_TOKEN_NUMBER:
4842 case JSON_TOKEN_TRUE:
4843 case JSON_TOKEN_FALSE:
4844 case JSON_TOKEN_NULL:
4845 res = pred->item_type == JS_TYPE_SCALAR;
4846 break;
4847 default:
4848 res = false;
4849 break;
4850 }
4851 }
4852
4853 /*
4854 * Do full parsing pass only for uniqueness check or for JSON text
4855 * validation.
4856 */
4857 if (res && (pred->unique_keys || exprtype == TEXTOID))
4858 res = json_validate(json, pred->unique_keys, false);
4859 }
4860 else if (exprtype == JSONBOID)
4861 {
4862 if (pred->item_type == JS_TYPE_ANY)
4863 res = true;
4864 else
4865 {
4866 Jsonb *jb = DatumGetJsonbP(js);
4867
4868 switch (pred->item_type)
4869 {
4870 case JS_TYPE_OBJECT:
4871 res = JB_ROOT_IS_OBJECT(jb);
4872 break;
4873 case JS_TYPE_ARRAY:
4875 break;
4876 case JS_TYPE_SCALAR:
4878 break;
4879 default:
4880 res = false;
4881 break;
4882 }
4883 }
4884
4885 /* Key uniqueness check is redundant for jsonb */
4886 }
4887 else
4888 res = false;
4889
4890 *op->resvalue = BoolGetDatum(res);
4891}
@ JSON_TOKEN_FALSE
Definition jsonapi.h:29
@ JSON_TOKEN_TRUE
Definition jsonapi.h:28
@ JSON_TOKEN_NULL
Definition jsonapi.h:30
@ JSON_TOKEN_OBJECT_START
Definition jsonapi.h:22
@ JSON_TOKEN_NUMBER
Definition jsonapi.h:21
@ JSON_TOKEN_STRING
Definition jsonapi.h:20
@ JSON_TOKEN_ARRAY_START
Definition jsonapi.h:24
#define JB_ROOT_IS_OBJECT(jbp_)
Definition jsonb.h:223
#define JB_ROOT_IS_ARRAY(jbp_)
Definition jsonb.h:224
static Jsonb * DatumGetJsonbP(Datum d)
Definition jsonb.h:401
#define JB_ROOT_IS_SCALAR(jbp_)
Definition jsonb.h:222
JsonTokenType json_get_first_token(text *json, bool throw_error)
Definition jsonfuncs.c:5940
@ JS_TYPE_ANY
Definition primnodes.h:1749
@ JS_TYPE_ARRAY
Definition primnodes.h:1751
@ JS_TYPE_OBJECT
Definition primnodes.h:1750
@ JS_TYPE_SCALAR
Definition primnodes.h:1752
JsonIsPredicate * pred
Definition execExpr.h:754
struct ExprEvalStep::@63::@110 is_json
JsonValueType item_type
Definition primnodes.h:1764
Definition jsonb.h:215

References BoolGetDatum(), DatumGetJsonbP(), DatumGetTextP, JsonIsPredicate::exprBaseType, fb(), 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, and JsonIsPredicate::unique_keys.

Referenced by ExecInterpExpr().

◆ ExecEvalMergeSupportFunc()

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

Definition at line 5346 of file execExprInterp.c.

5348{
5349 ModifyTableState *mtstate = castNode(ModifyTableState, state->parent);
5351
5352 if (!relaction)
5353 elog(ERROR, "no merge action in progress");
5354
5355 /* Return the MERGE action ("INSERT", "UPDATE", or "DELETE") */
5356 switch (relaction->mas_action->commandType)
5357 {
5358 case CMD_INSERT:
5360 *op->resnull = false;
5361 break;
5362 case CMD_UPDATE:
5364 *op->resnull = false;
5365 break;
5366 case CMD_DELETE:
5368 *op->resnull = false;
5369 break;
5370 case CMD_NOTHING:
5371 elog(ERROR, "unexpected merge action: DO NOTHING");
5372 break;
5373 default:
5374 elog(ERROR, "unrecognized commandType: %d",
5375 (int) relaction->mas_action->commandType);
5376 }
5377}
@ CMD_INSERT
Definition nodes.h:277
@ CMD_DELETE
Definition nodes.h:278
@ CMD_UPDATE
Definition nodes.h:276
@ CMD_NOTHING
Definition nodes.h:282
MergeActionState * mt_merge_action
Definition execnodes.h:1489
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, cstring_to_text_with_len(), elog, ERROR, fb(), ModifyTableState::mt_merge_action, ExprEvalStep::op, and PointerGetDatum.

Referenced by ExecInterpExpr().

◆ ExecEvalMinMax()

void ExecEvalMinMax ( ExprState state,
ExprEvalStep op 
)

Definition at line 3686 of file execExprInterp.c.

3687{
3688 Datum *values = op->d.minmax.values;
3689 bool *nulls = op->d.minmax.nulls;
3690 FunctionCallInfo fcinfo = op->d.minmax.fcinfo_data;
3691 MinMaxOp operator = op->d.minmax.op;
3692
3693 /* set at initialization */
3694 Assert(fcinfo->args[0].isnull == false);
3695 Assert(fcinfo->args[1].isnull == false);
3696
3697 /* default to null result */
3698 *op->resnull = true;
3699
3700 for (int off = 0; off < op->d.minmax.nelems; off++)
3701 {
3702 /* ignore NULL inputs */
3703 if (nulls[off])
3704 continue;
3705
3706 if (*op->resnull)
3707 {
3708 /* first nonnull input, adopt value */
3709 *op->resvalue = values[off];
3710 *op->resnull = false;
3711 }
3712 else
3713 {
3714 int cmpresult;
3715
3716 /* apply comparison function */
3717 fcinfo->args[0].value = *op->resvalue;
3718 fcinfo->args[1].value = values[off];
3719
3720 fcinfo->isnull = false;
3722 if (fcinfo->isnull) /* probably should not happen */
3723 continue;
3724
3725 if (cmpresult > 0 && operator == IS_LEAST)
3726 *op->resvalue = values[off];
3727 else if (cmpresult < 0 && operator == IS_GREATEST)
3728 *op->resvalue = values[off];
3729 }
3730 }
3731}
static Datum values[MAXATTR]
Definition bootstrap.c:190
static int32 DatumGetInt32(Datum X)
Definition postgres.h:202
MinMaxOp
Definition primnodes.h:1528
@ IS_LEAST
Definition primnodes.h:1530
@ IS_GREATEST
Definition primnodes.h:1529
MinMaxOp op
Definition execExpr.h:534
struct ExprEvalStep::@63::@88 minmax

References FunctionCallInfoBaseData::args, Assert, DatumGetInt32(), fb(), 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 3283 of file execExprInterp.c.

3284{
3286
3287 switch (op->d.nextvalueexpr.seqtypid)
3288 {
3289 case INT2OID:
3291 break;
3292 case INT4OID:
3294 break;
3295 case INT8OID:
3297 break;
3298 default:
3299 elog(ERROR, "unsupported sequence type %u",
3301 }
3302 *op->resnull = false;
3303}
int64_t int64
Definition c.h:621
int64 nextval_internal(Oid relid, bool check_permissions)
Definition sequence.c:624
#define newval
static Datum Int64GetDatum(int64 X)
Definition postgres.h:426
static Datum Int16GetDatum(int16 X)
Definition postgres.h:172
struct ExprEvalStep::@63::@82 nextvalueexpr

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

Referenced by ExecInterpExpr().

◆ ExecEvalParamExec()

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

Definition at line 3058 of file execExprInterp.c.

3059{
3061
3062 prm = &(econtext->ecxt_param_exec_vals[op->d.param.paramid]);
3063 if (unlikely(prm->execPlan != NULL))
3064 {
3065 /* Parameter not evaluated yet, so go do it */
3066 ExecSetParamPlan(prm->execPlan, econtext);
3067 /* ExecSetParamPlan should have processed this param... */
3068 Assert(prm->execPlan == NULL);
3069 }
3070 *op->resvalue = prm->value;
3071 *op->resnull = prm->isnull;
3072}
void ExecSetParamPlan(SubPlanState *node, ExprContext *econtext)
ParamExecData * ecxt_param_exec_vals
Definition execnodes.h:298
struct ExprEvalStep::@63::@76 param

References Assert, ExprContext::ecxt_param_exec_vals, ExecSetParamPlan(), fb(), ExprEvalStep::op, and unlikely.

Referenced by ExecInterpExpr().

◆ ExecEvalParamExtern()

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

Definition at line 3080 of file execExprInterp.c.

3081{
3083 int paramId = op->d.param.paramid;
3084
3085 if (likely(paramInfo &&
3086 paramId > 0 && paramId <= paramInfo->numParams))
3087 {
3090
3091 /* give hook a chance in case parameter is dynamic */
3092 if (paramInfo->paramFetch != NULL)
3093 prm = paramInfo->paramFetch(paramInfo, paramId, false, &prmdata);
3094 else
3095 prm = &paramInfo->params[paramId - 1];
3096
3097 if (likely(OidIsValid(prm->ptype)))
3098 {
3099 /* safety check in case hook did something unexpected */
3100 if (unlikely(prm->ptype != op->d.param.paramtype))
3101 ereport(ERROR,
3103 errmsg("type of parameter %d (%s) does not match that when preparing the plan (%s)",
3104 paramId,
3105 format_type_be(prm->ptype),
3107 *op->resvalue = prm->value;
3108 *op->resnull = prm->isnull;
3109 return;
3110 }
3111 }
3112
3113 ereport(ERROR,
3115 errmsg("no value found for parameter %d", paramId)));
3116}
#define likely(x)
Definition c.h:437
#define OidIsValid(objectId)
Definition c.h:858
ParamListInfo ecxt_param_list_info
Definition execnodes.h:299

References ExprContext::ecxt_param_list_info, ereport, errcode(), errmsg, ERROR, fb(), format_type_be(), likely, OidIsValid, ExprEvalStep::op, and unlikely.

Referenced by ExecInterpExpr().

◆ ExecEvalParamSet()

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

Definition at line 3123 of file execExprInterp.c.

3124{
3126
3127 prm = &(econtext->ecxt_param_exec_vals[op->d.param.paramid]);
3128
3129 /* Shouldn't have a pending evaluation anymore */
3130 Assert(prm->execPlan == NULL);
3131
3132 prm->value = *op->resvalue;
3133 prm->isnull = *op->resnull;
3134}

References Assert, ExprContext::ecxt_param_exec_vals, fb(), and ExprEvalStep::op.

Referenced by ExecInterpExpr().

◆ ExecEvalPreOrderedDistinctMulti()

bool ExecEvalPreOrderedDistinctMulti ( AggState aggstate,
AggStatePerTrans  pertrans 
)

Definition at line 5835 of file execExprInterp.c.

5836{
5837 ExprContext *tmpcontext = aggstate->tmpcontext;
5838 bool isdistinct = false; /* for now */
5841
5842 for (int i = 0; i < pertrans->numTransInputs; i++)
5843 {
5844 pertrans->sortslot->tts_values[i] = pertrans->transfn_fcinfo->args[i + 1].value;
5845 pertrans->sortslot->tts_isnull[i] = pertrans->transfn_fcinfo->args[i + 1].isnull;
5846 }
5847
5848 ExecClearTuple(pertrans->sortslot);
5849 pertrans->sortslot->tts_nvalid = pertrans->numInputs;
5851
5852 /* save the previous slots before we overwrite them */
5853 save_outer = tmpcontext->ecxt_outertuple;
5854 save_inner = tmpcontext->ecxt_innertuple;
5855
5856 tmpcontext->ecxt_outertuple = pertrans->sortslot;
5857 tmpcontext->ecxt_innertuple = pertrans->uniqslot;
5858
5859 if (!pertrans->haslast ||
5860 !ExecQual(pertrans->equalfnMulti, tmpcontext))
5861 {
5862 if (pertrans->haslast)
5863 ExecClearTuple(pertrans->uniqslot);
5864
5865 pertrans->haslast = true;
5866 ExecCopySlot(pertrans->uniqslot, pertrans->sortslot);
5867
5868 isdistinct = true;
5869 }
5870
5871 /* restore the original slots */
5872 tmpcontext->ecxt_outertuple = save_outer;
5873 tmpcontext->ecxt_innertuple = save_inner;
5874
5875 return isdistinct;
5876}
static bool ExecQual(ExprState *state, ExprContext *econtext)
Definition executor.h:529
ExprState * equalfnMulti
Definition nodeAgg.h:116
TupleTableSlot * uniqslot
Definition nodeAgg.h:142
bool * tts_isnull
Definition tuptable.h:133
Datum * tts_values
Definition tuptable.h:131
static TupleTableSlot * ExecCopySlot(TupleTableSlot *dstslot, TupleTableSlot *srcslot)
Definition tuptable.h:543

References FunctionCallInfoBaseData::args, ExprContext::ecxt_innertuple, ExprContext::ecxt_outertuple, AggStatePerTransData::equalfnMulti, ExecClearTuple(), ExecCopySlot(), ExecQual(), ExecStoreVirtualTuple(), fb(), AggStatePerTransData::haslast, i, NullableDatum::isnull, AggStatePerTransData::numInputs, AggStatePerTransData::numTransInputs, ExprEvalStep::pertrans, AggStatePerTransData::sortslot, 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 5792 of file execExprInterp.c.

5793{
5794 Datum value = pertrans->transfn_fcinfo->args[1].value;
5795 bool isnull = pertrans->transfn_fcinfo->args[1].isnull;
5796
5797 if (!pertrans->haslast ||
5798 pertrans->lastisnull != isnull ||
5799 (!isnull && !DatumGetBool(FunctionCall2Coll(&pertrans->equalfnOne,
5800 pertrans->aggCollation,
5801 pertrans->lastdatum, value))))
5802 {
5803 if (pertrans->haslast && !pertrans->inputtypeByVal &&
5804 !pertrans->lastisnull)
5805 pfree(DatumGetPointer(pertrans->lastdatum));
5806
5807 pertrans->haslast = true;
5808 if (!isnull)
5809 {
5811
5812 oldContext = MemoryContextSwitchTo(aggstate->curaggcontext->ecxt_per_tuple_memory);
5813
5814 pertrans->lastdatum = datumCopy(value, pertrans->inputtypeByVal,
5815 pertrans->inputtypeLen);
5816
5818 }
5819 else
5820 pertrans->lastdatum = (Datum) 0;
5821 pertrans->lastisnull = isnull;
5822 return true;
5823 }
5824
5825 return false;
5826}
Datum FunctionCall2Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2)
Definition fmgr.c:1151
FmgrInfo equalfnOne
Definition nodeAgg.h:115

References AggStatePerTransData::aggCollation, FunctionCallInfoBaseData::args, datumCopy(), DatumGetBool(), DatumGetPointer(), AggStatePerTransData::equalfnOne, fb(), 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 3666 of file execExprInterp.c.

3667{
3668 HeapTuple tuple;
3669
3670 /* build tuple from evaluated field values */
3671 tuple = heap_form_tuple(op->d.row.tupdesc,
3672 op->d.row.elemvalues,
3673 op->d.row.elemnulls);
3674
3675 *op->resvalue = HeapTupleGetDatum(tuple);
3676 *op->resnull = false;
3677}
TupleDesc tupdesc
Definition execExpr.h:350
struct ExprEvalStep::@63::@85 row

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

Referenced by ExecInterpExpr().

◆ ExecEvalRowNotNull()

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

Definition at line 3318 of file execExprInterp.c.

3319{
3320 ExecEvalRowNullInt(state, op, econtext, false);
3321}
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 3309 of file execExprInterp.c.

3310{
3311 ExecEvalRowNullInt(state, op, econtext, true);
3312}

References ExecEvalRowNullInt(), and ExprEvalStep::op.

Referenced by ExecInterpExpr().

◆ ExecEvalRowNullInt()

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

Definition at line 3325 of file execExprInterp.c.

3327{
3328 Datum value = *op->resvalue;
3329 bool isnull = *op->resnull;
3330 HeapTupleHeader tuple;
3331 Oid tupType;
3333 TupleDesc tupDesc;
3335
3336 *op->resnull = false;
3337
3338 /* NULL row variables are treated just as NULL scalar columns */
3339 if (isnull)
3340 {
3342 return;
3343 }
3344
3345 /*
3346 * The SQL standard defines IS [NOT] NULL for a non-null rowtype argument
3347 * as:
3348 *
3349 * "R IS NULL" is true if every field is the null value.
3350 *
3351 * "R IS NOT NULL" is true if no field is the null value.
3352 *
3353 * This definition is (apparently intentionally) not recursive; so our
3354 * tests on the fields are primitive attisnull tests, not recursive checks
3355 * to see if they are all-nulls or no-nulls rowtypes.
3356 *
3357 * The standard does not consider the possibility of zero-field rows, but
3358 * here we consider them to vacuously satisfy both predicates.
3359 */
3360
3362
3365
3366 /* Lookup tupdesc if first time through or if type changes */
3368 &op->d.nulltest_row.rowcache, NULL);
3369
3370 /*
3371 * heap_attisnull needs a HeapTuple not a bare HeapTupleHeader.
3372 */
3374 tmptup.t_data = tuple;
3375
3376 for (int att = 1; att <= tupDesc->natts; att++)
3377 {
3378 /* ignore dropped columns */
3379 if (TupleDescCompactAttr(tupDesc, att - 1)->attisdropped)
3380 continue;
3381 if (heap_attisnull(&tmptup, att, tupDesc))
3382 {
3383 /* null field disproves IS NOT NULL */
3384 if (!checkisnull)
3385 {
3386 *op->resvalue = BoolGetDatum(false);
3387 return;
3388 }
3389 }
3390 else
3391 {
3392 /* non-null field disproves IS NULL */
3393 if (checkisnull)
3394 {
3395 *op->resvalue = BoolGetDatum(false);
3396 return;
3397 }
3398 }
3399 }
3400
3401 *op->resvalue = BoolGetDatum(true);
3402}
bool heap_attisnull(HeapTuple tup, int attnum, TupleDesc tupleDesc)
Definition heaptuple.c:456
struct ExprEvalStep::@63::@75 nulltest_row
static CompactAttribute * TupleDescCompactAttr(TupleDesc tupdesc, int i)
Definition tupdesc.h:195

References BoolGetDatum(), DatumGetHeapTupleHeader, fb(), get_cached_rowtype(), heap_attisnull(), HeapTupleHeaderGetDatumLength(), HeapTupleHeaderGetTypeId(), HeapTupleHeaderGetTypMod(), ExprEvalStep::isnull, TupleDescData::natts, ExprEvalStep::op, TupleDescCompactAttr(), and value.

Referenced by ExecEvalRowNotNull(), and ExecEvalRowNull().

◆ ExecEvalScalarArrayOp()

void ExecEvalScalarArrayOp ( ExprState state,
ExprEvalStep op 
)

Definition at line 4033 of file execExprInterp.c.

4034{
4036 bool useOr = op->d.scalararrayop.useOr;
4038 ArrayType *arr;
4039 int nitems;
4040 Datum result;
4041 bool resultnull;
4042
4043 /*
4044 * If the array is NULL then we return NULL --- it's not very meaningful
4045 * to do anything else, even if the operator isn't strict.
4046 */
4047 if (*op->resnull)
4048 return;
4049
4050 /* Else okay to fetch and detoast the array */
4051 arr = DatumGetArrayTypeP(*op->resvalue);
4052
4053 /*
4054 * If the array is empty, we return either FALSE or TRUE per the useOr
4055 * flag. This is correct even if the scalar is NULL; since we would
4056 * evaluate the operator zero times, it matters not whether it would want
4057 * to return NULL.
4058 */
4059 nitems = ArrayGetNItems(ARR_NDIM(arr), ARR_DIMS(arr));
4060 if (nitems <= 0)
4061 {
4062 *op->resvalue = BoolGetDatum(!useOr);
4063 *op->resnull = false;
4064 return;
4065 }
4066
4067 /*
4068 * If the scalar is NULL, and the function is strict, return NULL; no
4069 * point in iterating the loop.
4070 */
4071 if (fcinfo->args[0].isnull && strictfunc)
4072 {
4073 *op->resnull = true;
4074 return;
4075 }
4076
4077 /*
4078 * We arrange to look up info about the element type only once per series
4079 * of calls, assuming the element type doesn't change underneath us.
4080 */
4081 if (op->d.scalararrayop.element_type != ARR_ELEMTYPE(arr))
4082 {
4084 &op->d.scalararrayop.typlen,
4086 &op->d.scalararrayop.typalign);
4088 }
4089
4091 arr,
4095 useOr,
4096 &result,
4097 &resultnull);
4098
4099 *op->resvalue = result;
4100 *op->resnull = resultnull;
4101}
bool typbyval
Definition execExpr.h:631
struct ExprEvalStep::@63::@97 scalararrayop
char typalign
Definition execExpr.h:632
int16 typlen
Definition execExpr.h:630
Oid element_type
Definition execExpr.h:628

References FunctionCallInfoBaseData::args, ARR_DIMS, ARR_ELEMTYPE, ARR_NDIM, ArrayGetNItems(), BoolGetDatum(), DatumGetArrayTypeP, ExecEvalArrayCompareInternal(), fb(), get_typlenbyvalalign(), NullableDatum::isnull, nitems, ExprEvalStep::op, result, and ExprEvalStep::useOr.

Referenced by ExecInterpExpr().

◆ ExecEvalSQLValueFunction()

void ExecEvalSQLValueFunction ( ExprState state,
ExprEvalStep op 
)

Definition at line 3205 of file execExprInterp.c.

3206{
3207 LOCAL_FCINFO(fcinfo, 0);
3209
3210 *op->resnull = false;
3211
3212 /*
3213 * Note: current_schema() can return NULL. current_user() etc currently
3214 * cannot, but might as well code those cases the same way for safety.
3215 */
3216 switch (svf->op)
3217 {
3218 case SVFOP_CURRENT_DATE:
3220 break;
3221 case SVFOP_CURRENT_TIME:
3224 break;
3228 break;
3229 case SVFOP_LOCALTIME:
3230 case SVFOP_LOCALTIME_N:
3232 break;
3236 break;
3237 case SVFOP_CURRENT_ROLE:
3238 case SVFOP_CURRENT_USER:
3239 case SVFOP_USER:
3241 *op->resvalue = current_user(fcinfo);
3242 *op->resnull = fcinfo->isnull;
3243 break;
3244 case SVFOP_SESSION_USER:
3246 *op->resvalue = session_user(fcinfo);
3247 *op->resnull = fcinfo->isnull;
3248 break;
3251 *op->resvalue = current_database(fcinfo);
3252 *op->resnull = fcinfo->isnull;
3253 break;
3256 *op->resvalue = current_schema(fcinfo);
3257 *op->resnull = fcinfo->isnull;
3258 break;
3259 }
3260}
Datum current_database(PG_FUNCTION_ARGS)
Definition misc.c:211
Timestamp GetSQLLocalTimestamp(int32 typmod)
Definition timestamp.c:1671
TimestampTz GetSQLCurrentTimestamp(int32 typmod)
Definition timestamp.c:1657
TimeADT GetSQLLocalTime(int32 typmod)
Definition date.c:363
DateADT GetSQLCurrentDate(void)
Definition date.c:310
TimeTzADT * GetSQLCurrentTime(int32 typmod)
Definition date.c:343
static Datum DateADTGetDatum(DateADT X)
Definition date.h:78
static Datum TimeTzADTPGetDatum(const TimeTzADT *X)
Definition date.h:90
static Datum TimeADTGetDatum(TimeADT X)
Definition date.h:84
#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:1576
@ SVFOP_LOCALTIME_N
Definition primnodes.h:1569
@ SVFOP_CURRENT_TIMESTAMP
Definition primnodes.h:1566
@ SVFOP_LOCALTIME
Definition primnodes.h:1568
@ SVFOP_CURRENT_TIMESTAMP_N
Definition primnodes.h:1567
@ SVFOP_CURRENT_ROLE
Definition primnodes.h:1572
@ SVFOP_USER
Definition primnodes.h:1574
@ SVFOP_CURRENT_SCHEMA
Definition primnodes.h:1577
@ SVFOP_LOCALTIMESTAMP_N
Definition primnodes.h:1571
@ SVFOP_CURRENT_DATE
Definition primnodes.h:1563
@ SVFOP_CURRENT_TIME_N
Definition primnodes.h:1565
@ SVFOP_CURRENT_TIME
Definition primnodes.h:1564
@ SVFOP_LOCALTIMESTAMP
Definition primnodes.h:1570
@ SVFOP_CURRENT_USER
Definition primnodes.h:1573
@ SVFOP_SESSION_USER
Definition primnodes.h:1575
struct ExprEvalStep::@63::@81 sqlvaluefunction
SQLValueFunction * svf
Definition execExpr.h:467
SQLValueFunctionOp op
Definition primnodes.h:1583
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(), fb(), 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 2970 of file execExprInterp.c.

2971{
2972#if defined(EEO_USE_COMPUTED_GOTO)
2973 if (state->flags & EEO_FLAG_DIRECT_THREADED)
2974 {
2976 ExprEvalOpLookup *res;
2977
2978 key.opcode = (void *) op->opcode;
2979 res = bsearch(&key,
2981 EEOP_LAST /* nmembers */ ,
2982 sizeof(ExprEvalOpLookup),
2984 Assert(res); /* unknown ops shouldn't get looked up */
2985 return res->op;
2986 }
2987#endif
2988 return (ExprEvalOp) op->opcode;
2989}
#define EEO_FLAG_DIRECT_THREADED
Definition execExpr.h:31
ExprEvalOp
Definition execExpr.h:67
@ EEOP_LAST
Definition execExpr.h:296
intptr_t opcode
Definition execExpr.h:307

References Assert, EEO_FLAG_DIRECT_THREADED, EEOP_LAST, fb(), and ExprEvalStep::op.

Referenced by CheckExprStillValid(), and llvm_compile_expr().

◆ ExecEvalSubPlan()

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

Definition at line 5383 of file execExprInterp.c.

5384{
5385 SubPlanState *sstate = op->d.subplan.sstate;
5386
5387 /* could potentially be nested, so make sure there's enough stack */
5389
5390 *op->resvalue = ExecSubPlan(sstate, econtext, op->resnull);
5391}
Datum ExecSubPlan(SubPlanState *node, ExprContext *econtext, bool *isNull)
Definition nodeSubplan.c:59
void check_stack_depth(void)
Definition stack_depth.c:95
SubPlanState * sstate
Definition execExpr.h:695
struct ExprEvalStep::@63::@104 subplan

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

Referenced by ExecInterpExpr().

◆ ExecEvalSysVar()

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

Definition at line 5659 of file execExprInterp.c.

5661{
5662 Datum d;
5663
5664 /* OLD/NEW system attribute is NULL if OLD/NEW row is NULL */
5666 state->flags & EEO_FLAG_OLD_IS_NULL) ||
5668 state->flags & EEO_FLAG_NEW_IS_NULL))
5669 {
5670 *op->resvalue = (Datum) 0;
5671 *op->resnull = true;
5672 return;
5673 }
5674
5675 /* slot_getsysattr has sufficient defenses against bad attnums */
5676 d = slot_getsysattr(slot,
5677 op->d.var.attnum,
5678 op->resnull);
5679 *op->resvalue = d;
5680 /* this ought to be unreachable, but it's cheap enough to check */
5681 if (unlikely(*op->resnull))
5682 elog(ERROR, "failed to fetch attribute from slot");
5683}
#define EEO_FLAG_NEW_IS_NULL
Definition execnodes.h:96
#define EEO_FLAG_OLD_IS_NULL
Definition execnodes.h:94
@ VAR_RETURNING_OLD
Definition primnodes.h:258
@ VAR_RETURNING_NEW
Definition primnodes.h:259
VarReturningType varreturningtype
Definition execExpr.h:341
static Datum slot_getsysattr(TupleTableSlot *slot, int attnum, bool *isnull)
Definition tuptable.h:438

References ExprEvalStep::d, EEO_FLAG_NEW_IS_NULL, EEO_FLAG_OLD_IS_NULL, elog, ERROR, ExprEvalStep::op, slot_getsysattr(), unlikely, VAR_RETURNING_NEW, and VAR_RETURNING_OLD.

Referenced by ExecInterpExpr().

◆ ExecEvalWholeRowVar()

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

Definition at line 5400 of file execExprInterp.c.

5401{
5402 Var *variable = op->d.wholerow.var;
5403 TupleTableSlot *slot = NULL;
5405 MemoryContext oldcontext;
5407 HeapTuple tuple;
5408
5409 /* This was checked by ExecInitExpr */
5410 Assert(variable->varattno == InvalidAttrNumber);
5411
5412 /* Get the input slot we want */
5413 switch (variable->varno)
5414 {
5415 case INNER_VAR:
5416 /* get the tuple from the inner node */
5417 slot = econtext->ecxt_innertuple;
5418 break;
5419
5420 case OUTER_VAR:
5421 /* get the tuple from the outer node */
5422 slot = econtext->ecxt_outertuple;
5423 break;
5424
5425 /* INDEX_VAR is handled by default case */
5426
5427 default:
5428
5429 /*
5430 * Get the tuple from the relation being scanned.
5431 *
5432 * By default, this uses the "scan" tuple slot, but a wholerow Var
5433 * in the RETURNING list may explicitly refer to OLD/NEW. If the
5434 * OLD/NEW row doesn't exist, we just return NULL.
5435 */
5436 switch (variable->varreturningtype)
5437 {
5439 slot = econtext->ecxt_scantuple;
5440 break;
5441
5442 case VAR_RETURNING_OLD:
5443 if (state->flags & EEO_FLAG_OLD_IS_NULL)
5444 {
5445 *op->resvalue = (Datum) 0;
5446 *op->resnull = true;
5447 return;
5448 }
5449 slot = econtext->ecxt_oldtuple;
5450 break;
5451
5452 case VAR_RETURNING_NEW:
5453 if (state->flags & EEO_FLAG_NEW_IS_NULL)
5454 {
5455 *op->resvalue = (Datum) 0;
5456 *op->resnull = true;
5457 return;
5458 }
5459 slot = econtext->ecxt_newtuple;
5460 break;
5461 }
5462 break;
5463 }
5464
5465 /* Apply the junkfilter if any */
5466 if (op->d.wholerow.junkFilter != NULL)
5467 slot = ExecFilterJunk(op->d.wholerow.junkFilter, slot);
5468
5469 /*
5470 * If first time through, obtain tuple descriptor and check compatibility.
5471 *
5472 * XXX: It'd be great if this could be moved to the expression
5473 * initialization phase, but due to using slots that's currently not
5474 * feasible.
5475 */
5476 if (op->d.wholerow.first)
5477 {
5478 /* optimistically assume we don't need slow path */
5479 op->d.wholerow.slow = false;
5480
5481 /*
5482 * If the Var identifies a named composite type, we must check that
5483 * the actual tuple type is compatible with it.
5484 */
5485 if (variable->vartype != RECORDOID)
5486 {
5489
5490 /*
5491 * We really only care about numbers of attributes and data types.
5492 * Also, we can ignore type mismatch on columns that are dropped
5493 * in the destination type, so long as (1) the physical storage
5494 * matches or (2) the actual column value is NULL. Case (1) is
5495 * helpful in some cases involving out-of-date cached plans, while
5496 * case (2) is expected behavior in situations such as an INSERT
5497 * into a table with dropped columns (the planner typically
5498 * generates an INT4 NULL regardless of the dropped column type).
5499 * If we find a dropped column and cannot verify that case (1)
5500 * holds, we have to use the slow path to check (2) for each row.
5501 *
5502 * If vartype is a domain over composite, just look through that
5503 * to the base composite type.
5504 */
5506 -1, false);
5507
5509
5510 if (var_tupdesc->natts != slot_tupdesc->natts)
5511 ereport(ERROR,
5513 errmsg("table row type and query-specified row type do not match"),
5514 errdetail_plural("Table row contains %d attribute, but query expects %d.",
5515 "Table row contains %d attributes, but query expects %d.",
5516 slot_tupdesc->natts,
5517 slot_tupdesc->natts,
5518 var_tupdesc->natts)));
5519
5520 for (int i = 0; i < var_tupdesc->natts; i++)
5521 {
5524
5525 if (vattr->atttypid == sattr->atttypid)
5526 continue; /* no worries */
5527 if (!vattr->attisdropped)
5528 ereport(ERROR,
5530 errmsg("table row type and query-specified row type do not match"),
5531 errdetail("Table has type %s at ordinal position %d, but query expects %s.",
5532 format_type_be(sattr->atttypid),
5533 i + 1,
5534 format_type_be(vattr->atttypid))));
5535
5536 if (vattr->attlen != sattr->attlen ||
5537 vattr->attalign != sattr->attalign)
5538 op->d.wholerow.slow = true; /* need to check for nulls */
5539 }
5540
5541 /*
5542 * Use the variable's declared rowtype as the descriptor for the
5543 * output values. In particular, we *must* absorb any
5544 * attisdropped markings.
5545 */
5546 oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
5548 MemoryContextSwitchTo(oldcontext);
5549
5551 }
5552 else
5553 {
5554 /*
5555 * In the RECORD case, we use the input slot's rowtype as the
5556 * descriptor for the output values, modulo possibly assigning new
5557 * column names below.
5558 */
5559 oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
5561 MemoryContextSwitchTo(oldcontext);
5562
5563 /*
5564 * It's possible that the input slot is a relation scan slot and
5565 * so is marked with that relation's rowtype. But we're supposed
5566 * to be returning RECORD, so reset to that.
5567 */
5568 output_tupdesc->tdtypeid = RECORDOID;
5569 output_tupdesc->tdtypmod = -1;
5570
5571 /*
5572 * We already got the correct physical datatype info above, but
5573 * now we should try to find the source RTE and adopt its column
5574 * aliases, since it's unlikely that the input slot has the
5575 * desired names.
5576 *
5577 * If we can't locate the RTE, assume the column names we've got
5578 * are OK. (As of this writing, the only cases where we can't
5579 * locate the RTE are in execution of trigger WHEN clauses, and
5580 * then the Var will have the trigger's relation's rowtype, so its
5581 * names are fine.) Also, if the creator of the RTE didn't bother
5582 * to fill in an eref field, assume our column names are OK. (This
5583 * happens in COPY, and perhaps other places.)
5584 */
5585 if (econtext->ecxt_estate &&
5586 variable->varno <= econtext->ecxt_estate->es_range_table_size)
5587 {
5589 econtext->ecxt_estate);
5590
5591 if (rte->eref)
5592 ExecTypeSetColNames(output_tupdesc, rte->eref->colnames);
5593 }
5594 }
5595
5596 /* Bless the tupdesc if needed, and save it in the execution state */
5598
5599 op->d.wholerow.first = false;
5600 }
5601
5602 /*
5603 * Make sure all columns of the slot are accessible in the slot's
5604 * Datum/isnull arrays.
5605 */
5606 slot_getallattrs(slot);
5607
5608 if (op->d.wholerow.slow)
5609 {
5610 /* Check to see if any dropped attributes are non-null */
5613
5614 Assert(var_tupdesc->natts == tupleDesc->natts);
5615
5616 for (int i = 0; i < var_tupdesc->natts; i++)
5617 {
5620
5621 if (!vattr->attisdropped)
5622 continue; /* already checked non-dropped cols */
5623 if (slot->tts_isnull[i])
5624 continue; /* null is always okay */
5625 if (vattr->attlen != sattr->attlen ||
5626 vattr->attalignby != sattr->attalignby)
5627 ereport(ERROR,
5629 errmsg("table row type and query-specified row type do not match"),
5630 errdetail("Physical storage mismatch on dropped attribute at ordinal position %d.",
5631 i + 1)));
5632 }
5633 }
5634
5635 /*
5636 * Build a composite datum, making sure any toasted fields get detoasted.
5637 *
5638 * (Note: it is critical that we not change the slot's state here.)
5639 */
5641 slot->tts_values,
5642 slot->tts_isnull);
5643 dtuple = tuple->t_data;
5644
5645 /*
5646 * Label the datum with the composite type info we identified before.
5647 *
5648 * (Note: we could skip doing this by passing op->d.wholerow.tupdesc to
5649 * the tuple build step; but that seems a tad risky so let's not.)
5650 */
5653
5655 *op->resnull = false;
5656}
#define InvalidAttrNumber
Definition attnum.h:23
int errdetail_plural(const char *fmt_singular, const char *fmt_plural, unsigned long n,...) pg_attribute_printf(1
TupleTableSlot * ExecFilterJunk(JunkFilter *junkfilter, TupleTableSlot *slot)
Definition execJunk.c:247
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
void ExecTypeSetColNames(TupleDesc typeInfo, List *namesList)
static RangeTblEntry * exec_rt_fetch(Index rti, EState *estate)
Definition executor.h:710
HeapTuple toast_build_flattened_tuple(TupleDesc tupleDesc, const Datum *values, const bool *isnull)
Definition heaptoast.c:563
static void HeapTupleHeaderSetTypMod(HeapTupleHeaderData *tup, int32 typmod)
static void HeapTupleHeaderSetTypeId(HeapTupleHeaderData *tup, Oid datum_typeid)
@ VAR_RETURNING_DEFAULT
Definition primnodes.h:257
#define OUTER_VAR
Definition primnodes.h:244
#define INNER_VAR
Definition primnodes.h:243
Index es_range_table_size
Definition execnodes.h:699
struct EState * ecxt_estate
Definition execnodes.h:329
JunkFilter * junkFilter
Definition execExpr.h:351
struct ExprEvalStep::@63::@66 wholerow
HeapTupleHeader t_data
Definition htup.h:68
int32 tdtypmod
Definition tupdesc.h:152
TupleDesc CreateTupleDescCopy(TupleDesc tupdesc)
Definition tupdesc.c:242
#define ReleaseTupleDesc(tupdesc)
Definition tupdesc.h:240
static void slot_getallattrs(TupleTableSlot *slot)
Definition tuptable.h:390
TupleDesc lookup_rowtype_tupdesc_domain(Oid type_id, int32 typmod, bool noError)
Definition typcache.c:2003

References Assert, BlessTupleDesc(), CreateTupleDescCopy(), ExprContext::ecxt_estate, ExprContext::ecxt_innertuple, ExprContext::ecxt_newtuple, ExprContext::ecxt_oldtuple, ExprContext::ecxt_outertuple, ExprContext::ecxt_per_query_memory, ExprContext::ecxt_scantuple, EEO_FLAG_NEW_IS_NULL, EEO_FLAG_OLD_IS_NULL, ereport, errcode(), errdetail(), errdetail_plural(), errmsg, ERROR, EState::es_range_table_size, exec_rt_fetch(), ExecFilterJunk(), ExecTypeSetColNames(), fb(), format_type_be(), HeapTupleHeaderSetTypeId(), HeapTupleHeaderSetTypMod(), i, INNER_VAR, InvalidAttrNumber, lookup_rowtype_tupdesc_domain(), MemoryContextSwitchTo(), ExprEvalStep::op, OUTER_VAR, PointerGetDatum, ReleaseTupleDesc, slot_getallattrs(), HeapTupleData::t_data, toast_build_flattened_tuple(), TupleTableSlot::tts_isnull, TupleTableSlot::tts_tupleDescriptor, TupleTableSlot::tts_values, TupleDescAttr(), TupleDescCompactAttr(), VAR_RETURNING_DEFAULT, VAR_RETURNING_NEW, and VAR_RETURNING_OLD.

Referenced by ExecInterpExpr().

◆ ExecEvalXmlExpr()

void ExecEvalXmlExpr ( ExprState state,
ExprEvalStep op 
)

Definition at line 4518 of file execExprInterp.c.

4519{
4520 XmlExpr *xexpr = op->d.xmlexpr.xexpr;
4521 Datum value;
4522
4523 *op->resnull = true; /* until we get a result */
4524 *op->resvalue = (Datum) 0;
4525
4526 switch (xexpr->op)
4527 {
4528 case IS_XMLCONCAT:
4529 {
4530 Datum *argvalue = op->d.xmlexpr.argvalue;
4531 bool *argnull = op->d.xmlexpr.argnull;
4532 List *values = NIL;
4533
4534 for (int i = 0; i < list_length(xexpr->args); i++)
4535 {
4536 if (!argnull[i])
4537 values = lappend(values, DatumGetPointer(argvalue[i]));
4538 }
4539
4540 if (values != NIL)
4541 {
4543 *op->resnull = false;
4544 }
4545 }
4546 break;
4547
4548 case IS_XMLFOREST:
4549 {
4550 Datum *argvalue = op->d.xmlexpr.named_argvalue;
4551 bool *argnull = op->d.xmlexpr.named_argnull;
4553 ListCell *lc;
4554 ListCell *lc2;
4555 int i;
4556
4558
4559 i = 0;
4560 forboth(lc, xexpr->named_args, lc2, xexpr->arg_names)
4561 {
4562 Expr *e = (Expr *) lfirst(lc);
4563 char *argname = strVal(lfirst(lc2));
4564
4565 if (!argnull[i])
4566 {
4567 value = argvalue[i];
4568 appendStringInfo(&buf, "<%s>%s</%s>",
4569 argname,
4571 exprType((Node *) e), true),
4572 argname);
4573 *op->resnull = false;
4574 }
4575 i++;
4576 }
4577
4578 if (!*op->resnull)
4579 {
4580 text *result;
4581
4584 }
4585
4586 pfree(buf.data);
4587 }
4588 break;
4589
4590 case IS_XMLELEMENT:
4591 *op->resvalue = PointerGetDatum(xmlelement(xexpr,
4594 op->d.xmlexpr.argvalue,
4595 op->d.xmlexpr.argnull));
4596 *op->resnull = false;
4597 break;
4598
4599 case IS_XMLPARSE:
4600 {
4601 Datum *argvalue = op->d.xmlexpr.argvalue;
4602 bool *argnull = op->d.xmlexpr.argnull;
4603 text *data;
4605
4606 /* arguments are known to be text, bool */
4607 Assert(list_length(xexpr->args) == 2);
4608
4609 if (argnull[0])
4610 return;
4611 value = argvalue[0];
4613
4614 if (argnull[1]) /* probably can't happen */
4615 return;
4616 value = argvalue[1];
4618
4620 xexpr->xmloption,
4622 *op->resnull = false;
4623 }
4624 break;
4625
4626 case IS_XMLPI:
4627 {
4628 text *arg;
4629 bool isnull;
4630
4631 /* optional argument is known to be text */
4632 Assert(list_length(xexpr->args) <= 1);
4633
4634 if (xexpr->args)
4635 {
4636 isnull = op->d.xmlexpr.argnull[0];
4637 if (isnull)
4638 arg = NULL;
4639 else
4641 }
4642 else
4643 {
4644 arg = NULL;
4645 isnull = false;
4646 }
4647
4648 *op->resvalue = PointerGetDatum(xmlpi(xexpr->name,
4649 arg,
4650 isnull,
4651 op->resnull));
4652 }
4653 break;
4654
4655 case IS_XMLROOT:
4656 {
4657 Datum *argvalue = op->d.xmlexpr.argvalue;
4658 bool *argnull = op->d.xmlexpr.argnull;
4659 xmltype *data;
4660 text *version;
4661 int standalone;
4662
4663 /* arguments are known to be xml, text, int */
4664 Assert(list_length(xexpr->args) == 3);
4665
4666 if (argnull[0])
4667 return;
4668 data = DatumGetXmlP(argvalue[0]);
4669
4670 if (argnull[1])
4671 version = NULL;
4672 else
4673 version = DatumGetTextPP(argvalue[1]);
4674
4675 Assert(!argnull[2]); /* always present */
4676 standalone = DatumGetInt32(argvalue[2]);
4677
4679 version,
4680 standalone));
4681 *op->resnull = false;
4682 }
4683 break;
4684
4685 case IS_XMLSERIALIZE:
4686 {
4687 Datum *argvalue = op->d.xmlexpr.argvalue;
4688 bool *argnull = op->d.xmlexpr.argnull;
4689
4690 /* argument type is known to be xml */
4691 Assert(list_length(xexpr->args) == 1);
4692
4693 if (argnull[0])
4694 return;
4695 value = argvalue[0];
4696
4697 *op->resvalue =
4699 xexpr->xmloption,
4700 xexpr->indent));
4701 *op->resnull = false;
4702 }
4703 break;
4704
4705 case IS_DOCUMENT:
4706 {
4707 Datum *argvalue = op->d.xmlexpr.argvalue;
4708 bool *argnull = op->d.xmlexpr.argnull;
4709
4710 /* optional argument is known to be xml */
4711 Assert(list_length(xexpr->args) == 1);
4712
4713 if (argnull[0])
4714 return;
4715 value = argvalue[0];
4716
4717 *op->resvalue =
4719 *op->resnull = false;
4720 }
4721 break;
4722
4723 default:
4724 elog(ERROR, "unrecognized XML operation");
4725 break;
4726 }
4727}
Datum arg
Definition elog.c:1323
#define DatumGetTextPP(X)
Definition fmgr.h:293
List * lappend(List *list, void *datum)
Definition list.c:339
Oid exprType(const Node *expr)
Definition nodeFuncs.c:42
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:550
static char buf[DEFAULT_XLOG_SEG_SIZE]
e
@ IS_DOCUMENT
Definition primnodes.h:1614
@ IS_XMLFOREST
Definition primnodes.h:1609
@ IS_XMLCONCAT
Definition primnodes.h:1607
@ IS_XMLPI
Definition primnodes.h:1611
@ IS_XMLPARSE
Definition primnodes.h:1610
@ IS_XMLSERIALIZE
Definition primnodes.h:1613
@ IS_XMLROOT
Definition primnodes.h:1612
@ IS_XMLELEMENT
Definition primnodes.h:1608
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition stringinfo.c:145
void initStringInfo(StringInfo str)
Definition stringinfo.c:97
XmlExpr * xexpr
Definition execExpr.h:657
bool * named_argnull
Definition execExpr.h:660
bool * argnull
Definition execExpr.h:663
struct ExprEvalStep::@63::@99 xmlexpr
Datum * named_argvalue
Definition execExpr.h:659
Datum * argvalue
Definition execExpr.h:662
Definition pg_list.h:54
List * args
Definition primnodes.h:1635
bool indent
Definition primnodes.h:1639
List * named_args
Definition primnodes.h:1631
XmlExprOp op
Definition primnodes.h:1627
#define strVal(v)
Definition value.h:82
xmltype * xmlroot(xmltype *data, text *version, int standalone)
Definition xml.c:1106
text * xmltotext_with_options(xmltype *data, XmlOptionType xmloption_arg, bool indent)
Definition xml.c:678
char * map_sql_value_to_xml_value(Datum value, Oid type, bool xml_escape_strings)
Definition xml.c:2520
xmltype * xmlconcat(List *args)
Definition xml.c:575
xmltype * xmlparse(text *data, XmlOptionType xmloption_arg, bool preserve_whitespace, Node *escontext)
Definition xml.c:1032
bool xml_is_document(xmltype *arg)
Definition xml.c:1172
xmltype * xmlelement(XmlExpr *xexpr, const Datum *named_argvalue, const bool *named_argnull, const Datum *argvalue, const bool *argnull)
Definition xml.c:894
xmltype * xmlpi(const char *target, text *arg, bool arg_is_null, bool *result_is_null)
Definition xml.c:1054
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(), fb(), 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, result, 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 5111 of file execExprInterp.c.

5112{
5113 *resnull = false;
5114
5115 /* get coercion state reference and datum of the corresponding SQL type */
5116 switch (item->type)
5117 {
5118 case jbvNull:
5119 *resnull = true;
5120 return NULL;
5121
5122 case jbvString:
5123 {
5124 char *str = palloc(item->val.string.len + 1);
5125
5126 memcpy(str, item->val.string.val, item->val.string.len);
5127 str[item->val.string.len] = '\0';
5128 return str;
5129 }
5130
5131 case jbvNumeric:
5133 NumericGetDatum(item->val.numeric)));
5134
5135 case jbvBool:
5137 BoolGetDatum(item->val.boolean)));
5138
5139 case jbvDatetime:
5140 switch (item->val.datetime.typid)
5141 {
5142 case DATEOID:
5144 item->val.datetime.value));
5145 case TIMEOID:
5147 item->val.datetime.value));
5148 case TIMETZOID:
5150 item->val.datetime.value));
5151 case TIMESTAMPOID:
5153 item->val.datetime.value));
5154 case TIMESTAMPTZOID:
5156 item->val.datetime.value));
5157 default:
5158 elog(ERROR, "unexpected jsonb datetime type oid %u",
5159 item->val.datetime.typid);
5160 }
5161 break;
5162
5163 case jbvArray:
5164 case jbvObject:
5165 case jbvBinary:
5168
5169 default:
5170 elog(ERROR, "unexpected jsonb value type %d", item->type);
5171 }
5172
5173 Assert(false);
5174 *resnull = true;
5175 return NULL;
5176}
Datum numeric_out(PG_FUNCTION_ARGS)
Definition numeric.c:799
Datum timestamptz_out(PG_FUNCTION_ARGS)
Definition timestamp.c:768
Datum timestamp_out(PG_FUNCTION_ARGS)
Definition timestamp.c:225
Datum boolout(PG_FUNCTION_ARGS)
Definition bool.c:158
Datum date_out(PG_FUNCTION_ARGS)
Definition date.c:178
Datum time_out(PG_FUNCTION_ARGS)
Definition date.c:1590
Datum timetz_out(PG_FUNCTION_ARGS)
Definition date.c:2403
@ jbvObject
Definition jsonb.h:236
@ jbvNumeric
Definition jsonb.h:232
@ jbvBool
Definition jsonb.h:233
@ jbvArray
Definition jsonb.h:235
@ jbvBinary
Definition jsonb.h:238
@ jbvNull
Definition jsonb.h:230
@ jbvDatetime
Definition jsonb.h:246
@ jbvString
Definition jsonb.h:231
static Datum NumericGetDatum(Numeric X)
Definition numeric.h:76
enum jbvType type
Definition jsonb.h:257
char * val
Definition jsonb.h:266

References Assert, BoolGetDatum(), boolout(), date_out(), DatumGetCString(), DirectFunctionCall1, elog, ERROR, fb(), jbvArray, jbvBinary, jbvBool, jbvDatetime, jbvNull, jbvNumeric, jbvObject, jbvString, jsonb_out(), JsonbPGetDatum(), JsonbValueToJsonb(), memcpy(), numeric_out(), NumericGetDatum(), palloc(), ExprEvalStep::resnull, 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 2938 of file execExprInterp.c.

2939{
2940#if defined(EEO_USE_COMPUTED_GOTO)
2941 /* Set up externally-visible pointer to dispatch table */
2942 if (dispatch_table == NULL)
2943 {
2944 dispatch_table = (const void **)
2946
2947 /* build reverse lookup table */
2948 for (int i = 0; i < EEOP_LAST; i++)
2949 {
2952 }
2953
2954 /* make it bsearch()able */
2956 EEOP_LAST /* nmembers */ ,
2957 sizeof(ExprEvalOpLookup),
2959 }
2960#endif
2961}
static Datum ExecInterpExpr(ExprState *state, ExprContext *econtext, bool *isnull)
#define qsort(a, b, c, d)
Definition port.h:495

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

Referenced by ExecReadyInterpretedExpr().

◆ ExecInterpExpr()

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

Definition at line 470 of file execExprInterp.c.

471{
472 ExprEvalStep *op;
473 TupleTableSlot *resultslot;
479
480 /*
481 * This array has to be in the same order as enum ExprEvalOp.
482 */
483#if defined(EEO_USE_COMPUTED_GOTO)
484 static const void *const dispatch_table[] = {
606 };
607
609 "dispatch_table out of whack with ExprEvalOp");
610
611 if (unlikely(state == NULL))
613#else
614 Assert(state != NULL);
615#endif /* EEO_USE_COMPUTED_GOTO */
616
617 /* setup state */
618 op = state->steps;
619 resultslot = state->resultslot;
620 innerslot = econtext->ecxt_innertuple;
621 outerslot = econtext->ecxt_outertuple;
622 scanslot = econtext->ecxt_scantuple;
623 oldslot = econtext->ecxt_oldtuple;
624 newslot = econtext->ecxt_newtuple;
625
626#if defined(EEO_USE_COMPUTED_GOTO)
627 EEO_DISPATCH();
628#endif
629
630 EEO_SWITCH()
631 {
633 {
634 *isnull = state->resnull;
635 return state->resvalue;
636 }
637
639 {
640 Assert(isnull == NULL);
641 return (Datum) 0;
642 }
643
645 {
647
649
650 EEO_NEXT();
651 }
652
654 {
656
658
659 EEO_NEXT();
660 }
661
663 {
665
667
668 EEO_NEXT();
669 }
670
672 {
674
676
677 EEO_NEXT();
678 }
679
681 {
683
685
686 EEO_NEXT();
687 }
688
690 {
691 int attnum = op->d.var.attnum;
692
693 /*
694 * Since we already extracted all referenced columns from the
695 * tuple with a FETCHSOME step, we can just grab the value
696 * directly out of the slot's decomposed-data arrays. But let's
697 * have an Assert to check that that did happen.
698 */
699 Assert(attnum >= 0 && attnum < innerslot->tts_nvalid);
700 *op->resvalue = innerslot->tts_values[attnum];
701 *op->resnull = innerslot->tts_isnull[attnum];
702
703 EEO_NEXT();
704 }
705
707 {
708 int attnum = op->d.var.attnum;
709
710 /* See EEOP_INNER_VAR comments */
711
712 Assert(attnum >= 0 && attnum < outerslot->tts_nvalid);
713 *op->resvalue = outerslot->tts_values[attnum];
714 *op->resnull = outerslot->tts_isnull[attnum];
715
716 EEO_NEXT();
717 }
718
720 {
721 int attnum = op->d.var.attnum;
722
723 /* See EEOP_INNER_VAR comments */
724
725 Assert(attnum >= 0 && attnum < scanslot->tts_nvalid);
726 *op->resvalue = scanslot->tts_values[attnum];
727 *op->resnull = scanslot->tts_isnull[attnum];
728
729 EEO_NEXT();
730 }
731
733 {
734 int attnum = op->d.var.attnum;
735
736 /* See EEOP_INNER_VAR comments */
737
738 Assert(attnum >= 0 && attnum < oldslot->tts_nvalid);
739 *op->resvalue = oldslot->tts_values[attnum];
740 *op->resnull = oldslot->tts_isnull[attnum];
741
742 EEO_NEXT();
743 }
744
746 {
747 int attnum = op->d.var.attnum;
748
749 /* See EEOP_INNER_VAR comments */
750
751 Assert(attnum >= 0 && attnum < newslot->tts_nvalid);
752 *op->resvalue = newslot->tts_values[attnum];
753 *op->resnull = newslot->tts_isnull[attnum];
754
755 EEO_NEXT();
756 }
757
759 {
760 ExecEvalSysVar(state, op, econtext, innerslot);
761 EEO_NEXT();
762 }
763
765 {
766 ExecEvalSysVar(state, op, econtext, outerslot);
767 EEO_NEXT();
768 }
769
771 {
772 ExecEvalSysVar(state, op, econtext, scanslot);
773 EEO_NEXT();
774 }
775
777 {
778 ExecEvalSysVar(state, op, econtext, oldslot);
779 EEO_NEXT();
780 }
781
783 {
784 ExecEvalSysVar(state, op, econtext, newslot);
785 EEO_NEXT();
786 }
787
789 {
790 /* too complex for an inline implementation */
791 ExecEvalWholeRowVar(state, op, econtext);
792
793 EEO_NEXT();
794 }
795
797 {
798 int resultnum = op->d.assign_var.resultnum;
799 int attnum = op->d.assign_var.attnum;
800
801 /*
802 * We do not need CheckVarSlotCompatibility here; that was taken
803 * care of at compilation time. But see EEOP_INNER_VAR comments.
804 */
805 Assert(attnum >= 0 && attnum < innerslot->tts_nvalid);
806 Assert(resultnum >= 0 && resultnum < resultslot->tts_tupleDescriptor->natts);
807 resultslot->tts_values[resultnum] = innerslot->tts_values[attnum];
808 resultslot->tts_isnull[resultnum] = innerslot->tts_isnull[attnum];
809
810 EEO_NEXT();
811 }
812
814 {
815 int resultnum = op->d.assign_var.resultnum;
816 int attnum = op->d.assign_var.attnum;
817
818 /*
819 * We do not need CheckVarSlotCompatibility here; that was taken
820 * care of at compilation time. But see EEOP_INNER_VAR comments.
821 */
822 Assert(attnum >= 0 && attnum < outerslot->tts_nvalid);
823 Assert(resultnum >= 0 && resultnum < resultslot->tts_tupleDescriptor->natts);
824 resultslot->tts_values[resultnum] = outerslot->tts_values[attnum];
825 resultslot->tts_isnull[resultnum] = outerslot->tts_isnull[attnum];
826
827 EEO_NEXT();
828 }
829
831 {
832 int resultnum = op->d.assign_var.resultnum;
833 int attnum = op->d.assign_var.attnum;
834
835 /*
836 * We do not need CheckVarSlotCompatibility here; that was taken
837 * care of at compilation time. But see EEOP_INNER_VAR comments.
838 */
839 Assert(attnum >= 0 && attnum < scanslot->tts_nvalid);
840 Assert(resultnum >= 0 && resultnum < resultslot->tts_tupleDescriptor->natts);
841 resultslot->tts_values[resultnum] = scanslot->tts_values[attnum];
842 resultslot->tts_isnull[resultnum] = scanslot->tts_isnull[attnum];
843
844 EEO_NEXT();
845 }
846
848 {
849 int resultnum = op->d.assign_var.resultnum;
850 int attnum = op->d.assign_var.attnum;
851
852 /*
853 * We do not need CheckVarSlotCompatibility here; that was taken
854 * care of at compilation time. But see EEOP_INNER_VAR comments.
855 */
856 Assert(attnum >= 0 && attnum < oldslot->tts_nvalid);
857 Assert(resultnum >= 0 && resultnum < resultslot->tts_tupleDescriptor->natts);
858 resultslot->tts_values[resultnum] = oldslot->tts_values[attnum];
859 resultslot->tts_isnull[resultnum] = oldslot->tts_isnull[attnum];
860
861 EEO_NEXT();
862 }
863
865 {
866 int resultnum = op->d.assign_var.resultnum;
867 int attnum = op->d.assign_var.attnum;
868
869 /*
870 * We do not need CheckVarSlotCompatibility here; that was taken
871 * care of at compilation time. But see EEOP_INNER_VAR comments.
872 */
873 Assert(attnum >= 0 && attnum < newslot->tts_nvalid);
874 Assert(resultnum >= 0 && resultnum < resultslot->tts_tupleDescriptor->natts);
875 resultslot->tts_values[resultnum] = newslot->tts_values[attnum];
876 resultslot->tts_isnull[resultnum] = newslot->tts_isnull[attnum];
877
878 EEO_NEXT();
879 }
880
882 {
883 int resultnum = op->d.assign_tmp.resultnum;
884
885 Assert(resultnum >= 0 && resultnum < resultslot->tts_tupleDescriptor->natts);
886 resultslot->tts_values[resultnum] = state->resvalue;
887 resultslot->tts_isnull[resultnum] = state->resnull;
888
889 EEO_NEXT();
890 }
891
893 {
894 int resultnum = op->d.assign_tmp.resultnum;
895
896 Assert(resultnum >= 0 && resultnum < resultslot->tts_tupleDescriptor->natts);
897 resultslot->tts_isnull[resultnum] = state->resnull;
898 if (!resultslot->tts_isnull[resultnum])
899 resultslot->tts_values[resultnum] =
901 else
902 resultslot->tts_values[resultnum] = state->resvalue;
903
904 EEO_NEXT();
905 }
906
908 {
909 *op->resnull = op->d.constval.isnull;
910 *op->resvalue = op->d.constval.value;
911
912 EEO_NEXT();
913 }
914
915 /*
916 * Function-call implementations. Arguments have previously been
917 * evaluated directly into fcinfo->args.
918 *
919 * As both STRICT checks and function-usage are noticeable performance
920 * wise, and function calls are a very hot-path (they also back
921 * operators!), it's worth having so many separate opcodes.
922 *
923 * Note: the reason for using a temporary variable "d", here and in
924 * other places, is that some compilers think "*op->resvalue = f();"
925 * requires them to evaluate op->resvalue into a register before
926 * calling f(), just in case f() is able to modify op->resvalue
927 * somehow. The extra line of code can save a useless register spill
928 * and reload across the function call.
929 */
931 {
932 FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
933 Datum d;
934
935 fcinfo->isnull = false;
936 d = op->d.func.fn_addr(fcinfo);
937 *op->resvalue = d;
938 *op->resnull = fcinfo->isnull;
939
940 EEO_NEXT();
941 }
942
943 /* strict function call with more than two arguments */
945 {
946 FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
947 NullableDatum *args = fcinfo->args;
948 int nargs = op->d.func.nargs;
949 Datum d;
950
951 Assert(nargs > 2);
952
953 /* strict function, so check for NULL args */
954 for (int argno = 0; argno < nargs; argno++)
955 {
956 if (args[argno].isnull)
957 {
958 *op->resnull = true;
959 goto strictfail;
960 }
961 }
962 fcinfo->isnull = false;
963 d = op->d.func.fn_addr(fcinfo);
964 *op->resvalue = d;
965 *op->resnull = fcinfo->isnull;
966
968 EEO_NEXT();
969 }
970
971 /* strict function call with one argument */
973 {
974 FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
975 NullableDatum *args = fcinfo->args;
976
977 Assert(op->d.func.nargs == 1);
978
979 /* strict function, so check for NULL args */
980 if (args[0].isnull)
981 *op->resnull = true;
982 else
983 {
984 Datum d;
985
986 fcinfo->isnull = false;
987 d = op->d.func.fn_addr(fcinfo);
988 *op->resvalue = d;
989 *op->resnull = fcinfo->isnull;
990 }
991
992 EEO_NEXT();
993 }
994
995 /* strict function call with two arguments */
997 {
998 FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
999 NullableDatum *args = fcinfo->args;
1000
1001 Assert(op->d.func.nargs == 2);
1002
1003 /* strict function, so check for NULL args */
1004 if (args[0].isnull || args[1].isnull)
1005 *op->resnull = true;
1006 else
1007 {
1008 Datum d;
1009
1010 fcinfo->isnull = false;
1011 d = op->d.func.fn_addr(fcinfo);
1012 *op->resvalue = d;
1013 *op->resnull = fcinfo->isnull;
1014 }
1015
1016 EEO_NEXT();
1017 }
1018
1020 {
1021 /* not common enough to inline */
1022 ExecEvalFuncExprFusage(state, op, econtext);
1023
1024 EEO_NEXT();
1025 }
1026
1028 {
1029 /* not common enough to inline */
1030 ExecEvalFuncExprStrictFusage(state, op, econtext);
1031
1032 EEO_NEXT();
1033 }
1034
1035 /*
1036 * If any of its clauses is FALSE, an AND's result is FALSE regardless
1037 * of the states of the rest of the clauses, so we can stop evaluating
1038 * and return FALSE immediately. If none are FALSE and one or more is
1039 * NULL, we return NULL; otherwise we return TRUE. This makes sense
1040 * when you interpret NULL as "don't know": perhaps one of the "don't
1041 * knows" would have been FALSE if we'd known its value. Only when
1042 * all the inputs are known to be TRUE can we state confidently that
1043 * the AND's result is TRUE.
1044 */
1046 {
1047 *op->d.boolexpr.anynull = false;
1048
1049 /*
1050 * EEOP_BOOL_AND_STEP_FIRST resets anynull, otherwise it's the
1051 * same as EEOP_BOOL_AND_STEP - so fall through to that.
1052 */
1053
1054 /* FALL THROUGH */
1055 }
1056
1058 {
1059 if (*op->resnull)
1060 {
1061 *op->d.boolexpr.anynull = true;
1062 }
1063 else if (!DatumGetBool(*op->resvalue))
1064 {
1065 /* result is already set to FALSE, need not change it */
1066 /* bail out early */
1068 }
1069
1070 EEO_NEXT();
1071 }
1072
1074 {
1075 if (*op->resnull)
1076 {
1077 /* result is already set to NULL, need not change it */
1078 }
1079 else if (!DatumGetBool(*op->resvalue))
1080 {
1081 /* result is already set to FALSE, need not change it */
1082
1083 /*
1084 * No point jumping early to jumpdone - would be same target
1085 * (as this is the last argument to the AND expression),
1086 * except more expensive.
1087 */
1088 }
1089 else if (*op->d.boolexpr.anynull)
1090 {
1091 *op->resvalue = (Datum) 0;
1092 *op->resnull = true;
1093 }
1094 else
1095 {
1096 /* result is already set to TRUE, need not change it */
1097 }
1098
1099 EEO_NEXT();
1100 }
1101
1102 /*
1103 * If any of its clauses is TRUE, an OR's result is TRUE regardless of
1104 * the states of the rest of the clauses, so we can stop evaluating
1105 * and return TRUE immediately. If none are TRUE and one or more is
1106 * NULL, we return NULL; otherwise we return FALSE. This makes sense
1107 * when you interpret NULL as "don't know": perhaps one of the "don't
1108 * knows" would have been TRUE if we'd known its value. Only when all
1109 * the inputs are known to be FALSE can we state confidently that the
1110 * OR's result is FALSE.
1111 */
1113 {
1114 *op->d.boolexpr.anynull = false;
1115
1116 /*
1117 * EEOP_BOOL_OR_STEP_FIRST resets anynull, otherwise it's the same
1118 * as EEOP_BOOL_OR_STEP - so fall through to that.
1119 */
1120
1121 /* FALL THROUGH */
1122 }
1123
1125 {
1126 if (*op->resnull)
1127 {
1128 *op->d.boolexpr.anynull = true;
1129 }
1130 else if (DatumGetBool(*op->resvalue))
1131 {
1132 /* result is already set to TRUE, need not change it */
1133 /* bail out early */
1135 }
1136
1137 EEO_NEXT();
1138 }
1139
1141 {
1142 if (*op->resnull)
1143 {
1144 /* result is already set to NULL, need not change it */
1145 }
1146 else if (DatumGetBool(*op->resvalue))
1147 {
1148 /* result is already set to TRUE, need not change it */
1149
1150 /*
1151 * No point jumping to jumpdone - would be same target (as
1152 * this is the last argument to the AND expression), except
1153 * more expensive.
1154 */
1155 }
1156 else if (*op->d.boolexpr.anynull)
1157 {
1158 *op->resvalue = (Datum) 0;
1159 *op->resnull = true;
1160 }
1161 else
1162 {
1163 /* result is already set to FALSE, need not change it */
1164 }
1165
1166 EEO_NEXT();
1167 }
1168
1170 {
1171 /*
1172 * Evaluation of 'not' is simple... if expr is false, then return
1173 * 'true' and vice versa. It's safe to do this even on a
1174 * nominally null value, so we ignore resnull; that means that
1175 * NULL in produces NULL out, which is what we want.
1176 */
1178
1179 EEO_NEXT();
1180 }
1181
1183 {
1184 /* simplified version of BOOL_AND_STEP for use by ExecQual() */
1185
1186 /* If argument (also result) is false or null ... */
1187 if (*op->resnull ||
1188 !DatumGetBool(*op->resvalue))
1189 {
1190 /* ... bail out early, returning FALSE */
1191 *op->resnull = false;
1192 *op->resvalue = BoolGetDatum(false);
1194 }
1195
1196 /*
1197 * Otherwise, leave the TRUE value in place, in case this is the
1198 * last qual. Then, TRUE is the correct answer.
1199 */
1200
1201 EEO_NEXT();
1202 }
1203
1205 {
1206 /* Unconditionally jump to target step */
1207 EEO_JUMP(op->d.jump.jumpdone);
1208 }
1209
1211 {
1212 /* Transfer control if current result is null */
1213 if (*op->resnull)
1214 EEO_JUMP(op->d.jump.jumpdone);
1215
1216 EEO_NEXT();
1217 }
1218
1220 {
1221 /* Transfer control if current result is non-null */
1222 if (!*op->resnull)
1223 EEO_JUMP(op->d.jump.jumpdone);
1224
1225 EEO_NEXT();
1226 }
1227
1229 {
1230 /* Transfer control if current result is null or false */
1231 if (*op->resnull || !DatumGetBool(*op->resvalue))
1232 EEO_JUMP(op->d.jump.jumpdone);
1233
1234 EEO_NEXT();
1235 }
1236
1238 {
1239 *op->resvalue = BoolGetDatum(*op->resnull);
1240 *op->resnull = false;
1241
1242 EEO_NEXT();
1243 }
1244
1246 {
1247 *op->resvalue = BoolGetDatum(!*op->resnull);
1248 *op->resnull = false;
1249
1250 EEO_NEXT();
1251 }
1252
1254 {
1255 /* out of line implementation: too large */
1256 ExecEvalRowNull(state, op, econtext);
1257
1258 EEO_NEXT();
1259 }
1260
1262 {
1263 /* out of line implementation: too large */
1264 ExecEvalRowNotNull(state, op, econtext);
1265
1266 EEO_NEXT();
1267 }
1268
1269 /* BooleanTest implementations for all booltesttypes */
1270
1272 {
1273 if (*op->resnull)
1274 {
1275 *op->resvalue = BoolGetDatum(false);
1276 *op->resnull = false;
1277 }
1278 /* else, input value is the correct output as well */
1279
1280 EEO_NEXT();
1281 }
1282
1284 {
1285 if (*op->resnull)
1286 {
1287 *op->resvalue = BoolGetDatum(true);
1288 *op->resnull = false;
1289 }
1290 else
1292
1293 EEO_NEXT();
1294 }
1295
1297 {
1298 if (*op->resnull)
1299 {
1300 *op->resvalue = BoolGetDatum(false);
1301 *op->resnull = false;
1302 }
1303 else
1305
1306 EEO_NEXT();
1307 }
1308
1310 {
1311 if (*op->resnull)
1312 {
1313 *op->resvalue = BoolGetDatum(true);
1314 *op->resnull = false;
1315 }
1316 /* else, input value is the correct output as well */
1317
1318 EEO_NEXT();
1319 }
1320
1322 {
1323 /* out of line implementation: too large */
1324 ExecEvalParamExec(state, op, econtext);
1325
1326 EEO_NEXT();
1327 }
1328
1330 {
1331 /* out of line implementation: too large */
1332 ExecEvalParamExtern(state, op, econtext);
1333 EEO_NEXT();
1334 }
1335
1337 {
1338 /* allow an extension module to supply a PARAM_EXTERN value */
1339 op->d.cparam.paramfunc(state, op, econtext);
1340 EEO_NEXT();
1341 }
1342
1344 {
1345 /* out of line, unlikely to matter performance-wise */
1346 ExecEvalParamSet(state, op, econtext);
1347 EEO_NEXT();
1348 }
1349
1351 {
1352 *op->resvalue = *op->d.casetest.value;
1353 *op->resnull = *op->d.casetest.isnull;
1354
1355 EEO_NEXT();
1356 }
1357
1359 {
1360 *op->resvalue = econtext->caseValue_datum;
1361 *op->resnull = econtext->caseValue_isNull;
1362
1363 EEO_NEXT();
1364 }
1365
1367 {
1368 /*
1369 * Force a varlena value that might be read multiple times to R/O
1370 */
1371 if (!*op->d.make_readonly.isnull)
1372 *op->resvalue =
1374 *op->resnull = *op->d.make_readonly.isnull;
1375
1376 EEO_NEXT();
1377 }
1378
1380 {
1381 /*
1382 * Evaluate a CoerceViaIO node. This can be quite a hot path, so
1383 * inline as much work as possible. The source value is in our
1384 * result variable.
1385 *
1386 * Also look at ExecEvalCoerceViaIOSafe() if you change anything
1387 * here.
1388 */
1389 char *str;
1390
1391 /* call output function (similar to OutputFunctionCall) */
1392 if (*op->resnull)
1393 {
1394 /* output functions are not called on nulls */
1395 str = NULL;
1396 }
1397 else
1398 {
1400
1402 fcinfo_out->args[0].value = *op->resvalue;
1403 fcinfo_out->args[0].isnull = false;
1404
1405 fcinfo_out->isnull = false;
1407
1408 /* OutputFunctionCall assumes result isn't null */
1409 Assert(!fcinfo_out->isnull);
1410 }
1411
1412 /* call input function (similar to InputFunctionCall) */
1413 if (!op->d.iocoerce.finfo_in->fn_strict || str != NULL)
1414 {
1416 Datum d;
1417
1420 fcinfo_in->args[0].isnull = *op->resnull;
1421 /* second and third arguments are already set up */
1422
1423 fcinfo_in->isnull = false;
1425 *op->resvalue = d;
1426
1427 /* Should get null result if and only if str is NULL */
1428 if (str == NULL)
1429 {
1430 Assert(*op->resnull);
1431 Assert(fcinfo_in->isnull);
1432 }
1433 else
1434 {
1435 Assert(!*op->resnull);
1436 Assert(!fcinfo_in->isnull);
1437 }
1438 }
1439
1440 EEO_NEXT();
1441 }
1442
1444 {
1446 EEO_NEXT();
1447 }
1448
1450 {
1451 /*
1452 * IS DISTINCT FROM must evaluate arguments (already done into
1453 * fcinfo->args) to determine whether they are NULL; if either is
1454 * NULL then the result is determined. If neither is NULL, then
1455 * proceed to evaluate the comparison function, which is just the
1456 * type's standard equality operator. We need not care whether
1457 * that function is strict. Because the handling of nulls is
1458 * different, we can't just reuse EEOP_FUNCEXPR.
1459 */
1460 FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
1461
1462 /* check function arguments for NULLness */
1463 if (fcinfo->args[0].isnull && fcinfo->args[1].isnull)
1464 {
1465 /* Both NULL? Then is not distinct... */
1466 *op->resvalue = BoolGetDatum(false);
1467 *op->resnull = false;
1468 }
1469 else if (fcinfo->args[0].isnull || fcinfo->args[1].isnull)
1470 {
1471 /* Only one is NULL? Then is distinct... */
1472 *op->resvalue = BoolGetDatum(true);
1473 *op->resnull = false;
1474 }
1475 else
1476 {
1477 /* Neither null, so apply the equality function */
1479
1480 fcinfo->isnull = false;
1481 eqresult = op->d.func.fn_addr(fcinfo);
1482 /* Must invert result of "="; safe to do even if null */
1484 *op->resnull = fcinfo->isnull;
1485 }
1486
1487 EEO_NEXT();
1488 }
1489
1490 /* see EEOP_DISTINCT for comments, this is just inverted */
1492 {
1493 FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
1494
1495 if (fcinfo->args[0].isnull && fcinfo->args[1].isnull)
1496 {
1497 *op->resvalue = BoolGetDatum(true);
1498 *op->resnull = false;
1499 }
1500 else if (fcinfo->args[0].isnull || fcinfo->args[1].isnull)
1501 {
1502 *op->resvalue = BoolGetDatum(false);
1503 *op->resnull = false;
1504 }
1505 else
1506 {
1508
1509 fcinfo->isnull = false;
1510 eqresult = op->d.func.fn_addr(fcinfo);
1511 *op->resvalue = eqresult;
1512 *op->resnull = fcinfo->isnull;
1513 }
1514
1515 EEO_NEXT();
1516 }
1517
1519 {
1520 /*
1521 * The arguments are already evaluated into fcinfo->args.
1522 */
1523 FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
1524 Datum save_arg0 = fcinfo->args[0].value;
1525
1526 /* if either argument is NULL they can't be equal */
1527 if (!fcinfo->args[0].isnull && !fcinfo->args[1].isnull)
1528 {
1529 Datum result;
1530
1531 /*
1532 * If first argument is of varlena type, it might be an
1533 * expanded datum. We need to ensure that the value passed to
1534 * the comparison function is a read-only pointer. However,
1535 * if we end by returning the first argument, that will be the
1536 * original read-write pointer if it was read-write.
1537 */
1538 if (op->d.func.make_ro)
1539 fcinfo->args[0].value =
1541
1542 fcinfo->isnull = false;
1543 result = op->d.func.fn_addr(fcinfo);
1544
1545 /* if the arguments are equal return null */
1546 if (!fcinfo->isnull && DatumGetBool(result))
1547 {
1548 *op->resvalue = (Datum) 0;
1549 *op->resnull = true;
1550
1551 EEO_NEXT();
1552 }
1553 }
1554
1555 /* Arguments aren't equal, so return the first one */
1556 *op->resvalue = save_arg0;
1557 *op->resnull = fcinfo->args[0].isnull;
1558
1559 EEO_NEXT();
1560 }
1561
1563 {
1564 /*
1565 * Doesn't seem worthwhile to have an inline implementation
1566 * efficiency-wise.
1567 */
1569
1570 EEO_NEXT();
1571 }
1572
1574 {
1575 /* error invocation uses space, and shouldn't ever occur */
1577
1578 EEO_NEXT();
1579 }
1580
1582 {
1583 /*
1584 * Doesn't seem worthwhile to have an inline implementation
1585 * efficiency-wise.
1586 */
1588
1589 EEO_NEXT();
1590 }
1591
1593 {
1594 /*
1595 * The next op actually evaluates the expression. If the OLD/NEW
1596 * row doesn't exist, skip that and return NULL.
1597 */
1598 if (state->flags & op->d.returningexpr.nullflag)
1599 {
1600 *op->resvalue = (Datum) 0;
1601 *op->resnull = true;
1602
1604 }
1605
1606 EEO_NEXT();
1607 }
1608
1610 {
1611 /* too complex for an inline implementation */
1613
1614 EEO_NEXT();
1615 }
1616
1618 {
1619 /* too complex for an inline implementation */
1620 ExecEvalArrayCoerce(state, op, econtext);
1621
1622 EEO_NEXT();
1623 }
1624
1626 {
1627 /* too complex for an inline implementation */
1628 ExecEvalRow(state, op);
1629
1630 EEO_NEXT();
1631 }
1632
1634 {
1636 Datum d;
1637
1638 /* force NULL result if strict fn and NULL input */
1639 if (op->d.rowcompare_step.finfo->fn_strict &&
1640 (fcinfo->args[0].isnull || fcinfo->args[1].isnull))
1641 {
1642 *op->resnull = true;
1644 }
1645
1646 /* Apply comparison function */
1647 fcinfo->isnull = false;
1648 d = op->d.rowcompare_step.fn_addr(fcinfo);
1649 *op->resvalue = d;
1650
1651 /* force NULL result if NULL function result */
1652 if (fcinfo->isnull)
1653 {
1654 *op->resnull = true;
1656 }
1657 *op->resnull = false;
1658
1659 /* If unequal, no need to compare remaining columns */
1660 if (DatumGetInt32(*op->resvalue) != 0)
1661 {
1663 }
1664
1665 EEO_NEXT();
1666 }
1667
1669 {
1671 CompareType cmptype = op->d.rowcompare_final.cmptype;
1672
1673 *op->resnull = false;
1674 switch (cmptype)
1675 {
1676 /* EQ and NE cases aren't allowed here */
1677 case COMPARE_LT:
1678 *op->resvalue = BoolGetDatum(cmpresult < 0);
1679 break;
1680 case COMPARE_LE:
1681 *op->resvalue = BoolGetDatum(cmpresult <= 0);
1682 break;
1683 case COMPARE_GE:
1684 *op->resvalue = BoolGetDatum(cmpresult >= 0);
1685 break;
1686 case COMPARE_GT:
1687 *op->resvalue = BoolGetDatum(cmpresult > 0);
1688 break;
1689 default:
1690 Assert(false);
1691 break;
1692 }
1693
1694 EEO_NEXT();
1695 }
1696
1698 {
1699 /* too complex for an inline implementation */
1700 ExecEvalMinMax(state, op);
1701
1702 EEO_NEXT();
1703 }
1704
1706 {
1707 /* too complex for an inline implementation */
1708 ExecEvalFieldSelect(state, op, econtext);
1709
1710 EEO_NEXT();
1711 }
1712
1714 {
1715 /* too complex for an inline implementation */
1716 ExecEvalFieldStoreDeForm(state, op, econtext);
1717
1718 EEO_NEXT();
1719 }
1720
1722 {
1723 /* too complex for an inline implementation */
1724 ExecEvalFieldStoreForm(state, op, econtext);
1725
1726 EEO_NEXT();
1727 }
1728
1730 {
1731 /* Precheck SubscriptingRef subscript(s) */
1732 if (op->d.sbsref_subscript.subscriptfunc(state, op, econtext))
1733 {
1734 EEO_NEXT();
1735 }
1736 else
1737 {
1738 /* Subscript is null, short-circuit SubscriptingRef to NULL */
1740 }
1741 }
1742
1746 {
1747 /* Perform a SubscriptingRef fetch or assignment */
1748 op->d.sbsref.subscriptfunc(state, op, econtext);
1749
1750 EEO_NEXT();
1751 }
1752
1754 {
1755 /* too complex for an inline implementation */
1756 ExecEvalConvertRowtype(state, op, econtext);
1757
1758 EEO_NEXT();
1759 }
1760
1762 {
1763 /* too complex for an inline implementation */
1765
1766 EEO_NEXT();
1767 }
1768
1770 {
1771 /* too complex for an inline implementation */
1772 ExecEvalHashedScalarArrayOp(state, op, econtext);
1773
1774 EEO_NEXT();
1775 }
1776
1778 {
1779 *op->resvalue = *op->d.casetest.value;
1780 *op->resnull = *op->d.casetest.isnull;
1781
1782 EEO_NEXT();
1783 }
1784
1786 {
1787 *op->resvalue = econtext->domainValue_datum;
1788 *op->resnull = econtext->domainValue_isNull;
1789
1790 EEO_NEXT();
1791 }
1792
1794 {
1795 /* too complex for an inline implementation */
1797
1798 EEO_NEXT();
1799 }
1800
1802 {
1803 /* too complex for an inline implementation */
1805
1806 EEO_NEXT();
1807 }
1808
1810 {
1812 *op->resnull = false;
1813
1814 EEO_NEXT();
1815 }
1816
1818 {
1820
1821 /*
1822 * Save the Datum on non-null inputs, otherwise store 0 so that
1823 * subsequent NEXT32 operations combine with an initialized value.
1824 */
1825 if (!fcinfo->args[0].isnull)
1826 *op->resvalue = op->d.hashdatum.fn_addr(fcinfo);
1827 else
1828 *op->resvalue = (Datum) 0;
1829
1830 *op->resnull = false;
1831
1832 EEO_NEXT();
1833 }
1834
1836 {
1838
1839 if (fcinfo->args[0].isnull)
1840 {
1841 /*
1842 * With strict we have the expression return NULL instead of
1843 * ignoring NULL input values. We've nothing more to do after
1844 * finding a NULL.
1845 */
1846 *op->resnull = true;
1847 *op->resvalue = (Datum) 0;
1849 }
1850
1851 /* execute the hash function and save the resulting value */
1852 *op->resvalue = op->d.hashdatum.fn_addr(fcinfo);
1853 *op->resnull = false;
1854
1855 EEO_NEXT();
1856 }
1857
1859 {
1862
1864 /* combine successive hash values by rotating */
1866
1867 /* leave the hash value alone on NULL inputs */
1868 if (!fcinfo->args[0].isnull)
1869 {
1870 uint32 hashvalue;
1871
1872 /* execute hash func and combine with previous hash value */
1873 hashvalue = DatumGetUInt32(op->d.hashdatum.fn_addr(fcinfo));
1874 existinghash = existinghash ^ hashvalue;
1875 }
1876
1878 *op->resnull = false;
1879
1880 EEO_NEXT();
1881 }
1882
1884 {
1886
1887 if (fcinfo->args[0].isnull)
1888 {
1889 /*
1890 * With strict we have the expression return NULL instead of
1891 * ignoring NULL input values. We've nothing more to do after
1892 * finding a NULL.
1893 */
1894 *op->resnull = true;
1895 *op->resvalue = (Datum) 0;
1897 }
1898 else
1899 {
1901 uint32 hashvalue;
1902
1904 /* combine successive hash values by rotating */
1906
1907 /* execute hash func and combine with previous hash value */
1908 hashvalue = DatumGetUInt32(op->d.hashdatum.fn_addr(fcinfo));
1909 *op->resvalue = UInt32GetDatum(existinghash ^ hashvalue);
1910 *op->resnull = false;
1911 }
1912
1913 EEO_NEXT();
1914 }
1915
1917 {
1918 /* too complex for an inline implementation */
1920
1921 EEO_NEXT();
1922 }
1923
1925 {
1926 /* too complex for an inline implementation */
1927 ExecEvalJsonConstructor(state, op, econtext);
1928 EEO_NEXT();
1929 }
1930
1932 {
1933 /* too complex for an inline implementation */
1935
1936 EEO_NEXT();
1937 }
1938
1940 {
1941 /* too complex for an inline implementation */
1942 EEO_JUMP(ExecEvalJsonExprPath(state, op, econtext));
1943 }
1944
1946 {
1947 /* too complex for an inline implementation */
1948 ExecEvalJsonCoercion(state, op, econtext);
1949
1950 EEO_NEXT();
1951 }
1952
1954 {
1955 /* too complex for an inline implementation */
1957
1958 EEO_NEXT();
1959 }
1960
1962 {
1963 /*
1964 * Returns a Datum whose value is the precomputed aggregate value
1965 * found in the given expression context.
1966 */
1967 int aggno = op->d.aggref.aggno;
1968
1969 Assert(econtext->ecxt_aggvalues != NULL);
1970
1971 *op->resvalue = econtext->ecxt_aggvalues[aggno];
1972 *op->resnull = econtext->ecxt_aggnulls[aggno];
1973
1974 EEO_NEXT();
1975 }
1976
1978 {
1979 /* too complex/uncommon for an inline implementation */
1981
1982 EEO_NEXT();
1983 }
1984
1986 {
1987 /*
1988 * Like Aggref, just return a precomputed value from the econtext.
1989 */
1991
1992 Assert(econtext->ecxt_aggvalues != NULL);
1993
1994 *op->resvalue = econtext->ecxt_aggvalues[wfunc->wfuncno];
1995 *op->resnull = econtext->ecxt_aggnulls[wfunc->wfuncno];
1996
1997 EEO_NEXT();
1998 }
1999
2001 {
2002 /* too complex/uncommon for an inline implementation */
2003 ExecEvalMergeSupportFunc(state, op, econtext);
2004
2005 EEO_NEXT();
2006 }
2007
2009 {
2010 /* too complex for an inline implementation */
2011 ExecEvalSubPlan(state, op, econtext);
2012
2013 EEO_NEXT();
2014 }
2015
2016 /* evaluate a strict aggregate deserialization function */
2018 {
2019 /* Don't call a strict deserialization function with NULL input */
2022
2023 /* fallthrough */
2024 }
2025
2026 /* evaluate aggregate deserialization function (non-strict portion) */
2028 {
2032
2033 /*
2034 * We run the deserialization functions in per-input-tuple memory
2035 * context.
2036 */
2037 oldContext = MemoryContextSwitchTo(aggstate->tmpcontext->ecxt_per_tuple_memory);
2038 fcinfo->isnull = false;
2039 *op->resvalue = FunctionCallInvoke(fcinfo);
2040 *op->resnull = fcinfo->isnull;
2042
2043 EEO_NEXT();
2044 }
2045
2046 /*
2047 * Check that a strict aggregate transition / combination function's
2048 * input is not NULL.
2049 */
2050
2051 /* when checking more than one argument */
2053 {
2055 int nargs = op->d.agg_strict_input_check.nargs;
2056
2057 Assert(nargs > 1);
2058
2059 for (int argno = 0; argno < nargs; argno++)
2060 {
2061 if (args[argno].isnull)
2063 }
2064 EEO_NEXT();
2065 }
2066
2067 /* special case for just one argument */
2069 {
2072
2073 Assert(nargs == 1);
2074
2075 if (args[0].isnull)
2077 EEO_NEXT();
2078 }
2079
2081 {
2082 bool *nulls = op->d.agg_strict_input_check.nulls;
2083 int nargs = op->d.agg_strict_input_check.nargs;
2084
2085 for (int argno = 0; argno < nargs; argno++)
2086 {
2087 if (nulls[argno])
2089 }
2090 EEO_NEXT();
2091 }
2092
2093 /*
2094 * Check for a NULL pointer to the per-group states.
2095 */
2096
2098 {
2101 aggstate->all_pergroups[op->d.agg_plain_pergroup_nullcheck.setoff];
2102
2103 if (pergroup_allaggs == NULL)
2105
2106 EEO_NEXT();
2107 }
2108
2109 /*
2110 * Different types of aggregate transition functions are implemented
2111 * as different types of steps, to avoid incurring unnecessary
2112 * overhead. There's a step type for each valid combination of having
2113 * a by value / by reference transition type, [not] needing to the
2114 * initialize the transition value for the first row in a group from
2115 * input, and [not] strict transition function.
2116 *
2117 * Could optimize further by splitting off by-reference for
2118 * fixed-length types, but currently that doesn't seem worth it.
2119 */
2120
2122 {
2124 AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
2126 &aggstate->all_pergroups[op->d.agg_trans.setoff][op->d.agg_trans.transno];
2127
2128 Assert(pertrans->transtypeByVal);
2129
2130 if (pergroup->noTransValue)
2131 {
2132 /* If transValue has not yet been initialized, do so now. */
2134 op->d.agg_trans.aggcontext);
2135 /* copied trans value from input, done this round */
2136 }
2137 else if (likely(!pergroup->transValueIsNull))
2138 {
2139 /* invoke transition function, unless prevented by strictness */
2142 op->d.agg_trans.setno);
2143 }
2144
2145 EEO_NEXT();
2146 }
2147
2148 /* see comments above EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYVAL */
2150 {
2152 AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
2154 &aggstate->all_pergroups[op->d.agg_trans.setoff][op->d.agg_trans.transno];
2155
2156 Assert(pertrans->transtypeByVal);
2157
2158 if (likely(!pergroup->transValueIsNull))
2161 op->d.agg_trans.setno);
2162
2163 EEO_NEXT();
2164 }
2165
2166 /* see comments above EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYVAL */
2168 {
2170 AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
2172 &aggstate->all_pergroups[op->d.agg_trans.setoff][op->d.agg_trans.transno];
2173
2174 Assert(pertrans->transtypeByVal);
2175
2178 op->d.agg_trans.setno);
2179
2180 EEO_NEXT();
2181 }
2182
2183 /* see comments above EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYVAL */
2185 {
2187 AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
2189 &aggstate->all_pergroups[op->d.agg_trans.setoff][op->d.agg_trans.transno];
2190
2191 Assert(!pertrans->transtypeByVal);
2192
2193 if (pergroup->noTransValue)
2195 op->d.agg_trans.aggcontext);
2196 else if (likely(!pergroup->transValueIsNull))
2199 op->d.agg_trans.setno);
2200
2201 EEO_NEXT();
2202 }
2203
2204 /* see comments above EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYVAL */
2206 {
2208 AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
2210 &aggstate->all_pergroups[op->d.agg_trans.setoff][op->d.agg_trans.transno];
2211
2212 Assert(!pertrans->transtypeByVal);
2213
2214 if (likely(!pergroup->transValueIsNull))
2217 op->d.agg_trans.setno);
2218 EEO_NEXT();
2219 }
2220
2221 /* see comments above EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYVAL */
2223 {
2225 AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
2227 &aggstate->all_pergroups[op->d.agg_trans.setoff][op->d.agg_trans.transno];
2228
2229 Assert(!pertrans->transtypeByVal);
2230
2233 op->d.agg_trans.setno);
2234
2235 EEO_NEXT();
2236 }
2237
2239 {
2242
2244 EEO_NEXT();
2245 else
2247 }
2248
2250 {
2253
2255 EEO_NEXT();
2256 else
2258 }
2259
2260 /* process single-column ordered aggregate datum */
2262 {
2263 /* too complex for an inline implementation */
2264 ExecEvalAggOrderedTransDatum(state, op, econtext);
2265
2266 EEO_NEXT();
2267 }
2268
2269 /* process multi-column ordered aggregate tuple */
2271 {
2272 /* too complex for an inline implementation */
2273 ExecEvalAggOrderedTransTuple(state, op, econtext);
2274
2275 EEO_NEXT();
2276 }
2277
2279 {
2280 /* unreachable */
2281 Assert(false);
2282 goto out_error;
2283 }
2284 }
2285
2286out_error:
2288 return (Datum) 0;
2289}
#define PG_USED_FOR_ASSERTS_ONLY
Definition c.h:249
#define pg_unreachable()
Definition c.h:367
uint32_t uint32
Definition c.h:624
#define lengthof(array)
Definition c.h:873
#define StaticAssertDecl(condition, errmessage)
Definition c.h:1008
CompareType
Definition cmptype.h:32
@ COMPARE_LE
Definition cmptype.h:35
@ COMPARE_GT
Definition cmptype.h:38
@ COMPARE_GE
Definition cmptype.h:37
@ COMPARE_LT
Definition cmptype.h:34
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 ExecEvalParamSet(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
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:110
@ EEOP_SUBPLAN
Definition execExpr.h:275
@ EEOP_CONVERT_ROWTYPE
Definition execExpr.h:262
@ EEOP_FUNCEXPR_STRICT_FUSAGE
Definition execExpr.h:127
@ EEOP_ARRAYEXPR
Definition execExpr.h:196
@ EEOP_JSONEXPR_PATH
Definition execExpr.h:268
@ EEOP_NOT_DISTINCT
Definition execExpr.h:190
@ EEOP_DOMAIN_TESTVAL
Definition execExpr.h:245
@ EEOP_PARAM_EXTERN
Definition execExpr.h:174
@ EEOP_HASHDATUM_NEXT32_STRICT
Definition execExpr.h:259
@ EEOP_IOCOERCE_SAFE
Definition execExpr.h:188
@ EEOP_BOOL_AND_STEP
Definition execExpr.h:136
@ EEOP_DONE_RETURN
Definition execExpr.h:69
@ EEOP_WHOLEROW
Definition execExpr.h:96
@ EEOP_JSONEXPR_COERCION_FINISH
Definition execExpr.h:270
@ EEOP_HASHDATUM_FIRST_STRICT
Definition execExpr.h:257
@ EEOP_AGGREF
Definition execExpr.h:271
@ EEOP_FUNCEXPR_STRICT_1
Definition execExpr.h:124
@ EEOP_AGG_PLAIN_PERGROUP_NULLCHECK
Definition execExpr.h:283
@ EEOP_HASHDATUM_NEXT32
Definition execExpr.h:258
@ EEOP_ROWCOMPARE_FINAL
Definition execExpr.h:207
@ EEOP_AGG_STRICT_DESERIALIZE
Definition execExpr.h:278
@ EEOP_IOCOERCE
Definition execExpr.h:187
@ EEOP_RETURNINGEXPR
Definition execExpr.h:195
@ EEOP_GROUPING_FUNC
Definition execExpr.h:272
@ EEOP_DOMAIN_CHECK
Definition execExpr.h:252
@ EEOP_BOOLTEST_IS_NOT_FALSE
Definition execExpr.h:170
@ EEOP_PARAM_SET
Definition execExpr.h:177
@ EEOP_NEXTVALUEEXPR
Definition execExpr.h:194
@ EEOP_NEW_SYSVAR
Definition execExpr.h:93
@ EEOP_AGG_PLAIN_TRANS_BYREF
Definition execExpr.h:289
@ EEOP_QUAL
Definition execExpr.h:148
@ EEOP_AGG_PRESORTED_DISTINCT_MULTI
Definition execExpr.h:291
@ EEOP_AGG_PLAIN_TRANS_BYVAL
Definition execExpr.h:286
@ EEOP_CASE_TESTVAL_EXT
Definition execExpr.h:181
@ EEOP_BOOL_NOT_STEP
Definition execExpr.h:145
@ EEOP_ASSIGN_SCAN_VAR
Definition execExpr.h:105
@ EEOP_SCAN_SYSVAR
Definition execExpr.h:91
@ EEOP_SCALARARRAYOP
Definition execExpr.h:263
@ EEOP_DOMAIN_NOTNULL
Definition execExpr.h:249
@ EEOP_WINDOW_FUNC
Definition execExpr.h:273
@ EEOP_INNER_FETCHSOME
Definition execExpr.h:75
@ EEOP_NULLTEST_ROWISNOTNULL
Definition execExpr.h:164
@ EEOP_ASSIGN_OUTER_VAR
Definition execExpr.h:104
@ EEOP_ROW
Definition execExpr.h:198
@ EEOP_MAKE_READONLY
Definition execExpr.h:184
@ EEOP_FIELDSTORE_FORM
Definition execExpr.h:226
@ EEOP_ASSIGN_OLD_VAR
Definition execExpr.h:106
@ EEOP_SBSREF_SUBSCRIPTS
Definition execExpr.h:229
@ EEOP_FUNCEXPR_STRICT_2
Definition execExpr.h:125
@ EEOP_SBSREF_FETCH
Definition execExpr.h:242
@ EEOP_FUNCEXPR_STRICT
Definition execExpr.h:123
@ EEOP_NULLIF
Definition execExpr.h:191
@ EEOP_CURRENTOFEXPR
Definition execExpr.h:193
@ EEOP_INNER_SYSVAR
Definition execExpr.h:89
@ EEOP_ASSIGN_TMP_MAKE_RO
Definition execExpr.h:112
@ EEOP_CONST
Definition execExpr.h:115
@ EEOP_BOOL_OR_STEP_LAST
Definition execExpr.h:142
@ EEOP_JSONEXPR_COERCION
Definition execExpr.h:269
@ EEOP_BOOL_OR_STEP_FIRST
Definition execExpr.h:140
@ EEOP_XMLEXPR
Definition execExpr.h:265
@ EEOP_AGG_STRICT_INPUT_CHECK_NULLS
Definition execExpr.h:282
@ EEOP_SBSREF_ASSIGN
Definition execExpr.h:239
@ EEOP_OUTER_SYSVAR
Definition execExpr.h:90
@ EEOP_ASSIGN_INNER_VAR
Definition execExpr.h:103
@ EEOP_BOOL_OR_STEP
Definition execExpr.h:141
@ EEOP_AGG_STRICT_INPUT_CHECK_ARGS_1
Definition execExpr.h:281
@ EEOP_OUTER_FETCHSOME
Definition execExpr.h:76
@ EEOP_AGG_STRICT_INPUT_CHECK_ARGS
Definition execExpr.h:280
@ EEOP_NULLTEST_ROWISNULL
Definition execExpr.h:163
@ EEOP_BOOLTEST_IS_TRUE
Definition execExpr.h:167
@ EEOP_FUNCEXPR
Definition execExpr.h:122
@ EEOP_NULLTEST_ISNOTNULL
Definition execExpr.h:160
@ EEOP_ROWCOMPARE_STEP
Definition execExpr.h:204
@ EEOP_MERGE_SUPPORT_FUNC
Definition execExpr.h:274
@ EEOP_AGG_DESERIALIZE
Definition execExpr.h:279
@ EEOP_HASHDATUM_FIRST
Definition execExpr.h:256
@ EEOP_DISTINCT
Definition execExpr.h:189
@ EEOP_JUMP_IF_NOT_TRUE
Definition execExpr.h:156
@ EEOP_FUNCEXPR_FUSAGE
Definition execExpr.h:126
@ EEOP_AGG_PRESORTED_DISTINCT_SINGLE
Definition execExpr.h:290
@ EEOP_BOOL_AND_STEP_FIRST
Definition execExpr.h:135
@ EEOP_JUMP
Definition execExpr.h:151
@ EEOP_DONE_NO_RETURN
Definition execExpr.h:72
@ EEOP_PARAM_CALLBACK
Definition execExpr.h:175
@ EEOP_DOMAIN_TESTVAL_EXT
Definition execExpr.h:246
@ EEOP_OLD_SYSVAR
Definition execExpr.h:92
@ EEOP_BOOL_AND_STEP_LAST
Definition execExpr.h:137
@ EEOP_NEW_FETCHSOME
Definition execExpr.h:79
@ EEOP_AGG_ORDERED_TRANS_DATUM
Definition execExpr.h:292
@ EEOP_OLD_FETCHSOME
Definition execExpr.h:78
@ EEOP_ASSIGN_NEW_VAR
Definition execExpr.h:107
@ EEOP_SBSREF_OLD
Definition execExpr.h:236
@ EEOP_SQLVALUEFUNCTION
Definition execExpr.h:192
@ EEOP_HASHDATUM_SET_INITVAL
Definition execExpr.h:255
@ EEOP_JUMP_IF_NOT_NULL
Definition execExpr.h:155
@ EEOP_AGG_PLAIN_TRANS_STRICT_BYREF
Definition execExpr.h:288
@ EEOP_FIELDSTORE_DEFORM
Definition execExpr.h:219
@ EEOP_BOOLTEST_IS_FALSE
Definition execExpr.h:169
@ EEOP_BOOLTEST_IS_NOT_TRUE
Definition execExpr.h:168
@ EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYVAL
Definition execExpr.h:284
@ EEOP_PARAM_EXEC
Definition execExpr.h:173
@ EEOP_JSON_CONSTRUCTOR
Definition execExpr.h:266
@ EEOP_AGG_PLAIN_TRANS_STRICT_BYVAL
Definition execExpr.h:285
@ EEOP_NULLTEST_ISNULL
Definition execExpr.h:159
@ EEOP_MINMAX
Definition execExpr.h:210
@ EEOP_JUMP_IF_NULL
Definition execExpr.h:154
@ EEOP_ARRAYCOERCE
Definition execExpr.h:197
@ EEOP_FIELDSELECT
Definition execExpr.h:213
@ EEOP_CASE_TESTVAL
Definition execExpr.h:180
@ EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYREF
Definition execExpr.h:287
@ EEOP_HASHED_SCALARARRAYOP
Definition execExpr.h:264
@ EEOP_AGG_ORDERED_TRANS_TUPLE
Definition execExpr.h:293
@ EEOP_SCAN_FETCHSOME
Definition execExpr.h:77
@ EEOP_IS_JSON
Definition execExpr.h:267
Datum MakeExpandedObjectReadOnlyInternal(Datum d)
static uint32 pg_rotate_left32(uint32 word, int n)
static uint32 DatumGetUInt32(Datum X)
Definition postgres.h:222
static Datum UInt32GetDatum(uint32 X)
Definition postgres.h:232
Datum domainValue_datum
Definition execnodes.h:318
Datum * ecxt_aggvalues
Definition execnodes.h:306
bool caseValue_isNull
Definition execnodes.h:314
Datum caseValue_datum
Definition execnodes.h:312
bool * ecxt_aggnulls
Definition execnodes.h:308
bool domainValue_isNull
Definition execnodes.h:320
uint8 nullflag
Definition execExpr.h:373
bool * anynull
Definition execExpr.h:399
WindowFuncExprState * wfstate
Definition execExpr.h:688
ExecEvalBoolSubroutine subscriptfunc
Definition execExpr.h:568
struct ExprEvalStep::@63::@69 returningexpr
struct ExprEvalStep::@63::@72 boolexpr
struct ExprEvalStep::@63::@67 assign_var
ExecEvalSubroutine paramfunc
Definition execExpr.h:432
struct ExprEvalStep::@63::@91 sbsref_subscript
NullableDatum * args
Definition execExpr.h:719
NullableDatum * iresult
Definition execExpr.h:610
struct ExprEvalStep::@63::@68 assign_tmp
struct ExprEvalStep::@63::@108 agg_presorted_distinctcheck
struct ExprEvalStep::@63::@78 casetest
int jumpdistinct
Definition execExpr.h:737
struct ExprEvalStep::@63::@70 constval
struct ExprEvalStep::@63::@95 hashdatum
struct ExprEvalStep::@63::@105 agg_deserialize
struct ExprEvalStep::@63::@106 agg_strict_input_check
struct ExprEvalStep::@63::@73 qualexpr
struct ExprEvalStep::@63::@103 window_func
struct ExprEvalStep::@63::@79 make_readonly
Datum value
Definition execExpr.h:381
struct ExprEvalStep::@63::@92 sbsref
CompareType cmptype
Definition execExpr.h:523
struct ExprEvalStep::@63::@86 rowcompare_step
struct ExprEvalStep::@63::@94 hashdatum_initvalue
struct ExprEvalStep::@63::@74 jump
struct ExprEvalStep::@63::@77 cparam
struct ExprEvalStep::@63::@101 aggref
Datum init_value
Definition execExpr.h:598
ExprContext * aggcontext
Definition execExpr.h:736
struct ExprEvalStep::@63::@87 rowcompare_final
struct ExprEvalStep::@63::@107 agg_plain_pergroup_nullcheck
static void slot_getsomeattrs(TupleTableSlot *slot, int attnum)
Definition tuptable.h:376

References ExprEvalStep::aggno, ExprEvalStep::args, FunctionCallInfoBaseData::args, Assert, attnum, BoolGetDatum(), ExprContext::caseValue_datum, ExprContext::caseValue_isNull, castNode, CheckOpSlotCompatibility(), ExprEvalStep::cmptype, COMPARE_GE, COMPARE_GT, COMPARE_LE, COMPARE_LT, ExprEvalStep::d, DatumGetBool(), DatumGetCString(), DatumGetInt32(), DatumGetUInt32(), ExprContext::domainValue_datum, ExprContext::domainValue_isNull, ExprContext::ecxt_aggnulls, ExprContext::ecxt_aggvalues, ExprContext::ecxt_innertuple, ExprContext::ecxt_newtuple, ExprContext::ecxt_oldtuple, ExprContext::ecxt_outertuple, 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_ARGS_1, EEOP_AGG_STRICT_INPUT_CHECK_NULLS, EEOP_AGGREF, EEOP_ARRAYCOERCE, EEOP_ARRAYEXPR, EEOP_ASSIGN_INNER_VAR, EEOP_ASSIGN_NEW_VAR, EEOP_ASSIGN_OLD_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_CASE_TESTVAL_EXT, EEOP_CONST, EEOP_CONVERT_ROWTYPE, EEOP_CURRENTOFEXPR, EEOP_DISTINCT, EEOP_DOMAIN_CHECK, EEOP_DOMAIN_NOTNULL, EEOP_DOMAIN_TESTVAL, EEOP_DOMAIN_TESTVAL_EXT, EEOP_DONE_NO_RETURN, EEOP_DONE_RETURN, EEOP_FIELDSELECT, EEOP_FIELDSTORE_DEFORM, EEOP_FIELDSTORE_FORM, EEOP_FUNCEXPR, EEOP_FUNCEXPR_FUSAGE, EEOP_FUNCEXPR_STRICT, EEOP_FUNCEXPR_STRICT_1, EEOP_FUNCEXPR_STRICT_2, EEOP_FUNCEXPR_STRICT_FUSAGE, EEOP_GROUPING_FUNC, EEOP_HASHDATUM_FIRST, EEOP_HASHDATUM_FIRST_STRICT, EEOP_HASHDATUM_NEXT32, EEOP_HASHDATUM_NEXT32_STRICT, EEOP_HASHDATUM_SET_INITVAL, 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_NEW_FETCHSOME, EEOP_NEW_SYSVAR, EEOP_NEW_VAR, EEOP_NEXTVALUEEXPR, EEOP_NOT_DISTINCT, EEOP_NULLIF, EEOP_NULLTEST_ISNOTNULL, EEOP_NULLTEST_ISNULL, EEOP_NULLTEST_ROWISNOTNULL, EEOP_NULLTEST_ROWISNULL, EEOP_OLD_FETCHSOME, EEOP_OLD_SYSVAR, EEOP_OLD_VAR, EEOP_OUTER_FETCHSOME, EEOP_OUTER_SYSVAR, EEOP_OUTER_VAR, EEOP_PARAM_CALLBACK, EEOP_PARAM_EXEC, EEOP_PARAM_EXTERN, EEOP_PARAM_SET, EEOP_QUAL, EEOP_RETURNINGEXPR, 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(), ExecEvalParamSet(), ExecEvalPreOrderedDistinctMulti(), ExecEvalPreOrderedDistinctSingle(), ExecEvalRow(), ExecEvalRowNotNull(), ExecEvalRowNull(), ExecEvalScalarArrayOp(), ExecEvalSQLValueFunction(), ExecEvalSubPlan(), ExecEvalSysVar(), ExecEvalWholeRowVar(), ExecEvalXmlExpr(), fb(), FunctionCallInvoke, ExprEvalStep::isnull, FunctionCallInfoBaseData::isnull, NullableDatum::isnull, lengthof, likely, MakeExpandedObjectReadOnlyInternal(), MemoryContextSwitchTo(), ExprEvalStep::nargs, ExprEvalStep::nulls, ExprEvalStep::op, ExprEvalStep::pertrans, pg_rotate_left32(), pg_unreachable, PG_USED_FOR_ASSERTS_ONLY, PointerGetDatum, result, ExprEvalStep::resultnum, slot_getsomeattrs(), StaticAssertDecl, str, AggStatePerTransData::transtypeByVal, TupleTableSlot::tts_isnull, TupleTableSlot::tts_values, UInt32GetDatum(), unlikely, NullableDatum::value, and WindowFuncExprState::wfuncno.

Referenced by ExecInitInterpreter(), and ExecReadyInterpretedExpr().

◆ ExecInterpExprStillValid()

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

Definition at line 2297 of file execExprInterp.c.

2298{
2299 /*
2300 * First time through, check whether attribute matches Var. Might not be
2301 * ok anymore, due to schema changes.
2302 */
2303 CheckExprStillValid(state, econtext);
2304
2305 /* skip the check during further executions */
2306 state->evalfunc = (ExprStateEvalFunc) state->evalfunc_private;
2307
2308 /* and actually execute */
2309 return state->evalfunc(state, econtext, isNull);
2310}
void CheckExprStillValid(ExprState *state, ExprContext *econtext)
Datum(* ExprStateEvalFunc)(ExprState *expression, ExprContext *econtext, bool *isNull)
Definition execnodes.h:82

References CheckExprStillValid().

Referenced by ExecReadyInterpretedExpr().

◆ ExecJustApplyFuncToCase()

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

Definition at line 2641 of file execExprInterp.c.

2642{
2643 ExprEvalStep *op = &state->steps[0];
2644 FunctionCallInfo fcinfo;
2646 int nargs;
2647 Datum d;
2648
2649 /*
2650 * XXX with some redesign of the CaseTestExpr mechanism, maybe we could
2651 * get rid of this data shuffling?
2652 */
2653 *op->resvalue = *op->d.casetest.value;
2654 *op->resnull = *op->d.casetest.isnull;
2655
2656 op++;
2657
2658 nargs = op->d.func.nargs;
2659 fcinfo = op->d.func.fcinfo_data;
2660 args = fcinfo->args;
2661
2662 /* strict function, so check for NULL args */
2663 for (int argno = 0; argno < nargs; argno++)
2664 {
2665 if (args[argno].isnull)
2666 {
2667 *isnull = true;
2668 return (Datum) 0;
2669 }
2670 }
2671 fcinfo->isnull = false;
2672 d = op->d.func.fn_addr(fcinfo);
2673 *isnull = fcinfo->isnull;
2674 return d;
2675}

References ExprEvalStep::args, FunctionCallInfoBaseData::args, ExprEvalStep::d, fb(), ExprEvalStep::isnull, FunctionCallInfoBaseData::isnull, ExprEvalStep::nargs, ExprEvalStep::op, and NullableDatum::value.

Referenced by ExecReadyInterpretedExpr().

◆ ExecJustAssignInnerVar()

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

Definition at line 2620 of file execExprInterp.c.

2621{
2622 return ExecJustAssignVarImpl(state, econtext->ecxt_innertuple, isnull);
2623}
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 2754 of file execExprInterp.c.

2755{
2756 return ExecJustAssignVarVirtImpl(state, econtext->ecxt_innertuple, isnull);
2757}
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 2627 of file execExprInterp.c.

2628{
2629 return ExecJustAssignVarImpl(state, econtext->ecxt_outertuple, isnull);
2630}

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

2762{
2763 return ExecJustAssignVarVirtImpl(state, econtext->ecxt_outertuple, isnull);
2764}

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

2635{
2636 return ExecJustAssignVarImpl(state, econtext->ecxt_scantuple, isnull);
2637}

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

2769{
2770 return ExecJustAssignVarVirtImpl(state, econtext->ecxt_scantuple, isnull);
2771}

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

2595{
2596 ExprEvalStep *op = &state->steps[1];
2597 int attnum = op->d.assign_var.attnum + 1;
2598 int resultnum = op->d.assign_var.resultnum;
2599 TupleTableSlot *outslot = state->resultslot;
2600
2602
2603 /*
2604 * We do not need CheckVarSlotCompatibility here; that was taken care of
2605 * at compilation time.
2606 *
2607 * Since we use slot_getattr(), we don't need to implement the FETCHSOME
2608 * step explicitly, and we also needn't Assert that the attnum is in range
2609 * --- slot_getattr() will take care of any problems. Nonetheless, check
2610 * that resultnum is in range.
2611 */
2612 Assert(resultnum >= 0 && resultnum < outslot->tts_tupleDescriptor->natts);
2613 outslot->tts_values[resultnum] =
2614 slot_getattr(inslot, attnum, &outslot->tts_isnull[resultnum]);
2615 return 0;
2616}
static Datum slot_getattr(TupleTableSlot *slot, int attnum, bool *isnull)
Definition tuptable.h:417

References Assert, attnum, CheckOpSlotCompatibility(), fb(), ExprEvalStep::op, ExprEvalStep::resultnum, and slot_getattr().

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

◆ ExecJustAssignVarVirtImpl()

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

Definition at line 2732 of file execExprInterp.c.

2733{
2734 ExprEvalStep *op = &state->steps[0];
2735 int attnum = op->d.assign_var.attnum;
2736 int resultnum = op->d.assign_var.resultnum;
2737 TupleTableSlot *outslot = state->resultslot;
2738
2739 /* see ExecJustVarVirtImpl for comments */
2740
2743 Assert(attnum >= 0 && attnum < inslot->tts_nvalid);
2744 Assert(resultnum >= 0 && resultnum < outslot->tts_tupleDescriptor->natts);
2745
2746 outslot->tts_values[resultnum] = inslot->tts_values[attnum];
2747 outslot->tts_isnull[resultnum] = inslot->tts_isnull[attnum];
2748
2749 return 0;
2750}
#define TTS_IS_VIRTUAL(slot)
Definition tuptable.h:253
#define TTS_FIXED(slot)
Definition tuptable.h:108

References Assert, attnum, fb(), ExprEvalStep::op, ExprEvalStep::resultnum, TTS_FIXED, and TTS_IS_VIRTUAL.

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

◆ ExecJustConst()

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

Definition at line 2679 of file execExprInterp.c.

2680{
2681 ExprEvalStep *op = &state->steps[0];
2682
2683 *isnull = op->d.constval.isnull;
2684 return op->d.constval.value;
2685}

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

Referenced by ExecReadyInterpretedExpr().

◆ ExecJustHashInnerVar()

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

Definition at line 2842 of file execExprInterp.c.

2843{
2844 return ExecJustHashVarImpl(state, econtext->ecxt_innertuple, isnull);
2845}
static pg_attribute_always_inline Datum ExecJustHashVarImpl(ExprState *state, TupleTableSlot *slot, bool *isnull)

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

Referenced by ExecReadyInterpretedExpr().

◆ ExecJustHashInnerVarVirt()

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

Definition at line 2869 of file execExprInterp.c.

2871{
2872 return ExecJustHashVarVirtImpl(state, econtext->ecxt_innertuple, isnull);
2873}
static pg_attribute_always_inline Datum ExecJustHashVarVirtImpl(ExprState *state, TupleTableSlot *slot, bool *isnull)

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

Referenced by ExecReadyInterpretedExpr().

◆ ExecJustHashInnerVarWithIV()

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

Definition at line 2777 of file execExprInterp.c.

2779{
2780 ExprEvalStep *fetchop = &state->steps[0];
2781 ExprEvalStep *setivop = &state->steps[1];
2782 ExprEvalStep *innervar = &state->steps[2];
2783 ExprEvalStep *hashop = &state->steps[3];
2784 FunctionCallInfo fcinfo = hashop->d.hashdatum.fcinfo_data;
2785 int attnum = innervar->d.var.attnum;
2787
2789 slot_getsomeattrs(econtext->ecxt_innertuple, fetchop->d.fetch.last_var);
2790
2791 fcinfo->args[0].value = econtext->ecxt_innertuple->tts_values[attnum];
2792 fcinfo->args[0].isnull = econtext->ecxt_innertuple->tts_isnull[attnum];
2793
2794 hashkey = DatumGetUInt32(setivop->d.hashdatum_initvalue.init_value);
2796
2797 if (!fcinfo->args[0].isnull)
2798 {
2799 uint32 hashvalue;
2800
2801 hashvalue = DatumGetUInt32(hashop->d.hashdatum.fn_addr(fcinfo));
2802 hashkey = hashkey ^ hashvalue;
2803 }
2804
2805 *isnull = false;
2806 return UInt32GetDatum(hashkey);
2807}

References FunctionCallInfoBaseData::args, attnum, CheckOpSlotCompatibility(), DatumGetUInt32(), ExprContext::ecxt_innertuple, fb(), ExprEvalStep::isnull, NullableDatum::isnull, pg_rotate_left32(), slot_getsomeattrs(), TupleTableSlot::tts_isnull, TupleTableSlot::tts_values, UInt32GetDatum(), and NullableDatum::value.

Referenced by ExecReadyInterpretedExpr().

◆ ExecJustHashOuterVar()

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

Definition at line 2835 of file execExprInterp.c.

2836{
2837 return ExecJustHashVarImpl(state, econtext->ecxt_outertuple, isnull);
2838}

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

Referenced by ExecReadyInterpretedExpr().

◆ ExecJustHashOuterVarStrict()

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

Definition at line 2887 of file execExprInterp.c.

2889{
2890 ExprEvalStep *fetchop = &state->steps[0];
2891 ExprEvalStep *var = &state->steps[1];
2892 ExprEvalStep *hashop = &state->steps[2];
2893 FunctionCallInfo fcinfo = hashop->d.hashdatum.fcinfo_data;
2894 int attnum = var->d.var.attnum;
2895
2897 slot_getsomeattrs(econtext->ecxt_outertuple, fetchop->d.fetch.last_var);
2898
2899 fcinfo->args[0].value = econtext->ecxt_outertuple->tts_values[attnum];
2900 fcinfo->args[0].isnull = econtext->ecxt_outertuple->tts_isnull[attnum];
2901
2902 if (!fcinfo->args[0].isnull)
2903 {
2904 *isnull = false;
2905 return hashop->d.hashdatum.fn_addr(fcinfo);
2906 }
2907 else
2908 {
2909 /* return NULL on NULL input */
2910 *isnull = true;
2911 return (Datum) 0;
2912 }
2913}

References FunctionCallInfoBaseData::args, attnum, CheckOpSlotCompatibility(), ExprContext::ecxt_outertuple, fb(), ExprEvalStep::isnull, NullableDatum::isnull, slot_getsomeattrs(), TupleTableSlot::tts_isnull, TupleTableSlot::tts_values, NullableDatum::value, and ExprEvalStep::var.

Referenced by ExecReadyInterpretedExpr().

◆ ExecJustHashOuterVarVirt()

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

Definition at line 2877 of file execExprInterp.c.

2879{
2880 return ExecJustHashVarVirtImpl(state, econtext->ecxt_outertuple, isnull);
2881}

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

Referenced by ExecReadyInterpretedExpr().

◆ ExecJustHashVarImpl()

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

Definition at line 2811 of file execExprInterp.c.

2812{
2813 ExprEvalStep *fetchop = &state->steps[0];
2814 ExprEvalStep *var = &state->steps[1];
2815 ExprEvalStep *hashop = &state->steps[2];
2816 FunctionCallInfo fcinfo = hashop->d.hashdatum.fcinfo_data;
2817 int attnum = var->d.var.attnum;
2818
2820 slot_getsomeattrs(slot, fetchop->d.fetch.last_var);
2821
2822 fcinfo->args[0].value = slot->tts_values[attnum];
2823 fcinfo->args[0].isnull = slot->tts_isnull[attnum];
2824
2825 *isnull = false;
2826
2827 if (!fcinfo->args[0].isnull)
2828 return hashop->d.hashdatum.fn_addr(fcinfo);
2829 else
2830 return (Datum) 0;
2831}

References FunctionCallInfoBaseData::args, attnum, CheckOpSlotCompatibility(), fb(), ExprEvalStep::isnull, NullableDatum::isnull, slot_getsomeattrs(), TupleTableSlot::tts_isnull, TupleTableSlot::tts_values, NullableDatum::value, and ExprEvalStep::var.

Referenced by ExecJustHashInnerVar(), and ExecJustHashOuterVar().

◆ ExecJustHashVarVirtImpl()

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

Definition at line 2849 of file execExprInterp.c.

2850{
2851 ExprEvalStep *var = &state->steps[0];
2852 ExprEvalStep *hashop = &state->steps[1];
2853 FunctionCallInfo fcinfo = hashop->d.hashdatum.fcinfo_data;
2854 int attnum = var->d.var.attnum;
2855
2856 fcinfo->args[0].value = slot->tts_values[attnum];
2857 fcinfo->args[0].isnull = slot->tts_isnull[attnum];
2858
2859 *isnull = false;
2860
2861 if (!fcinfo->args[0].isnull)
2862 return hashop->d.hashdatum.fn_addr(fcinfo);
2863 else
2864 return (Datum) 0;
2865}

References FunctionCallInfoBaseData::args, attnum, fb(), ExprEvalStep::isnull, NullableDatum::isnull, TupleTableSlot::tts_isnull, TupleTableSlot::tts_values, NullableDatum::value, and ExprEvalStep::var.

Referenced by ExecJustHashInnerVarVirt(), and ExecJustHashOuterVarVirt().

◆ ExecJustInnerVar()

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

Definition at line 2573 of file execExprInterp.c.

2574{
2575 return ExecJustVarImpl(state, econtext->ecxt_innertuple, isnull);
2576}
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 2711 of file execExprInterp.c.

2712{
2713 return ExecJustVarVirtImpl(state, econtext->ecxt_innertuple, isnull);
2714}
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 2580 of file execExprInterp.c.

2581{
2582 return ExecJustVarImpl(state, econtext->ecxt_outertuple, isnull);
2583}

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

2719{
2720 return ExecJustVarVirtImpl(state, econtext->ecxt_outertuple, isnull);
2721}

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

2588{
2589 return ExecJustVarImpl(state, econtext->ecxt_scantuple, isnull);
2590}

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

2726{
2727 return ExecJustVarVirtImpl(state, econtext->ecxt_scantuple, isnull);
2728}

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

2557{
2558 ExprEvalStep *op = &state->steps[1];
2559 int attnum = op->d.var.attnum + 1;
2560
2561 CheckOpSlotCompatibility(&state->steps[0], slot);
2562
2563 /*
2564 * Since we use slot_getattr(), we don't need to implement the FETCHSOME
2565 * step explicitly, and we also needn't Assert that the attnum is in range
2566 * --- slot_getattr() will take care of any problems.
2567 */
2568 return slot_getattr(slot, attnum, isnull);
2569}

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

2690{
2691 ExprEvalStep *op = &state->steps[0];
2692 int attnum = op->d.var.attnum;
2693
2694 /*
2695 * As it is guaranteed that a virtual slot is used, there never is a need
2696 * to perform tuple deforming (nor would it be possible). Therefore
2697 * execExpr.c has not emitted an EEOP_*_FETCHSOME step. Verify, as much as
2698 * possible, that that determination was accurate.
2699 */
2700 Assert(TTS_IS_VIRTUAL(slot));
2701 Assert(TTS_FIXED(slot));
2702 Assert(attnum >= 0 && attnum < slot->tts_nvalid);
2703
2704 *isnull = slot->tts_isnull[attnum];
2705
2706 return slot->tts_values[attnum];
2707}

References Assert, attnum, fb(), 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 252 of file execExprInterp.c.

253{
254 /* Ensure one-time interpreter setup has been done */
256
257 /* Simple validity checks on expression */
258 Assert(state->steps_len >= 1);
259 Assert(state->steps[state->steps_len - 1].opcode == EEOP_DONE_RETURN ||
260 state->steps[state->steps_len - 1].opcode == EEOP_DONE_NO_RETURN);
261
262 /*
263 * Don't perform redundant initialization. This is unreachable in current
264 * cases, but might be hit if there's additional expression evaluation
265 * methods that rely on interpreted execution to work.
266 */
268 return;
269
270 /*
271 * First time through, check whether attribute matches Var. Might not be
272 * ok anymore, due to schema changes. We do that by setting up a callback
273 * that does checking on the first call, which then sets the evalfunc
274 * callback to the actual method of execution.
275 */
277
278 /* DIRECT_THREADED should not already be set */
279 Assert((state->flags & EEO_FLAG_DIRECT_THREADED) == 0);
280
281 /*
282 * There shouldn't be any errors before the expression is fully
283 * initialized, and even if so, it'd lead to the expression being
284 * abandoned. So we can set the flag now and save some code.
285 */
287
288 /*
289 * Select fast-path evalfuncs for very simple expressions. "Starting up"
290 * the full interpreter is a measurable overhead for these, and these
291 * patterns occur often enough to be worth optimizing.
292 */
293 if (state->steps_len == 5)
294 {
295 ExprEvalOp step0 = state->steps[0].opcode;
296 ExprEvalOp step1 = state->steps[1].opcode;
297 ExprEvalOp step2 = state->steps[2].opcode;
298 ExprEvalOp step3 = state->steps[3].opcode;
299
304 {
305 state->evalfunc_private = (void *) ExecJustHashInnerVarWithIV;
306 return;
307 }
308 }
309 else if (state->steps_len == 4)
310 {
311 ExprEvalOp step0 = state->steps[0].opcode;
312 ExprEvalOp step1 = state->steps[1].opcode;
313 ExprEvalOp step2 = state->steps[2].opcode;
314
318 {
319 state->evalfunc_private = (void *) ExecJustHashOuterVar;
320 return;
321 }
322 else if (step0 == EEOP_INNER_FETCHSOME &&
325 {
326 state->evalfunc_private = (void *) ExecJustHashInnerVar;
327 return;
328 }
329 else if (step0 == EEOP_OUTER_FETCHSOME &&
332 {
333 state->evalfunc_private = (void *) ExecJustHashOuterVarStrict;
334 return;
335 }
336 }
337 else if (state->steps_len == 3)
338 {
339 ExprEvalOp step0 = state->steps[0].opcode;
340 ExprEvalOp step1 = state->steps[1].opcode;
341
344 {
345 state->evalfunc_private = ExecJustInnerVar;
346 return;
347 }
348 else if (step0 == EEOP_OUTER_FETCHSOME &&
350 {
351 state->evalfunc_private = ExecJustOuterVar;
352 return;
353 }
354 else if (step0 == EEOP_SCAN_FETCHSOME &&
356 {
357 state->evalfunc_private = ExecJustScanVar;
358 return;
359 }
360 else if (step0 == EEOP_INNER_FETCHSOME &&
362 {
363 state->evalfunc_private = ExecJustAssignInnerVar;
364 return;
365 }
366 else if (step0 == EEOP_OUTER_FETCHSOME &&
368 {
369 state->evalfunc_private = ExecJustAssignOuterVar;
370 return;
371 }
372 else if (step0 == EEOP_SCAN_FETCHSOME &&
374 {
375 state->evalfunc_private = ExecJustAssignScanVar;
376 return;
377 }
378 else if (step0 == EEOP_CASE_TESTVAL &&
382 {
383 state->evalfunc_private = ExecJustApplyFuncToCase;
384 return;
385 }
386 else if (step0 == EEOP_INNER_VAR &&
388 {
389 state->evalfunc_private = (void *) ExecJustHashInnerVarVirt;
390 return;
391 }
392 else if (step0 == EEOP_OUTER_VAR &&
394 {
395 state->evalfunc_private = (void *) ExecJustHashOuterVarVirt;
396 return;
397 }
398 }
399 else if (state->steps_len == 2)
400 {
401 ExprEvalOp step0 = state->steps[0].opcode;
402
403 if (step0 == EEOP_CONST)
404 {
405 state->evalfunc_private = ExecJustConst;
406 return;
407 }
408 else if (step0 == EEOP_INNER_VAR)
409 {
410 state->evalfunc_private = ExecJustInnerVarVirt;
411 return;
412 }
413 else if (step0 == EEOP_OUTER_VAR)
414 {
415 state->evalfunc_private = ExecJustOuterVarVirt;
416 return;
417 }
418 else if (step0 == EEOP_SCAN_VAR)
419 {
420 state->evalfunc_private = ExecJustScanVarVirt;
421 return;
422 }
423 else if (step0 == EEOP_ASSIGN_INNER_VAR)
424 {
425 state->evalfunc_private = ExecJustAssignInnerVarVirt;
426 return;
427 }
428 else if (step0 == EEOP_ASSIGN_OUTER_VAR)
429 {
430 state->evalfunc_private = ExecJustAssignOuterVarVirt;
431 return;
432 }
433 else if (step0 == EEOP_ASSIGN_SCAN_VAR)
434 {
435 state->evalfunc_private = ExecJustAssignScanVarVirt;
436 return;
437 }
438 }
439
440#if defined(EEO_USE_COMPUTED_GOTO)
441
442 /*
443 * In the direct-threaded implementation, replace each opcode with the
444 * address to jump to. (Use ExecEvalStepOp() to get back the opcode.)
445 */
446 for (int off = 0; off < state->steps_len; off++)
447 {
448 ExprEvalStep *op = &state->steps[off];
449
450 op->opcode = EEO_OPCODE(op->opcode);
451 }
452
454#endif /* EEO_USE_COMPUTED_GOTO */
455
456 state->evalfunc_private = ExecInterpExpr;
457}
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 ExecJustHashInnerVarVirt(ExprState *state, ExprContext *econtext, bool *isnull)
static Datum ExecJustInnerVarVirt(ExprState *state, ExprContext *econtext, bool *isnull)
static Datum ExecJustHashInnerVarWithIV(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 ExecJustHashOuterVarVirt(ExprState *state, ExprContext *econtext, bool *isnull)
static Datum ExecJustAssignScanVarVirt(ExprState *state, ExprContext *econtext, bool *isnull)
static Datum ExecJustHashOuterVarStrict(ExprState *state, ExprContext *econtext, bool *isnull)
static Datum ExecJustAssignOuterVar(ExprState *state, ExprContext *econtext, bool *isnull)
static Datum ExecJustHashOuterVar(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)
static Datum ExecJustHashInnerVar(ExprState *state, ExprContext *econtext, bool *isnull)
#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_NO_RETURN, EEOP_DONE_RETURN, EEOP_FUNCEXPR_STRICT, EEOP_FUNCEXPR_STRICT_1, EEOP_FUNCEXPR_STRICT_2, EEOP_HASHDATUM_FIRST, EEOP_HASHDATUM_FIRST_STRICT, EEOP_HASHDATUM_NEXT32, EEOP_HASHDATUM_SET_INITVAL, 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(), ExecJustHashInnerVar(), ExecJustHashInnerVarVirt(), ExecJustHashInnerVarWithIV(), ExecJustHashOuterVar(), ExecJustHashOuterVarStrict(), ExecJustHashOuterVarVirt(), ExecJustInnerVar(), ExecJustInnerVarVirt(), ExecJustOuterVar(), ExecJustOuterVarVirt(), ExecJustScanVar(), ExecJustScanVarVirt(), fb(), 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 2490 of file execExprInterp.c.

2493{
2494 if (type_id != RECORDOID)
2495 {
2496 /*
2497 * It's a named composite type, so use the regular typcache. Do a
2498 * lookup first time through, or if the composite type changed. Note:
2499 * "tupdesc_id == 0" may look redundant, but it protects against the
2500 * admittedly-theoretical possibility that type_id was RECORDOID the
2501 * last time through, so that the cacheptr isn't TypeCacheEntry *.
2502 */
2503 TypeCacheEntry *typentry = (TypeCacheEntry *) rowcache->cacheptr;
2504
2505 if (unlikely(typentry == NULL ||
2506 rowcache->tupdesc_id == 0 ||
2507 typentry->tupDesc_identifier != rowcache->tupdesc_id))
2508 {
2509 typentry = lookup_type_cache(type_id, TYPECACHE_TUPDESC);
2510 if (typentry->tupDesc == NULL)
2511 ereport(ERROR,
2513 errmsg("type %s is not composite",
2514 format_type_be(type_id))));
2515 rowcache->cacheptr = typentry;
2516 rowcache->tupdesc_id = typentry->tupDesc_identifier;
2517 if (changed)
2518 *changed = true;
2519 }
2520 return typentry->tupDesc;
2521 }
2522 else
2523 {
2524 /*
2525 * A RECORD type, once registered, doesn't change for the life of the
2526 * backend. So we don't need a typcache entry as such, which is good
2527 * because there isn't one. It's possible that the caller is asking
2528 * about a different type than before, though.
2529 */
2530 TupleDesc tupDesc = (TupleDesc) rowcache->cacheptr;
2531
2532 if (unlikely(tupDesc == NULL ||
2533 rowcache->tupdesc_id != 0 ||
2534 type_id != tupDesc->tdtypeid ||
2535 typmod != tupDesc->tdtypmod))
2536 {
2537 tupDesc = lookup_rowtype_tupdesc(type_id, typmod);
2538 /* Drop pin acquired by lookup_rowtype_tupdesc */
2539 ReleaseTupleDesc(tupDesc);
2540 rowcache->cacheptr = tupDesc;
2541 rowcache->tupdesc_id = 0; /* not a valid value for non-RECORD */
2542 if (changed)
2543 *changed = true;
2544 }
2545 return tupDesc;
2546 }
2547}
struct TupleDescData * TupleDesc
Definition tupdesc.h:163
TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod)
Definition typcache.c:1947
TypeCacheEntry * lookup_type_cache(Oid type_id, int flags)
Definition typcache.c:389
#define TYPECACHE_TUPDESC
Definition typcache.h:146

References ExprEvalRowtypeCache::cacheptr, ereport, errcode(), errmsg, ERROR, fb(), format_type_be(), 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().

◆ GetJsonBehaviorValueString()

static char * GetJsonBehaviorValueString ( JsonBehavior behavior)
static

Definition at line 5238 of file execExprInterp.c.

5239{
5240 /*
5241 * The order of array elements must correspond to the order of
5242 * JsonBehaviorType members.
5243 */
5244 const char *behavior_names[] =
5245 {
5246 "NULL",
5247 "ERROR",
5248 "EMPTY",
5249 "TRUE",
5250 "FALSE",
5251 "UNKNOWN",
5252 "EMPTY ARRAY",
5253 "EMPTY OBJECT",
5254 "DEFAULT"
5255 };
5256
5257 return pstrdup(behavior_names[behavior->btype]);
5258}
char * pstrdup(const char *in)
Definition mcxt.c:1781

References JsonBehavior::btype, fb(), and pstrdup().

Referenced by ExecEvalJsonCoercionFinish().

◆ saop_element_hash()

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

Definition at line 4207 of file execExprInterp.c.

4208{
4209 ScalarArrayOpExprHashTable *elements_tab = (ScalarArrayOpExprHashTable *) tb->private_data;
4210 FunctionCallInfo fcinfo = &elements_tab->hash_fcinfo_data;
4211 Datum hash;
4212
4213 fcinfo->args[0].value = key;
4214 fcinfo->args[0].isnull = false;
4215
4216 hash = elements_tab->hash_finfo.fn_addr(fcinfo);
4217
4218 return DatumGetUInt32(hash);
4219}
static unsigned hash(unsigned *uv, int n)
Definition rege_dfa.c:715

References FunctionCallInfoBaseData::args, DatumGetUInt32(), ExprEvalStep::elements_tab, fb(), FmgrInfo::fn_addr, hash(), ScalarArrayOpExprHashTable::hash_fcinfo_data, ScalarArrayOpExprHashTable::hash_finfo, NullableDatum::isnull, and NullableDatum::value.

◆ saop_hash_element_match()

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

Definition at line 4226 of file execExprInterp.c.

4227{
4228 Datum result;
4229
4230 ScalarArrayOpExprHashTable *elements_tab = (ScalarArrayOpExprHashTable *) tb->private_data;
4231 FunctionCallInfo fcinfo = elements_tab->op->d.hashedscalararrayop.fcinfo_data;
4232
4233 fcinfo->args[0].value = key1;
4234 fcinfo->args[0].isnull = false;
4235 fcinfo->args[1].value = key2;
4236 fcinfo->args[1].isnull = false;
4237
4238 result = elements_tab->op->d.hashedscalararrayop.finfo->fn_addr(fcinfo);
4239
4240 return DatumGetBool(result);
4241}

References FunctionCallInfoBaseData::args, ExprEvalStep::d, DatumGetBool(), ExprEvalStep::elements_tab, fb(), ExprEvalStep::fcinfo_data, ExprEvalStep::finfo, FmgrInfo::fn_addr, ExprEvalStep::hashedscalararrayop, NullableDatum::isnull, ScalarArrayOpExprHashTable::op, result, and NullableDatum::value.