Remove size increase in ExprEvalStep caused by hashed saops
[pgsql.git] / src / include / executor / execExpr.h
blob1e3f1bbee8614f56c22766fb0106005c59e96df0
1 /*-------------------------------------------------------------------------
3 * execExpr.h
4 * Low level infrastructure related to expression evaluation
7 * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * src/include/executor/execExpr.h
12 *-------------------------------------------------------------------------
14 #ifndef EXEC_EXPR_H
15 #define EXEC_EXPR_H
17 #include "executor/nodeAgg.h"
18 #include "nodes/execnodes.h"
20 /* forward references to avoid circularity */
21 struct ExprEvalStep;
22 struct SubscriptingRefState;
23 struct ScalarArrayOpExprHashTable;
24 struct JsonbValue;
25 struct JsonExprState;
26 struct JsonConstructorExprState;
28 /* Bits in ExprState->flags (see also execnodes.h for public flag bits): */
29 /* expression's interpreter has been initialized */
30 #define EEO_FLAG_INTERPRETER_INITIALIZED (1 << 1)
31 /* jump-threading is in use */
32 #define EEO_FLAG_DIRECT_THREADED (1 << 2)
34 /* Typical API for out-of-line evaluation subroutines */
35 typedef void (*ExecEvalSubroutine) (ExprState *state,
36 struct ExprEvalStep *op,
37 ExprContext *econtext);
39 /* API for out-of-line evaluation subroutines returning bool */
40 typedef bool (*ExecEvalBoolSubroutine) (ExprState *state,
41 struct ExprEvalStep *op,
42 ExprContext *econtext);
44 /* ExprEvalSteps that cache a composite type's tupdesc need one of these */
45 /* (it fits in-line in some step types, otherwise allocate out-of-line) */
46 typedef struct ExprEvalRowtypeCache
49 * cacheptr points to composite type's TypeCacheEntry if tupdesc_id is not
50 * 0; or for an anonymous RECORD type, it points directly at the cached
51 * tupdesc for the type, and tupdesc_id is 0. (We'd use separate fields
52 * if space were not at a premium.) Initial state is cacheptr == NULL.
54 void *cacheptr;
55 uint64 tupdesc_id; /* last-seen tupdesc identifier, or 0 */
56 } ExprEvalRowtypeCache;
59 * Discriminator for ExprEvalSteps.
61 * Identifies the operation to be executed and which member in the
62 * ExprEvalStep->d union is valid.
64 * The order of entries needs to be kept in sync with the dispatch_table[]
65 * array in execExprInterp.c:ExecInterpExpr().
67 typedef enum ExprEvalOp
69 /* entire expression has been evaluated completely, return */
70 EEOP_DONE,
72 /* apply slot_getsomeattrs on corresponding tuple slot */
73 EEOP_INNER_FETCHSOME,
74 EEOP_OUTER_FETCHSOME,
75 EEOP_SCAN_FETCHSOME,
77 /* compute non-system Var value */
78 EEOP_INNER_VAR,
79 EEOP_OUTER_VAR,
80 EEOP_SCAN_VAR,
82 /* compute system Var value */
83 EEOP_INNER_SYSVAR,
84 EEOP_OUTER_SYSVAR,
85 EEOP_SCAN_SYSVAR,
87 /* compute wholerow Var */
88 EEOP_WHOLEROW,
91 * Compute non-system Var value, assign it into ExprState's resultslot.
92 * These are not used if a CheckVarSlotCompatibility() check would be
93 * needed.
95 EEOP_ASSIGN_INNER_VAR,
96 EEOP_ASSIGN_OUTER_VAR,
97 EEOP_ASSIGN_SCAN_VAR,
99 /* assign ExprState's resvalue/resnull to a column of its resultslot */
100 EEOP_ASSIGN_TMP,
101 /* ditto, applying MakeExpandedObjectReadOnly() */
102 EEOP_ASSIGN_TMP_MAKE_RO,
104 /* evaluate Const value */
105 EEOP_CONST,
108 * Evaluate function call (including OpExprs etc). For speed, we
109 * distinguish in the opcode whether the function is strict and/or
110 * requires usage stats tracking.
112 EEOP_FUNCEXPR,
113 EEOP_FUNCEXPR_STRICT,
114 EEOP_FUNCEXPR_FUSAGE,
115 EEOP_FUNCEXPR_STRICT_FUSAGE,
118 * Evaluate boolean AND expression, one step per subexpression. FIRST/LAST
119 * subexpressions are special-cased for performance. Since AND always has
120 * at least two subexpressions, FIRST and LAST never apply to the same
121 * subexpression.
123 EEOP_BOOL_AND_STEP_FIRST,
124 EEOP_BOOL_AND_STEP,
125 EEOP_BOOL_AND_STEP_LAST,
127 /* similarly for boolean OR expression */
128 EEOP_BOOL_OR_STEP_FIRST,
129 EEOP_BOOL_OR_STEP,
130 EEOP_BOOL_OR_STEP_LAST,
132 /* evaluate boolean NOT expression */
133 EEOP_BOOL_NOT_STEP,
135 /* simplified version of BOOL_AND_STEP for use by ExecQual() */
136 EEOP_QUAL,
138 /* unconditional jump to another step */
139 EEOP_JUMP,
141 /* conditional jumps based on current result value */
142 EEOP_JUMP_IF_NULL,
143 EEOP_JUMP_IF_NOT_NULL,
144 EEOP_JUMP_IF_NOT_TRUE,
146 /* perform NULL tests for scalar values */
147 EEOP_NULLTEST_ISNULL,
148 EEOP_NULLTEST_ISNOTNULL,
150 /* perform NULL tests for row values */
151 EEOP_NULLTEST_ROWISNULL,
152 EEOP_NULLTEST_ROWISNOTNULL,
154 /* evaluate a BooleanTest expression */
155 EEOP_BOOLTEST_IS_TRUE,
156 EEOP_BOOLTEST_IS_NOT_TRUE,
157 EEOP_BOOLTEST_IS_FALSE,
158 EEOP_BOOLTEST_IS_NOT_FALSE,
160 /* evaluate PARAM_EXEC/EXTERN parameters */
161 EEOP_PARAM_EXEC,
162 EEOP_PARAM_EXTERN,
163 EEOP_PARAM_CALLBACK,
165 /* return CaseTestExpr value */
166 EEOP_CASE_TESTVAL,
168 /* apply MakeExpandedObjectReadOnly() to target value */
169 EEOP_MAKE_READONLY,
171 /* evaluate assorted special-purpose expression types */
172 EEOP_IOCOERCE,
173 EEOP_DISTINCT,
174 EEOP_NOT_DISTINCT,
175 EEOP_NULLIF,
176 EEOP_SQLVALUEFUNCTION,
177 EEOP_CURRENTOFEXPR,
178 EEOP_NEXTVALUEEXPR,
179 EEOP_ARRAYEXPR,
180 EEOP_ARRAYCOERCE,
181 EEOP_ROW,
184 * Compare two individual elements of each of two compared ROW()
185 * expressions. Skip to ROWCOMPARE_FINAL if elements are not equal.
187 EEOP_ROWCOMPARE_STEP,
189 /* evaluate boolean value based on previous ROWCOMPARE_STEP operations */
190 EEOP_ROWCOMPARE_FINAL,
192 /* evaluate GREATEST() or LEAST() */
193 EEOP_MINMAX,
195 /* evaluate FieldSelect expression */
196 EEOP_FIELDSELECT,
199 * Deform tuple before evaluating new values for individual fields in a
200 * FieldStore expression.
202 EEOP_FIELDSTORE_DEFORM,
205 * Form the new tuple for a FieldStore expression. Individual fields will
206 * have been evaluated into columns of the tuple deformed by the preceding
207 * DEFORM step.
209 EEOP_FIELDSTORE_FORM,
211 /* Process container subscripts; possibly short-circuit result to NULL */
212 EEOP_SBSREF_SUBSCRIPTS,
215 * Compute old container element/slice when a SubscriptingRef assignment
216 * expression contains SubscriptingRef/FieldStore subexpressions. Value is
217 * accessed using the CaseTest mechanism.
219 EEOP_SBSREF_OLD,
221 /* compute new value for SubscriptingRef assignment expression */
222 EEOP_SBSREF_ASSIGN,
224 /* compute element/slice for SubscriptingRef fetch expression */
225 EEOP_SBSREF_FETCH,
227 /* evaluate value for CoerceToDomainValue */
228 EEOP_DOMAIN_TESTVAL,
230 /* evaluate a domain's NOT NULL constraint */
231 EEOP_DOMAIN_NOTNULL,
233 /* evaluate a single domain CHECK constraint */
234 EEOP_DOMAIN_CHECK,
236 /* evaluate assorted special-purpose expression types */
237 EEOP_CONVERT_ROWTYPE,
238 EEOP_SCALARARRAYOP,
239 EEOP_HASHED_SCALARARRAYOP,
240 EEOP_XMLEXPR,
241 EEOP_AGGREF,
242 EEOP_GROUPING_FUNC,
243 EEOP_WINDOW_FUNC,
244 EEOP_SUBPLAN,
245 EEOP_JSON_CONSTRUCTOR,
246 EEOP_IS_JSON,
247 EEOP_JSONEXPR,
249 /* aggregation related nodes */
250 EEOP_AGG_STRICT_DESERIALIZE,
251 EEOP_AGG_DESERIALIZE,
252 EEOP_AGG_STRICT_INPUT_CHECK_ARGS,
253 EEOP_AGG_STRICT_INPUT_CHECK_NULLS,
254 EEOP_AGG_PLAIN_PERGROUP_NULLCHECK,
255 EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYVAL,
256 EEOP_AGG_PLAIN_TRANS_STRICT_BYVAL,
257 EEOP_AGG_PLAIN_TRANS_BYVAL,
258 EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYREF,
259 EEOP_AGG_PLAIN_TRANS_STRICT_BYREF,
260 EEOP_AGG_PLAIN_TRANS_BYREF,
261 EEOP_AGG_ORDERED_TRANS_DATUM,
262 EEOP_AGG_ORDERED_TRANS_TUPLE,
264 /* non-existent operation, used e.g. to check array lengths */
265 EEOP_LAST
266 } ExprEvalOp;
269 typedef struct ExprEvalStep
272 * Instruction to be executed. During instruction preparation this is an
273 * enum ExprEvalOp, but later it can be changed to some other type, e.g. a
274 * pointer for computed goto (that's why it's an intptr_t).
276 intptr_t opcode;
278 /* where to store the result of this step */
279 Datum *resvalue;
280 bool *resnull;
283 * Inline data for the operation. Inline data is faster to access, but
284 * also bloats the size of all instructions. The union should be kept to
285 * no more than 40 bytes on 64-bit systems (so that the entire struct is
286 * no more than 64 bytes, a single cacheline on common systems).
288 union
290 /* for EEOP_INNER/OUTER/SCAN_FETCHSOME */
291 struct
293 /* attribute number up to which to fetch (inclusive) */
294 int last_var;
295 /* will the type of slot be the same for every invocation */
296 bool fixed;
297 /* tuple descriptor, if known */
298 TupleDesc known_desc;
299 /* type of slot, can only be relied upon if fixed is set */
300 const TupleTableSlotOps *kind;
301 } fetch;
303 /* for EEOP_INNER/OUTER/SCAN_[SYS]VAR[_FIRST] */
304 struct
306 /* attnum is attr number - 1 for regular VAR ... */
307 /* but it's just the normal (negative) attr number for SYSVAR */
308 int attnum;
309 Oid vartype; /* type OID of variable */
310 } var;
312 /* for EEOP_WHOLEROW */
313 struct
315 Var *var; /* original Var node in plan tree */
316 bool first; /* first time through, need to initialize? */
317 bool slow; /* need runtime check for nulls? */
318 TupleDesc tupdesc; /* descriptor for resulting tuples */
319 JunkFilter *junkFilter; /* JunkFilter to remove resjunk cols */
320 } wholerow;
322 /* for EEOP_ASSIGN_*_VAR */
323 struct
325 /* target index in ExprState->resultslot->tts_values/nulls */
326 int resultnum;
327 /* source attribute number - 1 */
328 int attnum;
329 } assign_var;
331 /* for EEOP_ASSIGN_TMP[_MAKE_RO] */
332 struct
334 /* target index in ExprState->resultslot->tts_values/nulls */
335 int resultnum;
336 } assign_tmp;
338 /* for EEOP_CONST */
339 struct
341 /* constant's value */
342 Datum value;
343 bool isnull;
344 } constval;
346 /* for EEOP_FUNCEXPR_* / NULLIF / DISTINCT */
347 struct
349 FmgrInfo *finfo; /* function's lookup data */
350 FunctionCallInfo fcinfo_data; /* arguments etc */
351 /* faster to access without additional indirection: */
352 PGFunction fn_addr; /* actual call address */
353 int nargs; /* number of arguments */
354 } func;
356 /* for EEOP_BOOL_*_STEP */
357 struct
359 bool *anynull; /* track if any input was NULL */
360 int jumpdone; /* jump here if result determined */
361 } boolexpr;
363 /* for EEOP_QUAL */
364 struct
366 int jumpdone; /* jump here on false or null */
367 } qualexpr;
369 /* for EEOP_JUMP[_CONDITION] */
370 struct
372 int jumpdone; /* target instruction's index */
373 } jump;
375 /* for EEOP_NULLTEST_ROWIS[NOT]NULL */
376 struct
378 /* cached descriptor for composite type - filled at runtime */
379 ExprEvalRowtypeCache rowcache;
380 } nulltest_row;
382 /* for EEOP_PARAM_EXEC/EXTERN */
383 struct
385 int paramid; /* numeric ID for parameter */
386 Oid paramtype; /* OID of parameter's datatype */
387 } param;
389 /* for EEOP_PARAM_CALLBACK */
390 struct
392 ExecEvalSubroutine paramfunc; /* add-on evaluation subroutine */
393 void *paramarg; /* private data for same */
394 int paramid; /* numeric ID for parameter */
395 Oid paramtype; /* OID of parameter's datatype */
396 } cparam;
398 /* for EEOP_CASE_TESTVAL/DOMAIN_TESTVAL */
399 struct
401 Datum *value; /* value to return */
402 bool *isnull;
403 } casetest;
405 /* for EEOP_MAKE_READONLY */
406 struct
408 Datum *value; /* value to coerce to read-only */
409 bool *isnull;
410 } make_readonly;
412 /* for EEOP_IOCOERCE */
413 struct
415 /* lookup and call info for source type's output function */
416 FmgrInfo *finfo_out;
417 FunctionCallInfo fcinfo_data_out;
418 /* lookup and call info for result type's input function */
419 FmgrInfo *finfo_in;
420 FunctionCallInfo fcinfo_data_in;
421 } iocoerce;
423 /* for EEOP_SQLVALUEFUNCTION */
424 struct
426 SQLValueFunction *svf;
427 } sqlvaluefunction;
429 /* for EEOP_NEXTVALUEEXPR */
430 struct
432 Oid seqid;
433 Oid seqtypid;
434 } nextvalueexpr;
436 /* for EEOP_ARRAYEXPR */
437 struct
439 Datum *elemvalues; /* element values get stored here */
440 bool *elemnulls;
441 int nelems; /* length of the above arrays */
442 Oid elemtype; /* array element type */
443 int16 elemlength; /* typlen of the array element type */
444 bool elembyval; /* is the element type pass-by-value? */
445 char elemalign; /* typalign of the element type */
446 bool multidims; /* is array expression multi-D? */
447 } arrayexpr;
449 /* for EEOP_ARRAYCOERCE */
450 struct
452 ExprState *elemexprstate; /* null if no per-element work */
453 Oid resultelemtype; /* element type of result array */
454 struct ArrayMapState *amstate; /* workspace for array_map */
455 } arraycoerce;
457 /* for EEOP_ROW */
458 struct
460 TupleDesc tupdesc; /* descriptor for result tuples */
461 /* workspace for the values constituting the row: */
462 Datum *elemvalues;
463 bool *elemnulls;
464 } row;
466 /* for EEOP_ROWCOMPARE_STEP */
467 struct
469 /* lookup and call data for column comparison function */
470 FmgrInfo *finfo;
471 FunctionCallInfo fcinfo_data;
472 PGFunction fn_addr;
473 /* target for comparison resulting in NULL */
474 int jumpnull;
475 /* target for comparison yielding inequality */
476 int jumpdone;
477 } rowcompare_step;
479 /* for EEOP_ROWCOMPARE_FINAL */
480 struct
482 RowCompareType rctype;
483 } rowcompare_final;
485 /* for EEOP_MINMAX */
486 struct
488 /* workspace for argument values */
489 Datum *values;
490 bool *nulls;
491 int nelems;
492 /* is it GREATEST or LEAST? */
493 MinMaxOp op;
494 /* lookup and call data for comparison function */
495 FmgrInfo *finfo;
496 FunctionCallInfo fcinfo_data;
497 } minmax;
499 /* for EEOP_FIELDSELECT */
500 struct
502 AttrNumber fieldnum; /* field number to extract */
503 Oid resulttype; /* field's type */
504 /* cached descriptor for composite type - filled at runtime */
505 ExprEvalRowtypeCache rowcache;
506 } fieldselect;
508 /* for EEOP_FIELDSTORE_DEFORM / FIELDSTORE_FORM */
509 struct
511 /* original expression node */
512 FieldStore *fstore;
514 /* cached descriptor for composite type - filled at runtime */
515 /* note that a DEFORM and FORM pair share the same cache */
516 ExprEvalRowtypeCache *rowcache;
518 /* workspace for column values */
519 Datum *values;
520 bool *nulls;
521 int ncolumns;
522 } fieldstore;
524 /* for EEOP_SBSREF_SUBSCRIPTS */
525 struct
527 ExecEvalBoolSubroutine subscriptfunc; /* evaluation subroutine */
528 /* too big to have inline */
529 struct SubscriptingRefState *state;
530 int jumpdone; /* jump here on null */
531 } sbsref_subscript;
533 /* for EEOP_SBSREF_OLD / ASSIGN / FETCH */
534 struct
536 ExecEvalSubroutine subscriptfunc; /* evaluation subroutine */
537 /* too big to have inline */
538 struct SubscriptingRefState *state;
539 } sbsref;
541 /* for EEOP_DOMAIN_NOTNULL / DOMAIN_CHECK */
542 struct
544 /* name of constraint */
545 char *constraintname;
546 /* where the result of a CHECK constraint will be stored */
547 Datum *checkvalue;
548 bool *checknull;
549 /* OID of domain type */
550 Oid resulttype;
551 } domaincheck;
553 /* for EEOP_CONVERT_ROWTYPE */
554 struct
556 Oid inputtype; /* input composite type */
557 Oid outputtype; /* output composite type */
558 /* these three fields are filled at runtime: */
559 ExprEvalRowtypeCache *incache; /* cache for input type */
560 ExprEvalRowtypeCache *outcache; /* cache for output type */
561 TupleConversionMap *map; /* column mapping */
562 } convert_rowtype;
564 /* for EEOP_SCALARARRAYOP */
565 struct
567 /* element_type/typlen/typbyval/typalign are filled at runtime */
568 Oid element_type; /* InvalidOid if not yet filled */
569 bool useOr; /* use OR or AND semantics? */
570 int16 typlen; /* array element type storage info */
571 bool typbyval;
572 char typalign;
573 FmgrInfo *finfo; /* function's lookup data */
574 FunctionCallInfo fcinfo_data; /* arguments etc */
575 /* faster to access without additional indirection: */
576 PGFunction fn_addr; /* actual call address */
577 } scalararrayop;
579 /* for EEOP_HASHED_SCALARARRAYOP */
580 struct
582 bool has_nulls;
583 bool inclause; /* true for IN and false for NOT IN */
584 struct ScalarArrayOpExprHashTable *elements_tab;
585 FmgrInfo *finfo; /* function's lookup data */
586 FunctionCallInfo fcinfo_data; /* arguments etc */
587 ScalarArrayOpExpr *saop;
588 } hashedscalararrayop;
590 /* for EEOP_XMLEXPR */
591 struct
593 XmlExpr *xexpr; /* original expression node */
594 /* workspace for evaluating named args, if any */
595 Datum *named_argvalue;
596 bool *named_argnull;
597 /* workspace for evaluating unnamed args, if any */
598 Datum *argvalue;
599 bool *argnull;
600 } xmlexpr;
602 /* for EEOP_AGGREF */
603 struct
605 int aggno;
606 } aggref;
608 /* for EEOP_GROUPING_FUNC */
609 struct
611 List *clauses; /* integer list of column numbers */
612 } grouping_func;
614 /* for EEOP_WINDOW_FUNC */
615 struct
617 /* out-of-line state, modified by nodeWindowAgg.c */
618 WindowFuncExprState *wfstate;
619 } window_func;
621 /* for EEOP_SUBPLAN */
622 struct
624 /* out-of-line state, created by nodeSubplan.c */
625 SubPlanState *sstate;
626 } subplan;
628 /* for EEOP_AGG_*DESERIALIZE */
629 struct
631 FunctionCallInfo fcinfo_data;
632 int jumpnull;
633 } agg_deserialize;
635 /* for EEOP_AGG_STRICT_INPUT_CHECK_NULLS / STRICT_INPUT_CHECK_ARGS */
636 struct
639 * For EEOP_AGG_STRICT_INPUT_CHECK_ARGS args contains pointers to
640 * the NullableDatums that need to be checked for NULLs.
642 * For EEOP_AGG_STRICT_INPUT_CHECK_NULLS nulls contains pointers
643 * to booleans that need to be checked for NULLs.
645 * Both cases currently need to exist because sometimes the
646 * to-be-checked nulls are in TupleTableSlot.isnull array, and
647 * sometimes in FunctionCallInfoBaseData.args[i].isnull.
649 NullableDatum *args;
650 bool *nulls;
651 int nargs;
652 int jumpnull;
653 } agg_strict_input_check;
655 /* for EEOP_AGG_PLAIN_PERGROUP_NULLCHECK */
656 struct
658 int setoff;
659 int jumpnull;
660 } agg_plain_pergroup_nullcheck;
662 /* for EEOP_AGG_PLAIN_TRANS_[INIT_][STRICT_]{BYVAL,BYREF} */
663 /* for EEOP_AGG_ORDERED_TRANS_{DATUM,TUPLE} */
664 struct
666 AggStatePerTrans pertrans;
667 ExprContext *aggcontext;
668 int setno;
669 int transno;
670 int setoff;
671 } agg_trans;
673 /* for EEOP_JSON_CONSTRUCTOR */
674 struct
676 struct JsonConstructorExprState *jcstate;
677 } json_constructor;
679 /* for EEOP_IS_JSON */
680 struct
682 JsonIsPredicate *pred; /* original expression node */
683 } is_json;
685 /* for EEOP_JSONEXPR */
686 struct
688 struct JsonExprState *jsestate;
689 } jsonexpr;
691 } d;
692 } ExprEvalStep;
695 /* Non-inline data for container operations */
696 typedef struct SubscriptingRefState
698 bool isassignment; /* is it assignment, or just fetch? */
700 /* workspace for type-specific subscripting code */
701 void *workspace;
703 /* numupper and upperprovided[] are filled at expression compile time */
704 /* at runtime, subscripts are computed in upperindex[]/upperindexnull[] */
705 int numupper;
706 bool *upperprovided; /* indicates if this position is supplied */
707 Datum *upperindex;
708 bool *upperindexnull;
710 /* similarly for lower indexes, if any */
711 int numlower;
712 bool *lowerprovided;
713 Datum *lowerindex;
714 bool *lowerindexnull;
716 /* for assignment, new value to assign is evaluated into here */
717 Datum replacevalue;
718 bool replacenull;
720 /* if we have a nested assignment, sbs_fetch_old puts old value here */
721 Datum prevvalue;
722 bool prevnull;
723 } SubscriptingRefState;
725 /* Execution step methods used for SubscriptingRef */
726 typedef struct SubscriptExecSteps
728 /* See nodes/subscripting.h for more detail about these */
729 ExecEvalBoolSubroutine sbs_check_subscripts; /* process subscripts */
730 ExecEvalSubroutine sbs_fetch; /* fetch an element */
731 ExecEvalSubroutine sbs_assign; /* assign to an element */
732 ExecEvalSubroutine sbs_fetch_old; /* fetch old value for assignment */
733 } SubscriptExecSteps;
735 /* EEOP_JSON_CONSTRUCTOR state, too big to inline */
736 typedef struct JsonConstructorExprState
738 JsonConstructorExpr *constructor;
739 Datum *arg_values;
740 bool *arg_nulls;
741 Oid *arg_types;
742 struct
744 int category;
745 Oid outfuncid;
746 } *arg_type_cache; /* cache for datum_to_json[b]() */
747 int nargs;
748 } JsonConstructorExprState;
750 /* EEOP_JSONEXPR state, too big to inline */
751 typedef struct JsonExprState
753 JsonExpr *jsexpr; /* original expression node */
755 struct
757 FmgrInfo func; /* typinput function for output type */
758 Oid typioparam;
759 } input; /* I/O info for output type */
761 NullableDatum
762 *formatted_expr, /* formatted context item value */
763 *res_expr, /* result item */
764 *coercion_expr, /* input for JSON item coercion */
765 *pathspec; /* path specification value */
767 ExprState *result_expr; /* coerced to output type */
768 ExprState *default_on_empty; /* ON EMPTY DEFAULT expression */
769 ExprState *default_on_error; /* ON ERROR DEFAULT expression */
770 List *args; /* passing arguments */
772 void *cache; /* cache for json_populate_type() */
774 struct JsonCoercionsState
776 struct JsonCoercionState
778 JsonCoercion *coercion; /* coercion expression */
779 ExprState *estate; /* coercion expression state */
780 } null,
781 string,
782 numeric ,
783 boolean,
784 date,
785 time,
786 timetz,
787 timestamp,
788 timestamptz,
789 composite;
790 } coercions; /* states for coercion from SQL/JSON item
791 * types directly to the output type */
792 } JsonExprState;
794 /* functions in execExpr.c */
795 extern void ExprEvalPushStep(ExprState *es, const ExprEvalStep *s);
797 /* functions in execExprInterp.c */
798 extern void ExecReadyInterpretedExpr(ExprState *state);
799 extern ExprEvalOp ExecEvalStepOp(ExprState *state, ExprEvalStep *op);
801 extern Datum ExecInterpExprStillValid(ExprState *state, ExprContext *econtext, bool *isNull);
802 extern void CheckExprStillValid(ExprState *state, ExprContext *econtext);
805 * Non fast-path execution functions. These are externs instead of statics in
806 * execExprInterp.c, because that allows them to be used by other methods of
807 * expression evaluation, reducing code duplication.
809 extern void ExecEvalFuncExprFusage(ExprState *state, ExprEvalStep *op,
810 ExprContext *econtext);
811 extern void ExecEvalFuncExprStrictFusage(ExprState *state, ExprEvalStep *op,
812 ExprContext *econtext);
813 extern void ExecEvalParamExec(ExprState *state, ExprEvalStep *op,
814 ExprContext *econtext);
815 extern void ExecEvalParamExtern(ExprState *state, ExprEvalStep *op,
816 ExprContext *econtext);
817 extern void ExecEvalSQLValueFunction(ExprState *state, ExprEvalStep *op);
818 extern void ExecEvalCurrentOfExpr(ExprState *state, ExprEvalStep *op);
819 extern void ExecEvalNextValueExpr(ExprState *state, ExprEvalStep *op);
820 extern void ExecEvalRowNull(ExprState *state, ExprEvalStep *op,
821 ExprContext *econtext);
822 extern void ExecEvalRowNotNull(ExprState *state, ExprEvalStep *op,
823 ExprContext *econtext);
824 extern void ExecEvalArrayExpr(ExprState *state, ExprEvalStep *op);
825 extern void ExecEvalArrayCoerce(ExprState *state, ExprEvalStep *op,
826 ExprContext *econtext);
827 extern void ExecEvalRow(ExprState *state, ExprEvalStep *op);
828 extern void ExecEvalMinMax(ExprState *state, ExprEvalStep *op);
829 extern void ExecEvalFieldSelect(ExprState *state, ExprEvalStep *op,
830 ExprContext *econtext);
831 extern void ExecEvalFieldStoreDeForm(ExprState *state, ExprEvalStep *op,
832 ExprContext *econtext);
833 extern void ExecEvalFieldStoreForm(ExprState *state, ExprEvalStep *op,
834 ExprContext *econtext);
835 extern void ExecEvalConvertRowtype(ExprState *state, ExprEvalStep *op,
836 ExprContext *econtext);
837 extern void ExecEvalScalarArrayOp(ExprState *state, ExprEvalStep *op);
838 extern void ExecEvalHashedScalarArrayOp(ExprState *state, ExprEvalStep *op,
839 ExprContext *econtext);
840 extern void ExecEvalConstraintNotNull(ExprState *state, ExprEvalStep *op);
841 extern void ExecEvalConstraintCheck(ExprState *state, ExprEvalStep *op);
842 extern void ExecEvalXmlExpr(ExprState *state, ExprEvalStep *op);
843 extern void ExecEvalJsonIsPredicate(ExprState *state, ExprEvalStep *op);
844 extern void ExecEvalGroupingFunc(ExprState *state, ExprEvalStep *op);
845 extern void ExecEvalSubPlan(ExprState *state, ExprEvalStep *op,
846 ExprContext *econtext);
847 extern void ExecEvalWholeRowVar(ExprState *state, ExprEvalStep *op,
848 ExprContext *econtext);
849 extern void ExecEvalSysVar(ExprState *state, ExprEvalStep *op,
850 ExprContext *econtext, TupleTableSlot *slot);
851 extern void ExecEvalJsonConstructor(ExprState *state, ExprEvalStep *op,
852 ExprContext *econtext);
853 extern void ExecEvalJson(ExprState *state, ExprEvalStep *op,
854 ExprContext *econtext);
855 extern Datum ExecPrepareJsonItemCoercion(struct JsonbValue *item,
856 JsonReturning *returning,
857 struct JsonCoercionsState *coercions,
858 struct JsonCoercionState **pjcstate);
859 extern bool ExecEvalJsonNeedsSubTransaction(JsonExpr *jsexpr,
860 struct JsonCoercionsState *);
861 extern Datum ExecEvalExprPassingCaseValue(ExprState *estate,
862 ExprContext *econtext, bool *isnull,
863 Datum caseval_datum,
864 bool caseval_isnull);
866 extern void ExecAggInitGroup(AggState *aggstate, AggStatePerTrans pertrans, AggStatePerGroup pergroup,
867 ExprContext *aggcontext);
868 extern Datum ExecAggTransReparent(AggState *aggstate, AggStatePerTrans pertrans,
869 Datum newValue, bool newValueIsNull,
870 Datum oldValue, bool oldValueIsNull);
871 extern void ExecEvalAggOrderedTransDatum(ExprState *state, ExprEvalStep *op,
872 ExprContext *econtext);
873 extern void ExecEvalAggOrderedTransTuple(ExprState *state, ExprEvalStep *op,
874 ExprContext *econtext);
876 #endif /* EXEC_EXPR_H */