| 1 |
/*------------------------------------------------------------------------- |
| 2 |
* |
| 3 |
* execExpr.h |
| 4 |
* Low level infrastructure related to expression evaluation |
| 5 |
* |
| 6 |
* |
| 7 |
* Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group |
| 8 |
* Portions Copyright (c) 1994, Regents of the University of California |
| 9 |
* |
| 10 |
* src/include/executor/execExpr.h |
| 11 |
* |
| 12 |
*------------------------------------------------------------------------- |
| 13 |
*/ |
| 14 |
#ifndef EXEC_EXPR_H |
| 15 |
#define EXEC_EXPR_H |
| 16 |
|
| 17 |
#include "executor/nodeAgg.h" |
| 18 |
#include "nodes/execnodes.h" |
| 19 |
#include "nodes/miscnodes.h" |
| 20 |
|
| 21 |
/* forward references to avoid circularity */ |
| 22 |
struct ExprEvalStep; |
| 23 |
struct SubscriptingRefState; |
| 24 |
struct ScalarArrayOpExprHashTable; |
| 25 |
struct JsonConstructorExprState; |
| 26 |
|
| 27 |
/* Bits in ExprState->flags (see also execnodes.h for public flag bits): */ |
| 28 |
/* expression's interpreter has been initialized */ |
| 29 |
#define EEO_FLAG_INTERPRETER_INITIALIZED (1 << 5) |
| 30 |
/* jump-threading is in use */ |
| 31 |
#define EEO_FLAG_DIRECT_THREADED (1 << 6) |
| 32 |
|
| 33 |
/* Typical API for out-of-line evaluation subroutines */ |
| 34 |
typedef void (*ExecEvalSubroutine) (ExprState *state, |
| 35 |
struct ExprEvalStep *op, |
| 36 |
ExprContext *econtext); |
| 37 |
|
| 38 |
/* API for out-of-line evaluation subroutines returning bool */ |
| 39 |
typedef bool (*ExecEvalBoolSubroutine) (ExprState *state, |
| 40 |
struct ExprEvalStep *op, |
| 41 |
ExprContext *econtext); |
| 42 |
|
| 43 |
/* ExprEvalSteps that cache a composite type's tupdesc need one of these */ |
| 44 |
/* (it fits in-line in some step types, otherwise allocate out-of-line) */ |
| 45 |
typedef struct ExprEvalRowtypeCache |
| 46 |
{ |
| 47 |
/* |
| 48 |
* cacheptr points to composite type's TypeCacheEntry if tupdesc_id is not |
| 49 |
* 0; or for an anonymous RECORD type, it points directly at the cached |
| 50 |
* tupdesc for the type, and tupdesc_id is 0. (We'd use separate fields |
| 51 |
* if space were not at a premium.) Initial state is cacheptr == NULL. |
| 52 |
*/ |
| 53 |
void *cacheptr; |
| 54 |
uint64 tupdesc_id; /* last-seen tupdesc identifier, or 0 */ |
| 55 |
} ExprEvalRowtypeCache; |
| 56 |
|
| 57 |
/* |
| 58 |
* Discriminator for ExprEvalSteps. |
| 59 |
* |
| 60 |
* Identifies the operation to be executed and which member in the |
| 61 |
* ExprEvalStep->d union is valid. |
| 62 |
* |
| 63 |
* The order of entries needs to be kept in sync with the dispatch_table[] |
| 64 |
* array in execExprInterp.c:ExecInterpExpr(). |
| 65 |
*/ |
| 66 |
typedef enum ExprEvalOp |
| 67 |
{ |
| 68 |
/* entire expression has been evaluated, return value */ |
| 69 |
EEOP_DONE_RETURN, |
| 70 |
|
| 71 |
/* entire expression has been evaluated, no return value */ |
| 72 |
EEOP_DONE_NO_RETURN, |
| 73 |
|
| 74 |
/* apply slot_getsomeattrs on corresponding tuple slot */ |
| 75 |
EEOP_INNER_FETCHSOME, |
| 76 |
EEOP_OUTER_FETCHSOME, |
| 77 |
EEOP_SCAN_FETCHSOME, |
| 78 |
EEOP_OLD_FETCHSOME, |
| 79 |
EEOP_NEW_FETCHSOME, |
| 80 |
|
| 81 |
/* compute non-system Var value */ |
| 82 |
EEOP_INNER_VAR, |
| 83 |
EEOP_OUTER_VAR, |
| 84 |
EEOP_SCAN_VAR, |
| 85 |
EEOP_OLD_VAR, |
| 86 |
EEOP_NEW_VAR, |
| 87 |
|
| 88 |
/* compute system Var value */ |
| 89 |
EEOP_INNER_SYSVAR, |
| 90 |
EEOP_OUTER_SYSVAR, |
| 91 |
EEOP_SCAN_SYSVAR, |
| 92 |
EEOP_OLD_SYSVAR, |
| 93 |
EEOP_NEW_SYSVAR, |
| 94 |
|
| 95 |
/* compute wholerow Var */ |
| 96 |
EEOP_WHOLEROW, |
| 97 |
|
| 98 |
/* |
| 99 |
* Compute non-system Var value, assign it into ExprState's resultslot. |
| 100 |
* These are not used if a CheckVarSlotCompatibility() check would be |
| 101 |
* needed. |
| 102 |
*/ |
| 103 |
EEOP_ASSIGN_INNER_VAR, |
| 104 |
EEOP_ASSIGN_OUTER_VAR, |
| 105 |
EEOP_ASSIGN_SCAN_VAR, |
| 106 |
EEOP_ASSIGN_OLD_VAR, |
| 107 |
EEOP_ASSIGN_NEW_VAR, |
| 108 |
|
| 109 |
/* assign ExprState's resvalue/resnull to a column of its resultslot */ |
| 110 |
EEOP_ASSIGN_TMP, |
| 111 |
/* ditto, applying MakeExpandedObjectReadOnly() */ |
| 112 |
EEOP_ASSIGN_TMP_MAKE_RO, |
| 113 |
|
| 114 |
/* evaluate Const value */ |
| 115 |
EEOP_CONST, |
| 116 |
|
| 117 |
/* |
| 118 |
* Evaluate function call (including OpExprs etc). For speed, we |
| 119 |
* distinguish in the opcode whether the function is strict with 1, 2, or |
| 120 |
* more arguments and/or requires usage stats tracking. |
| 121 |
*/ |
| 122 |
EEOP_FUNCEXPR, |
| 123 |
EEOP_FUNCEXPR_STRICT, |
| 124 |
EEOP_FUNCEXPR_STRICT_1, |
| 125 |
EEOP_FUNCEXPR_STRICT_2, |
| 126 |
EEOP_FUNCEXPR_FUSAGE, |
| 127 |
EEOP_FUNCEXPR_STRICT_FUSAGE, |
| 128 |
|
| 129 |
/* |
| 130 |
* Evaluate boolean AND expression, one step per subexpression. FIRST/LAST |
| 131 |
* subexpressions are special-cased for performance. Since AND always has |
| 132 |
* at least two subexpressions, FIRST and LAST never apply to the same |
| 133 |
* subexpression. |
| 134 |
*/ |
| 135 |
EEOP_BOOL_AND_STEP_FIRST, |
| 136 |
EEOP_BOOL_AND_STEP, |
| 137 |
EEOP_BOOL_AND_STEP_LAST, |
| 138 |
|
| 139 |
/* similarly for boolean OR expression */ |
| 140 |
EEOP_BOOL_OR_STEP_FIRST, |
| 141 |
EEOP_BOOL_OR_STEP, |
| 142 |
EEOP_BOOL_OR_STEP_LAST, |
| 143 |
|
| 144 |
/* evaluate boolean NOT expression */ |
| 145 |
EEOP_BOOL_NOT_STEP, |
| 146 |
|
| 147 |
/* simplified version of BOOL_AND_STEP for use by ExecQual() */ |
| 148 |
EEOP_QUAL, |
| 149 |
|
| 150 |
/* unconditional jump to another step */ |
| 151 |
EEOP_JUMP, |
| 152 |
|
| 153 |
/* conditional jumps based on current result value */ |
| 154 |
EEOP_JUMP_IF_NULL, |
| 155 |
EEOP_JUMP_IF_NOT_NULL, |
| 156 |
EEOP_JUMP_IF_NOT_TRUE, |
| 157 |
|
| 158 |
/* perform NULL tests for scalar values */ |
| 159 |
EEOP_NULLTEST_ISNULL, |
| 160 |
EEOP_NULLTEST_ISNOTNULL, |
| 161 |
|
| 162 |
/* perform NULL tests for row values */ |
| 163 |
EEOP_NULLTEST_ROWISNULL, |
| 164 |
EEOP_NULLTEST_ROWISNOTNULL, |
| 165 |
|
| 166 |
/* evaluate a BooleanTest expression */ |
| 167 |
EEOP_BOOLTEST_IS_TRUE, |
| 168 |
EEOP_BOOLTEST_IS_NOT_TRUE, |
| 169 |
EEOP_BOOLTEST_IS_FALSE, |
| 170 |
EEOP_BOOLTEST_IS_NOT_FALSE, |
| 171 |
|
| 172 |
/* evaluate PARAM_EXEC/EXTERN parameters */ |
| 173 |
EEOP_PARAM_EXEC, |
| 174 |
EEOP_PARAM_EXTERN, |
| 175 |
EEOP_PARAM_CALLBACK, |
| 176 |
/* set PARAM_EXEC value */ |
| 177 |
EEOP_PARAM_SET, |
| 178 |
|
| 179 |
/* return CaseTestExpr value */ |
| 180 |
EEOP_CASE_TESTVAL, |
| 181 |
EEOP_CASE_TESTVAL_EXT, |
| 182 |
|
| 183 |
/* apply MakeExpandedObjectReadOnly() to target value */ |
| 184 |
EEOP_MAKE_READONLY, |
| 185 |
|
| 186 |
/* evaluate assorted special-purpose expression types */ |
| 187 |
EEOP_IOCOERCE, |
| 188 |
EEOP_IOCOERCE_SAFE, |
| 189 |
EEOP_DISTINCT, |
| 190 |
EEOP_NOT_DISTINCT, |
| 191 |
EEOP_NULLIF, |
| 192 |
EEOP_SQLVALUEFUNCTION, |
| 193 |
EEOP_CURRENTOFEXPR, |
| 194 |
EEOP_NEXTVALUEEXPR, |
| 195 |
EEOP_RETURNINGEXPR, |
| 196 |
EEOP_ARRAYEXPR, |
| 197 |
EEOP_ARRAYCOERCE, |
| 198 |
EEOP_ROW, |
| 199 |
|
| 200 |
/* |
| 201 |
* Compare two individual elements of each of two compared ROW() |
| 202 |
* expressions. Skip to ROWCOMPARE_FINAL if elements are not equal. |
| 203 |
*/ |
| 204 |
EEOP_ROWCOMPARE_STEP, |
| 205 |
|
| 206 |
/* evaluate boolean value based on previous ROWCOMPARE_STEP operations */ |
| 207 |
EEOP_ROWCOMPARE_FINAL, |
| 208 |
|
| 209 |
/* evaluate GREATEST() or LEAST() */ |
| 210 |
EEOP_MINMAX, |
| 211 |
|
| 212 |
/* evaluate FieldSelect expression */ |
| 213 |
EEOP_FIELDSELECT, |
| 214 |
|
| 215 |
/* |
| 216 |
* Deform tuple before evaluating new values for individual fields in a |
| 217 |
* FieldStore expression. |
| 218 |
*/ |
| 219 |
EEOP_FIELDSTORE_DEFORM, |
| 220 |
|
| 221 |
/* |
| 222 |
* Form the new tuple for a FieldStore expression. Individual fields will |
| 223 |
* have been evaluated into columns of the tuple deformed by the preceding |
| 224 |
* DEFORM step. |
| 225 |
*/ |
| 226 |
EEOP_FIELDSTORE_FORM, |
| 227 |
|
| 228 |
/* Process container subscripts; possibly short-circuit result to NULL */ |
| 229 |
EEOP_SBSREF_SUBSCRIPTS, |
| 230 |
|
| 231 |
/* |
| 232 |
* Compute old container element/slice when a SubscriptingRef assignment |
| 233 |
* expression contains SubscriptingRef/FieldStore subexpressions. Value is |
| 234 |
* accessed using the CaseTest mechanism. |
| 235 |
*/ |
| 236 |
EEOP_SBSREF_OLD, |
| 237 |
|
| 238 |
/* compute new value for SubscriptingRef assignment expression */ |
| 239 |
EEOP_SBSREF_ASSIGN, |
| 240 |
|
| 241 |
/* compute element/slice for SubscriptingRef fetch expression */ |
| 242 |
EEOP_SBSREF_FETCH, |
| 243 |
|
| 244 |
/* evaluate value for CoerceToDomainValue */ |
| 245 |
EEOP_DOMAIN_TESTVAL, |
| 246 |
EEOP_DOMAIN_TESTVAL_EXT, |
| 247 |
|
| 248 |
/* evaluate a domain's NOT NULL constraint */ |
| 249 |
EEOP_DOMAIN_NOTNULL, |
| 250 |
|
| 251 |
/* evaluate a single domain CHECK constraint */ |
| 252 |
EEOP_DOMAIN_CHECK, |
| 253 |
|
| 254 |
/* evaluation steps for hashing */ |
| 255 |
EEOP_HASHDATUM_SET_INITVAL, |
| 256 |
EEOP_HASHDATUM_FIRST, |
| 257 |
EEOP_HASHDATUM_FIRST_STRICT, |
| 258 |
EEOP_HASHDATUM_NEXT32, |
| 259 |
EEOP_HASHDATUM_NEXT32_STRICT, |
| 260 |
|
| 261 |
/* evaluate assorted special-purpose expression types */ |
| 262 |
EEOP_CONVERT_ROWTYPE, |
| 263 |
EEOP_SCALARARRAYOP, |
| 264 |
EEOP_HASHED_SCALARARRAYOP, |
| 265 |
EEOP_XMLEXPR, |
| 266 |
EEOP_JSON_CONSTRUCTOR, |
| 267 |
EEOP_IS_JSON, |
| 268 |
EEOP_JSONEXPR_PATH, |
| 269 |
EEOP_JSONEXPR_COERCION, |
| 270 |
EEOP_JSONEXPR_COERCION_FINISH, |
| 271 |
EEOP_AGGREF, |
| 272 |
EEOP_GROUPING_FUNC, |
| 273 |
EEOP_WINDOW_FUNC, |
| 274 |
EEOP_MERGE_SUPPORT_FUNC, |
| 275 |
EEOP_SUBPLAN, |
| 276 |
|
| 277 |
/* aggregation related nodes */ |
| 278 |
EEOP_AGG_STRICT_DESERIALIZE, |
| 279 |
EEOP_AGG_DESERIALIZE, |
| 280 |
EEOP_AGG_STRICT_INPUT_CHECK_ARGS, |
| 281 |
EEOP_AGG_STRICT_INPUT_CHECK_ARGS_1, |
| 282 |
EEOP_AGG_STRICT_INPUT_CHECK_NULLS, |
| 283 |
EEOP_AGG_PLAIN_PERGROUP_NULLCHECK, |
| 284 |
EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYVAL, |
| 285 |
EEOP_AGG_PLAIN_TRANS_STRICT_BYVAL, |
| 286 |
EEOP_AGG_PLAIN_TRANS_BYVAL, |
| 287 |
EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYREF, |
| 288 |
EEOP_AGG_PLAIN_TRANS_STRICT_BYREF, |
| 289 |
EEOP_AGG_PLAIN_TRANS_BYREF, |
| 290 |
EEOP_AGG_PRESORTED_DISTINCT_SINGLE, |
| 291 |
EEOP_AGG_PRESORTED_DISTINCT_MULTI, |
| 292 |
EEOP_AGG_ORDERED_TRANS_DATUM, |
| 293 |
EEOP_AGG_ORDERED_TRANS_TUPLE, |
| 294 |
|
| 295 |
/* non-existent operation, used e.g. to check array lengths */ |
| 296 |
EEOP_LAST |
| 297 |
} ExprEvalOp; |
| 298 |
|
| 299 |
|
| 300 |
typedef struct ExprEvalStep |
| 301 |
{ |
| 302 |
/* |
| 303 |
* Instruction to be executed. During instruction preparation this is an |
| 304 |
* enum ExprEvalOp, but later it can be changed to some other type, e.g. a |
| 305 |
* pointer for computed goto (that's why it's an intptr_t). |
| 306 |
*/ |
| 307 |
intptr_t opcode; |
| 308 |
|
| 309 |
/* where to store the result of this step */ |
| 310 |
Datum *resvalue; |
| 311 |
bool *resnull; |
| 312 |
|
| 313 |
/* |
| 314 |
* Inline data for the operation. Inline data is faster to access, but |
| 315 |
* also bloats the size of all instructions. The union should be kept to |
| 316 |
* no more than 40 bytes on 64-bit systems (so that the entire struct is |
| 317 |
* no more than 64 bytes, a single cacheline on common systems). |
| 318 |
*/ |
| 319 |
union |
| 320 |
{ |
| 321 |
/* for EEOP_INNER/OUTER/SCAN/OLD/NEW_FETCHSOME */ |
| 322 |
struct |
| 323 |
{ |
| 324 |
/* attribute number up to which to fetch (inclusive) */ |
| 325 |
int last_var; |
| 326 |
/* will the type of slot be the same for every invocation */ |
| 327 |
bool fixed; |
| 328 |
/* tuple descriptor, if known */ |
| 329 |
TupleDesc known_desc; |
| 330 |
/* type of slot, can only be relied upon if fixed is set */ |
| 331 |
const TupleTableSlotOps *kind; |
| 332 |
} fetch; |
| 333 |
|
| 334 |
/* for EEOP_INNER/OUTER/SCAN/OLD/NEW_[SYS]VAR */ |
| 335 |
struct |
| 336 |
{ |
| 337 |
/* attnum is attr number - 1 for regular VAR ... */ |
| 338 |
/* but it's just the normal (negative) attr number for SYSVAR */ |
| 339 |
int attnum; |
| 340 |
Oid vartype; /* type OID of variable */ |
| 341 |
VarReturningType varreturningtype; /* return old/new/default */ |
| 342 |
} var; |
| 343 |
|
| 344 |
/* for EEOP_WHOLEROW */ |
| 345 |
struct |
| 346 |
{ |
| 347 |
Var *var; /* original Var node in plan tree */ |
| 348 |
bool first; /* first time through, need to initialize? */ |
| 349 |
bool slow; /* need runtime check for nulls? */ |
| 350 |
TupleDesc tupdesc; /* descriptor for resulting tuples */ |
| 351 |
JunkFilter *junkFilter; /* JunkFilter to remove resjunk cols */ |
| 352 |
} wholerow; |
| 353 |
|
| 354 |
/* for EEOP_ASSIGN_*_VAR */ |
| 355 |
struct |
| 356 |
{ |
| 357 |
/* target index in ExprState->resultslot->tts_values/nulls */ |
| 358 |
int resultnum; |
| 359 |
/* source attribute number - 1 */ |
| 360 |
int attnum; |
| 361 |
} assign_var; |
| 362 |
|
| 363 |
/* for EEOP_ASSIGN_TMP[_MAKE_RO] */ |
| 364 |
struct |
| 365 |
{ |
| 366 |
/* target index in ExprState->resultslot->tts_values/nulls */ |
| 367 |
int resultnum; |
| 368 |
} assign_tmp; |
| 369 |
|
| 370 |
/* for EEOP_RETURNINGEXPR */ |
| 371 |
struct |
| 372 |
{ |
| 373 |
uint8 nullflag; /* flag to test if OLD/NEW row is NULL */ |
| 374 |
int jumpdone; /* jump here if OLD/NEW row is NULL */ |
| 375 |
} returningexpr; |
| 376 |
|
| 377 |
/* for EEOP_CONST */ |
| 378 |
struct |
| 379 |
{ |
| 380 |
/* constant's value */ |
| 381 |
Datum value; |
| 382 |
bool isnull; |
| 383 |
} constval; |
| 384 |
|
| 385 |
/* for EEOP_FUNCEXPR_* / NULLIF / DISTINCT */ |
| 386 |
struct |
| 387 |
{ |
| 388 |
FmgrInfo *finfo; /* function's lookup data */ |
| 389 |
FunctionCallInfo fcinfo_data; /* arguments etc */ |
| 390 |
/* faster to access without additional indirection: */ |
| 391 |
PGFunction fn_addr; /* actual call address */ |
| 392 |
int nargs; /* number of arguments */ |
| 393 |
bool make_ro; /* make arg0 R/O (used only for NULLIF) */ |
| 394 |
} func; |
| 395 |
|
| 396 |
/* for EEOP_BOOL_*_STEP */ |
| 397 |
struct |
| 398 |
{ |
| 399 |
bool *anynull; /* track if any input was NULL */ |
| 400 |
int jumpdone; /* jump here if result determined */ |
| 401 |
} boolexpr; |
| 402 |
|
| 403 |
/* for EEOP_QUAL */ |
| 404 |
struct |
| 405 |
{ |
| 406 |
int jumpdone; /* jump here on false or null */ |
| 407 |
} qualexpr; |
| 408 |
|
| 409 |
/* for EEOP_JUMP[_CONDITION] */ |
| 410 |
struct |
| 411 |
{ |
| 412 |
int jumpdone; /* target instruction's index */ |
| 413 |
} jump; |
| 414 |
|
| 415 |
/* for EEOP_NULLTEST_ROWIS[NOT]NULL */ |
| 416 |
struct |
| 417 |
{ |
| 418 |
/* cached descriptor for composite type - filled at runtime */ |
| 419 |
ExprEvalRowtypeCache rowcache; |
| 420 |
} nulltest_row; |
| 421 |
|
| 422 |
/* for EEOP_PARAM_EXEC/EXTERN and EEOP_PARAM_SET */ |
| 423 |
struct |
| 424 |
{ |
| 425 |
int paramid; /* numeric ID for parameter */ |
| 426 |
Oid paramtype; /* OID of parameter's datatype */ |
| 427 |
} param; |
| 428 |
|
| 429 |
/* for EEOP_PARAM_CALLBACK */ |
| 430 |
struct |
| 431 |
{ |
| 432 |
ExecEvalSubroutine paramfunc; /* add-on evaluation subroutine */ |
| 433 |
void *paramarg; /* private data for same */ |
| 434 |
void *paramarg2; /* more private data for same */ |
| 435 |
int paramid; /* numeric ID for parameter */ |
| 436 |
Oid paramtype; /* OID of parameter's datatype */ |
| 437 |
} cparam; |
| 438 |
|
| 439 |
/* for EEOP_CASE_TESTVAL/DOMAIN_TESTVAL */ |
| 440 |
struct |
| 441 |
{ |
| 442 |
Datum *value; /* value to return */ |
| 443 |
bool *isnull; |
| 444 |
} casetest; |
| 445 |
|
| 446 |
/* for EEOP_MAKE_READONLY */ |
| 447 |
struct |
| 448 |
{ |
| 449 |
Datum *value; /* value to coerce to read-only */ |
| 450 |
bool *isnull; |
| 451 |
} make_readonly; |
| 452 |
|
| 453 |
/* for EEOP_IOCOERCE */ |
| 454 |
struct |
| 455 |
{ |
| 456 |
/* lookup and call info for source type's output function */ |
| 457 |
FmgrInfo *finfo_out; |
| 458 |
FunctionCallInfo fcinfo_data_out; |
| 459 |
/* lookup and call info for result type's input function */ |
| 460 |
FmgrInfo *finfo_in; |
| 461 |
FunctionCallInfo fcinfo_data_in; |
| 462 |
} iocoerce; |
| 463 |
|
| 464 |
/* for EEOP_SQLVALUEFUNCTION */ |
| 465 |
struct |
| 466 |
{ |
| 467 |
SQLValueFunction *svf; |
| 468 |
} sqlvaluefunction; |
| 469 |
|
| 470 |
/* for EEOP_NEXTVALUEEXPR */ |
| 471 |
struct |
| 472 |
{ |
| 473 |
Oid seqid; |
| 474 |
Oid seqtypid; |
| 475 |
} nextvalueexpr; |
| 476 |
|
| 477 |
/* for EEOP_ARRAYEXPR */ |
| 478 |
struct |
| 479 |
{ |
| 480 |
Datum *elemvalues; /* element values get stored here */ |
| 481 |
bool *elemnulls; |
| 482 |
int nelems; /* length of the above arrays */ |
| 483 |
Oid elemtype; /* array element type */ |
| 484 |
int16 elemlength; /* typlen of the array element type */ |
| 485 |
bool elembyval; /* is the element type pass-by-value? */ |
| 486 |
char elemalign; /* typalign of the element type */ |
| 487 |
bool multidims; /* is array expression multi-D? */ |
| 488 |
} arrayexpr; |
| 489 |
|
| 490 |
/* for EEOP_ARRAYCOERCE */ |
| 491 |
struct |
| 492 |
{ |
| 493 |
ExprState *elemexprstate; /* null if no per-element work */ |
| 494 |
Oid resultelemtype; /* element type of result array */ |
| 495 |
struct ArrayMapState *amstate; /* workspace for array_map */ |
| 496 |
} arraycoerce; |
| 497 |
|
| 498 |
/* for EEOP_ROW */ |
| 499 |
struct |
| 500 |
{ |
| 501 |
TupleDesc tupdesc; /* descriptor for result tuples */ |
| 502 |
/* workspace for the values constituting the row: */ |
| 503 |
Datum *elemvalues; |
| 504 |
bool *elemnulls; |
| 505 |
} row; |
| 506 |
|
| 507 |
/* for EEOP_ROWCOMPARE_STEP */ |
| 508 |
struct |
| 509 |
{ |
| 510 |
/* lookup and call data for column comparison function */ |
| 511 |
FmgrInfo *finfo; |
| 512 |
FunctionCallInfo fcinfo_data; |
| 513 |
PGFunction fn_addr; |
| 514 |
/* target for comparison resulting in NULL */ |
| 515 |
int jumpnull; |
| 516 |
/* target for comparison yielding inequality */ |
| 517 |
int jumpdone; |
| 518 |
} rowcompare_step; |
| 519 |
|
| 520 |
/* for EEOP_ROWCOMPARE_FINAL */ |
| 521 |
struct |
| 522 |
{ |
| 523 |
CompareType cmptype; |
| 524 |
} rowcompare_final; |
| 525 |
|
| 526 |
/* for EEOP_MINMAX */ |
| 527 |
struct |
| 528 |
{ |
| 529 |
/* workspace for argument values */ |
| 530 |
Datum *values; |
| 531 |
bool *nulls; |
| 532 |
int nelems; |
| 533 |
/* is it GREATEST or LEAST? */ |
| 534 |
MinMaxOp op; |
| 535 |
/* lookup and call data for comparison function */ |
| 536 |
FmgrInfo *finfo; |
| 537 |
FunctionCallInfo fcinfo_data; |
| 538 |
} minmax; |
| 539 |
|
| 540 |
/* for EEOP_FIELDSELECT */ |
| 541 |
struct |
| 542 |
{ |
| 543 |
AttrNumber fieldnum; /* field number to extract */ |
| 544 |
Oid resulttype; /* field's type */ |
| 545 |
/* cached descriptor for composite type - filled at runtime */ |
| 546 |
ExprEvalRowtypeCache rowcache; |
| 547 |
} fieldselect; |
| 548 |
|
| 549 |
/* for EEOP_FIELDSTORE_DEFORM / FIELDSTORE_FORM */ |
| 550 |
struct |
| 551 |
{ |
| 552 |
/* original expression node */ |
| 553 |
FieldStore *fstore; |
| 554 |
|
| 555 |
/* cached descriptor for composite type - filled at runtime */ |
| 556 |
/* note that a DEFORM and FORM pair share the same cache */ |
| 557 |
ExprEvalRowtypeCache *rowcache; |
| 558 |
|
| 559 |
/* workspace for column values */ |
| 560 |
Datum *values; |
| 561 |
bool *nulls; |
| 562 |
int ncolumns; |
| 563 |
} fieldstore; |
| 564 |
|
| 565 |
/* for EEOP_SBSREF_SUBSCRIPTS */ |
| 566 |
struct |
| 567 |
{ |
| 568 |
ExecEvalBoolSubroutine subscriptfunc; /* evaluation subroutine */ |
| 569 |
/* too big to have inline */ |
| 570 |
struct SubscriptingRefState *state; |
| 571 |
int jumpdone; /* jump here on null */ |
| 572 |
} sbsref_subscript; |
| 573 |
|
| 574 |
/* for EEOP_SBSREF_OLD / ASSIGN / FETCH */ |
| 575 |
struct |
| 576 |
{ |
| 577 |
ExecEvalSubroutine subscriptfunc; /* evaluation subroutine */ |
| 578 |
/* too big to have inline */ |
| 579 |
struct SubscriptingRefState *state; |
| 580 |
} sbsref; |
| 581 |
|
| 582 |
/* for EEOP_DOMAIN_NOTNULL / DOMAIN_CHECK */ |
| 583 |
struct |
| 584 |
{ |
| 585 |
/* name of constraint */ |
| 586 |
char *constraintname; |
| 587 |
/* where the result of a CHECK constraint will be stored */ |
| 588 |
Datum *checkvalue; |
| 589 |
bool *checknull; |
| 590 |
/* OID of domain type */ |
| 591 |
Oid resulttype; |
| 592 |
ErrorSaveContext *escontext; |
| 593 |
} domaincheck; |
| 594 |
|
| 595 |
/* for EEOP_HASH_SET_INITVAL */ |
| 596 |
struct |
| 597 |
{ |
| 598 |
Datum init_value; |
| 599 |
|
| 600 |
} hashdatum_initvalue; |
| 601 |
|
| 602 |
/* for EEOP_HASHDATUM_(FIRST|NEXT32)[_STRICT] */ |
| 603 |
struct |
| 604 |
{ |
| 605 |
FmgrInfo *finfo; /* function's lookup data */ |
| 606 |
FunctionCallInfo fcinfo_data; /* arguments etc */ |
| 607 |
/* faster to access without additional indirection: */ |
| 608 |
PGFunction fn_addr; /* actual call address */ |
| 609 |
int jumpdone; /* jump here on null */ |
| 610 |
NullableDatum *iresult; /* intermediate hash result */ |
| 611 |
} hashdatum; |
| 612 |
|
| 613 |
/* for EEOP_CONVERT_ROWTYPE */ |
| 614 |
struct |
| 615 |
{ |
| 616 |
Oid inputtype; /* input composite type */ |
| 617 |
Oid outputtype; /* output composite type */ |
| 618 |
/* these three fields are filled at runtime: */ |
| 619 |
ExprEvalRowtypeCache *incache; /* cache for input type */ |
| 620 |
ExprEvalRowtypeCache *outcache; /* cache for output type */ |
| 621 |
TupleConversionMap *map; /* column mapping */ |
| 622 |
} convert_rowtype; |
| 623 |
|
| 624 |
/* for EEOP_SCALARARRAYOP */ |
| 625 |
struct |
| 626 |
{ |
| 627 |
/* element_type/typlen/typbyval/typalign are filled at runtime */ |
| 628 |
Oid element_type; /* InvalidOid if not yet filled */ |
| 629 |
bool useOr; /* use OR or AND semantics? */ |
| 630 |
int16 typlen; /* array element type storage info */ |
| 631 |
bool typbyval; |
| 632 |
char typalign; |
| 633 |
FmgrInfo *finfo; /* function's lookup data */ |
| 634 |
FunctionCallInfo fcinfo_data; /* arguments etc */ |
| 635 |
/* faster to access without additional indirection: */ |
| 636 |
PGFunction fn_addr; /* actual call address */ |
| 637 |
} scalararrayop; |
| 638 |
|
| 639 |
/* for EEOP_HASHED_SCALARARRAYOP */ |
| 640 |
struct |
| 641 |
{ |
| 642 |
bool has_nulls; |
| 643 |
bool inclause; /* true for IN and false for NOT IN */ |
| 644 |
bool null_lhs_result; /* for non-strict lookups, we |
| 645 |
* cache what looking up NULL |
| 646 |
* returns. */ |
| 647 |
bool null_lhs_isnull; |
| 648 |
struct ScalarArrayOpExprHashTable *elements_tab; |
| 649 |
FmgrInfo *finfo; /* function's lookup data */ |
| 650 |
FunctionCallInfo fcinfo_data; /* arguments etc */ |
| 651 |
ScalarArrayOpExpr *saop; |
| 652 |
} hashedscalararrayop; |
| 653 |
|
| 654 |
/* for EEOP_XMLEXPR */ |
| 655 |
struct |
| 656 |
{ |
| 657 |
XmlExpr *xexpr; /* original expression node */ |
| 658 |
/* workspace for evaluating named args, if any */ |
| 659 |
Datum *named_argvalue; |
| 660 |
bool *named_argnull; |
| 661 |
/* workspace for evaluating unnamed args, if any */ |
| 662 |
Datum *argvalue; |
| 663 |
bool *argnull; |
| 664 |
} xmlexpr; |
| 665 |
|
| 666 |
/* for EEOP_JSON_CONSTRUCTOR */ |
| 667 |
struct |
| 668 |
{ |
| 669 |
struct JsonConstructorExprState *jcstate; |
| 670 |
} json_constructor; |
| 671 |
|
| 672 |
/* for EEOP_AGGREF */ |
| 673 |
struct |
| 674 |
{ |
| 675 |
int aggno; |
| 676 |
} aggref; |
| 677 |
|
| 678 |
/* for EEOP_GROUPING_FUNC */ |
| 679 |
struct |
| 680 |
{ |
| 681 |
List *clauses; /* integer list of column numbers */ |
| 682 |
} grouping_func; |
| 683 |
|
| 684 |
/* for EEOP_WINDOW_FUNC */ |
| 685 |
struct |
| 686 |
{ |
| 687 |
/* out-of-line state, modified by nodeWindowAgg.c */ |
| 688 |
WindowFuncExprState *wfstate; |
| 689 |
} window_func; |
| 690 |
|
| 691 |
/* for EEOP_SUBPLAN */ |
| 692 |
struct |
| 693 |
{ |
| 694 |
/* out-of-line state, created by nodeSubplan.c */ |
| 695 |
SubPlanState *sstate; |
| 696 |
} subplan; |
| 697 |
|
| 698 |
/* for EEOP_AGG_*DESERIALIZE */ |
| 699 |
struct |
| 700 |
{ |
| 701 |
FunctionCallInfo fcinfo_data; |
| 702 |
int jumpnull; |
| 703 |
} agg_deserialize; |
| 704 |
|
| 705 |
/* for EEOP_AGG_STRICT_INPUT_CHECK_NULLS / STRICT_INPUT_CHECK_ARGS */ |
| 706 |
struct |
| 707 |
{ |
| 708 |
/* |
| 709 |
* For EEOP_AGG_STRICT_INPUT_CHECK_ARGS args contains pointers to |
| 710 |
* the NullableDatums that need to be checked for NULLs. |
| 711 |
* |
| 712 |
* For EEOP_AGG_STRICT_INPUT_CHECK_NULLS nulls contains pointers |
| 713 |
* to booleans that need to be checked for NULLs. |
| 714 |
* |
| 715 |
* Both cases currently need to exist because sometimes the |
| 716 |
* to-be-checked nulls are in TupleTableSlot.isnull array, and |
| 717 |
* sometimes in FunctionCallInfoBaseData.args[i].isnull. |
| 718 |
*/ |
| 719 |
NullableDatum *args; |
| 720 |
bool *nulls; |
| 721 |
int nargs; |
| 722 |
int jumpnull; |
| 723 |
} agg_strict_input_check; |
| 724 |
|
| 725 |
/* for EEOP_AGG_PLAIN_PERGROUP_NULLCHECK */ |
| 726 |
struct |
| 727 |
{ |
| 728 |
int setoff; |
| 729 |
int jumpnull; |
| 730 |
} agg_plain_pergroup_nullcheck; |
| 731 |
|
| 732 |
/* for EEOP_AGG_PRESORTED_DISTINCT_{SINGLE,MULTI} */ |
| 733 |
struct |
| 734 |
{ |
| 735 |
AggStatePerTrans pertrans; |
| 736 |
ExprContext *aggcontext; |
| 737 |
int jumpdistinct; |
| 738 |
} agg_presorted_distinctcheck; |
| 739 |
|
| 740 |
/* for EEOP_AGG_PLAIN_TRANS_[INIT_][STRICT_]{BYVAL,BYREF} */ |
| 741 |
/* for EEOP_AGG_ORDERED_TRANS_{DATUM,TUPLE} */ |
| 742 |
struct |
| 743 |
{ |
| 744 |
AggStatePerTrans pertrans; |
| 745 |
ExprContext *aggcontext; |
| 746 |
int setno; |
| 747 |
int transno; |
| 748 |
int setoff; |
| 749 |
} agg_trans; |
| 750 |
|
| 751 |
/* for EEOP_IS_JSON */ |
| 752 |
struct |
| 753 |
{ |
| 754 |
JsonIsPredicate *pred; /* original expression node */ |
| 755 |
} is_json; |
| 756 |
|
| 757 |
/* for EEOP_JSONEXPR_PATH */ |
| 758 |
struct |
| 759 |
{ |
| 760 |
struct JsonExprState *jsestate; |
| 761 |
} jsonexpr; |
| 762 |
|
| 763 |
/* for EEOP_JSONEXPR_COERCION */ |
| 764 |
struct |
| 765 |
{ |
| 766 |
Oid targettype; |
| 767 |
int32 targettypmod; |
| 768 |
bool omit_quotes; |
| 769 |
/* exists_* fields only relevant for JSON_EXISTS_OP. */ |
| 770 |
bool exists_coerce; |
| 771 |
bool exists_cast_to_int; |
| 772 |
bool exists_check_domain; |
| 773 |
void *json_coercion_cache; |
| 774 |
ErrorSaveContext *escontext; |
| 775 |
} jsonexpr_coercion; |
| 776 |
} d; |
| 777 |
} ExprEvalStep; |
| 778 |
|
| 779 |
/* Enforce the size rule given in the comment above */ |
| 780 |
StaticAssertDecl(sizeof(ExprEvalStep) <= 64, |
| 781 |
"size of ExprEvalStep exceeds 64 bytes"); |
| 782 |
|
| 783 |
|
| 784 |
/* Non-inline data for container operations */ |
| 785 |
typedef struct SubscriptingRefState |
| 786 |
{ |
| 787 |
bool isassignment; /* is it assignment, or just fetch? */ |
| 788 |
|
| 789 |
/* workspace for type-specific subscripting code */ |
| 790 |
void *workspace; |
| 791 |
|
| 792 |
/* numupper and upperprovided[] are filled at expression compile time */ |
| 793 |
/* at runtime, subscripts are computed in upperindex[]/upperindexnull[] */ |
| 794 |
int numupper; |
| 795 |
bool *upperprovided; /* indicates if this position is supplied */ |
| 796 |
Datum *upperindex; |
| 797 |
bool *upperindexnull; |
| 798 |
|
| 799 |
/* similarly for lower indexes, if any */ |
| 800 |
int numlower; |
| 801 |
bool *lowerprovided; |
| 802 |
Datum *lowerindex; |
| 803 |
bool *lowerindexnull; |
| 804 |
|
| 805 |
/* for assignment, new value to assign is evaluated into here */ |
| 806 |
Datum replacevalue; |
| 807 |
bool replacenull; |
| 808 |
|
| 809 |
/* if we have a nested assignment, sbs_fetch_old puts old value here */ |
| 810 |
Datum prevvalue; |
| 811 |
bool prevnull; |
| 812 |
} SubscriptingRefState; |
| 813 |
|
| 814 |
/* Execution step methods used for SubscriptingRef */ |
| 815 |
typedef struct SubscriptExecSteps |
| 816 |
{ |
| 817 |
/* See nodes/subscripting.h for more detail about these */ |
| 818 |
ExecEvalBoolSubroutine sbs_check_subscripts; /* process subscripts */ |
| 819 |
ExecEvalSubroutine sbs_fetch; /* fetch an element */ |
| 820 |
ExecEvalSubroutine sbs_assign; /* assign to an element */ |
| 821 |
ExecEvalSubroutine sbs_fetch_old; /* fetch old value for assignment */ |
| 822 |
} SubscriptExecSteps; |
| 823 |
|
| 824 |
/* EEOP_JSON_CONSTRUCTOR state, too big to inline */ |
| 825 |
typedef struct JsonConstructorExprState |
| 826 |
{ |
| 827 |
JsonConstructorExpr *constructor; |
| 828 |
Datum *arg_values; |
| 829 |
bool *arg_nulls; |
| 830 |
Oid *arg_types; |
| 831 |
struct |
| 832 |
{ |
| 833 |
int category; |
| 834 |
Oid outfuncid; |
| 835 |
} *arg_type_cache; /* cache for datum_to_json[b]() */ |
| 836 |
int nargs; |
| 837 |
} JsonConstructorExprState; |
| 838 |
|
| 839 |
|
| 840 |
/* functions in execExpr.c */ |
| 841 |
extern void ExprEvalPushStep(ExprState *es, const ExprEvalStep *s); |
| 842 |
|
| 843 |
/* functions in execExprInterp.c */ |
| 844 |
extern void ExecReadyInterpretedExpr(ExprState *state); |
| 845 |
extern ExprEvalOp ExecEvalStepOp(ExprState *state, ExprEvalStep *op); |
| 846 |
|
| 847 |
extern Datum ExecInterpExprStillValid(ExprState *state, ExprContext *econtext, bool *isNull); |
| 848 |
extern void CheckExprStillValid(ExprState *state, ExprContext *econtext); |
| 849 |
|
| 850 |
/* |
| 851 |
* Non fast-path execution functions. These are externs instead of statics in |
| 852 |
* execExprInterp.c, because that allows them to be used by other methods of |
| 853 |
* expression evaluation, reducing code duplication. |
| 854 |
*/ |
| 855 |
extern void ExecEvalFuncExprFusage(ExprState *state, ExprEvalStep *op, |
| 856 |
ExprContext *econtext); |
| 857 |
extern void ExecEvalFuncExprStrictFusage(ExprState *state, ExprEvalStep *op, |
| 858 |
ExprContext *econtext); |
| 859 |
extern void ExecEvalParamExec(ExprState *state, ExprEvalStep *op, |
| 860 |
ExprContext *econtext); |
| 861 |
extern void ExecEvalParamSet(ExprState *state, ExprEvalStep *op, |
| 862 |
ExprContext *econtext); |
| 863 |
extern void ExecEvalParamExtern(ExprState *state, ExprEvalStep *op, |
| 864 |
ExprContext *econtext); |
| 865 |
extern void ExecEvalCoerceViaIOSafe(ExprState *state, ExprEvalStep *op); |
| 866 |
extern void ExecEvalSQLValueFunction(ExprState *state, ExprEvalStep *op); |
| 867 |
extern void ExecEvalCurrentOfExpr(ExprState *state, ExprEvalStep *op); |
| 868 |
extern void ExecEvalNextValueExpr(ExprState *state, ExprEvalStep *op); |
| 869 |
extern void ExecEvalRowNull(ExprState *state, ExprEvalStep *op, |
| 870 |
ExprContext *econtext); |
| 871 |
extern void ExecEvalRowNotNull(ExprState *state, ExprEvalStep *op, |
| 872 |
ExprContext *econtext); |
| 873 |
extern void ExecEvalArrayExpr(ExprState *state, ExprEvalStep *op); |
| 874 |
extern void ExecEvalArrayCoerce(ExprState *state, ExprEvalStep *op, |
| 875 |
ExprContext *econtext); |
| 876 |
extern void ExecEvalRow(ExprState *state, ExprEvalStep *op); |
| 877 |
extern void ExecEvalMinMax(ExprState *state, ExprEvalStep *op); |
| 878 |
extern void ExecEvalFieldSelect(ExprState *state, ExprEvalStep *op, |
| 879 |
ExprContext *econtext); |
| 880 |
extern void ExecEvalFieldStoreDeForm(ExprState *state, ExprEvalStep *op, |
| 881 |
ExprContext *econtext); |
| 882 |
extern void ExecEvalFieldStoreForm(ExprState *state, ExprEvalStep *op, |
| 883 |
ExprContext *econtext); |
| 884 |
extern void ExecEvalConvertRowtype(ExprState *state, ExprEvalStep *op, |
| 885 |
ExprContext *econtext); |
| 886 |
extern void ExecEvalScalarArrayOp(ExprState *state, ExprEvalStep *op); |
| 887 |
extern void ExecEvalHashedScalarArrayOp(ExprState *state, ExprEvalStep *op, |
| 888 |
ExprContext *econtext); |
| 889 |
extern void ExecEvalConstraintNotNull(ExprState *state, ExprEvalStep *op); |
| 890 |
extern void ExecEvalConstraintCheck(ExprState *state, ExprEvalStep *op); |
| 891 |
extern void ExecEvalXmlExpr(ExprState *state, ExprEvalStep *op); |
| 892 |
extern void ExecEvalJsonConstructor(ExprState *state, ExprEvalStep *op, |
| 893 |
ExprContext *econtext); |
| 894 |
extern void ExecEvalJsonIsPredicate(ExprState *state, ExprEvalStep *op); |
| 895 |
extern int ExecEvalJsonExprPath(ExprState *state, ExprEvalStep *op, |
| 896 |
ExprContext *econtext); |
| 897 |
extern void ExecEvalJsonCoercion(ExprState *state, ExprEvalStep *op, |
| 898 |
ExprContext *econtext); |
| 899 |
extern void ExecEvalJsonCoercionFinish(ExprState *state, ExprEvalStep *op); |
| 900 |
extern void ExecEvalGroupingFunc(ExprState *state, ExprEvalStep *op); |
| 901 |
extern void ExecEvalMergeSupportFunc(ExprState *state, ExprEvalStep *op, |
| 902 |
ExprContext *econtext); |
| 903 |
extern void ExecEvalSubPlan(ExprState *state, ExprEvalStep *op, |
| 904 |
ExprContext *econtext); |
| 905 |
extern void ExecEvalWholeRowVar(ExprState *state, ExprEvalStep *op, |
| 906 |
ExprContext *econtext); |
| 907 |
extern void ExecEvalSysVar(ExprState *state, ExprEvalStep *op, |
| 908 |
ExprContext *econtext, TupleTableSlot *slot); |
| 909 |
|
| 910 |
extern void ExecAggInitGroup(AggState *aggstate, AggStatePerTrans pertrans, AggStatePerGroup pergroup, |
| 911 |
ExprContext *aggcontext); |
| 912 |
extern Datum ExecAggCopyTransValue(AggState *aggstate, AggStatePerTrans pertrans, |
| 913 |
Datum newValue, bool newValueIsNull, |
| 914 |
Datum oldValue, bool oldValueIsNull); |
| 915 |
extern bool ExecEvalPreOrderedDistinctSingle(AggState *aggstate, |
| 916 |
AggStatePerTrans pertrans); |
| 917 |
extern bool ExecEvalPreOrderedDistinctMulti(AggState *aggstate, |
| 918 |
AggStatePerTrans pertrans); |
| 919 |
extern void ExecEvalAggOrderedTransDatum(ExprState *state, ExprEvalStep *op, |
| 920 |
ExprContext *econtext); |
| 921 |
extern void ExecEvalAggOrderedTransTuple(ExprState *state, ExprEvalStep *op, |
| 922 |
ExprContext *econtext); |
| 923 |
|
| 924 |
#endif /* EXEC_EXPR_H */ |