execExpr.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778
  1. /*-------------------------------------------------------------------------
  2. *
  3. * execExpr.h
  4. * Low level infrastructure related to expression evaluation
  5. *
  6. *
  7. * Portions Copyright (c) 1996-2022, 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. #include "executor/nodeAgg.h"
  17. #include "nodes/execnodes.h"
  18. /* forward references to avoid circularity */
  19. struct ExprEvalStep;
  20. struct SubscriptingRefState;
  21. struct ScalarArrayOpExprHashTable;
  22. /* Bits in ExprState->flags (see also execnodes.h for public flag bits): */
  23. /* expression's interpreter has been initialized */
  24. #define EEO_FLAG_INTERPRETER_INITIALIZED (1 << 1)
  25. /* jump-threading is in use */
  26. #define EEO_FLAG_DIRECT_THREADED (1 << 2)
  27. /* Typical API for out-of-line evaluation subroutines */
  28. typedef void (*ExecEvalSubroutine) (ExprState *state,
  29. struct ExprEvalStep *op,
  30. ExprContext *econtext);
  31. /* API for out-of-line evaluation subroutines returning bool */
  32. typedef bool (*ExecEvalBoolSubroutine) (ExprState *state,
  33. struct ExprEvalStep *op,
  34. ExprContext *econtext);
  35. /* ExprEvalSteps that cache a composite type's tupdesc need one of these */
  36. /* (it fits in-line in some step types, otherwise allocate out-of-line) */
  37. typedef struct ExprEvalRowtypeCache
  38. {
  39. /*
  40. * cacheptr points to composite type's TypeCacheEntry if tupdesc_id is not
  41. * 0; or for an anonymous RECORD type, it points directly at the cached
  42. * tupdesc for the type, and tupdesc_id is 0. (We'd use separate fields
  43. * if space were not at a premium.) Initial state is cacheptr == NULL.
  44. */
  45. void *cacheptr;
  46. uint64 tupdesc_id; /* last-seen tupdesc identifier, or 0 */
  47. } ExprEvalRowtypeCache;
  48. /*
  49. * Discriminator for ExprEvalSteps.
  50. *
  51. * Identifies the operation to be executed and which member in the
  52. * ExprEvalStep->d union is valid.
  53. *
  54. * The order of entries needs to be kept in sync with the dispatch_table[]
  55. * array in execExprInterp.c:ExecInterpExpr().
  56. */
  57. typedef enum ExprEvalOp
  58. {
  59. /* entire expression has been evaluated completely, return */
  60. EEOP_DONE,
  61. /* apply slot_getsomeattrs on corresponding tuple slot */
  62. EEOP_INNER_FETCHSOME,
  63. EEOP_OUTER_FETCHSOME,
  64. EEOP_SCAN_FETCHSOME,
  65. /* compute non-system Var value */
  66. EEOP_INNER_VAR,
  67. EEOP_OUTER_VAR,
  68. EEOP_SCAN_VAR,
  69. /* compute system Var value */
  70. EEOP_INNER_SYSVAR,
  71. EEOP_OUTER_SYSVAR,
  72. EEOP_SCAN_SYSVAR,
  73. /* compute wholerow Var */
  74. EEOP_WHOLEROW,
  75. /*
  76. * Compute non-system Var value, assign it into ExprState's resultslot.
  77. * These are not used if a CheckVarSlotCompatibility() check would be
  78. * needed.
  79. */
  80. EEOP_ASSIGN_INNER_VAR,
  81. EEOP_ASSIGN_OUTER_VAR,
  82. EEOP_ASSIGN_SCAN_VAR,
  83. /* assign ExprState's resvalue/resnull to a column of its resultslot */
  84. EEOP_ASSIGN_TMP,
  85. /* ditto, applying MakeExpandedObjectReadOnly() */
  86. EEOP_ASSIGN_TMP_MAKE_RO,
  87. /* evaluate Const value */
  88. EEOP_CONST,
  89. /*
  90. * Evaluate function call (including OpExprs etc). For speed, we
  91. * distinguish in the opcode whether the function is strict and/or
  92. * requires usage stats tracking.
  93. */
  94. EEOP_FUNCEXPR,
  95. EEOP_FUNCEXPR_STRICT,
  96. EEOP_FUNCEXPR_FUSAGE,
  97. EEOP_FUNCEXPR_STRICT_FUSAGE,
  98. /*
  99. * Evaluate boolean AND expression, one step per subexpression. FIRST/LAST
  100. * subexpressions are special-cased for performance. Since AND always has
  101. * at least two subexpressions, FIRST and LAST never apply to the same
  102. * subexpression.
  103. */
  104. EEOP_BOOL_AND_STEP_FIRST,
  105. EEOP_BOOL_AND_STEP,
  106. EEOP_BOOL_AND_STEP_LAST,
  107. /* similarly for boolean OR expression */
  108. EEOP_BOOL_OR_STEP_FIRST,
  109. EEOP_BOOL_OR_STEP,
  110. EEOP_BOOL_OR_STEP_LAST,
  111. /* evaluate boolean NOT expression */
  112. EEOP_BOOL_NOT_STEP,
  113. /* simplified version of BOOL_AND_STEP for use by ExecQual() */
  114. EEOP_QUAL,
  115. /* unconditional jump to another step */
  116. EEOP_JUMP,
  117. /* conditional jumps based on current result value */
  118. EEOP_JUMP_IF_NULL,
  119. EEOP_JUMP_IF_NOT_NULL,
  120. EEOP_JUMP_IF_NOT_TRUE,
  121. /* perform NULL tests for scalar values */
  122. EEOP_NULLTEST_ISNULL,
  123. EEOP_NULLTEST_ISNOTNULL,
  124. /* perform NULL tests for row values */
  125. EEOP_NULLTEST_ROWISNULL,
  126. EEOP_NULLTEST_ROWISNOTNULL,
  127. /* evaluate a BooleanTest expression */
  128. EEOP_BOOLTEST_IS_TRUE,
  129. EEOP_BOOLTEST_IS_NOT_TRUE,
  130. EEOP_BOOLTEST_IS_FALSE,
  131. EEOP_BOOLTEST_IS_NOT_FALSE,
  132. /* evaluate PARAM_EXEC/EXTERN parameters */
  133. EEOP_PARAM_EXEC,
  134. EEOP_PARAM_EXTERN,
  135. EEOP_PARAM_CALLBACK,
  136. /* return CaseTestExpr value */
  137. EEOP_CASE_TESTVAL,
  138. /* apply MakeExpandedObjectReadOnly() to target value */
  139. EEOP_MAKE_READONLY,
  140. /* evaluate assorted special-purpose expression types */
  141. EEOP_IOCOERCE,
  142. EEOP_DISTINCT,
  143. EEOP_NOT_DISTINCT,
  144. EEOP_NULLIF,
  145. EEOP_SQLVALUEFUNCTION,
  146. EEOP_CURRENTOFEXPR,
  147. EEOP_NEXTVALUEEXPR,
  148. EEOP_ARRAYEXPR,
  149. EEOP_ARRAYCOERCE,
  150. EEOP_ROW,
  151. /*
  152. * Compare two individual elements of each of two compared ROW()
  153. * expressions. Skip to ROWCOMPARE_FINAL if elements are not equal.
  154. */
  155. EEOP_ROWCOMPARE_STEP,
  156. /* evaluate boolean value based on previous ROWCOMPARE_STEP operations */
  157. EEOP_ROWCOMPARE_FINAL,
  158. /* evaluate GREATEST() or LEAST() */
  159. EEOP_MINMAX,
  160. /* evaluate FieldSelect expression */
  161. EEOP_FIELDSELECT,
  162. /*
  163. * Deform tuple before evaluating new values for individual fields in a
  164. * FieldStore expression.
  165. */
  166. EEOP_FIELDSTORE_DEFORM,
  167. /*
  168. * Form the new tuple for a FieldStore expression. Individual fields will
  169. * have been evaluated into columns of the tuple deformed by the preceding
  170. * DEFORM step.
  171. */
  172. EEOP_FIELDSTORE_FORM,
  173. /* Process container subscripts; possibly short-circuit result to NULL */
  174. EEOP_SBSREF_SUBSCRIPTS,
  175. /*
  176. * Compute old container element/slice when a SubscriptingRef assignment
  177. * expression contains SubscriptingRef/FieldStore subexpressions. Value is
  178. * accessed using the CaseTest mechanism.
  179. */
  180. EEOP_SBSREF_OLD,
  181. /* compute new value for SubscriptingRef assignment expression */
  182. EEOP_SBSREF_ASSIGN,
  183. /* compute element/slice for SubscriptingRef fetch expression */
  184. EEOP_SBSREF_FETCH,
  185. /* evaluate value for CoerceToDomainValue */
  186. EEOP_DOMAIN_TESTVAL,
  187. /* evaluate a domain's NOT NULL constraint */
  188. EEOP_DOMAIN_NOTNULL,
  189. /* evaluate a single domain CHECK constraint */
  190. EEOP_DOMAIN_CHECK,
  191. /* evaluate assorted special-purpose expression types */
  192. EEOP_CONVERT_ROWTYPE,
  193. EEOP_SCALARARRAYOP,
  194. EEOP_HASHED_SCALARARRAYOP,
  195. EEOP_XMLEXPR,
  196. EEOP_AGGREF,
  197. EEOP_GROUPING_FUNC,
  198. EEOP_WINDOW_FUNC,
  199. EEOP_SUBPLAN,
  200. /* aggregation related nodes */
  201. EEOP_AGG_STRICT_DESERIALIZE,
  202. EEOP_AGG_DESERIALIZE,
  203. EEOP_AGG_STRICT_INPUT_CHECK_ARGS,
  204. EEOP_AGG_STRICT_INPUT_CHECK_NULLS,
  205. EEOP_AGG_PLAIN_PERGROUP_NULLCHECK,
  206. EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYVAL,
  207. EEOP_AGG_PLAIN_TRANS_STRICT_BYVAL,
  208. EEOP_AGG_PLAIN_TRANS_BYVAL,
  209. EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYREF,
  210. EEOP_AGG_PLAIN_TRANS_STRICT_BYREF,
  211. EEOP_AGG_PLAIN_TRANS_BYREF,
  212. EEOP_AGG_ORDERED_TRANS_DATUM,
  213. EEOP_AGG_ORDERED_TRANS_TUPLE,
  214. /* non-existent operation, used e.g. to check array lengths */
  215. EEOP_LAST
  216. } ExprEvalOp;
  217. typedef struct ExprEvalStep
  218. {
  219. /*
  220. * Instruction to be executed. During instruction preparation this is an
  221. * enum ExprEvalOp, but later it can be changed to some other type, e.g. a
  222. * pointer for computed goto (that's why it's an intptr_t).
  223. */
  224. intptr_t opcode;
  225. /* where to store the result of this step */
  226. Datum *resvalue;
  227. bool *resnull;
  228. /*
  229. * Inline data for the operation. Inline data is faster to access, but
  230. * also bloats the size of all instructions. The union should be kept to
  231. * no more than 40 bytes on 64-bit systems (so that the entire struct is
  232. * no more than 64 bytes, a single cacheline on common systems).
  233. */
  234. union
  235. {
  236. /* for EEOP_INNER/OUTER/SCAN_FETCHSOME */
  237. struct
  238. {
  239. /* attribute number up to which to fetch (inclusive) */
  240. int last_var;
  241. /* will the type of slot be the same for every invocation */
  242. bool fixed;
  243. /* tuple descriptor, if known */
  244. TupleDesc known_desc;
  245. /* type of slot, can only be relied upon if fixed is set */
  246. const TupleTableSlotOps *kind;
  247. } fetch;
  248. /* for EEOP_INNER/OUTER/SCAN_[SYS]VAR[_FIRST] */
  249. struct
  250. {
  251. /* attnum is attr number - 1 for regular VAR ... */
  252. /* but it's just the normal (negative) attr number for SYSVAR */
  253. int attnum;
  254. Oid vartype; /* type OID of variable */
  255. } var;
  256. /* for EEOP_WHOLEROW */
  257. struct
  258. {
  259. Var *var; /* original Var node in plan tree */
  260. bool first; /* first time through, need to initialize? */
  261. bool slow; /* need runtime check for nulls? */
  262. TupleDesc tupdesc; /* descriptor for resulting tuples */
  263. JunkFilter *junkFilter; /* JunkFilter to remove resjunk cols */
  264. } wholerow;
  265. /* for EEOP_ASSIGN_*_VAR */
  266. struct
  267. {
  268. /* target index in ExprState->resultslot->tts_values/nulls */
  269. int resultnum;
  270. /* source attribute number - 1 */
  271. int attnum;
  272. } assign_var;
  273. /* for EEOP_ASSIGN_TMP[_MAKE_RO] */
  274. struct
  275. {
  276. /* target index in ExprState->resultslot->tts_values/nulls */
  277. int resultnum;
  278. } assign_tmp;
  279. /* for EEOP_CONST */
  280. struct
  281. {
  282. /* constant's value */
  283. Datum value;
  284. bool isnull;
  285. } constval;
  286. /* for EEOP_FUNCEXPR_* / NULLIF / DISTINCT */
  287. struct
  288. {
  289. FmgrInfo *finfo; /* function's lookup data */
  290. FunctionCallInfo fcinfo_data; /* arguments etc */
  291. /* faster to access without additional indirection: */
  292. PGFunction fn_addr; /* actual call address */
  293. int nargs; /* number of arguments */
  294. } func;
  295. /* for EEOP_BOOL_*_STEP */
  296. struct
  297. {
  298. bool *anynull; /* track if any input was NULL */
  299. int jumpdone; /* jump here if result determined */
  300. } boolexpr;
  301. /* for EEOP_QUAL */
  302. struct
  303. {
  304. int jumpdone; /* jump here on false or null */
  305. } qualexpr;
  306. /* for EEOP_JUMP[_CONDITION] */
  307. struct
  308. {
  309. int jumpdone; /* target instruction's index */
  310. } jump;
  311. /* for EEOP_NULLTEST_ROWIS[NOT]NULL */
  312. struct
  313. {
  314. /* cached descriptor for composite type - filled at runtime */
  315. ExprEvalRowtypeCache rowcache;
  316. } nulltest_row;
  317. /* for EEOP_PARAM_EXEC/EXTERN */
  318. struct
  319. {
  320. int paramid; /* numeric ID for parameter */
  321. Oid paramtype; /* OID of parameter's datatype */
  322. } param;
  323. /* for EEOP_PARAM_CALLBACK */
  324. struct
  325. {
  326. ExecEvalSubroutine paramfunc; /* add-on evaluation subroutine */
  327. void *paramarg; /* private data for same */
  328. int paramid; /* numeric ID for parameter */
  329. Oid paramtype; /* OID of parameter's datatype */
  330. } cparam;
  331. /* for EEOP_CASE_TESTVAL/DOMAIN_TESTVAL */
  332. struct
  333. {
  334. Datum *value; /* value to return */
  335. bool *isnull;
  336. } casetest;
  337. /* for EEOP_MAKE_READONLY */
  338. struct
  339. {
  340. Datum *value; /* value to coerce to read-only */
  341. bool *isnull;
  342. } make_readonly;
  343. /* for EEOP_IOCOERCE */
  344. struct
  345. {
  346. /* lookup and call info for source type's output function */
  347. FmgrInfo *finfo_out;
  348. FunctionCallInfo fcinfo_data_out;
  349. /* lookup and call info for result type's input function */
  350. FmgrInfo *finfo_in;
  351. FunctionCallInfo fcinfo_data_in;
  352. } iocoerce;
  353. /* for EEOP_SQLVALUEFUNCTION */
  354. struct
  355. {
  356. SQLValueFunction *svf;
  357. } sqlvaluefunction;
  358. /* for EEOP_NEXTVALUEEXPR */
  359. struct
  360. {
  361. Oid seqid;
  362. Oid seqtypid;
  363. } nextvalueexpr;
  364. /* for EEOP_ARRAYEXPR */
  365. struct
  366. {
  367. Datum *elemvalues; /* element values get stored here */
  368. bool *elemnulls;
  369. int nelems; /* length of the above arrays */
  370. Oid elemtype; /* array element type */
  371. int16 elemlength; /* typlen of the array element type */
  372. bool elembyval; /* is the element type pass-by-value? */
  373. char elemalign; /* typalign of the element type */
  374. bool multidims; /* is array expression multi-D? */
  375. } arrayexpr;
  376. /* for EEOP_ARRAYCOERCE */
  377. struct
  378. {
  379. ExprState *elemexprstate; /* null if no per-element work */
  380. Oid resultelemtype; /* element type of result array */
  381. struct ArrayMapState *amstate; /* workspace for array_map */
  382. } arraycoerce;
  383. /* for EEOP_ROW */
  384. struct
  385. {
  386. TupleDesc tupdesc; /* descriptor for result tuples */
  387. /* workspace for the values constituting the row: */
  388. Datum *elemvalues;
  389. bool *elemnulls;
  390. } row;
  391. /* for EEOP_ROWCOMPARE_STEP */
  392. struct
  393. {
  394. /* lookup and call data for column comparison function */
  395. FmgrInfo *finfo;
  396. FunctionCallInfo fcinfo_data;
  397. PGFunction fn_addr;
  398. /* target for comparison resulting in NULL */
  399. int jumpnull;
  400. /* target for comparison yielding inequality */
  401. int jumpdone;
  402. } rowcompare_step;
  403. /* for EEOP_ROWCOMPARE_FINAL */
  404. struct
  405. {
  406. RowCompareType rctype;
  407. } rowcompare_final;
  408. /* for EEOP_MINMAX */
  409. struct
  410. {
  411. /* workspace for argument values */
  412. Datum *values;
  413. bool *nulls;
  414. int nelems;
  415. /* is it GREATEST or LEAST? */
  416. MinMaxOp op;
  417. /* lookup and call data for comparison function */
  418. FmgrInfo *finfo;
  419. FunctionCallInfo fcinfo_data;
  420. } minmax;
  421. /* for EEOP_FIELDSELECT */
  422. struct
  423. {
  424. AttrNumber fieldnum; /* field number to extract */
  425. Oid resulttype; /* field's type */
  426. /* cached descriptor for composite type - filled at runtime */
  427. ExprEvalRowtypeCache rowcache;
  428. } fieldselect;
  429. /* for EEOP_FIELDSTORE_DEFORM / FIELDSTORE_FORM */
  430. struct
  431. {
  432. /* original expression node */
  433. FieldStore *fstore;
  434. /* cached descriptor for composite type - filled at runtime */
  435. /* note that a DEFORM and FORM pair share the same cache */
  436. ExprEvalRowtypeCache *rowcache;
  437. /* workspace for column values */
  438. Datum *values;
  439. bool *nulls;
  440. int ncolumns;
  441. } fieldstore;
  442. /* for EEOP_SBSREF_SUBSCRIPTS */
  443. struct
  444. {
  445. ExecEvalBoolSubroutine subscriptfunc; /* evaluation subroutine */
  446. /* too big to have inline */
  447. struct SubscriptingRefState *state;
  448. int jumpdone; /* jump here on null */
  449. } sbsref_subscript;
  450. /* for EEOP_SBSREF_OLD / ASSIGN / FETCH */
  451. struct
  452. {
  453. ExecEvalSubroutine subscriptfunc; /* evaluation subroutine */
  454. /* too big to have inline */
  455. struct SubscriptingRefState *state;
  456. } sbsref;
  457. /* for EEOP_DOMAIN_NOTNULL / DOMAIN_CHECK */
  458. struct
  459. {
  460. /* name of constraint */
  461. char *constraintname;
  462. /* where the result of a CHECK constraint will be stored */
  463. Datum *checkvalue;
  464. bool *checknull;
  465. /* OID of domain type */
  466. Oid resulttype;
  467. } domaincheck;
  468. /* for EEOP_CONVERT_ROWTYPE */
  469. struct
  470. {
  471. Oid inputtype; /* input composite type */
  472. Oid outputtype; /* output composite type */
  473. /* these three fields are filled at runtime: */
  474. ExprEvalRowtypeCache *incache; /* cache for input type */
  475. ExprEvalRowtypeCache *outcache; /* cache for output type */
  476. TupleConversionMap *map; /* column mapping */
  477. } convert_rowtype;
  478. /* for EEOP_SCALARARRAYOP */
  479. struct
  480. {
  481. /* element_type/typlen/typbyval/typalign are filled at runtime */
  482. Oid element_type; /* InvalidOid if not yet filled */
  483. bool useOr; /* use OR or AND semantics? */
  484. int16 typlen; /* array element type storage info */
  485. bool typbyval;
  486. char typalign;
  487. FmgrInfo *finfo; /* function's lookup data */
  488. FunctionCallInfo fcinfo_data; /* arguments etc */
  489. /* faster to access without additional indirection: */
  490. PGFunction fn_addr; /* actual call address */
  491. } scalararrayop;
  492. /* for EEOP_HASHED_SCALARARRAYOP */
  493. struct
  494. {
  495. bool has_nulls;
  496. bool inclause; /* true for IN and false for NOT IN */
  497. struct ScalarArrayOpExprHashTable *elements_tab;
  498. FmgrInfo *finfo; /* function's lookup data */
  499. FunctionCallInfo fcinfo_data; /* arguments etc */
  500. ScalarArrayOpExpr *saop;
  501. } hashedscalararrayop;
  502. /* for EEOP_XMLEXPR */
  503. struct
  504. {
  505. XmlExpr *xexpr; /* original expression node */
  506. /* workspace for evaluating named args, if any */
  507. Datum *named_argvalue;
  508. bool *named_argnull;
  509. /* workspace for evaluating unnamed args, if any */
  510. Datum *argvalue;
  511. bool *argnull;
  512. } xmlexpr;
  513. /* for EEOP_AGGREF */
  514. struct
  515. {
  516. int aggno;
  517. } aggref;
  518. /* for EEOP_GROUPING_FUNC */
  519. struct
  520. {
  521. List *clauses; /* integer list of column numbers */
  522. } grouping_func;
  523. /* for EEOP_WINDOW_FUNC */
  524. struct
  525. {
  526. /* out-of-line state, modified by nodeWindowAgg.c */
  527. WindowFuncExprState *wfstate;
  528. } window_func;
  529. /* for EEOP_SUBPLAN */
  530. struct
  531. {
  532. /* out-of-line state, created by nodeSubplan.c */
  533. SubPlanState *sstate;
  534. } subplan;
  535. /* for EEOP_AGG_*DESERIALIZE */
  536. struct
  537. {
  538. FunctionCallInfo fcinfo_data;
  539. int jumpnull;
  540. } agg_deserialize;
  541. /* for EEOP_AGG_STRICT_INPUT_CHECK_NULLS / STRICT_INPUT_CHECK_ARGS */
  542. struct
  543. {
  544. /*
  545. * For EEOP_AGG_STRICT_INPUT_CHECK_ARGS args contains pointers to
  546. * the NullableDatums that need to be checked for NULLs.
  547. *
  548. * For EEOP_AGG_STRICT_INPUT_CHECK_NULLS nulls contains pointers
  549. * to booleans that need to be checked for NULLs.
  550. *
  551. * Both cases currently need to exist because sometimes the
  552. * to-be-checked nulls are in TupleTableSlot.isnull array, and
  553. * sometimes in FunctionCallInfoBaseData.args[i].isnull.
  554. */
  555. NullableDatum *args;
  556. bool *nulls;
  557. int nargs;
  558. int jumpnull;
  559. } agg_strict_input_check;
  560. /* for EEOP_AGG_PLAIN_PERGROUP_NULLCHECK */
  561. struct
  562. {
  563. int setoff;
  564. int jumpnull;
  565. } agg_plain_pergroup_nullcheck;
  566. /* for EEOP_AGG_PLAIN_TRANS_[INIT_][STRICT_]{BYVAL,BYREF} */
  567. /* for EEOP_AGG_ORDERED_TRANS_{DATUM,TUPLE} */
  568. struct
  569. {
  570. AggStatePerTrans pertrans;
  571. ExprContext *aggcontext;
  572. int setno;
  573. int transno;
  574. int setoff;
  575. } agg_trans;
  576. } d;
  577. } ExprEvalStep;
  578. /* Non-inline data for container operations */
  579. typedef struct SubscriptingRefState
  580. {
  581. bool isassignment; /* is it assignment, or just fetch? */
  582. /* workspace for type-specific subscripting code */
  583. void *workspace;
  584. /* numupper and upperprovided[] are filled at expression compile time */
  585. /* at runtime, subscripts are computed in upperindex[]/upperindexnull[] */
  586. int numupper;
  587. bool *upperprovided; /* indicates if this position is supplied */
  588. Datum *upperindex;
  589. bool *upperindexnull;
  590. /* similarly for lower indexes, if any */
  591. int numlower;
  592. bool *lowerprovided;
  593. Datum *lowerindex;
  594. bool *lowerindexnull;
  595. /* for assignment, new value to assign is evaluated into here */
  596. Datum replacevalue;
  597. bool replacenull;
  598. /* if we have a nested assignment, sbs_fetch_old puts old value here */
  599. Datum prevvalue;
  600. bool prevnull;
  601. } SubscriptingRefState;
  602. /* Execution step methods used for SubscriptingRef */
  603. typedef struct SubscriptExecSteps
  604. {
  605. /* See nodes/subscripting.h for more detail about these */
  606. ExecEvalBoolSubroutine sbs_check_subscripts; /* process subscripts */
  607. ExecEvalSubroutine sbs_fetch; /* fetch an element */
  608. ExecEvalSubroutine sbs_assign; /* assign to an element */
  609. ExecEvalSubroutine sbs_fetch_old; /* fetch old value for assignment */
  610. } SubscriptExecSteps;
  611. /* functions in execExpr.c */
  612. extern void ExprEvalPushStep(ExprState *es, const ExprEvalStep *s);
  613. /* functions in execExprInterp.c */
  614. extern void ExecReadyInterpretedExpr(ExprState *state);
  615. extern ExprEvalOp ExecEvalStepOp(ExprState *state, ExprEvalStep *op);
  616. extern Datum ExecInterpExprStillValid(ExprState *state, ExprContext *econtext, bool *isNull);
  617. extern void CheckExprStillValid(ExprState *state, ExprContext *econtext);
  618. /*
  619. * Non fast-path execution functions. These are externs instead of statics in
  620. * execExprInterp.c, because that allows them to be used by other methods of
  621. * expression evaluation, reducing code duplication.
  622. */
  623. extern void ExecEvalFuncExprFusage(ExprState *state, ExprEvalStep *op,
  624. ExprContext *econtext);
  625. extern void ExecEvalFuncExprStrictFusage(ExprState *state, ExprEvalStep *op,
  626. ExprContext *econtext);
  627. extern void ExecEvalParamExec(ExprState *state, ExprEvalStep *op,
  628. ExprContext *econtext);
  629. extern void ExecEvalParamExtern(ExprState *state, ExprEvalStep *op,
  630. ExprContext *econtext);
  631. extern void ExecEvalSQLValueFunction(ExprState *state, ExprEvalStep *op);
  632. extern void ExecEvalCurrentOfExpr(ExprState *state, ExprEvalStep *op);
  633. extern void ExecEvalNextValueExpr(ExprState *state, ExprEvalStep *op);
  634. extern void ExecEvalRowNull(ExprState *state, ExprEvalStep *op,
  635. ExprContext *econtext);
  636. extern void ExecEvalRowNotNull(ExprState *state, ExprEvalStep *op,
  637. ExprContext *econtext);
  638. extern void ExecEvalArrayExpr(ExprState *state, ExprEvalStep *op);
  639. extern void ExecEvalArrayCoerce(ExprState *state, ExprEvalStep *op,
  640. ExprContext *econtext);
  641. extern void ExecEvalRow(ExprState *state, ExprEvalStep *op);
  642. extern void ExecEvalMinMax(ExprState *state, ExprEvalStep *op);
  643. extern void ExecEvalFieldSelect(ExprState *state, ExprEvalStep *op,
  644. ExprContext *econtext);
  645. extern void ExecEvalFieldStoreDeForm(ExprState *state, ExprEvalStep *op,
  646. ExprContext *econtext);
  647. extern void ExecEvalFieldStoreForm(ExprState *state, ExprEvalStep *op,
  648. ExprContext *econtext);
  649. extern void ExecEvalConvertRowtype(ExprState *state, ExprEvalStep *op,
  650. ExprContext *econtext);
  651. extern void ExecEvalScalarArrayOp(ExprState *state, ExprEvalStep *op);
  652. extern void ExecEvalHashedScalarArrayOp(ExprState *state, ExprEvalStep *op,
  653. ExprContext *econtext);
  654. extern void ExecEvalConstraintNotNull(ExprState *state, ExprEvalStep *op);
  655. extern void ExecEvalConstraintCheck(ExprState *state, ExprEvalStep *op);
  656. extern void ExecEvalXmlExpr(ExprState *state, ExprEvalStep *op);
  657. extern void ExecEvalGroupingFunc(ExprState *state, ExprEvalStep *op);
  658. extern void ExecEvalSubPlan(ExprState *state, ExprEvalStep *op,
  659. ExprContext *econtext);
  660. extern void ExecEvalWholeRowVar(ExprState *state, ExprEvalStep *op,
  661. ExprContext *econtext);
  662. extern void ExecEvalSysVar(ExprState *state, ExprEvalStep *op,
  663. ExprContext *econtext, TupleTableSlot *slot);
  664. extern void ExecAggInitGroup(AggState *aggstate, AggStatePerTrans pertrans, AggStatePerGroup pergroup,
  665. ExprContext *aggcontext);
  666. extern Datum ExecAggTransReparent(AggState *aggstate, AggStatePerTrans pertrans,
  667. Datum newValue, bool newValueIsNull,
  668. Datum oldValue, bool oldValueIsNull);
  669. extern void ExecEvalAggOrderedTransDatum(ExprState *state, ExprEvalStep *op,
  670. ExprContext *econtext);
  671. extern void ExecEvalAggOrderedTransTuple(ExprState *state, ExprEvalStep *op,
  672. ExprContext *econtext);
  673. #endif /* EXEC_EXPR_H */