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

◆ SH_DEFINE

#define SH_DEFINE

Definition at line 237 of file execExprInterp.c.

◆ SH_ELEMENT_TYPE [1/2]

#define SH_ELEMENT_TYPE   ScalarArrayOpExprHashEntry

Definition at line 205 of file execExprInterp.c.

◆ SH_ELEMENT_TYPE [2/2]

#define SH_ELEMENT_TYPE   ScalarArrayOpExprHashEntry

Definition at line 205 of file execExprInterp.c.

◆ SH_EQUAL

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

Definition at line 233 of file execExprInterp.c.

◆ SH_GET_HASH

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

Definition at line 236 of file execExprInterp.c.

◆ SH_HASH_KEY

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

Definition at line 232 of file execExprInterp.c.

◆ SH_KEY

#define SH_KEY   key

Definition at line 231 of file execExprInterp.c.

◆ SH_KEY_TYPE [1/2]

#define SH_KEY_TYPE   Datum

Definition at line 206 of file execExprInterp.c.

◆ SH_KEY_TYPE [2/2]

#define SH_KEY_TYPE   Datum

Definition at line 206 of file execExprInterp.c.

◆ SH_PREFIX [1/2]

#define SH_PREFIX   saophash

Definition at line 204 of file execExprInterp.c.

◆ SH_PREFIX [2/2]

#define SH_PREFIX   saophash

Definition at line 204 of file execExprInterp.c.

◆ SH_SCOPE [1/2]

#define SH_SCOPE   static inline

Definition at line 207 of file execExprInterp.c.

◆ SH_SCOPE [2/2]

#define SH_SCOPE   static inline

Definition at line 207 of file execExprInterp.c.

◆ SH_STORE_HASH

#define SH_STORE_HASH

Definition at line 235 of file execExprInterp.c.

Typedef Documentation

◆ ScalarArrayOpExprHashEntry

◆ ScalarArrayOpExprHashTable

Function Documentation

◆ CheckExprStillValid()

void CheckExprStillValid ( ExprState state,
ExprContext econtext 
)

Definition at line 2309 of file execExprInterp.c.

2310{
2316
2317 innerslot = econtext->ecxt_innertuple;
2318 outerslot = econtext->ecxt_outertuple;
2319 scanslot = econtext->ecxt_scantuple;
2320 oldslot = econtext->ecxt_oldtuple;
2321 newslot = econtext->ecxt_newtuple;
2322
2323 for (int i = 0; i < state->steps_len; i++)
2324 {
2325 ExprEvalStep *op = &state->steps[i];
2326
2327 switch (ExecEvalStepOp(state, op))
2328 {
2329 case EEOP_INNER_VAR:
2330 {
2331 int attnum = op->d.var.attnum;
2332
2334 break;
2335 }
2336
2337 case EEOP_OUTER_VAR:
2338 {
2339 int attnum = op->d.var.attnum;
2340
2342 break;
2343 }
2344
2345 case EEOP_SCAN_VAR:
2346 {
2347 int attnum = op->d.var.attnum;
2348
2350 break;
2351 }
2352
2353 case EEOP_OLD_VAR:
2354 {
2355 int attnum = op->d.var.attnum;
2356
2358 break;
2359 }
2360
2361 case EEOP_NEW_VAR:
2362 {
2363 int attnum = op->d.var.attnum;
2364
2366 break;
2367 }
2368 default:
2369 break;
2370 }
2371 }
2372}
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:286
TupleTableSlot * ecxt_newtuple
Definition execnodes.h:323
TupleTableSlot * ecxt_scantuple
Definition execnodes.h:284
TupleTableSlot * ecxt_oldtuple
Definition execnodes.h:321
TupleTableSlot * ecxt_outertuple
Definition execnodes.h:288
union ExprEvalStep::@60 d
struct ExprEvalStep::@60::@62 var

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

2436{
2437#ifdef USE_ASSERT_CHECKING
2438 /* there's nothing to check */
2439 if (!op->d.fetch.fixed)
2440 return;
2441
2442 /*
2443 * Should probably fixed at some point, but for now it's easier to allow
2444 * buffer and heap tuples to be used interchangeably.
2445 */
2446 if (slot->tts_ops == &TTSOpsBufferHeapTuple &&
2447 op->d.fetch.kind == &TTSOpsHeapTuple)
2448 return;
2449 if (slot->tts_ops == &TTSOpsHeapTuple &&
2451 return;
2452
2453 /*
2454 * At the moment we consider it OK if a virtual slot is used instead of a
2455 * specific type of slot, as a virtual slot never needs to be deformed.
2456 */
2457 if (slot->tts_ops == &TTSOpsVirtual)
2458 return;
2459
2460 Assert(op->d.fetch.kind == slot->tts_ops);
2461#endif
2462}
#define Assert(condition)
Definition c.h:945
const TupleTableSlotOps TTSOpsVirtual
Definition execTuples.c:84
const TupleTableSlotOps TTSOpsBufferHeapTuple
Definition execTuples.c:87
const TupleTableSlotOps TTSOpsHeapTuple
Definition execTuples.c:85
const TupleTableSlotOps * kind
Definition execExpr.h:331
struct ExprEvalStep::@60::@61 fetch
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 2380 of file execExprInterp.c.

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

5676{
5678
5679 if (!newValueIsNull)
5680 {
5681 MemoryContextSwitchTo(aggstate->curaggcontext->ecxt_per_tuple_memory);
5683 false,
5684 pertrans->transtypeLen) &&
5686 /* do nothing */ ;
5687 else
5689 pertrans->transtypeByVal,
5690 pertrans->transtypeLen);
5691 }
5692 else
5693 {
5694 /*
5695 * Ensure that AggStatePerGroup->transValue ends up being 0, so
5696 * callers can safely compare newValue/oldValue without having to
5697 * check their respective nullness.
5698 */
5699 newValue = (Datum) 0;
5700 }
5701
5702 if (!oldValueIsNull)
5703 {
5705 false,
5706 pertrans->transtypeLen))
5708 else
5710 }
5711
5712 return newValue;
5713}
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 5620 of file execExprInterp.c.

5622{
5623 FunctionCallInfo fcinfo = pertrans->transfn_fcinfo;
5625
5626 /*
5627 * We must copy the datum into aggcontext if it is pass-by-ref. We do not
5628 * need to pfree the old transValue, since it's NULL. (We already checked
5629 * that the agg's input type is binary-compatible with its transtype, so
5630 * straight copy here is OK.)
5631 */
5633 pergroup->transValue = datumCopy(fcinfo->args[1].value,
5634 pertrans->transtypeByVal,
5635 pertrans->transtypeLen);
5636 pergroup->transValueIsNull = false;
5637 pergroup->noTransValue = false;
5639}
FunctionCallInfo transfn_fcinfo
Definition nodeAgg.h:170
MemoryContext ecxt_per_tuple_memory
Definition execnodes.h:292
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 5872 of file execExprInterp.c.

5875{
5876 FunctionCallInfo fcinfo = pertrans->transfn_fcinfo;
5878 Datum newVal;
5879
5880 /* cf. select_current_set() */
5881 aggstate->curaggcontext = aggcontext;
5882 aggstate->current_set = setno;
5883
5884 /* set up aggstate->curpertrans for AggGetAggref() */
5885 aggstate->curpertrans = pertrans;
5886
5887 /* invoke transition function in per-tuple context */
5888 oldContext = MemoryContextSwitchTo(aggstate->tmpcontext->ecxt_per_tuple_memory);
5889
5890 fcinfo->args[0].value = pergroup->transValue;
5891 fcinfo->args[0].isnull = pergroup->transValueIsNull;
5892 fcinfo->isnull = false; /* just in case transfn doesn't set it */
5893
5894 newVal = FunctionCallInvoke(fcinfo);
5895
5896 /*
5897 * For pass-by-ref datatype, must copy the new value into aggcontext and
5898 * free the prior transValue. But if transfn returned a pointer to its
5899 * first input, we don't need to do anything.
5900 *
5901 * It's safe to compare newVal with pergroup->transValue without regard
5902 * for either being NULL, because ExecAggCopyTransValue takes care to set
5903 * transValue to 0 when NULL. Otherwise we could end up accidentally not
5904 * reparenting, when the transValue has the same numerical value as
5905 * newValue, despite being NULL. This is a somewhat hot path, making it
5906 * undesirable to instead solve this with another branch for the common
5907 * case of the transition function returning its (modified) input
5908 * argument.
5909 */
5910 if (DatumGetPointer(newVal) != DatumGetPointer(pergroup->transValue))
5911 newVal = ExecAggCopyTransValue(aggstate, pertrans,
5912 newVal, fcinfo->isnull,
5913 pergroup->transValue,
5914 pergroup->transValueIsNull);
5915
5916 pergroup->transValue = newVal;
5917 pergroup->transValueIsNull = fcinfo->isnull;
5918
5920}
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 5840 of file execExprInterp.c.

5843{
5844 FunctionCallInfo fcinfo = pertrans->transfn_fcinfo;
5846 Datum newVal;
5847
5848 /* cf. select_current_set() */
5849 aggstate->curaggcontext = aggcontext;
5850 aggstate->current_set = setno;
5851
5852 /* set up aggstate->curpertrans for AggGetAggref() */
5853 aggstate->curpertrans = pertrans;
5854
5855 /* invoke transition function in per-tuple context */
5856 oldContext = MemoryContextSwitchTo(aggstate->tmpcontext->ecxt_per_tuple_memory);
5857
5858 fcinfo->args[0].value = pergroup->transValue;
5859 fcinfo->args[0].isnull = pergroup->transValueIsNull;
5860 fcinfo->isnull = false; /* just in case transfn doesn't set it */
5861
5862 newVal = FunctionCallInvoke(fcinfo);
5863
5864 pergroup->transValue = newVal;
5865 pergroup->transValueIsNull = fcinfo->isnull;
5866
5868}

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

5814{
5815 AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
5816 int setno = op->d.agg_trans.setno;
5817
5818 tuplesort_putdatum(pertrans->sortstates[setno],
5819 *op->resvalue, *op->resnull);
5820}
Tuplesortstate ** sortstates
Definition nodeAgg.h:162
AggStatePerTrans pertrans
Definition execExpr.h:731
Datum * resvalue
Definition execExpr.h:310
struct ExprEvalStep::@60::@106 agg_trans
bool * resnull
Definition execExpr.h:311
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 5826 of file execExprInterp.c.

5828{
5829 AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
5830 int setno = op->d.agg_trans.setno;
5831
5832 ExecClearTuple(pertrans->sortslot);
5833 pertrans->sortslot->tts_nvalid = pertrans->numInputs;
5835 tuplesort_puttupleslot(pertrans->sortstates[setno], pertrans->sortslot);
5836}
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 3617 of file execExprInterp.c.

3618{
3620
3621 /* NULL array -> NULL result */
3622 if (*op->resnull)
3623 return;
3624
3625 arraydatum = *op->resvalue;
3626
3627 /*
3628 * If it's binary-compatible, modify the element type in the array header,
3629 * but otherwise leave the array as we received it.
3630 */
3631 if (op->d.arraycoerce.elemexprstate == NULL)
3632 {
3633 /* Detoast input array if necessary, and copy in any case */
3635
3637 *op->resvalue = PointerGetDatum(array);
3638 return;
3639 }
3640
3641 /*
3642 * Use array_map to apply the sub-expression to each array element.
3643 */
3646 econtext,
3648 op->d.arraycoerce.amstate);
3649}
#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)
static Datum PointerGetDatum(const void *X)
Definition postgres.h:342
ExprState * elemexprstate
Definition execExpr.h:493
struct ExprEvalStep::@60::@81 arraycoerce
Oid resultelemtype
Definition execExpr.h:494
struct ArrayMapState * amstate
Definition execExpr.h:495

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

Referenced by ExecInterpExpr().

◆ ExecEvalArrayExpr()

void ExecEvalArrayExpr ( ExprState state,
ExprEvalStep op 
)

Definition at line 3403 of file execExprInterp.c.

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

Referenced by ExecInterpExpr().

◆ ExecEvalCoerceViaIOSafe()

void ExecEvalCoerceViaIOSafe ( ExprState state,
ExprEvalStep op 
)

Definition at line 3137 of file execExprInterp.c.

3138{
3139 char *str;
3140
3141 /* call output function (similar to OutputFunctionCall) */
3142 if (*op->resnull)
3143 {
3144 /* output functions are not called on nulls */
3145 str = NULL;
3146 }
3147 else
3148 {
3150
3152 fcinfo_out->args[0].value = *op->resvalue;
3153 fcinfo_out->args[0].isnull = false;
3154
3155 fcinfo_out->isnull = false;
3157
3158 /* OutputFunctionCall assumes result isn't null */
3159 Assert(!fcinfo_out->isnull);
3160 }
3161
3162 /* call input function (similar to InputFunctionCallSafe) */
3163 if (!op->d.iocoerce.finfo_in->fn_strict || str != NULL)
3164 {
3166
3169 fcinfo_in->args[0].isnull = *op->resnull;
3170 /* second and third arguments are already set up */
3171
3172 /* ErrorSaveContext must be present. */
3174
3175 fcinfo_in->isnull = false;
3177
3178 if (SOFT_ERROR_OCCURRED(fcinfo_in->context))
3179 {
3180 *op->resnull = true;
3181 *op->resvalue = (Datum) 0;
3182 return;
3183 }
3184
3185 /* Should get null result if and only if str is NULL */
3186 if (str == NULL)
3187 Assert(*op->resnull);
3188 else
3189 Assert(!*op->resnull);
3190 }
3191}
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:355
struct ExprEvalStep::@60::@77 iocoerce
FunctionCallInfo fcinfo_data_in
Definition execExpr.h:461
FmgrInfo * finfo_in
Definition execExpr.h:460
FunctionCallInfo fcinfo_data_out
Definition execExpr.h:458
bool fn_strict
Definition fmgr.h:61

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

4429{
4430 if (!*op->d.domaincheck.checknull &&
4434 errmsg("value for domain %s violates check constraint \"%s\"",
4439}
int errdomainconstraint(Oid datatypeOid, const char *conname)
Definition domains.c:431
#define errsave(context,...)
Definition elog.h:262
static bool DatumGetBool(Datum X)
Definition postgres.h:100
bool * checknull
Definition execExpr.h:589
Datum * checkvalue
Definition execExpr.h:588
ErrorSaveContext * escontext
Definition execExpr.h:592
struct ExprEvalStep::@60::@90 domaincheck
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 4414 of file execExprInterp.c.

4415{
4416 if (*op->resnull)
4419 errmsg("domain %s does not allow null values",
4422}
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 3930 of file execExprInterp.c.

3931{
3932 HeapTuple result;
3934 HeapTupleHeader tuple;
3936 TupleDesc indesc,
3937 outdesc;
3938 bool changed = false;
3939
3940 /* NULL in -> NULL out */
3941 if (*op->resnull)
3942 return;
3943
3944 tupDatum = *op->resvalue;
3946
3947 /*
3948 * Lookup tupdescs if first time through or if type changes. We'd better
3949 * pin them since type conversion functions could do catalog lookups and
3950 * hence cause cache invalidation.
3951 */
3954 &changed);
3955 IncrTupleDescRefCount(indesc);
3958 &changed);
3959 IncrTupleDescRefCount(outdesc);
3960
3961 /*
3962 * We used to be able to assert that incoming tuples are marked with
3963 * exactly the rowtype of indesc. However, now that ExecEvalWholeRowVar
3964 * might change the tuples' marking to plain RECORD due to inserting
3965 * aliases, we can only make this weak test:
3966 */
3967 Assert(HeapTupleHeaderGetTypeId(tuple) == indesc->tdtypeid ||
3969
3970 /* if first time through, or after change, initialize conversion map */
3971 if (changed)
3972 {
3974
3975 /* allocate map in long-lived memory context */
3977
3978 /* prepare map from old to new attribute numbers */
3979 op->d.convert_rowtype.map = convert_tuples_by_name(indesc, outdesc);
3980
3982 }
3983
3984 /* Following steps need a HeapTuple not a bare HeapTupleHeader */
3986 tmptup.t_data = tuple;
3987
3988 if (op->d.convert_rowtype.map != NULL)
3989 {
3990 /* Full conversion with attribute rearrangement needed */
3992 /* Result already has appropriate composite-datum header fields */
3993 *op->resvalue = HeapTupleGetDatum(result);
3994 }
3995 else
3996 {
3997 /*
3998 * The tuple is physically compatible as-is, but we need to insert the
3999 * destination rowtype OID in its composite-datum header field, so we
4000 * have to copy it anyway. heap_copy_tuple_as_datum() is convenient
4001 * for this since it will both make the physical copy and insert the
4002 * correct composite header fields. Note that we aren't expecting to
4003 * have to flatten any toasted fields: the input was a composite
4004 * datum, so it shouldn't contain any. So heap_copy_tuple_as_datum()
4005 * is overkill here, but its check for external fields is cheap.
4006 */
4007 *op->resvalue = heap_copy_tuple_as_datum(&tmptup, outdesc);
4008 }
4009
4010 DecrTupleDescRefCount(indesc);
4011 DecrTupleDescRefCount(outdesc);
4012}
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:1001
static uint32 HeapTupleHeaderGetDatumLength(const HeapTupleHeaderData *tup)
static Oid HeapTupleHeaderGetTypeId(const HeapTupleHeaderData *tup)
MemoryContext ecxt_per_query_memory
Definition execnodes.h:291
struct ExprEvalStep::@60::@93 convert_rowtype
TupleConversionMap * map
Definition execExpr.h:621
ExprEvalRowtypeCache * incache
Definition execExpr.h:619
ExprEvalRowtypeCache * outcache
Definition execExpr.h:620
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:632
void IncrTupleDescRefCount(TupleDesc tupdesc)
Definition tupdesc.c:614

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, and TupleDescData::tdtypeid.

Referenced by ExecInterpExpr().

◆ ExecEvalCurrentOfExpr()

void ExecEvalCurrentOfExpr ( ExprState state,
ExprEvalStep op 
)

Definition at line 3264 of file execExprInterp.c.

3265{
3266 ereport(ERROR,
3268 errmsg("WHERE CURRENT OF is not supported for this table type")));
3269}

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

Referenced by ExecInterpExpr().

◆ ExecEvalFieldSelect()

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

Definition at line 3731 of file execExprInterp.c.

3732{
3733 AttrNumber fieldnum = op->d.fieldselect.fieldnum;
3735 HeapTupleHeader tuple;
3736 Oid tupType;
3738 TupleDesc tupDesc;
3739 Form_pg_attribute attr;
3741
3742 /* NULL record -> NULL result */
3743 if (*op->resnull)
3744 return;
3745
3746 tupDatum = *op->resvalue;
3747
3748 /* We can special-case expanded records for speed */
3750 {
3752
3753 Assert(erh->er_magic == ER_MAGIC);
3754
3755 /* Extract record's TupleDesc */
3756 tupDesc = expanded_record_get_tupdesc(erh);
3757
3758 /*
3759 * Find field's attr record. Note we don't support system columns
3760 * here: a datum tuple doesn't have valid values for most of the
3761 * interesting system columns anyway.
3762 */
3763 if (fieldnum <= 0) /* should never happen */
3764 elog(ERROR, "unsupported reference to system column %d in FieldSelect",
3765 fieldnum);
3766 if (fieldnum > tupDesc->natts) /* should never happen */
3767 elog(ERROR, "attribute number %d exceeds number of columns %d",
3768 fieldnum, tupDesc->natts);
3769 attr = TupleDescAttr(tupDesc, fieldnum - 1);
3770
3771 /* Check for dropped column, and force a NULL result if so */
3772 if (attr->attisdropped)
3773 {
3774 *op->resnull = true;
3775 return;
3776 }
3777
3778 /* Check for type mismatch --- possible after ALTER COLUMN TYPE? */
3779 /* As in CheckVarSlotCompatibility, we should but can't check typmod */
3780 if (op->d.fieldselect.resulttype != attr->atttypid)
3781 ereport(ERROR,
3783 errmsg("attribute %d has wrong type", fieldnum),
3784 errdetail("Table has type %s, but query expects %s.",
3785 format_type_be(attr->atttypid),
3787
3788 /* extract the field */
3789 *op->resvalue = expanded_record_get_field(erh, fieldnum,
3790 op->resnull);
3791 }
3792 else
3793 {
3794 /* Get the composite datum and extract its type fields */
3796
3799
3800 /* Lookup tupdesc if first time through or if type changes */
3802 &op->d.fieldselect.rowcache, NULL);
3803
3804 /*
3805 * Find field's attr record. Note we don't support system columns
3806 * here: a datum tuple doesn't have valid values for most of the
3807 * interesting system columns anyway.
3808 */
3809 if (fieldnum <= 0) /* should never happen */
3810 elog(ERROR, "unsupported reference to system column %d in FieldSelect",
3811 fieldnum);
3812 if (fieldnum > tupDesc->natts) /* should never happen */
3813 elog(ERROR, "attribute number %d exceeds number of columns %d",
3814 fieldnum, tupDesc->natts);
3815 attr = TupleDescAttr(tupDesc, fieldnum - 1);
3816
3817 /* Check for dropped column, and force a NULL result if so */
3818 if (attr->attisdropped)
3819 {
3820 *op->resnull = true;
3821 return;
3822 }
3823
3824 /* Check for type mismatch --- possible after ALTER COLUMN TYPE? */
3825 /* As in CheckVarSlotCompatibility, we should but can't check typmod */
3826 if (op->d.fieldselect.resulttype != attr->atttypid)
3827 ereport(ERROR,
3829 errmsg("attribute %d has wrong type", fieldnum),
3830 errdetail("Table has type %s, but query expects %s.",
3831 format_type_be(attr->atttypid),
3833
3834 /* heap_getattr needs a HeapTuple not a bare HeapTupleHeader */
3836 tmptup.t_data = tuple;
3837
3838 /* extract the field */
3840 fieldnum,
3841 tupDesc,
3842 op->resnull);
3843 }
3844}
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)
struct ExprEvalStep::@60::@86 fieldselect
AttrNumber fieldnum
Definition execExpr.h:543
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 3856 of file execExprInterp.c.

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

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

3907{
3908 TupleDesc tupDesc;
3909 HeapTuple tuple;
3910
3911 /* Lookup tupdesc (should be valid already) */
3912 tupDesc = get_cached_rowtype(op->d.fieldstore.fstore->resulttype, -1,
3913 op->d.fieldstore.rowcache, NULL);
3914
3915 tuple = heap_form_tuple(tupDesc,
3916 op->d.fieldstore.values,
3917 op->d.fieldstore.nulls);
3918
3919 *op->resvalue = HeapTupleGetDatum(tuple);
3920 *op->resnull = false;
3921}
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
Definition heaptuple.c:1037

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

2994{
2995 FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
2997 Datum d;
2998
3000
3001 fcinfo->isnull = false;
3002 d = op->d.func.fn_addr(fcinfo);
3003 *op->resvalue = d;
3004 *op->resnull = fcinfo->isnull;
3005
3007}
void pgstat_init_function_usage(FunctionCallInfo fcinfo, PgStat_FunctionCallUsage *fcu)
void pgstat_end_function_usage(PgStat_FunctionCallUsage *fcu, bool finalize)
PGFunction fn_addr
Definition execExpr.h:391
FunctionCallInfo fcinfo_data
Definition execExpr.h:389
struct ExprEvalStep::@60::@68 func

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

3015{
3016
3017 FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
3019 NullableDatum *args = fcinfo->args;
3020 int nargs = op->d.func.nargs;
3021 Datum d;
3022
3023 /* strict function, so check for NULL args */
3024 for (int argno = 0; argno < nargs; argno++)
3025 {
3026 if (args[argno].isnull)
3027 {
3028 *op->resnull = true;
3029 return;
3030 }
3031 }
3032
3034
3035 fcinfo->isnull = false;
3036 d = op->d.func.fn_addr(fcinfo);
3037 *op->resvalue = d;
3038 *op->resnull = fcinfo->isnull;
3039
3041}

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

5250{
5252 int result = 0;
5253 Bitmapset *grouped_cols = aggstate->grouped_cols;
5254 ListCell *lc;
5255
5256 foreach(lc, op->d.grouping_func.clauses)
5257 {
5258 int attnum = lfirst_int(lc);
5259
5260 result <<= 1;
5261
5262 if (!bms_is_member(attnum, grouped_cols))
5263 result |= 1;
5264 }
5265
5266 *op->resvalue = Int32GetDatum(result);
5267 *op->resnull = false;
5268}
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
List * clauses
Definition execExpr.h:677
struct ExprEvalStep::@60::@99 grouping_func

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

Referenced by ExecInterpExpr().

◆ ExecEvalHashedScalarArrayOp()

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

Definition at line 4230 of file execExprInterp.c.

4231{
4234 bool inclause = op->d.hashedscalararrayop.inclause;
4236 Datum scalar = fcinfo->args[0].value;
4237 bool scalar_isnull = fcinfo->args[0].isnull;
4238 Datum result;
4239 bool resultnull;
4240 bool hashfound;
4241
4242 /* We don't setup a hashed scalar array op if the array const is null. */
4243 Assert(!*op->resnull);
4244
4245 /*
4246 * If the scalar is NULL, and the function is strict, return NULL; no
4247 * point in executing the search.
4248 */
4249 if (fcinfo->args[0].isnull && strictfunc)
4250 {
4251 *op->resnull = true;
4252 return;
4253 }
4254
4255 /* Build the hash table on first evaluation */
4256 if (elements_tab == NULL)
4257 {
4258 ScalarArrayOpExpr *saop;
4259 int16 typlen;
4260 bool typbyval;
4261 char typalign;
4262 uint8 typalignby;
4263 int nitems;
4264 bool has_nulls = false;
4265 char *s;
4266 bits8 *bitmap;
4267 int bitmask;
4268 MemoryContext oldcontext;
4269 ArrayType *arr;
4270
4271 saop = op->d.hashedscalararrayop.saop;
4272
4273 arr = DatumGetArrayTypeP(*op->resvalue);
4274 nitems = ArrayGetNItems(ARR_NDIM(arr), ARR_DIMS(arr));
4275
4277 &typlen,
4278 &typbyval,
4279 &typalign);
4280 typalignby = typalign_to_alignby(typalign);
4281
4282 oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
4283
4284 elements_tab = (ScalarArrayOpExprHashTable *)
4285 palloc0(offsetof(ScalarArrayOpExprHashTable, hash_fcinfo_data) +
4287 op->d.hashedscalararrayop.elements_tab = elements_tab;
4288 elements_tab->op = op;
4289
4290 fmgr_info(saop->hashfuncid, &elements_tab->hash_finfo);
4291 fmgr_info_set_expr((Node *) saop, &elements_tab->hash_finfo);
4292
4294 &elements_tab->hash_finfo,
4295 1,
4296 saop->inputcollid,
4297 NULL,
4298 NULL);
4299
4300 /*
4301 * Create the hash table sizing it according to the number of elements
4302 * in the array. This does assume that the array has no duplicates.
4303 * If the array happens to contain many duplicate values then it'll
4304 * just mean that we sized the table a bit on the large side.
4305 */
4307 elements_tab);
4308
4309 MemoryContextSwitchTo(oldcontext);
4310
4311 s = (char *) ARR_DATA_PTR(arr);
4312 bitmap = ARR_NULLBITMAP(arr);
4313 bitmask = 1;
4314 for (int i = 0; i < nitems; i++)
4315 {
4316 /* Get array element, checking for NULL. */
4317 if (bitmap && (*bitmap & bitmask) == 0)
4318 {
4319 has_nulls = true;
4320 }
4321 else
4322 {
4323 Datum element;
4324
4325 element = fetch_att(s, typbyval, typlen);
4326 s = att_addlength_pointer(s, typlen, s);
4327 s = (char *) att_nominal_alignby(s, typalignby);
4328
4329 saophash_insert(elements_tab->hashtab, element, &hashfound);
4330 }
4331
4332 /* Advance bitmap pointer if any. */
4333 if (bitmap)
4334 {
4335 bitmask <<= 1;
4336 if (bitmask == 0x100)
4337 {
4338 bitmap++;
4339 bitmask = 1;
4340 }
4341 }
4342 }
4343
4344 /*
4345 * Remember if we had any nulls so that we know if we need to execute
4346 * non-strict functions with a null lhs value if no match is found.
4347 */
4348 op->d.hashedscalararrayop.has_nulls = has_nulls;
4349 }
4350
4351 /* Check the hash to see if we have a match. */
4352 hashfound = NULL != saophash_lookup(elements_tab->hashtab, scalar);
4353
4354 /* the result depends on if the clause is an IN or NOT IN clause */
4355 if (inclause)
4356 result = BoolGetDatum(hashfound); /* IN */
4357 else
4358 result = BoolGetDatum(!hashfound); /* NOT IN */
4359
4360 resultnull = false;
4361
4362 /*
4363 * If we didn't find a match in the array, we still might need to handle
4364 * the possibility of null values. We didn't put any NULLs into the
4365 * hashtable, but instead marked if we found any when building the table
4366 * in has_nulls.
4367 */
4369 {
4370 if (strictfunc)
4371 {
4372
4373 /*
4374 * We have nulls in the array so a non-null lhs and no match must
4375 * yield NULL.
4376 */
4377 result = (Datum) 0;
4378 resultnull = true;
4379 }
4380 else
4381 {
4382 /*
4383 * Execute function will null rhs just once.
4384 *
4385 * The hash lookup path will have scribbled on the lhs argument so
4386 * we need to set it up also (even though we entered this function
4387 * with it already set).
4388 */
4389 fcinfo->args[0].value = scalar;
4390 fcinfo->args[0].isnull = scalar_isnull;
4391 fcinfo->args[1].value = (Datum) 0;
4392 fcinfo->args[1].isnull = true;
4393
4394 result = op->d.hashedscalararrayop.finfo->fn_addr(fcinfo);
4395 resultnull = fcinfo->isnull;
4396
4397 /*
4398 * Reverse the result for NOT IN clauses since the above function
4399 * is the equality function and we need not-equals.
4400 */
4401 if (!inclause)
4402 result = BoolGetDatum(!DatumGetBool(result));
4403 }
4404 }
4405
4406 *op->resvalue = result;
4407 *op->resnull = resultnull;
4408}
uint8_t uint8
Definition c.h:616
int16_t int16
Definition c.h:613
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:2491
char typalign
Definition pg_type.h:178
static Datum BoolGetDatum(bool X)
Definition postgres.h:112
static chr element(struct vars *v, const chr *startp, const chr *endp)
struct ExprEvalStep::@60::@95 hashedscalararrayop
bool has_nulls
Definition execExpr.h:642
struct ScalarArrayOpExprHashTable * elements_tab
Definition execExpr.h:644
bool inclause
Definition execExpr.h:643
ScalarArrayOpExpr * saop
Definition execExpr.h:647
FmgrInfo * finfo
Definition execExpr.h:388
PGFunction fn_addr
Definition fmgr.h:58
FunctionCallInfoBaseData hash_fcinfo_data
struct ExprEvalStep * op
#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_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, 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, ScalarArrayOpExprHashTable::op, ExprEvalStep::op, palloc0(), 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 5116 of file execExprInterp.c.

5118{
5120
5121 /*
5122 * Prepare to call json_populate_type() to coerce the boolean result of
5123 * JSON_EXISTS_OP to the target type. If the target type is integer or a
5124 * domain over integer, call the boolean-to-integer cast function instead,
5125 * because the integer's input function (which is what
5126 * json_populate_type() calls to coerce to scalar target types) doesn't
5127 * accept boolean literals as valid input. We only have a special case
5128 * for integer and domains thereof as it seems common to use those types
5129 * for EXISTS columns in JSON_TABLE().
5130 */
5132 {
5134 {
5135 /* Check domain constraints if any. */
5140 econtext->ecxt_per_query_memory,
5141 (Node *) escontext))
5142 {
5143 *op->resnull = true;
5144 *op->resvalue = (Datum) 0;
5145 }
5146 else
5148 return;
5149 }
5150
5152 DatumGetBool(*op->resvalue) ?
5153 CStringGetDatum("true") :
5154 CStringGetDatum("false"));
5155 }
5156
5161 econtext->ecxt_per_query_memory,
5162 op->resnull,
5164 (Node *) escontext);
5165}
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:370
void * json_coercion_cache
Definition execExpr.h:769
bool exists_coerce
Definition execExpr.h:766
bool exists_cast_to_int
Definition execExpr.h:767
struct ExprEvalStep::@60::@109 jsonexpr_coercion
bool exists_check_domain
Definition execExpr.h:768
int32 targettypmod
Definition execExpr.h:763
bool omit_quotes
Definition execExpr.h:764

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

5197{
5198 JsonExprState *jsestate = op->d.jsonexpr.jsestate;
5199
5200 if (SOFT_ERROR_OCCURRED(&jsestate->escontext))
5201 {
5202 /*
5203 * jsestate->error or jsestate->empty being set means that the error
5204 * occurred when coercing the JsonBehavior value. Throw the error in
5205 * that case with the actual coercion error message shown in the
5206 * DETAIL part.
5207 */
5208 if (DatumGetBool(jsestate->error.value))
5209 ereport(ERROR,
5211 /*- translator: first %s is a SQL/JSON clause (e.g. ON ERROR) */
5212 errmsg("could not coerce %s expression (%s) to the RETURNING type",
5213 "ON ERROR",
5215 errdetail("%s", jsestate->escontext.error_data->message)));
5216 else if (DatumGetBool(jsestate->empty.value))
5217 ereport(ERROR,
5219 /*- translator: first %s is a SQL/JSON clause (e.g. ON ERROR) */
5220 errmsg("could not coerce %s expression (%s) to the RETURNING type",
5221 "ON EMPTY",
5223 errdetail("%s", jsestate->escontext.error_data->message)));
5224
5225 *op->resvalue = (Datum) 0;
5226 *op->resnull = true;
5227
5228 jsestate->error.value = BoolGetDatum(true);
5229
5230 /*
5231 * Reset for next use such as for catching errors when coercing a
5232 * JsonBehavior expression.
5233 */
5234 jsestate->escontext.error_occurred = false;
5235 jsestate->escontext.details_wanted = true;
5236 }
5237}
static char * GetJsonBehaviorValueString(JsonBehavior *behavior)
char * message
Definition elog.h:432
ErrorData * error_data
Definition miscnodes.h:49
struct JsonExprState * jsestate
Definition execExpr.h:756
struct ExprEvalStep::@60::@108 jsonexpr
NullableDatum empty
Definition execnodes.h:1105
JsonExpr * jsexpr
Definition execnodes.h:1083
NullableDatum error
Definition execnodes.h:1102
ErrorSaveContext escontext
Definition execnodes.h:1142
JsonBehavior * on_empty
Definition primnodes.h:1866
JsonBehavior * on_error
Definition primnodes.h:1867

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

4665{
4666 Datum res;
4670 bool isnull = false;
4671
4672 if (ctor->type == JSCTOR_JSON_ARRAY)
4673 res = (is_jsonb ?
4675 json_build_array_worker) (jcstate->nargs,
4676 jcstate->arg_values,
4677 jcstate->arg_nulls,
4678 jcstate->arg_types,
4679 jcstate->constructor->absent_on_null);
4680 else if (ctor->type == JSCTOR_JSON_OBJECT)
4681 res = (is_jsonb ?
4684 jcstate->arg_values,
4685 jcstate->arg_nulls,
4686 jcstate->arg_types,
4687 jcstate->constructor->absent_on_null,
4688 jcstate->constructor->unique);
4689 else if (ctor->type == JSCTOR_JSON_SCALAR)
4690 {
4691 if (jcstate->arg_nulls[0])
4692 {
4693 res = (Datum) 0;
4694 isnull = true;
4695 }
4696 else
4697 {
4698 Datum value = jcstate->arg_values[0];
4699 Oid outfuncid = jcstate->arg_type_cache[0].outfuncid;
4701 jcstate->arg_type_cache[0].category;
4702
4703 if (is_jsonb)
4704 res = datum_to_jsonb(value, category, outfuncid);
4705 else
4706 res = datum_to_json(value, category, outfuncid);
4707 }
4708 }
4709 else if (ctor->type == JSCTOR_JSON_PARSE)
4710 {
4711 if (jcstate->arg_nulls[0])
4712 {
4713 res = (Datum) 0;
4714 isnull = true;
4715 }
4716 else
4717 {
4718 Datum value = jcstate->arg_values[0];
4719 text *js = DatumGetTextP(value);
4720
4721 if (is_jsonb)
4722 res = jsonb_from_text(js, true);
4723 else
4724 {
4725 (void) json_validate(js, true, true);
4726 res = value;
4727 }
4728 }
4729 }
4730 else
4731 elog(ERROR, "invalid JsonConstructorExpr type %d", ctor->type);
4732
4733 *op->resvalue = res;
4734 *op->resnull = isnull;
4735}
#define DatumGetTextP(X)
Definition fmgr.h:333
static struct @174 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:1666
@ JSCTOR_JSON_PARSE
Definition primnodes.h:1720
@ JSCTOR_JSON_OBJECT
Definition primnodes.h:1716
@ JSCTOR_JSON_SCALAR
Definition primnodes.h:1721
@ JSCTOR_JSON_ARRAY
Definition primnodes.h:1717
struct ExprEvalStep::@60::@97 json_constructor
struct JsonConstructorExprState * jcstate
Definition execExpr.h:665
JsonConstructorExpr * constructor
Definition execExpr.h:823
struct JsonConstructorExprState::@110 * arg_type_cache
JsonReturning * returning
Definition primnodes.h:1736
JsonFormatType format_type
Definition primnodes.h:1677
JsonFormat * format
Definition primnodes.h:1689
Definition c.h:778

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

4841{
4842 JsonExprState *jsestate = op->d.jsonexpr.jsestate;
4843 JsonExpr *jsexpr = jsestate->jsexpr;
4844 Datum item;
4845 JsonPath *path;
4846 bool throw_error = jsexpr->on_error->btype == JSON_BEHAVIOR_ERROR;
4847 bool error = false,
4848 empty = false;
4849 int jump_eval_coercion = jsestate->jump_eval_coercion;
4850 char *val_string = NULL;
4851
4852 item = jsestate->formatted_expr.value;
4853 path = DatumGetJsonPathP(jsestate->pathspec.value);
4854
4855 /* Set error/empty to false. */
4856 memset(&jsestate->error, 0, sizeof(NullableDatum));
4857 memset(&jsestate->empty, 0, sizeof(NullableDatum));
4858
4859 /* Also reset ErrorSaveContext contents for the next row. */
4860 if (jsestate->escontext.details_wanted)
4861 {
4862 jsestate->escontext.error_data = NULL;
4863 jsestate->escontext.details_wanted = false;
4864 }
4865 jsestate->escontext.error_occurred = false;
4866
4867 switch (jsexpr->op)
4868 {
4869 case JSON_EXISTS_OP:
4870 {
4871 bool exists = JsonPathExists(item, path,
4872 !throw_error ? &error : NULL,
4873 jsestate->args);
4874
4875 if (!error)
4876 {
4877 *op->resnull = false;
4879 }
4880 }
4881 break;
4882
4883 case JSON_QUERY_OP:
4884 *op->resvalue = JsonPathQuery(item, path, jsexpr->wrapper, &empty,
4885 !throw_error ? &error : NULL,
4886 jsestate->args,
4887 jsexpr->column_name);
4888
4889 *op->resnull = (DatumGetPointer(*op->resvalue) == NULL);
4890 break;
4891
4892 case JSON_VALUE_OP:
4893 {
4894 JsonbValue *jbv = JsonPathValue(item, path, &empty,
4895 !throw_error ? &error : NULL,
4896 jsestate->args,
4897 jsexpr->column_name);
4898
4899 if (jbv == NULL)
4900 {
4901 /* Will be coerced with json_populate_type(), if needed. */
4902 *op->resvalue = (Datum) 0;
4903 *op->resnull = true;
4904 }
4905 else if (!error && !empty)
4906 {
4907 if (jsexpr->returning->typid == JSONOID ||
4908 jsexpr->returning->typid == JSONBOID)
4909 {
4912 }
4913 else if (jsexpr->use_json_coercion)
4914 {
4916 *op->resnull = false;
4917 }
4918 else
4919 {
4921
4922 /*
4923 * Simply convert to the default RETURNING type (text)
4924 * if no coercion needed.
4925 */
4926 if (!jsexpr->use_io_coercion)
4929 }
4930 }
4931 break;
4932 }
4933
4934 /* JSON_TABLE_OP can't happen here */
4935
4936 default:
4937 elog(ERROR, "unrecognized SQL/JSON expression op %d",
4938 (int) jsexpr->op);
4939 return false;
4940 }
4941
4942 /*
4943 * Coerce the result value to the RETURNING type by calling its input
4944 * function.
4945 */
4946 if (!*op->resnull && jsexpr->use_io_coercion)
4947 {
4948 FunctionCallInfo fcinfo;
4949
4950 Assert(jump_eval_coercion == -1);
4951 fcinfo = jsestate->input_fcinfo;
4952 Assert(fcinfo != NULL);
4954 fcinfo->args[0].value = PointerGetDatum(val_string);
4955 fcinfo->args[0].isnull = *op->resnull;
4956
4957 /*
4958 * Second and third arguments are already set up in
4959 * ExecInitJsonExpr().
4960 */
4961
4962 fcinfo->isnull = false;
4963 *op->resvalue = FunctionCallInvoke(fcinfo);
4964 if (SOFT_ERROR_OCCURRED(&jsestate->escontext))
4965 error = true;
4966 }
4967
4968 /*
4969 * When setting up the ErrorSaveContext (if needed) for capturing the
4970 * errors that occur when coercing the JsonBehavior expression, set
4971 * details_wanted to be able to show the actual error message as the
4972 * DETAIL of the error message that tells that it is the JsonBehavior
4973 * expression that caused the error; see ExecEvalJsonCoercionFinish().
4974 */
4975
4976 /* Handle ON EMPTY. */
4977 if (empty)
4978 {
4979 *op->resvalue = (Datum) 0;
4980 *op->resnull = true;
4981 if (jsexpr->on_empty)
4982 {
4983 if (jsexpr->on_empty->btype != JSON_BEHAVIOR_ERROR)
4984 {
4985 jsestate->empty.value = BoolGetDatum(true);
4986 /* Set up to catch coercion errors of the ON EMPTY value. */
4987 jsestate->escontext.error_occurred = false;
4988 jsestate->escontext.details_wanted = true;
4989 /* Jump to end if the ON EMPTY behavior is to return NULL */
4990 return jsestate->jump_empty >= 0 ? jsestate->jump_empty : jsestate->jump_end;
4991 }
4992 }
4993 else if (jsexpr->on_error->btype != JSON_BEHAVIOR_ERROR)
4994 {
4995 jsestate->error.value = BoolGetDatum(true);
4996 /* Set up to catch coercion errors of the ON ERROR value. */
4997 jsestate->escontext.error_occurred = false;
4998 jsestate->escontext.details_wanted = true;
5000 /* Jump to end if the ON ERROR behavior is to return NULL */
5001 return jsestate->jump_error >= 0 ? jsestate->jump_error : jsestate->jump_end;
5002 }
5003
5004 if (jsexpr->column_name)
5005 ereport(ERROR,
5007 errmsg("no SQL/JSON item found for specified path of column \"%s\"",
5008 jsexpr->column_name));
5009 else
5010 ereport(ERROR,
5012 errmsg("no SQL/JSON item found for specified path"));
5013 }
5014
5015 /*
5016 * ON ERROR. Wouldn't get here if the behavior is ERROR, because they
5017 * would have already been thrown.
5018 */
5019 if (error)
5020 {
5022 *op->resvalue = (Datum) 0;
5023 *op->resnull = true;
5024 jsestate->error.value = BoolGetDatum(true);
5025 /* Set up to catch coercion errors of the ON ERROR value. */
5026 jsestate->escontext.error_occurred = false;
5027 jsestate->escontext.details_wanted = true;
5028 /* Jump to end if the ON ERROR behavior is to return NULL */
5029 return jsestate->jump_error >= 0 ? jsestate->jump_error : jsestate->jump_end;
5030 }
5031
5032 return jump_eval_coercion >= 0 ? jump_eval_coercion : jsestate->jump_end;
5033}
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:1793
@ JSON_QUERY_OP
Definition primnodes.h:1830
@ JSON_EXISTS_OP
Definition primnodes.h:1829
@ JSON_VALUE_OP
Definition primnodes.h:1831
static void error(void)
JsonBehaviorType btype
Definition primnodes.h:1817
int jump_eval_coercion
Definition execnodes.h:1119
FunctionCallInfo input_fcinfo
Definition execnodes.h:1133
NullableDatum pathspec
Definition execnodes.h:1089
NullableDatum formatted_expr
Definition execnodes.h:1086
char * column_name
Definition primnodes.h:1846
bool use_io_coercion
Definition primnodes.h:1873
JsonReturning * returning
Definition primnodes.h:1859
bool use_json_coercion
Definition primnodes.h:1874
JsonWrapper wrapper
Definition primnodes.h:1877
JsonExprOp op
Definition primnodes.h:1844
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 4741 of file execExprInterp.c.

4742{
4743 JsonIsPredicate *pred = op->d.is_json.pred;
4744 Datum js = *op->resvalue;
4745 Oid exprtype = pred->exprBaseType;
4746 bool res;
4747
4748 if (*op->resnull)
4749 {
4750 *op->resvalue = BoolGetDatum(false);
4751 return;
4752 }
4753
4754 if (exprtype == TEXTOID || exprtype == JSONOID)
4755 {
4756 text *json = DatumGetTextP(js);
4757
4758 if (pred->item_type == JS_TYPE_ANY)
4759 res = true;
4760 else
4761 {
4762 switch (json_get_first_token(json, false))
4763 {
4765 res = pred->item_type == JS_TYPE_OBJECT;
4766 break;
4768 res = pred->item_type == JS_TYPE_ARRAY;
4769 break;
4770 case JSON_TOKEN_STRING:
4771 case JSON_TOKEN_NUMBER:
4772 case JSON_TOKEN_TRUE:
4773 case JSON_TOKEN_FALSE:
4774 case JSON_TOKEN_NULL:
4775 res = pred->item_type == JS_TYPE_SCALAR;
4776 break;
4777 default:
4778 res = false;
4779 break;
4780 }
4781 }
4782
4783 /*
4784 * Do full parsing pass only for uniqueness check or for JSON text
4785 * validation.
4786 */
4787 if (res && (pred->unique_keys || exprtype == TEXTOID))
4788 res = json_validate(json, pred->unique_keys, false);
4789 }
4790 else if (exprtype == JSONBOID)
4791 {
4792 if (pred->item_type == JS_TYPE_ANY)
4793 res = true;
4794 else
4795 {
4796 Jsonb *jb = DatumGetJsonbP(js);
4797
4798 switch (pred->item_type)
4799 {
4800 case JS_TYPE_OBJECT:
4801 res = JB_ROOT_IS_OBJECT(jb);
4802 break;
4803 case JS_TYPE_ARRAY:
4805 break;
4806 case JS_TYPE_SCALAR:
4808 break;
4809 default:
4810 res = false;
4811 break;
4812 }
4813 }
4814
4815 /* Key uniqueness check is redundant for jsonb */
4816 }
4817 else
4818 res = false;
4819
4820 *op->resvalue = BoolGetDatum(res);
4821}
@ 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:1748
@ JS_TYPE_ARRAY
Definition primnodes.h:1750
@ JS_TYPE_OBJECT
Definition primnodes.h:1749
@ JS_TYPE_SCALAR
Definition primnodes.h:1751
JsonIsPredicate * pred
Definition execExpr.h:750
struct ExprEvalStep::@60::@107 is_json
JsonValueType item_type
Definition primnodes.h:1763
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 5276 of file execExprInterp.c.

5278{
5279 ModifyTableState *mtstate = castNode(ModifyTableState, state->parent);
5281
5282 if (!relaction)
5283 elog(ERROR, "no merge action in progress");
5284
5285 /* Return the MERGE action ("INSERT", "UPDATE", or "DELETE") */
5286 switch (relaction->mas_action->commandType)
5287 {
5288 case CMD_INSERT:
5290 *op->resnull = false;
5291 break;
5292 case CMD_UPDATE:
5294 *op->resnull = false;
5295 break;
5296 case CMD_DELETE:
5298 *op->resnull = false;
5299 break;
5300 case CMD_NOTHING:
5301 elog(ERROR, "unexpected merge action: DO NOTHING");
5302 break;
5303 default:
5304 elog(ERROR, "unrecognized commandType: %d",
5305 (int) relaction->mas_action->commandType);
5306 }
5307}
@ 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:1463
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 3678 of file execExprInterp.c.

3679{
3680 Datum *values = op->d.minmax.values;
3681 bool *nulls = op->d.minmax.nulls;
3682 FunctionCallInfo fcinfo = op->d.minmax.fcinfo_data;
3683 MinMaxOp operator = op->d.minmax.op;
3684
3685 /* set at initialization */
3686 Assert(fcinfo->args[0].isnull == false);
3687 Assert(fcinfo->args[1].isnull == false);
3688
3689 /* default to null result */
3690 *op->resnull = true;
3691
3692 for (int off = 0; off < op->d.minmax.nelems; off++)
3693 {
3694 /* ignore NULL inputs */
3695 if (nulls[off])
3696 continue;
3697
3698 if (*op->resnull)
3699 {
3700 /* first nonnull input, adopt value */
3701 *op->resvalue = values[off];
3702 *op->resnull = false;
3703 }
3704 else
3705 {
3706 int cmpresult;
3707
3708 /* apply comparison function */
3709 fcinfo->args[0].value = *op->resvalue;
3710 fcinfo->args[1].value = values[off];
3711
3712 fcinfo->isnull = false;
3714 if (fcinfo->isnull) /* probably should not happen */
3715 continue;
3716
3717 if (cmpresult > 0 && operator == IS_LEAST)
3718 *op->resvalue = values[off];
3719 else if (cmpresult < 0 && operator == IS_GREATEST)
3720 *op->resvalue = values[off];
3721 }
3722 }
3723}
static Datum values[MAXATTR]
Definition bootstrap.c:188
static int32 DatumGetInt32(Datum X)
Definition postgres.h:202
MinMaxOp
Definition primnodes.h:1527
@ IS_LEAST
Definition primnodes.h:1529
@ IS_GREATEST
Definition primnodes.h:1528
MinMaxOp op
Definition execExpr.h:534
struct ExprEvalStep::@60::@85 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 3275 of file execExprInterp.c.

3276{
3278
3279 switch (op->d.nextvalueexpr.seqtypid)
3280 {
3281 case INT2OID:
3283 break;
3284 case INT4OID:
3286 break;
3287 case INT8OID:
3289 break;
3290 default:
3291 elog(ERROR, "unsupported sequence type %u",
3293 }
3294 *op->resnull = false;
3295}
int64_t int64
Definition c.h:615
int64 nextval_internal(Oid relid, bool check_permissions)
Definition sequence.c:624
#define newval
static Datum Int64GetDatum(int64 X)
Definition postgres.h:413
static Datum Int16GetDatum(int16 X)
Definition postgres.h:172
struct ExprEvalStep::@60::@79 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 3050 of file execExprInterp.c.

3051{
3053
3054 prm = &(econtext->ecxt_param_exec_vals[op->d.param.paramid]);
3055 if (unlikely(prm->execPlan != NULL))
3056 {
3057 /* Parameter not evaluated yet, so go do it */
3058 ExecSetParamPlan(prm->execPlan, econtext);
3059 /* ExecSetParamPlan should have processed this param... */
3060 Assert(prm->execPlan == NULL);
3061 }
3062 *op->resvalue = prm->value;
3063 *op->resnull = prm->isnull;
3064}
void ExecSetParamPlan(SubPlanState *node, ExprContext *econtext)
ParamExecData * ecxt_param_exec_vals
Definition execnodes.h:295
struct ExprEvalStep::@60::@73 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 3072 of file execExprInterp.c.

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

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

3116{
3118
3119 prm = &(econtext->ecxt_param_exec_vals[op->d.param.paramid]);
3120
3121 /* Shouldn't have a pending evaluation anymore */
3122 Assert(prm->execPlan == NULL);
3123
3124 prm->value = *op->resvalue;
3125 prm->isnull = *op->resnull;
3126}

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

Referenced by ExecInterpExpr().

◆ ExecEvalPreOrderedDistinctMulti()

bool ExecEvalPreOrderedDistinctMulti ( AggState aggstate,
AggStatePerTrans  pertrans 
)

Definition at line 5765 of file execExprInterp.c.

5766{
5767 ExprContext *tmpcontext = aggstate->tmpcontext;
5768 bool isdistinct = false; /* for now */
5771
5772 for (int i = 0; i < pertrans->numTransInputs; i++)
5773 {
5774 pertrans->sortslot->tts_values[i] = pertrans->transfn_fcinfo->args[i + 1].value;
5775 pertrans->sortslot->tts_isnull[i] = pertrans->transfn_fcinfo->args[i + 1].isnull;
5776 }
5777
5778 ExecClearTuple(pertrans->sortslot);
5779 pertrans->sortslot->tts_nvalid = pertrans->numInputs;
5781
5782 /* save the previous slots before we overwrite them */
5783 save_outer = tmpcontext->ecxt_outertuple;
5784 save_inner = tmpcontext->ecxt_innertuple;
5785
5786 tmpcontext->ecxt_outertuple = pertrans->sortslot;
5787 tmpcontext->ecxt_innertuple = pertrans->uniqslot;
5788
5789 if (!pertrans->haslast ||
5790 !ExecQual(pertrans->equalfnMulti, tmpcontext))
5791 {
5792 if (pertrans->haslast)
5793 ExecClearTuple(pertrans->uniqslot);
5794
5795 pertrans->haslast = true;
5796 ExecCopySlot(pertrans->uniqslot, pertrans->sortslot);
5797
5798 isdistinct = true;
5799 }
5800
5801 /* restore the original slots */
5802 tmpcontext->ecxt_outertuple = save_outer;
5803 tmpcontext->ecxt_innertuple = save_inner;
5804
5805 return isdistinct;
5806}
static bool ExecQual(ExprState *state, ExprContext *econtext)
Definition executor.h:522
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 5722 of file execExprInterp.c.

5723{
5724 Datum value = pertrans->transfn_fcinfo->args[1].value;
5725 bool isnull = pertrans->transfn_fcinfo->args[1].isnull;
5726
5727 if (!pertrans->haslast ||
5728 pertrans->lastisnull != isnull ||
5729 (!isnull && !DatumGetBool(FunctionCall2Coll(&pertrans->equalfnOne,
5730 pertrans->aggCollation,
5731 pertrans->lastdatum, value))))
5732 {
5733 if (pertrans->haslast && !pertrans->inputtypeByVal &&
5734 !pertrans->lastisnull)
5735 pfree(DatumGetPointer(pertrans->lastdatum));
5736
5737 pertrans->haslast = true;
5738 if (!isnull)
5739 {
5741
5742 oldContext = MemoryContextSwitchTo(aggstate->curaggcontext->ecxt_per_tuple_memory);
5743
5744 pertrans->lastdatum = datumCopy(value, pertrans->inputtypeByVal,
5745 pertrans->inputtypeLen);
5746
5748 }
5749 else
5750 pertrans->lastdatum = (Datum) 0;
5751 pertrans->lastisnull = isnull;
5752 return true;
5753 }
5754
5755 return false;
5756}
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 3658 of file execExprInterp.c.

3659{
3660 HeapTuple tuple;
3661
3662 /* build tuple from evaluated field values */
3663 tuple = heap_form_tuple(op->d.row.tupdesc,
3664 op->d.row.elemvalues,
3665 op->d.row.elemnulls);
3666
3667 *op->resvalue = HeapTupleGetDatum(tuple);
3668 *op->resnull = false;
3669}
TupleDesc tupdesc
Definition execExpr.h:350
struct ExprEvalStep::@60::@82 row

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

Referenced by ExecInterpExpr().

◆ ExecEvalRowNotNull()

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

Definition at line 3310 of file execExprInterp.c.

3311{
3312 ExecEvalRowNullInt(state, op, econtext, false);
3313}
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 3301 of file execExprInterp.c.

3302{
3303 ExecEvalRowNullInt(state, op, econtext, true);
3304}

References ExecEvalRowNullInt(), and ExprEvalStep::op.

Referenced by ExecInterpExpr().

◆ ExecEvalRowNullInt()

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

Definition at line 3317 of file execExprInterp.c.

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

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

4026{
4028 bool useOr = op->d.scalararrayop.useOr;
4030 ArrayType *arr;
4031 int nitems;
4032 Datum result;
4033 bool resultnull;
4034 int16 typlen;
4035 bool typbyval;
4036 char typalign;
4037 uint8 typalignby;
4038 char *s;
4039 bits8 *bitmap;
4040 int bitmask;
4041
4042 /*
4043 * If the array is NULL then we return NULL --- it's not very meaningful
4044 * to do anything else, even if the operator isn't strict.
4045 */
4046 if (*op->resnull)
4047 return;
4048
4049 /* Else okay to fetch and detoast the array */
4050 arr = DatumGetArrayTypeP(*op->resvalue);
4051
4052 /*
4053 * If the array is empty, we return either FALSE or TRUE per the useOr
4054 * flag. This is correct even if the scalar is NULL; since we would
4055 * evaluate the operator zero times, it matters not whether it would want
4056 * to return NULL.
4057 */
4058 nitems = ArrayGetNItems(ARR_NDIM(arr), ARR_DIMS(arr));
4059 if (nitems <= 0)
4060 {
4061 *op->resvalue = BoolGetDatum(!useOr);
4062 *op->resnull = false;
4063 return;
4064 }
4065
4066 /*
4067 * If the scalar is NULL, and the function is strict, return NULL; no
4068 * point in iterating the loop.
4069 */
4070 if (fcinfo->args[0].isnull && strictfunc)
4071 {
4072 *op->resnull = true;
4073 return;
4074 }
4075
4076 /*
4077 * We arrange to look up info about the element type only once per series
4078 * of calls, assuming the element type doesn't change underneath us.
4079 */
4080 if (op->d.scalararrayop.element_type != ARR_ELEMTYPE(arr))
4081 {
4083 &op->d.scalararrayop.typlen,
4085 &op->d.scalararrayop.typalign);
4087 }
4088
4089 typlen = op->d.scalararrayop.typlen;
4090 typbyval = op->d.scalararrayop.typbyval;
4092 typalignby = typalign_to_alignby(typalign);
4093
4094 /* Initialize result appropriately depending on useOr */
4095 result = BoolGetDatum(!useOr);
4096 resultnull = false;
4097
4098 /* Loop over the array elements */
4099 s = (char *) ARR_DATA_PTR(arr);
4100 bitmap = ARR_NULLBITMAP(arr);
4101 bitmask = 1;
4102
4103 for (int i = 0; i < nitems; i++)
4104 {
4105 Datum elt;
4107
4108 /* Get array element, checking for NULL */
4109 if (bitmap && (*bitmap & bitmask) == 0)
4110 {
4111 fcinfo->args[1].value = (Datum) 0;
4112 fcinfo->args[1].isnull = true;
4113 }
4114 else
4115 {
4116 elt = fetch_att(s, typbyval, typlen);
4117 s = att_addlength_pointer(s, typlen, s);
4118 s = (char *) att_nominal_alignby(s, typalignby);
4119 fcinfo->args[1].value = elt;
4120 fcinfo->args[1].isnull = false;
4121 }
4122
4123 /* Call comparison function */
4124 if (fcinfo->args[1].isnull && strictfunc)
4125 {
4126 fcinfo->isnull = true;
4127 thisresult = (Datum) 0;
4128 }
4129 else
4130 {
4131 fcinfo->isnull = false;
4132 thisresult = op->d.scalararrayop.fn_addr(fcinfo);
4133 }
4134
4135 /* Combine results per OR or AND semantics */
4136 if (fcinfo->isnull)
4137 resultnull = true;
4138 else if (useOr)
4139 {
4141 {
4142 result = BoolGetDatum(true);
4143 resultnull = false;
4144 break; /* needn't look at any more elements */
4145 }
4146 }
4147 else
4148 {
4150 {
4151 result = BoolGetDatum(false);
4152 resultnull = false;
4153 break; /* needn't look at any more elements */
4154 }
4155 }
4156
4157 /* advance bitmap pointer if any */
4158 if (bitmap)
4159 {
4160 bitmask <<= 1;
4161 if (bitmask == 0x100)
4162 {
4163 bitmap++;
4164 bitmask = 1;
4165 }
4166 }
4167 }
4168
4169 *op->resvalue = result;
4170 *op->resnull = resultnull;
4171}
bool typbyval
Definition execExpr.h:631
struct ExprEvalStep::@60::@94 scalararrayop
char typalign
Definition execExpr.h:632
int16 typlen
Definition execExpr.h:630
Oid element_type
Definition execExpr.h:628

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

Referenced by ExecInterpExpr().

◆ ExecEvalSQLValueFunction()

void ExecEvalSQLValueFunction ( ExprState state,
ExprEvalStep op 
)

Definition at line 3197 of file execExprInterp.c.

3198{
3199 LOCAL_FCINFO(fcinfo, 0);
3201
3202 *op->resnull = false;
3203
3204 /*
3205 * Note: current_schema() can return NULL. current_user() etc currently
3206 * cannot, but might as well code those cases the same way for safety.
3207 */
3208 switch (svf->op)
3209 {
3210 case SVFOP_CURRENT_DATE:
3212 break;
3213 case SVFOP_CURRENT_TIME:
3216 break;
3220 break;
3221 case SVFOP_LOCALTIME:
3222 case SVFOP_LOCALTIME_N:
3224 break;
3228 break;
3229 case SVFOP_CURRENT_ROLE:
3230 case SVFOP_CURRENT_USER:
3231 case SVFOP_USER:
3233 *op->resvalue = current_user(fcinfo);
3234 *op->resnull = fcinfo->isnull;
3235 break;
3236 case SVFOP_SESSION_USER:
3238 *op->resvalue = session_user(fcinfo);
3239 *op->resnull = fcinfo->isnull;
3240 break;
3243 *op->resvalue = current_database(fcinfo);
3244 *op->resnull = fcinfo->isnull;
3245 break;
3248 *op->resvalue = current_schema(fcinfo);
3249 *op->resnull = fcinfo->isnull;
3250 break;
3251 }
3252}
Datum current_database(PG_FUNCTION_ARGS)
Definition misc.c:211
Timestamp GetSQLLocalTimestamp(int32 typmod)
Definition timestamp.c:1668
TimestampTz GetSQLCurrentTimestamp(int32 typmod)
Definition timestamp.c:1654
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:1575
@ SVFOP_LOCALTIME_N
Definition primnodes.h:1568
@ SVFOP_CURRENT_TIMESTAMP
Definition primnodes.h:1565
@ SVFOP_LOCALTIME
Definition primnodes.h:1567
@ SVFOP_CURRENT_TIMESTAMP_N
Definition primnodes.h:1566
@ SVFOP_CURRENT_ROLE
Definition primnodes.h:1571
@ SVFOP_USER
Definition primnodes.h:1573
@ SVFOP_CURRENT_SCHEMA
Definition primnodes.h:1576
@ SVFOP_LOCALTIMESTAMP_N
Definition primnodes.h:1570
@ SVFOP_CURRENT_DATE
Definition primnodes.h:1562
@ SVFOP_CURRENT_TIME_N
Definition primnodes.h:1564
@ SVFOP_CURRENT_TIME
Definition primnodes.h:1563
@ SVFOP_LOCALTIMESTAMP
Definition primnodes.h:1569
@ SVFOP_CURRENT_USER
Definition primnodes.h:1572
@ SVFOP_SESSION_USER
Definition primnodes.h:1574
struct ExprEvalStep::@60::@78 sqlvaluefunction
SQLValueFunction * svf
Definition execExpr.h:467
SQLValueFunctionOp op
Definition primnodes.h:1582
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 2962 of file execExprInterp.c.

2963{
2964#if defined(EEO_USE_COMPUTED_GOTO)
2965 if (state->flags & EEO_FLAG_DIRECT_THREADED)
2966 {
2968 ExprEvalOpLookup *res;
2969
2970 key.opcode = (void *) op->opcode;
2971 res = bsearch(&key,
2973 EEOP_LAST /* nmembers */ ,
2974 sizeof(ExprEvalOpLookup),
2976 Assert(res); /* unknown ops shouldn't get looked up */
2977 return res->op;
2978 }
2979#endif
2980 return (ExprEvalOp) op->opcode;
2981}
#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 5313 of file execExprInterp.c.

5314{
5315 SubPlanState *sstate = op->d.subplan.sstate;
5316
5317 /* could potentially be nested, so make sure there's enough stack */
5319
5320 *op->resvalue = ExecSubPlan(sstate, econtext, op->resnull);
5321}
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:691
struct ExprEvalStep::@60::@101 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 5589 of file execExprInterp.c.

5591{
5592 Datum d;
5593
5594 /* OLD/NEW system attribute is NULL if OLD/NEW row is NULL */
5596 state->flags & EEO_FLAG_OLD_IS_NULL) ||
5598 state->flags & EEO_FLAG_NEW_IS_NULL))
5599 {
5600 *op->resvalue = (Datum) 0;
5601 *op->resnull = true;
5602 return;
5603 }
5604
5605 /* slot_getsysattr has sufficient defenses against bad attnums */
5606 d = slot_getsysattr(slot,
5607 op->d.var.attnum,
5608 op->resnull);
5609 *op->resvalue = d;
5610 /* this ought to be unreachable, but it's cheap enough to check */
5611 if (unlikely(*op->resnull))
5612 elog(ERROR, "failed to fetch attribute from slot");
5613}
#define EEO_FLAG_NEW_IS_NULL
Definition execnodes.h:93
#define EEO_FLAG_OLD_IS_NULL
Definition execnodes.h:91
@ 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 5330 of file execExprInterp.c.

5331{
5332 Var *variable = op->d.wholerow.var;
5333 TupleTableSlot *slot = NULL;
5335 MemoryContext oldcontext;
5337 HeapTuple tuple;
5338
5339 /* This was checked by ExecInitExpr */
5340 Assert(variable->varattno == InvalidAttrNumber);
5341
5342 /* Get the input slot we want */
5343 switch (variable->varno)
5344 {
5345 case INNER_VAR:
5346 /* get the tuple from the inner node */
5347 slot = econtext->ecxt_innertuple;
5348 break;
5349
5350 case OUTER_VAR:
5351 /* get the tuple from the outer node */
5352 slot = econtext->ecxt_outertuple;
5353 break;
5354
5355 /* INDEX_VAR is handled by default case */
5356
5357 default:
5358
5359 /*
5360 * Get the tuple from the relation being scanned.
5361 *
5362 * By default, this uses the "scan" tuple slot, but a wholerow Var
5363 * in the RETURNING list may explicitly refer to OLD/NEW. If the
5364 * OLD/NEW row doesn't exist, we just return NULL.
5365 */
5366 switch (variable->varreturningtype)
5367 {
5369 slot = econtext->ecxt_scantuple;
5370 break;
5371
5372 case VAR_RETURNING_OLD:
5373 if (state->flags & EEO_FLAG_OLD_IS_NULL)
5374 {
5375 *op->resvalue = (Datum) 0;
5376 *op->resnull = true;
5377 return;
5378 }
5379 slot = econtext->ecxt_oldtuple;
5380 break;
5381
5382 case VAR_RETURNING_NEW:
5383 if (state->flags & EEO_FLAG_NEW_IS_NULL)
5384 {
5385 *op->resvalue = (Datum) 0;
5386 *op->resnull = true;
5387 return;
5388 }
5389 slot = econtext->ecxt_newtuple;
5390 break;
5391 }
5392 break;
5393 }
5394
5395 /* Apply the junkfilter if any */
5396 if (op->d.wholerow.junkFilter != NULL)
5397 slot = ExecFilterJunk(op->d.wholerow.junkFilter, slot);
5398
5399 /*
5400 * If first time through, obtain tuple descriptor and check compatibility.
5401 *
5402 * XXX: It'd be great if this could be moved to the expression
5403 * initialization phase, but due to using slots that's currently not
5404 * feasible.
5405 */
5406 if (op->d.wholerow.first)
5407 {
5408 /* optimistically assume we don't need slow path */
5409 op->d.wholerow.slow = false;
5410
5411 /*
5412 * If the Var identifies a named composite type, we must check that
5413 * the actual tuple type is compatible with it.
5414 */
5415 if (variable->vartype != RECORDOID)
5416 {
5419
5420 /*
5421 * We really only care about numbers of attributes and data types.
5422 * Also, we can ignore type mismatch on columns that are dropped
5423 * in the destination type, so long as (1) the physical storage
5424 * matches or (2) the actual column value is NULL. Case (1) is
5425 * helpful in some cases involving out-of-date cached plans, while
5426 * case (2) is expected behavior in situations such as an INSERT
5427 * into a table with dropped columns (the planner typically
5428 * generates an INT4 NULL regardless of the dropped column type).
5429 * If we find a dropped column and cannot verify that case (1)
5430 * holds, we have to use the slow path to check (2) for each row.
5431 *
5432 * If vartype is a domain over composite, just look through that
5433 * to the base composite type.
5434 */
5436 -1, false);
5437
5439
5440 if (var_tupdesc->natts != slot_tupdesc->natts)
5441 ereport(ERROR,
5443 errmsg("table row type and query-specified row type do not match"),
5444 errdetail_plural("Table row contains %d attribute, but query expects %d.",
5445 "Table row contains %d attributes, but query expects %d.",
5446 slot_tupdesc->natts,
5447 slot_tupdesc->natts,
5448 var_tupdesc->natts)));
5449
5450 for (int i = 0; i < var_tupdesc->natts; i++)
5451 {
5454
5455 if (vattr->atttypid == sattr->atttypid)
5456 continue; /* no worries */
5457 if (!vattr->attisdropped)
5458 ereport(ERROR,
5460 errmsg("table row type and query-specified row type do not match"),
5461 errdetail("Table has type %s at ordinal position %d, but query expects %s.",
5462 format_type_be(sattr->atttypid),
5463 i + 1,
5464 format_type_be(vattr->atttypid))));
5465
5466 if (vattr->attlen != sattr->attlen ||
5467 vattr->attalign != sattr->attalign)
5468 op->d.wholerow.slow = true; /* need to check for nulls */
5469 }
5470
5471 /*
5472 * Use the variable's declared rowtype as the descriptor for the
5473 * output values. In particular, we *must* absorb any
5474 * attisdropped markings.
5475 */
5476 oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
5478 MemoryContextSwitchTo(oldcontext);
5479
5481 }
5482 else
5483 {
5484 /*
5485 * In the RECORD case, we use the input slot's rowtype as the
5486 * descriptor for the output values, modulo possibly assigning new
5487 * column names below.
5488 */
5489 oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
5491 MemoryContextSwitchTo(oldcontext);
5492
5493 /*
5494 * It's possible that the input slot is a relation scan slot and
5495 * so is marked with that relation's rowtype. But we're supposed
5496 * to be returning RECORD, so reset to that.
5497 */
5498 output_tupdesc->tdtypeid = RECORDOID;
5499 output_tupdesc->tdtypmod = -1;
5500
5501 /*
5502 * We already got the correct physical datatype info above, but
5503 * now we should try to find the source RTE and adopt its column
5504 * aliases, since it's unlikely that the input slot has the
5505 * desired names.
5506 *
5507 * If we can't locate the RTE, assume the column names we've got
5508 * are OK. (As of this writing, the only cases where we can't
5509 * locate the RTE are in execution of trigger WHEN clauses, and
5510 * then the Var will have the trigger's relation's rowtype, so its
5511 * names are fine.) Also, if the creator of the RTE didn't bother
5512 * to fill in an eref field, assume our column names are OK. (This
5513 * happens in COPY, and perhaps other places.)
5514 */
5515 if (econtext->ecxt_estate &&
5516 variable->varno <= econtext->ecxt_estate->es_range_table_size)
5517 {
5519 econtext->ecxt_estate);
5520
5521 if (rte->eref)
5522 ExecTypeSetColNames(output_tupdesc, rte->eref->colnames);
5523 }
5524 }
5525
5526 /* Bless the tupdesc if needed, and save it in the execution state */
5528
5529 op->d.wholerow.first = false;
5530 }
5531
5532 /*
5533 * Make sure all columns of the slot are accessible in the slot's
5534 * Datum/isnull arrays.
5535 */
5536 slot_getallattrs(slot);
5537
5538 if (op->d.wholerow.slow)
5539 {
5540 /* Check to see if any dropped attributes are non-null */
5543
5544 Assert(var_tupdesc->natts == tupleDesc->natts);
5545
5546 for (int i = 0; i < var_tupdesc->natts; i++)
5547 {
5550
5551 if (!vattr->attisdropped)
5552 continue; /* already checked non-dropped cols */
5553 if (slot->tts_isnull[i])
5554 continue; /* null is always okay */
5555 if (vattr->attlen != sattr->attlen ||
5556 vattr->attalignby != sattr->attalignby)
5557 ereport(ERROR,
5559 errmsg("table row type and query-specified row type do not match"),
5560 errdetail("Physical storage mismatch on dropped attribute at ordinal position %d.",
5561 i + 1)));
5562 }
5563 }
5564
5565 /*
5566 * Build a composite datum, making sure any toasted fields get detoasted.
5567 *
5568 * (Note: it is critical that we not change the slot's state here.)
5569 */
5571 slot->tts_values,
5572 slot->tts_isnull);
5573 dtuple = tuple->t_data;
5574
5575 /*
5576 * Label the datum with the composite type info we identified before.
5577 *
5578 * (Note: we could skip doing this by passing op->d.wholerow.tupdesc to
5579 * the tuple build step; but that seems a tad risky so let's not.)
5580 */
5583
5585 *op->resnull = false;
5586}
#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:701
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:675
struct EState * ecxt_estate
Definition execnodes.h:326
JunkFilter * junkFilter
Definition execExpr.h:351
struct ExprEvalStep::@60::@63 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:238
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 4448 of file execExprInterp.c.

4449{
4450 XmlExpr *xexpr = op->d.xmlexpr.xexpr;
4451 Datum value;
4452
4453 *op->resnull = true; /* until we get a result */
4454 *op->resvalue = (Datum) 0;
4455
4456 switch (xexpr->op)
4457 {
4458 case IS_XMLCONCAT:
4459 {
4460 Datum *argvalue = op->d.xmlexpr.argvalue;
4461 bool *argnull = op->d.xmlexpr.argnull;
4462 List *values = NIL;
4463
4464 for (int i = 0; i < list_length(xexpr->args); i++)
4465 {
4466 if (!argnull[i])
4467 values = lappend(values, DatumGetPointer(argvalue[i]));
4468 }
4469
4470 if (values != NIL)
4471 {
4473 *op->resnull = false;
4474 }
4475 }
4476 break;
4477
4478 case IS_XMLFOREST:
4479 {
4480 Datum *argvalue = op->d.xmlexpr.named_argvalue;
4481 bool *argnull = op->d.xmlexpr.named_argnull;
4483 ListCell *lc;
4484 ListCell *lc2;
4485 int i;
4486
4488
4489 i = 0;
4490 forboth(lc, xexpr->named_args, lc2, xexpr->arg_names)
4491 {
4492 Expr *e = (Expr *) lfirst(lc);
4493 char *argname = strVal(lfirst(lc2));
4494
4495 if (!argnull[i])
4496 {
4497 value = argvalue[i];
4498 appendStringInfo(&buf, "<%s>%s</%s>",
4499 argname,
4501 exprType((Node *) e), true),
4502 argname);
4503 *op->resnull = false;
4504 }
4505 i++;
4506 }
4507
4508 if (!*op->resnull)
4509 {
4510 text *result;
4511
4512 result = cstring_to_text_with_len(buf.data, buf.len);
4513 *op->resvalue = PointerGetDatum(result);
4514 }
4515
4516 pfree(buf.data);
4517 }
4518 break;
4519
4520 case IS_XMLELEMENT:
4521 *op->resvalue = PointerGetDatum(xmlelement(xexpr,
4524 op->d.xmlexpr.argvalue,
4525 op->d.xmlexpr.argnull));
4526 *op->resnull = false;
4527 break;
4528
4529 case IS_XMLPARSE:
4530 {
4531 Datum *argvalue = op->d.xmlexpr.argvalue;
4532 bool *argnull = op->d.xmlexpr.argnull;
4533 text *data;
4535
4536 /* arguments are known to be text, bool */
4537 Assert(list_length(xexpr->args) == 2);
4538
4539 if (argnull[0])
4540 return;
4541 value = argvalue[0];
4543
4544 if (argnull[1]) /* probably can't happen */
4545 return;
4546 value = argvalue[1];
4548
4550 xexpr->xmloption,
4552 *op->resnull = false;
4553 }
4554 break;
4555
4556 case IS_XMLPI:
4557 {
4558 text *arg;
4559 bool isnull;
4560
4561 /* optional argument is known to be text */
4562 Assert(list_length(xexpr->args) <= 1);
4563
4564 if (xexpr->args)
4565 {
4566 isnull = op->d.xmlexpr.argnull[0];
4567 if (isnull)
4568 arg = NULL;
4569 else
4571 }
4572 else
4573 {
4574 arg = NULL;
4575 isnull = false;
4576 }
4577
4578 *op->resvalue = PointerGetDatum(xmlpi(xexpr->name,
4579 arg,
4580 isnull,
4581 op->resnull));
4582 }
4583 break;
4584
4585 case IS_XMLROOT:
4586 {
4587 Datum *argvalue = op->d.xmlexpr.argvalue;
4588 bool *argnull = op->d.xmlexpr.argnull;
4589 xmltype *data;
4590 text *version;
4591 int standalone;
4592
4593 /* arguments are known to be xml, text, int */
4594 Assert(list_length(xexpr->args) == 3);
4595
4596 if (argnull[0])
4597 return;
4598 data = DatumGetXmlP(argvalue[0]);
4599
4600 if (argnull[1])
4601 version = NULL;
4602 else
4603 version = DatumGetTextPP(argvalue[1]);
4604
4605 Assert(!argnull[2]); /* always present */
4606 standalone = DatumGetInt32(argvalue[2]);
4607
4609 version,
4610 standalone));
4611 *op->resnull = false;
4612 }
4613 break;
4614
4615 case IS_XMLSERIALIZE:
4616 {
4617 Datum *argvalue = op->d.xmlexpr.argvalue;
4618 bool *argnull = op->d.xmlexpr.argnull;
4619
4620 /* argument type is known to be xml */
4621 Assert(list_length(xexpr->args) == 1);
4622
4623 if (argnull[0])
4624 return;
4625 value = argvalue[0];
4626
4627 *op->resvalue =
4629 xexpr->xmloption,
4630 xexpr->indent));
4631 *op->resnull = false;
4632 }
4633 break;
4634
4635 case IS_DOCUMENT:
4636 {
4637 Datum *argvalue = op->d.xmlexpr.argvalue;
4638 bool *argnull = op->d.xmlexpr.argnull;
4639
4640 /* optional argument is known to be xml */
4641 Assert(list_length(xexpr->args) == 1);
4642
4643 if (argnull[0])
4644 return;
4645 value = argvalue[0];
4646
4647 *op->resvalue =
4649 *op->resnull = false;
4650 }
4651 break;
4652
4653 default:
4654 elog(ERROR, "unrecognized XML operation");
4655 break;
4656 }
4657}
Datum arg
Definition elog.c:1322
#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:518
static char buf[DEFAULT_XLOG_SEG_SIZE]
e
@ IS_DOCUMENT
Definition primnodes.h:1613
@ IS_XMLFOREST
Definition primnodes.h:1608
@ IS_XMLCONCAT
Definition primnodes.h:1606
@ IS_XMLPI
Definition primnodes.h:1610
@ IS_XMLPARSE
Definition primnodes.h:1609
@ IS_XMLSERIALIZE
Definition primnodes.h:1612
@ IS_XMLROOT
Definition primnodes.h:1611
@ IS_XMLELEMENT
Definition primnodes.h:1607
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition stringinfo.c:145
void initStringInfo(StringInfo str)
Definition stringinfo.c:97
XmlExpr * xexpr
Definition execExpr.h:653
bool * named_argnull
Definition execExpr.h:656
bool * argnull
Definition execExpr.h:659
Datum * named_argvalue
Definition execExpr.h:655
Datum * argvalue
Definition execExpr.h:658
struct ExprEvalStep::@60::@96 xmlexpr
Definition pg_list.h:54
List * args
Definition primnodes.h:1634
bool indent
Definition primnodes.h:1638
List * named_args
Definition primnodes.h:1630
XmlExprOp op
Definition primnodes.h:1626
#define strVal(v)
Definition value.h:82
xmltype * xmlroot(xmltype *data, text *version, int standalone)
Definition xml.c:1102
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:2516
xmltype * xmlconcat(List *args)
Definition xml.c:575
bool xml_is_document(xmltype *arg)
Definition xml.c:1168
xmltype * xmlparse(text *data, XmlOptionType xmloption_arg, bool preserve_whitespace)
Definition xml.c:1032
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:1050
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(), 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 5041 of file execExprInterp.c.

5042{
5043 *resnull = false;
5044
5045 /* get coercion state reference and datum of the corresponding SQL type */
5046 switch (item->type)
5047 {
5048 case jbvNull:
5049 *resnull = true;
5050 return NULL;
5051
5052 case jbvString:
5053 {
5054 char *str = palloc(item->val.string.len + 1);
5055
5056 memcpy(str, item->val.string.val, item->val.string.len);
5057 str[item->val.string.len] = '\0';
5058 return str;
5059 }
5060
5061 case jbvNumeric:
5063 NumericGetDatum(item->val.numeric)));
5064
5065 case jbvBool:
5067 BoolGetDatum(item->val.boolean)));
5068
5069 case jbvDatetime:
5070 switch (item->val.datetime.typid)
5071 {
5072 case DATEOID:
5074 item->val.datetime.value));
5075 case TIMEOID:
5077 item->val.datetime.value));
5078 case TIMETZOID:
5080 item->val.datetime.value));
5081 case TIMESTAMPOID:
5083 item->val.datetime.value));
5084 case TIMESTAMPTZOID:
5086 item->val.datetime.value));
5087 default:
5088 elog(ERROR, "unexpected jsonb datetime type oid %u",
5089 item->val.datetime.typid);
5090 }
5091 break;
5092
5093 case jbvArray:
5094 case jbvObject:
5095 case jbvBinary:
5098
5099 default:
5100 elog(ERROR, "unexpected jsonb value type %d", item->type);
5101 }
5102
5103 Assert(false);
5104 *resnull = true;
5105 return NULL;
5106}
Datum numeric_out(PG_FUNCTION_ARGS)
Definition numeric.c:799
Datum timestamptz_out(PG_FUNCTION_ARGS)
Definition timestamp.c:767
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:1589
Datum timetz_out(PG_FUNCTION_ARGS)
Definition date.c:2402
@ 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(), 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 2930 of file execExprInterp.c.

2931{
2932#if defined(EEO_USE_COMPUTED_GOTO)
2933 /* Set up externally-visible pointer to dispatch table */
2934 if (dispatch_table == NULL)
2935 {
2936 dispatch_table = (const void **)
2938
2939 /* build reverse lookup table */
2940 for (int i = 0; i < EEOP_LAST; i++)
2941 {
2944 }
2945
2946 /* make it bsearch()able */
2948 EEOP_LAST /* nmembers */ ,
2949 sizeof(ExprEvalOpLookup),
2951 }
2952#endif
2953}
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 462 of file execExprInterp.c.

463{
464 ExprEvalStep *op;
465 TupleTableSlot *resultslot;
471
472 /*
473 * This array has to be in the same order as enum ExprEvalOp.
474 */
475#if defined(EEO_USE_COMPUTED_GOTO)
476 static const void *const dispatch_table[] = {
598 };
599
601 "dispatch_table out of whack with ExprEvalOp");
602
603 if (unlikely(state == NULL))
605#else
606 Assert(state != NULL);
607#endif /* EEO_USE_COMPUTED_GOTO */
608
609 /* setup state */
610 op = state->steps;
611 resultslot = state->resultslot;
612 innerslot = econtext->ecxt_innertuple;
613 outerslot = econtext->ecxt_outertuple;
614 scanslot = econtext->ecxt_scantuple;
615 oldslot = econtext->ecxt_oldtuple;
616 newslot = econtext->ecxt_newtuple;
617
618#if defined(EEO_USE_COMPUTED_GOTO)
619 EEO_DISPATCH();
620#endif
621
622 EEO_SWITCH()
623 {
625 {
626 *isnull = state->resnull;
627 return state->resvalue;
628 }
629
631 {
632 Assert(isnull == NULL);
633 return (Datum) 0;
634 }
635
637 {
639
641
642 EEO_NEXT();
643 }
644
646 {
648
650
651 EEO_NEXT();
652 }
653
655 {
657
659
660 EEO_NEXT();
661 }
662
664 {
666
668
669 EEO_NEXT();
670 }
671
673 {
675
677
678 EEO_NEXT();
679 }
680
682 {
683 int attnum = op->d.var.attnum;
684
685 /*
686 * Since we already extracted all referenced columns from the
687 * tuple with a FETCHSOME step, we can just grab the value
688 * directly out of the slot's decomposed-data arrays. But let's
689 * have an Assert to check that that did happen.
690 */
691 Assert(attnum >= 0 && attnum < innerslot->tts_nvalid);
692 *op->resvalue = innerslot->tts_values[attnum];
693 *op->resnull = innerslot->tts_isnull[attnum];
694
695 EEO_NEXT();
696 }
697
699 {
700 int attnum = op->d.var.attnum;
701
702 /* See EEOP_INNER_VAR comments */
703
704 Assert(attnum >= 0 && attnum < outerslot->tts_nvalid);
705 *op->resvalue = outerslot->tts_values[attnum];
706 *op->resnull = outerslot->tts_isnull[attnum];
707
708 EEO_NEXT();
709 }
710
712 {
713 int attnum = op->d.var.attnum;
714
715 /* See EEOP_INNER_VAR comments */
716
717 Assert(attnum >= 0 && attnum < scanslot->tts_nvalid);
718 *op->resvalue = scanslot->tts_values[attnum];
719 *op->resnull = scanslot->tts_isnull[attnum];
720
721 EEO_NEXT();
722 }
723
725 {
726 int attnum = op->d.var.attnum;
727
728 /* See EEOP_INNER_VAR comments */
729
730 Assert(attnum >= 0 && attnum < oldslot->tts_nvalid);
731 *op->resvalue = oldslot->tts_values[attnum];
732 *op->resnull = oldslot->tts_isnull[attnum];
733
734 EEO_NEXT();
735 }
736
738 {
739 int attnum = op->d.var.attnum;
740
741 /* See EEOP_INNER_VAR comments */
742
743 Assert(attnum >= 0 && attnum < newslot->tts_nvalid);
744 *op->resvalue = newslot->tts_values[attnum];
745 *op->resnull = newslot->tts_isnull[attnum];
746
747 EEO_NEXT();
748 }
749
751 {
752 ExecEvalSysVar(state, op, econtext, innerslot);
753 EEO_NEXT();
754 }
755
757 {
758 ExecEvalSysVar(state, op, econtext, outerslot);
759 EEO_NEXT();
760 }
761
763 {
764 ExecEvalSysVar(state, op, econtext, scanslot);
765 EEO_NEXT();
766 }
767
769 {
770 ExecEvalSysVar(state, op, econtext, oldslot);
771 EEO_NEXT();
772 }
773
775 {
776 ExecEvalSysVar(state, op, econtext, newslot);
777 EEO_NEXT();
778 }
779
781 {
782 /* too complex for an inline implementation */
783 ExecEvalWholeRowVar(state, op, econtext);
784
785 EEO_NEXT();
786 }
787
789 {
790 int resultnum = op->d.assign_var.resultnum;
791 int attnum = op->d.assign_var.attnum;
792
793 /*
794 * We do not need CheckVarSlotCompatibility here; that was taken
795 * care of at compilation time. But see EEOP_INNER_VAR comments.
796 */
797 Assert(attnum >= 0 && attnum < innerslot->tts_nvalid);
798 Assert(resultnum >= 0 && resultnum < resultslot->tts_tupleDescriptor->natts);
799 resultslot->tts_values[resultnum] = innerslot->tts_values[attnum];
800 resultslot->tts_isnull[resultnum] = innerslot->tts_isnull[attnum];
801
802 EEO_NEXT();
803 }
804
806 {
807 int resultnum = op->d.assign_var.resultnum;
808 int attnum = op->d.assign_var.attnum;
809
810 /*
811 * We do not need CheckVarSlotCompatibility here; that was taken
812 * care of at compilation time. But see EEOP_INNER_VAR comments.
813 */
814 Assert(attnum >= 0 && attnum < outerslot->tts_nvalid);
815 Assert(resultnum >= 0 && resultnum < resultslot->tts_tupleDescriptor->natts);
816 resultslot->tts_values[resultnum] = outerslot->tts_values[attnum];
817 resultslot->tts_isnull[resultnum] = outerslot->tts_isnull[attnum];
818
819 EEO_NEXT();
820 }
821
823 {
824 int resultnum = op->d.assign_var.resultnum;
825 int attnum = op->d.assign_var.attnum;
826
827 /*
828 * We do not need CheckVarSlotCompatibility here; that was taken
829 * care of at compilation time. But see EEOP_INNER_VAR comments.
830 */
831 Assert(attnum >= 0 && attnum < scanslot->tts_nvalid);
832 Assert(resultnum >= 0 && resultnum < resultslot->tts_tupleDescriptor->natts);
833 resultslot->tts_values[resultnum] = scanslot->tts_values[attnum];
834 resultslot->tts_isnull[resultnum] = scanslot->tts_isnull[attnum];
835
836 EEO_NEXT();
837 }
838
840 {
841 int resultnum = op->d.assign_var.resultnum;
842 int attnum = op->d.assign_var.attnum;
843
844 /*
845 * We do not need CheckVarSlotCompatibility here; that was taken
846 * care of at compilation time. But see EEOP_INNER_VAR comments.
847 */
848 Assert(attnum >= 0 && attnum < oldslot->tts_nvalid);
849 Assert(resultnum >= 0 && resultnum < resultslot->tts_tupleDescriptor->natts);
850 resultslot->tts_values[resultnum] = oldslot->tts_values[attnum];
851 resultslot->tts_isnull[resultnum] = oldslot->tts_isnull[attnum];
852
853 EEO_NEXT();
854 }
855
857 {
858 int resultnum = op->d.assign_var.resultnum;
859 int attnum = op->d.assign_var.attnum;
860
861 /*
862 * We do not need CheckVarSlotCompatibility here; that was taken
863 * care of at compilation time. But see EEOP_INNER_VAR comments.
864 */
865 Assert(attnum >= 0 && attnum < newslot->tts_nvalid);
866 Assert(resultnum >= 0 && resultnum < resultslot->tts_tupleDescriptor->natts);
867 resultslot->tts_values[resultnum] = newslot->tts_values[attnum];
868 resultslot->tts_isnull[resultnum] = newslot->tts_isnull[attnum];
869
870 EEO_NEXT();
871 }
872
874 {
875 int resultnum = op->d.assign_tmp.resultnum;
876
877 Assert(resultnum >= 0 && resultnum < resultslot->tts_tupleDescriptor->natts);
878 resultslot->tts_values[resultnum] = state->resvalue;
879 resultslot->tts_isnull[resultnum] = state->resnull;
880
881 EEO_NEXT();
882 }
883
885 {
886 int resultnum = op->d.assign_tmp.resultnum;
887
888 Assert(resultnum >= 0 && resultnum < resultslot->tts_tupleDescriptor->natts);
889 resultslot->tts_isnull[resultnum] = state->resnull;
890 if (!resultslot->tts_isnull[resultnum])
891 resultslot->tts_values[resultnum] =
893 else
894 resultslot->tts_values[resultnum] = state->resvalue;
895
896 EEO_NEXT();
897 }
898
900 {
901 *op->resnull = op->d.constval.isnull;
902 *op->resvalue = op->d.constval.value;
903
904 EEO_NEXT();
905 }
906
907 /*
908 * Function-call implementations. Arguments have previously been
909 * evaluated directly into fcinfo->args.
910 *
911 * As both STRICT checks and function-usage are noticeable performance
912 * wise, and function calls are a very hot-path (they also back
913 * operators!), it's worth having so many separate opcodes.
914 *
915 * Note: the reason for using a temporary variable "d", here and in
916 * other places, is that some compilers think "*op->resvalue = f();"
917 * requires them to evaluate op->resvalue into a register before
918 * calling f(), just in case f() is able to modify op->resvalue
919 * somehow. The extra line of code can save a useless register spill
920 * and reload across the function call.
921 */
923 {
924 FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
925 Datum d;
926
927 fcinfo->isnull = false;
928 d = op->d.func.fn_addr(fcinfo);
929 *op->resvalue = d;
930 *op->resnull = fcinfo->isnull;
931
932 EEO_NEXT();
933 }
934
935 /* strict function call with more than two arguments */
937 {
938 FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
939 NullableDatum *args = fcinfo->args;
940 int nargs = op->d.func.nargs;
941 Datum d;
942
943 Assert(nargs > 2);
944
945 /* strict function, so check for NULL args */
946 for (int argno = 0; argno < nargs; argno++)
947 {
948 if (args[argno].isnull)
949 {
950 *op->resnull = true;
951 goto strictfail;
952 }
953 }
954 fcinfo->isnull = false;
955 d = op->d.func.fn_addr(fcinfo);
956 *op->resvalue = d;
957 *op->resnull = fcinfo->isnull;
958
960 EEO_NEXT();
961 }
962
963 /* strict function call with one argument */
965 {
966 FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
967 NullableDatum *args = fcinfo->args;
968
969 Assert(op->d.func.nargs == 1);
970
971 /* strict function, so check for NULL args */
972 if (args[0].isnull)
973 *op->resnull = true;
974 else
975 {
976 Datum d;
977
978 fcinfo->isnull = false;
979 d = op->d.func.fn_addr(fcinfo);
980 *op->resvalue = d;
981 *op->resnull = fcinfo->isnull;
982 }
983
984 EEO_NEXT();
985 }
986
987 /* strict function call with two arguments */
989 {
990 FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
991 NullableDatum *args = fcinfo->args;
992
993 Assert(op->d.func.nargs == 2);
994
995 /* strict function, so check for NULL args */
996 if (args[0].isnull || args[1].isnull)
997 *op->resnull = true;
998 else
999 {
1000 Datum d;
1001
1002 fcinfo->isnull = false;
1003 d = op->d.func.fn_addr(fcinfo);
1004 *op->resvalue = d;
1005 *op->resnull = fcinfo->isnull;
1006 }
1007
1008 EEO_NEXT();
1009 }
1010
1012 {
1013 /* not common enough to inline */
1014 ExecEvalFuncExprFusage(state, op, econtext);
1015
1016 EEO_NEXT();
1017 }
1018
1020 {
1021 /* not common enough to inline */
1022 ExecEvalFuncExprStrictFusage(state, op, econtext);
1023
1024 EEO_NEXT();
1025 }
1026
1027 /*
1028 * If any of its clauses is FALSE, an AND's result is FALSE regardless
1029 * of the states of the rest of the clauses, so we can stop evaluating
1030 * and return FALSE immediately. If none are FALSE and one or more is
1031 * NULL, we return NULL; otherwise we return TRUE. This makes sense
1032 * when you interpret NULL as "don't know": perhaps one of the "don't
1033 * knows" would have been FALSE if we'd known its value. Only when
1034 * all the inputs are known to be TRUE can we state confidently that
1035 * the AND's result is TRUE.
1036 */
1038 {
1039 *op->d.boolexpr.anynull = false;
1040
1041 /*
1042 * EEOP_BOOL_AND_STEP_FIRST resets anynull, otherwise it's the
1043 * same as EEOP_BOOL_AND_STEP - so fall through to that.
1044 */
1045
1046 /* FALL THROUGH */
1047 }
1048
1050 {
1051 if (*op->resnull)
1052 {
1053 *op->d.boolexpr.anynull = true;
1054 }
1055 else if (!DatumGetBool(*op->resvalue))
1056 {
1057 /* result is already set to FALSE, need not change it */
1058 /* bail out early */
1060 }
1061
1062 EEO_NEXT();
1063 }
1064
1066 {
1067 if (*op->resnull)
1068 {
1069 /* result is already set to NULL, need not change it */
1070 }
1071 else if (!DatumGetBool(*op->resvalue))
1072 {
1073 /* result is already set to FALSE, need not change it */
1074
1075 /*
1076 * No point jumping early to jumpdone - would be same target
1077 * (as this is the last argument to the AND expression),
1078 * except more expensive.
1079 */
1080 }
1081 else if (*op->d.boolexpr.anynull)
1082 {
1083 *op->resvalue = (Datum) 0;
1084 *op->resnull = true;
1085 }
1086 else
1087 {
1088 /* result is already set to TRUE, need not change it */
1089 }
1090
1091 EEO_NEXT();
1092 }
1093
1094 /*
1095 * If any of its clauses is TRUE, an OR's result is TRUE regardless of
1096 * the states of the rest of the clauses, so we can stop evaluating
1097 * and return TRUE immediately. If none are TRUE and one or more is
1098 * NULL, we return NULL; otherwise we return FALSE. This makes sense
1099 * when you interpret NULL as "don't know": perhaps one of the "don't
1100 * knows" would have been TRUE if we'd known its value. Only when all
1101 * the inputs are known to be FALSE can we state confidently that the
1102 * OR's result is FALSE.
1103 */
1105 {
1106 *op->d.boolexpr.anynull = false;
1107
1108 /*
1109 * EEOP_BOOL_OR_STEP_FIRST resets anynull, otherwise it's the same
1110 * as EEOP_BOOL_OR_STEP - so fall through to that.
1111 */
1112
1113 /* FALL THROUGH */
1114 }
1115
1117 {
1118 if (*op->resnull)
1119 {
1120 *op->d.boolexpr.anynull = true;
1121 }
1122 else if (DatumGetBool(*op->resvalue))
1123 {
1124 /* result is already set to TRUE, need not change it */
1125 /* bail out early */
1127 }
1128
1129 EEO_NEXT();
1130 }
1131
1133 {
1134 if (*op->resnull)
1135 {
1136 /* result is already set to NULL, need not change it */
1137 }
1138 else if (DatumGetBool(*op->resvalue))
1139 {
1140 /* result is already set to TRUE, need not change it */
1141
1142 /*
1143 * No point jumping to jumpdone - would be same target (as
1144 * this is the last argument to the AND expression), except
1145 * more expensive.
1146 */
1147 }
1148 else if (*op->d.boolexpr.anynull)
1149 {
1150 *op->resvalue = (Datum) 0;
1151 *op->resnull = true;
1152 }
1153 else
1154 {
1155 /* result is already set to FALSE, need not change it */
1156 }
1157
1158 EEO_NEXT();
1159 }
1160
1162 {
1163 /*
1164 * Evaluation of 'not' is simple... if expr is false, then return
1165 * 'true' and vice versa. It's safe to do this even on a
1166 * nominally null value, so we ignore resnull; that means that
1167 * NULL in produces NULL out, which is what we want.
1168 */
1170
1171 EEO_NEXT();
1172 }
1173
1175 {
1176 /* simplified version of BOOL_AND_STEP for use by ExecQual() */
1177
1178 /* If argument (also result) is false or null ... */
1179 if (*op->resnull ||
1180 !DatumGetBool(*op->resvalue))
1181 {
1182 /* ... bail out early, returning FALSE */
1183 *op->resnull = false;
1184 *op->resvalue = BoolGetDatum(false);
1186 }
1187
1188 /*
1189 * Otherwise, leave the TRUE value in place, in case this is the
1190 * last qual. Then, TRUE is the correct answer.
1191 */
1192
1193 EEO_NEXT();
1194 }
1195
1197 {
1198 /* Unconditionally jump to target step */
1199 EEO_JUMP(op->d.jump.jumpdone);
1200 }
1201
1203 {
1204 /* Transfer control if current result is null */
1205 if (*op->resnull)
1206 EEO_JUMP(op->d.jump.jumpdone);
1207
1208 EEO_NEXT();
1209 }
1210
1212 {
1213 /* Transfer control if current result is non-null */
1214 if (!*op->resnull)
1215 EEO_JUMP(op->d.jump.jumpdone);
1216
1217 EEO_NEXT();
1218 }
1219
1221 {
1222 /* Transfer control if current result is null or false */
1223 if (*op->resnull || !DatumGetBool(*op->resvalue))
1224 EEO_JUMP(op->d.jump.jumpdone);
1225
1226 EEO_NEXT();
1227 }
1228
1230 {
1231 *op->resvalue = BoolGetDatum(*op->resnull);
1232 *op->resnull = false;
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 /* out of line implementation: too large */
1248 ExecEvalRowNull(state, op, econtext);
1249
1250 EEO_NEXT();
1251 }
1252
1254 {
1255 /* out of line implementation: too large */
1256 ExecEvalRowNotNull(state, op, econtext);
1257
1258 EEO_NEXT();
1259 }
1260
1261 /* BooleanTest implementations for all booltesttypes */
1262
1264 {
1265 if (*op->resnull)
1266 {
1267 *op->resvalue = BoolGetDatum(false);
1268 *op->resnull = false;
1269 }
1270 /* else, input value is the correct output as well */
1271
1272 EEO_NEXT();
1273 }
1274
1276 {
1277 if (*op->resnull)
1278 {
1279 *op->resvalue = BoolGetDatum(true);
1280 *op->resnull = false;
1281 }
1282 else
1284
1285 EEO_NEXT();
1286 }
1287
1289 {
1290 if (*op->resnull)
1291 {
1292 *op->resvalue = BoolGetDatum(false);
1293 *op->resnull = false;
1294 }
1295 else
1297
1298 EEO_NEXT();
1299 }
1300
1302 {
1303 if (*op->resnull)
1304 {
1305 *op->resvalue = BoolGetDatum(true);
1306 *op->resnull = false;
1307 }
1308 /* else, input value is the correct output as well */
1309
1310 EEO_NEXT();
1311 }
1312
1314 {
1315 /* out of line implementation: too large */
1316 ExecEvalParamExec(state, op, econtext);
1317
1318 EEO_NEXT();
1319 }
1320
1322 {
1323 /* out of line implementation: too large */
1324 ExecEvalParamExtern(state, op, econtext);
1325 EEO_NEXT();
1326 }
1327
1329 {
1330 /* allow an extension module to supply a PARAM_EXTERN value */
1331 op->d.cparam.paramfunc(state, op, econtext);
1332 EEO_NEXT();
1333 }
1334
1336 {
1337 /* out of line, unlikely to matter performance-wise */
1338 ExecEvalParamSet(state, op, econtext);
1339 EEO_NEXT();
1340 }
1341
1343 {
1344 *op->resvalue = *op->d.casetest.value;
1345 *op->resnull = *op->d.casetest.isnull;
1346
1347 EEO_NEXT();
1348 }
1349
1351 {
1352 *op->resvalue = econtext->caseValue_datum;
1353 *op->resnull = econtext->caseValue_isNull;
1354
1355 EEO_NEXT();
1356 }
1357
1359 {
1360 /*
1361 * Force a varlena value that might be read multiple times to R/O
1362 */
1363 if (!*op->d.make_readonly.isnull)
1364 *op->resvalue =
1366 *op->resnull = *op->d.make_readonly.isnull;
1367
1368 EEO_NEXT();
1369 }
1370
1372 {
1373 /*
1374 * Evaluate a CoerceViaIO node. This can be quite a hot path, so
1375 * inline as much work as possible. The source value is in our
1376 * result variable.
1377 *
1378 * Also look at ExecEvalCoerceViaIOSafe() if you change anything
1379 * here.
1380 */
1381 char *str;
1382
1383 /* call output function (similar to OutputFunctionCall) */
1384 if (*op->resnull)
1385 {
1386 /* output functions are not called on nulls */
1387 str = NULL;
1388 }
1389 else
1390 {
1392
1394 fcinfo_out->args[0].value = *op->resvalue;
1395 fcinfo_out->args[0].isnull = false;
1396
1397 fcinfo_out->isnull = false;
1399
1400 /* OutputFunctionCall assumes result isn't null */
1401 Assert(!fcinfo_out->isnull);
1402 }
1403
1404 /* call input function (similar to InputFunctionCall) */
1405 if (!op->d.iocoerce.finfo_in->fn_strict || str != NULL)
1406 {
1408 Datum d;
1409
1412 fcinfo_in->args[0].isnull = *op->resnull;
1413 /* second and third arguments are already set up */
1414
1415 fcinfo_in->isnull = false;
1417 *op->resvalue = d;
1418
1419 /* Should get null result if and only if str is NULL */
1420 if (str == NULL)
1421 {
1422 Assert(*op->resnull);
1423 Assert(fcinfo_in->isnull);
1424 }
1425 else
1426 {
1427 Assert(!*op->resnull);
1428 Assert(!fcinfo_in->isnull);
1429 }
1430 }
1431
1432 EEO_NEXT();
1433 }
1434
1436 {
1438 EEO_NEXT();
1439 }
1440
1442 {
1443 /*
1444 * IS DISTINCT FROM must evaluate arguments (already done into
1445 * fcinfo->args) to determine whether they are NULL; if either is
1446 * NULL then the result is determined. If neither is NULL, then
1447 * proceed to evaluate the comparison function, which is just the
1448 * type's standard equality operator. We need not care whether
1449 * that function is strict. Because the handling of nulls is
1450 * different, we can't just reuse EEOP_FUNCEXPR.
1451 */
1452 FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
1453
1454 /* check function arguments for NULLness */
1455 if (fcinfo->args[0].isnull && fcinfo->args[1].isnull)
1456 {
1457 /* Both NULL? Then is not distinct... */
1458 *op->resvalue = BoolGetDatum(false);
1459 *op->resnull = false;
1460 }
1461 else if (fcinfo->args[0].isnull || fcinfo->args[1].isnull)
1462 {
1463 /* Only one is NULL? Then is distinct... */
1464 *op->resvalue = BoolGetDatum(true);
1465 *op->resnull = false;
1466 }
1467 else
1468 {
1469 /* Neither null, so apply the equality function */
1471
1472 fcinfo->isnull = false;
1473 eqresult = op->d.func.fn_addr(fcinfo);
1474 /* Must invert result of "="; safe to do even if null */
1476 *op->resnull = fcinfo->isnull;
1477 }
1478
1479 EEO_NEXT();
1480 }
1481
1482 /* see EEOP_DISTINCT for comments, this is just inverted */
1484 {
1485 FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
1486
1487 if (fcinfo->args[0].isnull && fcinfo->args[1].isnull)
1488 {
1489 *op->resvalue = BoolGetDatum(true);
1490 *op->resnull = false;
1491 }
1492 else if (fcinfo->args[0].isnull || fcinfo->args[1].isnull)
1493 {
1494 *op->resvalue = BoolGetDatum(false);
1495 *op->resnull = false;
1496 }
1497 else
1498 {
1500
1501 fcinfo->isnull = false;
1502 eqresult = op->d.func.fn_addr(fcinfo);
1503 *op->resvalue = eqresult;
1504 *op->resnull = fcinfo->isnull;
1505 }
1506
1507 EEO_NEXT();
1508 }
1509
1511 {
1512 /*
1513 * The arguments are already evaluated into fcinfo->args.
1514 */
1515 FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
1516 Datum save_arg0 = fcinfo->args[0].value;
1517
1518 /* if either argument is NULL they can't be equal */
1519 if (!fcinfo->args[0].isnull && !fcinfo->args[1].isnull)
1520 {
1521 Datum result;
1522
1523 /*
1524 * If first argument is of varlena type, it might be an
1525 * expanded datum. We need to ensure that the value passed to
1526 * the comparison function is a read-only pointer. However,
1527 * if we end by returning the first argument, that will be the
1528 * original read-write pointer if it was read-write.
1529 */
1530 if (op->d.func.make_ro)
1531 fcinfo->args[0].value =
1533
1534 fcinfo->isnull = false;
1535 result = op->d.func.fn_addr(fcinfo);
1536
1537 /* if the arguments are equal return null */
1538 if (!fcinfo->isnull && DatumGetBool(result))
1539 {
1540 *op->resvalue = (Datum) 0;
1541 *op->resnull = true;
1542
1543 EEO_NEXT();
1544 }
1545 }
1546
1547 /* Arguments aren't equal, so return the first one */
1548 *op->resvalue = save_arg0;
1549 *op->resnull = fcinfo->args[0].isnull;
1550
1551 EEO_NEXT();
1552 }
1553
1555 {
1556 /*
1557 * Doesn't seem worthwhile to have an inline implementation
1558 * efficiency-wise.
1559 */
1561
1562 EEO_NEXT();
1563 }
1564
1566 {
1567 /* error invocation uses space, and shouldn't ever occur */
1569
1570 EEO_NEXT();
1571 }
1572
1574 {
1575 /*
1576 * Doesn't seem worthwhile to have an inline implementation
1577 * efficiency-wise.
1578 */
1580
1581 EEO_NEXT();
1582 }
1583
1585 {
1586 /*
1587 * The next op actually evaluates the expression. If the OLD/NEW
1588 * row doesn't exist, skip that and return NULL.
1589 */
1590 if (state->flags & op->d.returningexpr.nullflag)
1591 {
1592 *op->resvalue = (Datum) 0;
1593 *op->resnull = true;
1594
1596 }
1597
1598 EEO_NEXT();
1599 }
1600
1602 {
1603 /* too complex for an inline implementation */
1605
1606 EEO_NEXT();
1607 }
1608
1610 {
1611 /* too complex for an inline implementation */
1612 ExecEvalArrayCoerce(state, op, econtext);
1613
1614 EEO_NEXT();
1615 }
1616
1618 {
1619 /* too complex for an inline implementation */
1620 ExecEvalRow(state, op);
1621
1622 EEO_NEXT();
1623 }
1624
1626 {
1628 Datum d;
1629
1630 /* force NULL result if strict fn and NULL input */
1631 if (op->d.rowcompare_step.finfo->fn_strict &&
1632 (fcinfo->args[0].isnull || fcinfo->args[1].isnull))
1633 {
1634 *op->resnull = true;
1636 }
1637
1638 /* Apply comparison function */
1639 fcinfo->isnull = false;
1640 d = op->d.rowcompare_step.fn_addr(fcinfo);
1641 *op->resvalue = d;
1642
1643 /* force NULL result if NULL function result */
1644 if (fcinfo->isnull)
1645 {
1646 *op->resnull = true;
1648 }
1649 *op->resnull = false;
1650
1651 /* If unequal, no need to compare remaining columns */
1652 if (DatumGetInt32(*op->resvalue) != 0)
1653 {
1655 }
1656
1657 EEO_NEXT();
1658 }
1659
1661 {
1663 CompareType cmptype = op->d.rowcompare_final.cmptype;
1664
1665 *op->resnull = false;
1666 switch (cmptype)
1667 {
1668 /* EQ and NE cases aren't allowed here */
1669 case COMPARE_LT:
1670 *op->resvalue = BoolGetDatum(cmpresult < 0);
1671 break;
1672 case COMPARE_LE:
1673 *op->resvalue = BoolGetDatum(cmpresult <= 0);
1674 break;
1675 case COMPARE_GE:
1676 *op->resvalue = BoolGetDatum(cmpresult >= 0);
1677 break;
1678 case COMPARE_GT:
1679 *op->resvalue = BoolGetDatum(cmpresult > 0);
1680 break;
1681 default:
1682 Assert(false);
1683 break;
1684 }
1685
1686 EEO_NEXT();
1687 }
1688
1690 {
1691 /* too complex for an inline implementation */
1692 ExecEvalMinMax(state, op);
1693
1694 EEO_NEXT();
1695 }
1696
1698 {
1699 /* too complex for an inline implementation */
1700 ExecEvalFieldSelect(state, op, econtext);
1701
1702 EEO_NEXT();
1703 }
1704
1706 {
1707 /* too complex for an inline implementation */
1708 ExecEvalFieldStoreDeForm(state, op, econtext);
1709
1710 EEO_NEXT();
1711 }
1712
1714 {
1715 /* too complex for an inline implementation */
1716 ExecEvalFieldStoreForm(state, op, econtext);
1717
1718 EEO_NEXT();
1719 }
1720
1722 {
1723 /* Precheck SubscriptingRef subscript(s) */
1724 if (op->d.sbsref_subscript.subscriptfunc(state, op, econtext))
1725 {
1726 EEO_NEXT();
1727 }
1728 else
1729 {
1730 /* Subscript is null, short-circuit SubscriptingRef to NULL */
1732 }
1733 }
1734
1738 {
1739 /* Perform a SubscriptingRef fetch or assignment */
1740 op->d.sbsref.subscriptfunc(state, op, econtext);
1741
1742 EEO_NEXT();
1743 }
1744
1746 {
1747 /* too complex for an inline implementation */
1748 ExecEvalConvertRowtype(state, op, econtext);
1749
1750 EEO_NEXT();
1751 }
1752
1754 {
1755 /* too complex for an inline implementation */
1757
1758 EEO_NEXT();
1759 }
1760
1762 {
1763 /* too complex for an inline implementation */
1764 ExecEvalHashedScalarArrayOp(state, op, econtext);
1765
1766 EEO_NEXT();
1767 }
1768
1770 {
1771 *op->resvalue = *op->d.casetest.value;
1772 *op->resnull = *op->d.casetest.isnull;
1773
1774 EEO_NEXT();
1775 }
1776
1778 {
1779 *op->resvalue = econtext->domainValue_datum;
1780 *op->resnull = econtext->domainValue_isNull;
1781
1782 EEO_NEXT();
1783 }
1784
1786 {
1787 /* too complex for an inline implementation */
1789
1790 EEO_NEXT();
1791 }
1792
1794 {
1795 /* too complex for an inline implementation */
1797
1798 EEO_NEXT();
1799 }
1800
1802 {
1804 *op->resnull = false;
1805
1806 EEO_NEXT();
1807 }
1808
1810 {
1812
1813 /*
1814 * Save the Datum on non-null inputs, otherwise store 0 so that
1815 * subsequent NEXT32 operations combine with an initialized value.
1816 */
1817 if (!fcinfo->args[0].isnull)
1818 *op->resvalue = op->d.hashdatum.fn_addr(fcinfo);
1819 else
1820 *op->resvalue = (Datum) 0;
1821
1822 *op->resnull = false;
1823
1824 EEO_NEXT();
1825 }
1826
1828 {
1830
1831 if (fcinfo->args[0].isnull)
1832 {
1833 /*
1834 * With strict we have the expression return NULL instead of
1835 * ignoring NULL input values. We've nothing more to do after
1836 * finding a NULL.
1837 */
1838 *op->resnull = true;
1839 *op->resvalue = (Datum) 0;
1841 }
1842
1843 /* execute the hash function and save the resulting value */
1844 *op->resvalue = op->d.hashdatum.fn_addr(fcinfo);
1845 *op->resnull = false;
1846
1847 EEO_NEXT();
1848 }
1849
1851 {
1854
1856 /* combine successive hash values by rotating */
1858
1859 /* leave the hash value alone on NULL inputs */
1860 if (!fcinfo->args[0].isnull)
1861 {
1862 uint32 hashvalue;
1863
1864 /* execute hash func and combine with previous hash value */
1865 hashvalue = DatumGetUInt32(op->d.hashdatum.fn_addr(fcinfo));
1866 existinghash = existinghash ^ hashvalue;
1867 }
1868
1870 *op->resnull = false;
1871
1872 EEO_NEXT();
1873 }
1874
1876 {
1878
1879 if (fcinfo->args[0].isnull)
1880 {
1881 /*
1882 * With strict we have the expression return NULL instead of
1883 * ignoring NULL input values. We've nothing more to do after
1884 * finding a NULL.
1885 */
1886 *op->resnull = true;
1887 *op->resvalue = (Datum) 0;
1889 }
1890 else
1891 {
1893 uint32 hashvalue;
1894
1896 /* combine successive hash values by rotating */
1898
1899 /* execute hash func and combine with previous hash value */
1900 hashvalue = DatumGetUInt32(op->d.hashdatum.fn_addr(fcinfo));
1901 *op->resvalue = UInt32GetDatum(existinghash ^ hashvalue);
1902 *op->resnull = false;
1903 }
1904
1905 EEO_NEXT();
1906 }
1907
1909 {
1910 /* too complex for an inline implementation */
1912
1913 EEO_NEXT();
1914 }
1915
1917 {
1918 /* too complex for an inline implementation */
1919 ExecEvalJsonConstructor(state, op, econtext);
1920 EEO_NEXT();
1921 }
1922
1924 {
1925 /* too complex for an inline implementation */
1927
1928 EEO_NEXT();
1929 }
1930
1932 {
1933 /* too complex for an inline implementation */
1934 EEO_JUMP(ExecEvalJsonExprPath(state, op, econtext));
1935 }
1936
1938 {
1939 /* too complex for an inline implementation */
1940 ExecEvalJsonCoercion(state, op, econtext);
1941
1942 EEO_NEXT();
1943 }
1944
1946 {
1947 /* too complex for an inline implementation */
1949
1950 EEO_NEXT();
1951 }
1952
1954 {
1955 /*
1956 * Returns a Datum whose value is the precomputed aggregate value
1957 * found in the given expression context.
1958 */
1959 int aggno = op->d.aggref.aggno;
1960
1961 Assert(econtext->ecxt_aggvalues != NULL);
1962
1963 *op->resvalue = econtext->ecxt_aggvalues[aggno];
1964 *op->resnull = econtext->ecxt_aggnulls[aggno];
1965
1966 EEO_NEXT();
1967 }
1968
1970 {
1971 /* too complex/uncommon for an inline implementation */
1973
1974 EEO_NEXT();
1975 }
1976
1978 {
1979 /*
1980 * Like Aggref, just return a precomputed value from the econtext.
1981 */
1983
1984 Assert(econtext->ecxt_aggvalues != NULL);
1985
1986 *op->resvalue = econtext->ecxt_aggvalues[wfunc->wfuncno];
1987 *op->resnull = econtext->ecxt_aggnulls[wfunc->wfuncno];
1988
1989 EEO_NEXT();
1990 }
1991
1993 {
1994 /* too complex/uncommon for an inline implementation */
1995 ExecEvalMergeSupportFunc(state, op, econtext);
1996
1997 EEO_NEXT();
1998 }
1999
2001 {
2002 /* too complex for an inline implementation */
2003 ExecEvalSubPlan(state, op, econtext);
2004
2005 EEO_NEXT();
2006 }
2007
2008 /* evaluate a strict aggregate deserialization function */
2010 {
2011 /* Don't call a strict deserialization function with NULL input */
2014
2015 /* fallthrough */
2016 }
2017
2018 /* evaluate aggregate deserialization function (non-strict portion) */
2020 {
2024
2025 /*
2026 * We run the deserialization functions in per-input-tuple memory
2027 * context.
2028 */
2029 oldContext = MemoryContextSwitchTo(aggstate->tmpcontext->ecxt_per_tuple_memory);
2030 fcinfo->isnull = false;
2031 *op->resvalue = FunctionCallInvoke(fcinfo);
2032 *op->resnull = fcinfo->isnull;
2034
2035 EEO_NEXT();
2036 }
2037
2038 /*
2039 * Check that a strict aggregate transition / combination function's
2040 * input is not NULL.
2041 */
2042
2043 /* when checking more than one argument */
2045 {
2047 int nargs = op->d.agg_strict_input_check.nargs;
2048
2049 Assert(nargs > 1);
2050
2051 for (int argno = 0; argno < nargs; argno++)
2052 {
2053 if (args[argno].isnull)
2055 }
2056 EEO_NEXT();
2057 }
2058
2059 /* special case for just one argument */
2061 {
2064
2065 Assert(nargs == 1);
2066
2067 if (args[0].isnull)
2069 EEO_NEXT();
2070 }
2071
2073 {
2074 bool *nulls = op->d.agg_strict_input_check.nulls;
2075 int nargs = op->d.agg_strict_input_check.nargs;
2076
2077 for (int argno = 0; argno < nargs; argno++)
2078 {
2079 if (nulls[argno])
2081 }
2082 EEO_NEXT();
2083 }
2084
2085 /*
2086 * Check for a NULL pointer to the per-group states.
2087 */
2088
2090 {
2093 aggstate->all_pergroups[op->d.agg_plain_pergroup_nullcheck.setoff];
2094
2095 if (pergroup_allaggs == NULL)
2097
2098 EEO_NEXT();
2099 }
2100
2101 /*
2102 * Different types of aggregate transition functions are implemented
2103 * as different types of steps, to avoid incurring unnecessary
2104 * overhead. There's a step type for each valid combination of having
2105 * a by value / by reference transition type, [not] needing to the
2106 * initialize the transition value for the first row in a group from
2107 * input, and [not] strict transition function.
2108 *
2109 * Could optimize further by splitting off by-reference for
2110 * fixed-length types, but currently that doesn't seem worth it.
2111 */
2112
2114 {
2116 AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
2118 &aggstate->all_pergroups[op->d.agg_trans.setoff][op->d.agg_trans.transno];
2119
2120 Assert(pertrans->transtypeByVal);
2121
2122 if (pergroup->noTransValue)
2123 {
2124 /* If transValue has not yet been initialized, do so now. */
2126 op->d.agg_trans.aggcontext);
2127 /* copied trans value from input, done this round */
2128 }
2129 else if (likely(!pergroup->transValueIsNull))
2130 {
2131 /* invoke transition function, unless prevented by strictness */
2134 op->d.agg_trans.setno);
2135 }
2136
2137 EEO_NEXT();
2138 }
2139
2140 /* see comments above EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYVAL */
2142 {
2144 AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
2146 &aggstate->all_pergroups[op->d.agg_trans.setoff][op->d.agg_trans.transno];
2147
2148 Assert(pertrans->transtypeByVal);
2149
2150 if (likely(!pergroup->transValueIsNull))
2153 op->d.agg_trans.setno);
2154
2155 EEO_NEXT();
2156 }
2157
2158 /* see comments above EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYVAL */
2160 {
2162 AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
2164 &aggstate->all_pergroups[op->d.agg_trans.setoff][op->d.agg_trans.transno];
2165
2166 Assert(pertrans->transtypeByVal);
2167
2170 op->d.agg_trans.setno);
2171
2172 EEO_NEXT();
2173 }
2174
2175 /* see comments above EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYVAL */
2177 {
2179 AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
2181 &aggstate->all_pergroups[op->d.agg_trans.setoff][op->d.agg_trans.transno];
2182
2183 Assert(!pertrans->transtypeByVal);
2184
2185 if (pergroup->noTransValue)
2187 op->d.agg_trans.aggcontext);
2188 else if (likely(!pergroup->transValueIsNull))
2191 op->d.agg_trans.setno);
2192
2193 EEO_NEXT();
2194 }
2195
2196 /* see comments above EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYVAL */
2198 {
2200 AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
2202 &aggstate->all_pergroups[op->d.agg_trans.setoff][op->d.agg_trans.transno];
2203
2204 Assert(!pertrans->transtypeByVal);
2205
2206 if (likely(!pergroup->transValueIsNull))
2209 op->d.agg_trans.setno);
2210 EEO_NEXT();
2211 }
2212
2213 /* see comments above EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYVAL */
2215 {
2217 AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
2219 &aggstate->all_pergroups[op->d.agg_trans.setoff][op->d.agg_trans.transno];
2220
2221 Assert(!pertrans->transtypeByVal);
2222
2225 op->d.agg_trans.setno);
2226
2227 EEO_NEXT();
2228 }
2229
2231 {
2234
2236 EEO_NEXT();
2237 else
2239 }
2240
2242 {
2245
2247 EEO_NEXT();
2248 else
2250 }
2251
2252 /* process single-column ordered aggregate datum */
2254 {
2255 /* too complex for an inline implementation */
2256 ExecEvalAggOrderedTransDatum(state, op, econtext);
2257
2258 EEO_NEXT();
2259 }
2260
2261 /* process multi-column ordered aggregate tuple */
2263 {
2264 /* too complex for an inline implementation */
2265 ExecEvalAggOrderedTransTuple(state, op, econtext);
2266
2267 EEO_NEXT();
2268 }
2269
2271 {
2272 /* unreachable */
2273 Assert(false);
2274 goto out_error;
2275 }
2276 }
2277
2278out_error:
2280 return (Datum) 0;
2281}
#define PG_USED_FOR_ASSERTS_ONLY
Definition c.h:243
#define pg_unreachable()
Definition c.h:361
uint32_t uint32
Definition c.h:618
#define lengthof(array)
Definition c.h:875
#define StaticAssertDecl(condition, errmessage)
Definition c.h:1010
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:315
Datum * ecxt_aggvalues
Definition execnodes.h:303
bool caseValue_isNull
Definition execnodes.h:311
Datum caseValue_datum
Definition execnodes.h:309
bool * ecxt_aggnulls
Definition execnodes.h:305
bool domainValue_isNull
Definition execnodes.h:317
struct ExprEvalStep::@60::@84 rowcompare_final
uint8 nullflag
Definition execExpr.h:373
bool * anynull
Definition execExpr.h:399
WindowFuncExprState * wfstate
Definition execExpr.h:684
struct ExprEvalStep::@60::@105 agg_presorted_distinctcheck
ExecEvalBoolSubroutine subscriptfunc
Definition execExpr.h:568
struct ExprEvalStep::@60::@92 hashdatum
struct ExprEvalStep::@60::@67 constval
struct ExprEvalStep::@60::@64 assign_var
struct ExprEvalStep::@60::@65 assign_tmp
struct ExprEvalStep::@60::@104 agg_plain_pergroup_nullcheck
struct ExprEvalStep::@60::@98 aggref
struct ExprEvalStep::@60::@88 sbsref_subscript
struct ExprEvalStep::@60::@91 hashdatum_initvalue
ExecEvalSubroutine paramfunc
Definition execExpr.h:432
NullableDatum * args
Definition execExpr.h:715
NullableDatum * iresult
Definition execExpr.h:610
struct ExprEvalStep::@60::@74 cparam
struct ExprEvalStep::@60::@70 qualexpr
struct ExprEvalStep::@60::@66 returningexpr
int jumpdistinct
Definition execExpr.h:733
struct ExprEvalStep::@60::@69 boolexpr
struct ExprEvalStep::@60::@83 rowcompare_step
struct ExprEvalStep::@60::@103 agg_strict_input_check
Datum value
Definition execExpr.h:381
CompareType cmptype
Definition execExpr.h:523
struct ExprEvalStep::@60::@100 window_func
struct ExprEvalStep::@60::@75 casetest
struct ExprEvalStep::@60::@71 jump
struct ExprEvalStep::@60::@89 sbsref
Datum init_value
Definition execExpr.h:598
struct ExprEvalStep::@60::@76 make_readonly
ExprContext * aggcontext
Definition execExpr.h:732
struct ExprEvalStep::@60::@102 agg_deserialize
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(), 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 2289 of file execExprInterp.c.

2290{
2291 /*
2292 * First time through, check whether attribute matches Var. Might not be
2293 * ok anymore, due to schema changes.
2294 */
2295 CheckExprStillValid(state, econtext);
2296
2297 /* skip the check during further executions */
2298 state->evalfunc = (ExprStateEvalFunc) state->evalfunc_private;
2299
2300 /* and actually execute */
2301 return state->evalfunc(state, econtext, isNull);
2302}
void CheckExprStillValid(ExprState *state, ExprContext *econtext)
Datum(* ExprStateEvalFunc)(ExprState *expression, ExprContext *econtext, bool *isNull)
Definition execnodes.h:79

References CheckExprStillValid().

Referenced by ExecReadyInterpretedExpr().

◆ ExecJustApplyFuncToCase()

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

Definition at line 2633 of file execExprInterp.c.

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

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

2613{
2614 return ExecJustAssignVarImpl(state, econtext->ecxt_innertuple, isnull);
2615}
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 2746 of file execExprInterp.c.

2747{
2748 return ExecJustAssignVarVirtImpl(state, econtext->ecxt_innertuple, isnull);
2749}
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 2619 of file execExprInterp.c.

2620{
2621 return ExecJustAssignVarImpl(state, econtext->ecxt_outertuple, isnull);
2622}

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

2754{
2755 return ExecJustAssignVarVirtImpl(state, econtext->ecxt_outertuple, isnull);
2756}

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

2627{
2628 return ExecJustAssignVarImpl(state, econtext->ecxt_scantuple, isnull);
2629}

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

2761{
2762 return ExecJustAssignVarVirtImpl(state, econtext->ecxt_scantuple, isnull);
2763}

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

2587{
2588 ExprEvalStep *op = &state->steps[1];
2589 int attnum = op->d.assign_var.attnum + 1;
2590 int resultnum = op->d.assign_var.resultnum;
2591 TupleTableSlot *outslot = state->resultslot;
2592
2594
2595 /*
2596 * We do not need CheckVarSlotCompatibility here; that was taken care of
2597 * at compilation time.
2598 *
2599 * Since we use slot_getattr(), we don't need to implement the FETCHSOME
2600 * step explicitly, and we also needn't Assert that the attnum is in range
2601 * --- slot_getattr() will take care of any problems. Nonetheless, check
2602 * that resultnum is in range.
2603 */
2604 Assert(resultnum >= 0 && resultnum < outslot->tts_tupleDescriptor->natts);
2605 outslot->tts_values[resultnum] =
2606 slot_getattr(inslot, attnum, &outslot->tts_isnull[resultnum]);
2607 return 0;
2608}
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 2724 of file execExprInterp.c.

2725{
2726 ExprEvalStep *op = &state->steps[0];
2727 int attnum = op->d.assign_var.attnum;
2728 int resultnum = op->d.assign_var.resultnum;
2729 TupleTableSlot *outslot = state->resultslot;
2730
2731 /* see ExecJustVarVirtImpl for comments */
2732
2735 Assert(attnum >= 0 && attnum < inslot->tts_nvalid);
2736 Assert(resultnum >= 0 && resultnum < outslot->tts_tupleDescriptor->natts);
2737
2738 outslot->tts_values[resultnum] = inslot->tts_values[attnum];
2739 outslot->tts_isnull[resultnum] = inslot->tts_isnull[attnum];
2740
2741 return 0;
2742}
#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 2671 of file execExprInterp.c.

2672{
2673 ExprEvalStep *op = &state->steps[0];
2674
2675 *isnull = op->d.constval.isnull;
2676 return op->d.constval.value;
2677}

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

Referenced by ExecReadyInterpretedExpr().

◆ ExecJustHashInnerVar()

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

Definition at line 2834 of file execExprInterp.c.

2835{
2836 return ExecJustHashVarImpl(state, econtext->ecxt_innertuple, isnull);
2837}
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 2861 of file execExprInterp.c.

2863{
2864 return ExecJustHashVarVirtImpl(state, econtext->ecxt_innertuple, isnull);
2865}
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 2769 of file execExprInterp.c.

2771{
2772 ExprEvalStep *fetchop = &state->steps[0];
2773 ExprEvalStep *setivop = &state->steps[1];
2774 ExprEvalStep *innervar = &state->steps[2];
2775 ExprEvalStep *hashop = &state->steps[3];
2776 FunctionCallInfo fcinfo = hashop->d.hashdatum.fcinfo_data;
2777 int attnum = innervar->d.var.attnum;
2779
2781 slot_getsomeattrs(econtext->ecxt_innertuple, fetchop->d.fetch.last_var);
2782
2783 fcinfo->args[0].value = econtext->ecxt_innertuple->tts_values[attnum];
2784 fcinfo->args[0].isnull = econtext->ecxt_innertuple->tts_isnull[attnum];
2785
2786 hashkey = DatumGetUInt32(setivop->d.hashdatum_initvalue.init_value);
2788
2789 if (!fcinfo->args[0].isnull)
2790 {
2791 uint32 hashvalue;
2792
2793 hashvalue = DatumGetUInt32(hashop->d.hashdatum.fn_addr(fcinfo));
2794 hashkey = hashkey ^ hashvalue;
2795 }
2796
2797 *isnull = false;
2798 return UInt32GetDatum(hashkey);
2799}

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

2828{
2829 return ExecJustHashVarImpl(state, econtext->ecxt_outertuple, isnull);
2830}

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

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

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

2871{
2872 return ExecJustHashVarVirtImpl(state, econtext->ecxt_outertuple, isnull);
2873}

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

2804{
2805 ExprEvalStep *fetchop = &state->steps[0];
2806 ExprEvalStep *var = &state->steps[1];
2807 ExprEvalStep *hashop = &state->steps[2];
2808 FunctionCallInfo fcinfo = hashop->d.hashdatum.fcinfo_data;
2809 int attnum = var->d.var.attnum;
2810
2812 slot_getsomeattrs(slot, fetchop->d.fetch.last_var);
2813
2814 fcinfo->args[0].value = slot->tts_values[attnum];
2815 fcinfo->args[0].isnull = slot->tts_isnull[attnum];
2816
2817 *isnull = false;
2818
2819 if (!fcinfo->args[0].isnull)
2820 return hashop->d.hashdatum.fn_addr(fcinfo);
2821 else
2822 return (Datum) 0;
2823}

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

2842{
2843 ExprEvalStep *var = &state->steps[0];
2844 ExprEvalStep *hashop = &state->steps[1];
2845 FunctionCallInfo fcinfo = hashop->d.hashdatum.fcinfo_data;
2846 int attnum = var->d.var.attnum;
2847
2848 fcinfo->args[0].value = slot->tts_values[attnum];
2849 fcinfo->args[0].isnull = slot->tts_isnull[attnum];
2850
2851 *isnull = false;
2852
2853 if (!fcinfo->args[0].isnull)
2854 return hashop->d.hashdatum.fn_addr(fcinfo);
2855 else
2856 return (Datum) 0;
2857}

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

2566{
2567 return ExecJustVarImpl(state, econtext->ecxt_innertuple, isnull);
2568}
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 2703 of file execExprInterp.c.

2704{
2705 return ExecJustVarVirtImpl(state, econtext->ecxt_innertuple, isnull);
2706}
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 2572 of file execExprInterp.c.

2573{
2574 return ExecJustVarImpl(state, econtext->ecxt_outertuple, isnull);
2575}

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

2711{
2712 return ExecJustVarVirtImpl(state, econtext->ecxt_outertuple, isnull);
2713}

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

2580{
2581 return ExecJustVarImpl(state, econtext->ecxt_scantuple, isnull);
2582}

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

2718{
2719 return ExecJustVarVirtImpl(state, econtext->ecxt_scantuple, isnull);
2720}

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

2549{
2550 ExprEvalStep *op = &state->steps[1];
2551 int attnum = op->d.var.attnum + 1;
2552
2553 CheckOpSlotCompatibility(&state->steps[0], slot);
2554
2555 /*
2556 * Since we use slot_getattr(), we don't need to implement the FETCHSOME
2557 * step explicitly, and we also needn't Assert that the attnum is in range
2558 * --- slot_getattr() will take care of any problems.
2559 */
2560 return slot_getattr(slot, attnum, isnull);
2561}

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

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

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

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

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

5169{
5170 /*
5171 * The order of array elements must correspond to the order of
5172 * JsonBehaviorType members.
5173 */
5174 const char *behavior_names[] =
5175 {
5176 "NULL",
5177 "ERROR",
5178 "EMPTY",
5179 "TRUE",
5180 "FALSE",
5181 "UNKNOWN",
5182 "EMPTY ARRAY",
5183 "EMPTY OBJECT",
5184 "DEFAULT"
5185 };
5186
5187 return pstrdup(behavior_names[behavior->btype]);
5188}
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 4180 of file execExprInterp.c.

4181{
4182 ScalarArrayOpExprHashTable *elements_tab = (ScalarArrayOpExprHashTable *) tb->private_data;
4183 FunctionCallInfo fcinfo = &elements_tab->hash_fcinfo_data;
4184 Datum hash;
4185
4186 fcinfo->args[0].value = key;
4187 fcinfo->args[0].isnull = false;
4188
4189 hash = elements_tab->hash_finfo.fn_addr(fcinfo);
4190
4191 return DatumGetUInt32(hash);
4192}
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 4199 of file execExprInterp.c.

4200{
4201 Datum result;
4202
4203 ScalarArrayOpExprHashTable *elements_tab = (ScalarArrayOpExprHashTable *) tb->private_data;
4204 FunctionCallInfo fcinfo = elements_tab->op->d.hashedscalararrayop.fcinfo_data;
4205
4206 fcinfo->args[0].value = key1;
4207 fcinfo->args[0].isnull = false;
4208 fcinfo->args[1].value = key2;
4209 fcinfo->args[1].isnull = false;
4210
4211 result = elements_tab->op->d.hashedscalararrayop.finfo->fn_addr(fcinfo);
4212
4213 return DatumGetBool(result);
4214}

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