plannodes.h 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947
  1. /*-------------------------------------------------------------------------
  2. *
  3. * plannodes.h
  4. * definitions for query plan nodes
  5. *
  6. *
  7. * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
  8. * Portions Copyright (c) 1994, Regents of the University of California
  9. *
  10. * src/include/nodes/plannodes.h
  11. *
  12. *-------------------------------------------------------------------------
  13. */
  14. #ifndef PLANNODES_H
  15. #define PLANNODES_H
  16. #include "access/sdir.h"
  17. #include "lib/stringinfo.h"
  18. #include "nodes/bitmapset.h"
  19. #include "nodes/lockoptions.h"
  20. #include "nodes/primnodes.h"
  21. /* ----------------------------------------------------------------
  22. * node definitions
  23. * ----------------------------------------------------------------
  24. */
  25. /* ----------------
  26. * PlannedStmt node
  27. *
  28. * The output of the planner is a Plan tree headed by a PlannedStmt node.
  29. * PlannedStmt holds the "one time" information needed by the executor.
  30. * ----------------
  31. */
  32. typedef struct PlannedStmt
  33. {
  34. NodeTag type;
  35. CmdType commandType; /* select|insert|update|delete */
  36. uint32 queryId; /* query identifier (copied from Query) */
  37. bool hasReturning; /* is it insert|update|delete RETURNING? */
  38. bool hasModifyingCTE; /* has insert|update|delete in WITH? */
  39. bool canSetTag; /* do I set the command result tag? */
  40. bool transientPlan; /* redo plan when TransactionXmin changes? */
  41. bool dependsOnRole; /* is plan specific to current role? */
  42. bool parallelModeNeeded; /* parallel mode required to execute? */
  43. struct Plan *planTree; /* tree of Plan nodes */
  44. List *rtable; /* list of RangeTblEntry nodes */
  45. /* rtable indexes of target relations for INSERT/UPDATE/DELETE */
  46. List *resultRelations; /* integer list of RT indexes, or NIL */
  47. Node *utilityStmt; /* non-null if this is DECLARE CURSOR */
  48. List *subplans; /* Plan trees for SubPlan expressions */
  49. Bitmapset *rewindPlanIDs; /* indices of subplans that require REWIND */
  50. List *rowMarks; /* a list of PlanRowMark's */
  51. List *relationOids; /* OIDs of relations the plan depends on */
  52. List *invalItems; /* other dependencies, as PlanInvalItems */
  53. int nParamExec; /* number of PARAM_EXEC Params used */
  54. } PlannedStmt;
  55. /* macro for fetching the Plan associated with a SubPlan node */
  56. #define exec_subplan_get_plan(plannedstmt, subplan) \
  57. ((Plan *) list_nth((plannedstmt)->subplans, (subplan)->plan_id - 1))
  58. /* ----------------
  59. * Plan node
  60. *
  61. * All plan nodes "derive" from the Plan structure by having the
  62. * Plan structure as the first field. This ensures that everything works
  63. * when nodes are cast to Plan's. (node pointers are frequently cast to Plan*
  64. * when passed around generically in the executor)
  65. *
  66. * We never actually instantiate any Plan nodes; this is just the common
  67. * abstract superclass for all Plan-type nodes.
  68. * ----------------
  69. */
  70. typedef struct Plan
  71. {
  72. NodeTag type;
  73. /*
  74. * estimated execution costs for plan (see costsize.c for more info)
  75. */
  76. Cost startup_cost; /* cost expended before fetching any tuples */
  77. Cost total_cost; /* total cost (assuming all tuples fetched) */
  78. /*
  79. * planner's estimate of result size of this plan step
  80. */
  81. double plan_rows; /* number of rows plan is expected to emit */
  82. int plan_width; /* average row width in bytes */
  83. /*
  84. * information needed for parallel query
  85. */
  86. bool parallel_aware; /* engage parallel-aware logic? */
  87. /*
  88. * Common structural data for all Plan types.
  89. */
  90. int plan_node_id; /* unique across entire final plan tree */
  91. List *targetlist; /* target list to be computed at this node */
  92. List *qual; /* implicitly-ANDed qual conditions */
  93. struct Plan *lefttree; /* input plan tree(s) */
  94. struct Plan *righttree;
  95. List *initPlan; /* Init Plan nodes (un-correlated expr
  96. * subselects) */
  97. /*
  98. * Information for management of parameter-change-driven rescanning
  99. *
  100. * extParam includes the paramIDs of all external PARAM_EXEC params
  101. * affecting this plan node or its children. setParam params from the
  102. * node's initPlans are not included, but their extParams are.
  103. *
  104. * allParam includes all the extParam paramIDs, plus the IDs of local
  105. * params that affect the node (i.e., the setParams of its initplans).
  106. * These are _all_ the PARAM_EXEC params that affect this node.
  107. */
  108. Bitmapset *extParam;
  109. Bitmapset *allParam;
  110. } Plan;
  111. /* ----------------
  112. * these are defined to avoid confusion problems with "left"
  113. * and "right" and "inner" and "outer". The convention is that
  114. * the "left" plan is the "outer" plan and the "right" plan is
  115. * the inner plan, but these make the code more readable.
  116. * ----------------
  117. */
  118. #define innerPlan(node) (((Plan *)(node))->righttree)
  119. #define outerPlan(node) (((Plan *)(node))->lefttree)
  120. /* ----------------
  121. * Result node -
  122. * If no outer plan, evaluate a variable-free targetlist.
  123. * If outer plan, return tuples from outer plan (after a level of
  124. * projection as shown by targetlist).
  125. *
  126. * If resconstantqual isn't NULL, it represents a one-time qualification
  127. * test (i.e., one that doesn't depend on any variables from the outer plan,
  128. * so needs to be evaluated only once).
  129. * ----------------
  130. */
  131. typedef struct Result
  132. {
  133. Plan plan;
  134. Node *resconstantqual;
  135. } Result;
  136. /* ----------------
  137. * ModifyTable node -
  138. * Apply rows produced by subplan(s) to result table(s),
  139. * by inserting, updating, or deleting.
  140. *
  141. * Note that rowMarks and epqParam are presumed to be valid for all the
  142. * subplan(s); they can't contain any info that varies across subplans.
  143. * ----------------
  144. */
  145. typedef struct ModifyTable
  146. {
  147. Plan plan;
  148. CmdType operation; /* INSERT, UPDATE, or DELETE */
  149. bool canSetTag; /* do we set the command tag/es_processed? */
  150. Index nominalRelation; /* Parent RT index for use of EXPLAIN */
  151. List *resultRelations; /* integer list of RT indexes */
  152. int resultRelIndex; /* index of first resultRel in plan's list */
  153. List *plans; /* plan(s) producing source data */
  154. List *withCheckOptionLists; /* per-target-table WCO lists */
  155. List *returningLists; /* per-target-table RETURNING tlists */
  156. List *fdwPrivLists; /* per-target-table FDW private data lists */
  157. Bitmapset *fdwDirectModifyPlans; /* indices of FDW DM plans */
  158. List *rowMarks; /* PlanRowMarks (non-locking only) */
  159. int epqParam; /* ID of Param for EvalPlanQual re-eval */
  160. OnConflictAction onConflictAction; /* ON CONFLICT action */
  161. List *arbiterIndexes; /* List of ON CONFLICT arbiter index OIDs */
  162. List *onConflictSet; /* SET for INSERT ON CONFLICT DO UPDATE */
  163. Node *onConflictWhere; /* WHERE for ON CONFLICT UPDATE */
  164. Index exclRelRTI; /* RTI of the EXCLUDED pseudo relation */
  165. List *exclRelTlist; /* tlist of the EXCLUDED pseudo relation */
  166. } ModifyTable;
  167. /* ----------------
  168. * Append node -
  169. * Generate the concatenation of the results of sub-plans.
  170. * ----------------
  171. */
  172. typedef struct Append
  173. {
  174. Plan plan;
  175. List *appendplans;
  176. } Append;
  177. /* ----------------
  178. * MergeAppend node -
  179. * Merge the results of pre-sorted sub-plans to preserve the ordering.
  180. * ----------------
  181. */
  182. typedef struct MergeAppend
  183. {
  184. Plan plan;
  185. List *mergeplans;
  186. /* remaining fields are just like the sort-key info in struct Sort */
  187. int numCols; /* number of sort-key columns */
  188. AttrNumber *sortColIdx; /* their indexes in the target list */
  189. Oid *sortOperators; /* OIDs of operators to sort them by */
  190. Oid *collations; /* OIDs of collations */
  191. bool *nullsFirst; /* NULLS FIRST/LAST directions */
  192. } MergeAppend;
  193. /* ----------------
  194. * RecursiveUnion node -
  195. * Generate a recursive union of two subplans.
  196. *
  197. * The "outer" subplan is always the non-recursive term, and the "inner"
  198. * subplan is the recursive term.
  199. * ----------------
  200. */
  201. typedef struct RecursiveUnion
  202. {
  203. Plan plan;
  204. int wtParam; /* ID of Param representing work table */
  205. /* Remaining fields are zero/null in UNION ALL case */
  206. int numCols; /* number of columns to check for
  207. * duplicate-ness */
  208. AttrNumber *dupColIdx; /* their indexes in the target list */
  209. Oid *dupOperators; /* equality operators to compare with */
  210. long numGroups; /* estimated number of groups in input */
  211. } RecursiveUnion;
  212. /* ----------------
  213. * BitmapAnd node -
  214. * Generate the intersection of the results of sub-plans.
  215. *
  216. * The subplans must be of types that yield tuple bitmaps. The targetlist
  217. * and qual fields of the plan are unused and are always NIL.
  218. * ----------------
  219. */
  220. typedef struct BitmapAnd
  221. {
  222. Plan plan;
  223. List *bitmapplans;
  224. } BitmapAnd;
  225. /* ----------------
  226. * BitmapOr node -
  227. * Generate the union of the results of sub-plans.
  228. *
  229. * The subplans must be of types that yield tuple bitmaps. The targetlist
  230. * and qual fields of the plan are unused and are always NIL.
  231. * ----------------
  232. */
  233. typedef struct BitmapOr
  234. {
  235. Plan plan;
  236. List *bitmapplans;
  237. } BitmapOr;
  238. /*
  239. * ==========
  240. * Scan nodes
  241. * ==========
  242. */
  243. typedef struct Scan
  244. {
  245. Plan plan;
  246. Index scanrelid; /* relid is index into the range table */
  247. } Scan;
  248. /* ----------------
  249. * sequential scan node
  250. * ----------------
  251. */
  252. typedef Scan SeqScan;
  253. /* ----------------
  254. * table sample scan node
  255. * ----------------
  256. */
  257. typedef struct SampleScan
  258. {
  259. Scan scan;
  260. /* use struct pointer to avoid including parsenodes.h here */
  261. struct TableSampleClause *tablesample;
  262. } SampleScan;
  263. /* ----------------
  264. * index scan node
  265. *
  266. * indexqualorig is an implicitly-ANDed list of index qual expressions, each
  267. * in the same form it appeared in the query WHERE condition. Each should
  268. * be of the form (indexkey OP comparisonval) or (comparisonval OP indexkey).
  269. * The indexkey is a Var or expression referencing column(s) of the index's
  270. * base table. The comparisonval might be any expression, but it won't use
  271. * any columns of the base table. The expressions are ordered by index
  272. * column position (but items referencing the same index column can appear
  273. * in any order). indexqualorig is used at runtime only if we have to recheck
  274. * a lossy indexqual.
  275. *
  276. * indexqual has the same form, but the expressions have been commuted if
  277. * necessary to put the indexkeys on the left, and the indexkeys are replaced
  278. * by Var nodes identifying the index columns (their varno is INDEX_VAR and
  279. * their varattno is the index column number).
  280. *
  281. * indexorderbyorig is similarly the original form of any ORDER BY expressions
  282. * that are being implemented by the index, while indexorderby is modified to
  283. * have index column Vars on the left-hand side. Here, multiple expressions
  284. * must appear in exactly the ORDER BY order, and this is not necessarily the
  285. * index column order. Only the expressions are provided, not the auxiliary
  286. * sort-order information from the ORDER BY SortGroupClauses; it's assumed
  287. * that the sort ordering is fully determinable from the top-level operators.
  288. * indexorderbyorig is used at runtime to recheck the ordering, if the index
  289. * cannot calculate an accurate ordering. It is also needed for EXPLAIN.
  290. *
  291. * indexorderbyops is a list of the OIDs of the operators used to sort the
  292. * ORDER BY expressions. This is used together with indexorderbyorig to
  293. * recheck ordering at run time. (Note that indexorderby, indexorderbyorig,
  294. * and indexorderbyops are used for amcanorderbyop cases, not amcanorder.)
  295. *
  296. * indexorderdir specifies the scan ordering, for indexscans on amcanorder
  297. * indexes (for other indexes it should be "don't care").
  298. * ----------------
  299. */
  300. typedef struct IndexScan
  301. {
  302. Scan scan;
  303. Oid indexid; /* OID of index to scan */
  304. List *indexqual; /* list of index quals (usually OpExprs) */
  305. List *indexqualorig; /* the same in original form */
  306. List *indexorderby; /* list of index ORDER BY exprs */
  307. List *indexorderbyorig; /* the same in original form */
  308. List *indexorderbyops; /* OIDs of sort ops for ORDER BY exprs */
  309. ScanDirection indexorderdir; /* forward or backward or don't care */
  310. } IndexScan;
  311. /* ----------------
  312. * index-only scan node
  313. *
  314. * IndexOnlyScan is very similar to IndexScan, but it specifies an
  315. * index-only scan, in which the data comes from the index not the heap.
  316. * Because of this, *all* Vars in the plan node's targetlist, qual, and
  317. * index expressions reference index columns and have varno = INDEX_VAR.
  318. * Hence we do not need separate indexqualorig and indexorderbyorig lists,
  319. * since their contents would be equivalent to indexqual and indexorderby.
  320. *
  321. * To help EXPLAIN interpret the index Vars for display, we provide
  322. * indextlist, which represents the contents of the index as a targetlist
  323. * with one TLE per index column. Vars appearing in this list reference
  324. * the base table, and this is the only field in the plan node that may
  325. * contain such Vars.
  326. * ----------------
  327. */
  328. typedef struct IndexOnlyScan
  329. {
  330. Scan scan;
  331. Oid indexid; /* OID of index to scan */
  332. List *indexqual; /* list of index quals (usually OpExprs) */
  333. List *indexorderby; /* list of index ORDER BY exprs */
  334. List *indextlist; /* TargetEntry list describing index's cols */
  335. ScanDirection indexorderdir; /* forward or backward or don't care */
  336. } IndexOnlyScan;
  337. /* ----------------
  338. * bitmap index scan node
  339. *
  340. * BitmapIndexScan delivers a bitmap of potential tuple locations;
  341. * it does not access the heap itself. The bitmap is used by an
  342. * ancestor BitmapHeapScan node, possibly after passing through
  343. * intermediate BitmapAnd and/or BitmapOr nodes to combine it with
  344. * the results of other BitmapIndexScans.
  345. *
  346. * The fields have the same meanings as for IndexScan, except we don't
  347. * store a direction flag because direction is uninteresting.
  348. *
  349. * In a BitmapIndexScan plan node, the targetlist and qual fields are
  350. * not used and are always NIL. The indexqualorig field is unused at
  351. * run time too, but is saved for the benefit of EXPLAIN.
  352. * ----------------
  353. */
  354. typedef struct BitmapIndexScan
  355. {
  356. Scan scan;
  357. Oid indexid; /* OID of index to scan */
  358. List *indexqual; /* list of index quals (OpExprs) */
  359. List *indexqualorig; /* the same in original form */
  360. } BitmapIndexScan;
  361. /* ----------------
  362. * bitmap sequential scan node
  363. *
  364. * This needs a copy of the qual conditions being used by the input index
  365. * scans because there are various cases where we need to recheck the quals;
  366. * for example, when the bitmap is lossy about the specific rows on a page
  367. * that meet the index condition.
  368. * ----------------
  369. */
  370. typedef struct BitmapHeapScan
  371. {
  372. Scan scan;
  373. List *bitmapqualorig; /* index quals, in standard expr form */
  374. } BitmapHeapScan;
  375. /* ----------------
  376. * tid scan node
  377. *
  378. * tidquals is an implicitly OR'ed list of qual expressions of the form
  379. * "CTID = pseudoconstant" or "CTID = ANY(pseudoconstant_array)".
  380. * ----------------
  381. */
  382. typedef struct TidScan
  383. {
  384. Scan scan;
  385. List *tidquals; /* qual(s) involving CTID = something */
  386. } TidScan;
  387. /* ----------------
  388. * subquery scan node
  389. *
  390. * SubqueryScan is for scanning the output of a sub-query in the range table.
  391. * We often need an extra plan node above the sub-query's plan to perform
  392. * expression evaluations (which we can't push into the sub-query without
  393. * risking changing its semantics). Although we are not scanning a physical
  394. * relation, we make this a descendant of Scan anyway for code-sharing
  395. * purposes.
  396. *
  397. * Note: we store the sub-plan in the type-specific subplan field, not in
  398. * the generic lefttree field as you might expect. This is because we do
  399. * not want plan-tree-traversal routines to recurse into the subplan without
  400. * knowing that they are changing Query contexts.
  401. * ----------------
  402. */
  403. typedef struct SubqueryScan
  404. {
  405. Scan scan;
  406. Plan *subplan;
  407. } SubqueryScan;
  408. /* ----------------
  409. * FunctionScan node
  410. * ----------------
  411. */
  412. typedef struct FunctionScan
  413. {
  414. Scan scan;
  415. List *functions; /* list of RangeTblFunction nodes */
  416. bool funcordinality; /* WITH ORDINALITY */
  417. } FunctionScan;
  418. /* ----------------
  419. * ValuesScan node
  420. * ----------------
  421. */
  422. typedef struct ValuesScan
  423. {
  424. Scan scan;
  425. List *values_lists; /* list of expression lists */
  426. } ValuesScan;
  427. /* ----------------
  428. * CteScan node
  429. * ----------------
  430. */
  431. typedef struct CteScan
  432. {
  433. Scan scan;
  434. int ctePlanId; /* ID of init SubPlan for CTE */
  435. int cteParam; /* ID of Param representing CTE output */
  436. } CteScan;
  437. /* ----------------
  438. * WorkTableScan node
  439. * ----------------
  440. */
  441. typedef struct WorkTableScan
  442. {
  443. Scan scan;
  444. int wtParam; /* ID of Param representing work table */
  445. } WorkTableScan;
  446. /* ----------------
  447. * ForeignScan node
  448. *
  449. * fdw_exprs and fdw_private are both under the control of the foreign-data
  450. * wrapper, but fdw_exprs is presumed to contain expression trees and will
  451. * be post-processed accordingly by the planner; fdw_private won't be.
  452. * Note that everything in both lists must be copiable by copyObject().
  453. * One way to store an arbitrary blob of bytes is to represent it as a bytea
  454. * Const. Usually, though, you'll be better off choosing a representation
  455. * that can be dumped usefully by nodeToString().
  456. *
  457. * fdw_scan_tlist is a targetlist describing the contents of the scan tuple
  458. * returned by the FDW; it can be NIL if the scan tuple matches the declared
  459. * rowtype of the foreign table, which is the normal case for a simple foreign
  460. * table scan. (If the plan node represents a foreign join, fdw_scan_tlist
  461. * is required since there is no rowtype available from the system catalogs.)
  462. * When fdw_scan_tlist is provided, Vars in the node's tlist and quals must
  463. * have varno INDEX_VAR, and their varattnos correspond to resnos in the
  464. * fdw_scan_tlist (which are also column numbers in the actual scan tuple).
  465. * fdw_scan_tlist is never actually executed; it just holds expression trees
  466. * describing what is in the scan tuple's columns.
  467. *
  468. * fdw_recheck_quals should contain any quals which the core system passed to
  469. * the FDW but which were not added to scan.plan.qual; that is, it should
  470. * contain the quals being checked remotely. This is needed for correct
  471. * behavior during EvalPlanQual rechecks.
  472. *
  473. * When the plan node represents a foreign join, scan.scanrelid is zero and
  474. * fs_relids must be consulted to identify the join relation. (fs_relids
  475. * is valid for simple scans as well, but will always match scan.scanrelid.)
  476. * ----------------
  477. */
  478. typedef struct ForeignScan
  479. {
  480. Scan scan;
  481. CmdType operation; /* SELECT/INSERT/UPDATE/DELETE */
  482. Oid fs_server; /* OID of foreign server */
  483. List *fdw_exprs; /* expressions that FDW may evaluate */
  484. List *fdw_private; /* private data for FDW */
  485. List *fdw_scan_tlist; /* optional tlist describing scan tuple */
  486. List *fdw_recheck_quals; /* original quals not in
  487. * scan.plan.qual */
  488. Bitmapset *fs_relids; /* RTIs generated by this scan */
  489. bool fsSystemCol; /* true if any "system column" is needed */
  490. } ForeignScan;
  491. /* ----------------
  492. * CustomScan node
  493. *
  494. * The comments for ForeignScan's fdw_exprs, fdw_private, fdw_scan_tlist,
  495. * and fs_relids fields apply equally to CustomScan's custom_exprs,
  496. * custom_private, custom_scan_tlist, and custom_relids fields. The
  497. * convention of setting scan.scanrelid to zero for joins applies as well.
  498. *
  499. * Note that since Plan trees can be copied, custom scan providers *must*
  500. * fit all plan data they need into those fields; embedding CustomScan in
  501. * a larger struct will not work.
  502. * ----------------
  503. */
  504. struct CustomScanMethods;
  505. typedef struct CustomScan
  506. {
  507. Scan scan;
  508. uint32 flags; /* mask of CUSTOMPATH_* flags, see
  509. * nodes/extensible.h */
  510. List *custom_plans; /* list of Plan nodes, if any */
  511. List *custom_exprs; /* expressions that custom code may evaluate */
  512. List *custom_private; /* private data for custom code */
  513. List *custom_scan_tlist; /* optional tlist describing scan
  514. * tuple */
  515. Bitmapset *custom_relids; /* RTIs generated by this scan */
  516. const struct CustomScanMethods *methods;
  517. } CustomScan;
  518. /*
  519. * ==========
  520. * Join nodes
  521. * ==========
  522. */
  523. /* ----------------
  524. * Join node
  525. *
  526. * jointype: rule for joining tuples from left and right subtrees
  527. * joinqual: qual conditions that came from JOIN/ON or JOIN/USING
  528. * (plan.qual contains conditions that came from WHERE)
  529. *
  530. * When jointype is INNER, joinqual and plan.qual are semantically
  531. * interchangeable. For OUTER jointypes, the two are *not* interchangeable;
  532. * only joinqual is used to determine whether a match has been found for
  533. * the purpose of deciding whether to generate null-extended tuples.
  534. * (But plan.qual is still applied before actually returning a tuple.)
  535. * For an outer join, only joinquals are allowed to be used as the merge
  536. * or hash condition of a merge or hash join.
  537. * ----------------
  538. */
  539. typedef struct Join
  540. {
  541. Plan plan;
  542. JoinType jointype;
  543. List *joinqual; /* JOIN quals (in addition to plan.qual) */
  544. } Join;
  545. /* ----------------
  546. * nest loop join node
  547. *
  548. * The nestParams list identifies any executor Params that must be passed
  549. * into execution of the inner subplan carrying values from the current row
  550. * of the outer subplan. Currently we restrict these values to be simple
  551. * Vars, but perhaps someday that'd be worth relaxing. (Note: during plan
  552. * creation, the paramval can actually be a PlaceHolderVar expression; but it
  553. * must be a Var with varno OUTER_VAR by the time it gets to the executor.)
  554. * ----------------
  555. */
  556. typedef struct NestLoop
  557. {
  558. Join join;
  559. List *nestParams; /* list of NestLoopParam nodes */
  560. } NestLoop;
  561. typedef struct NestLoopParam
  562. {
  563. NodeTag type;
  564. int paramno; /* number of the PARAM_EXEC Param to set */
  565. Var *paramval; /* outer-relation Var to assign to Param */
  566. } NestLoopParam;
  567. /* ----------------
  568. * merge join node
  569. *
  570. * The expected ordering of each mergeable column is described by a btree
  571. * opfamily OID, a collation OID, a direction (BTLessStrategyNumber or
  572. * BTGreaterStrategyNumber) and a nulls-first flag. Note that the two sides
  573. * of each mergeclause may be of different datatypes, but they are ordered the
  574. * same way according to the common opfamily and collation. The operator in
  575. * each mergeclause must be an equality operator of the indicated opfamily.
  576. * ----------------
  577. */
  578. typedef struct MergeJoin
  579. {
  580. Join join;
  581. List *mergeclauses; /* mergeclauses as expression trees */
  582. /* these are arrays, but have the same length as the mergeclauses list: */
  583. Oid *mergeFamilies; /* per-clause OIDs of btree opfamilies */
  584. Oid *mergeCollations; /* per-clause OIDs of collations */
  585. int *mergeStrategies; /* per-clause ordering (ASC or DESC) */
  586. bool *mergeNullsFirst; /* per-clause nulls ordering */
  587. } MergeJoin;
  588. /* ----------------
  589. * hash join node
  590. * ----------------
  591. */
  592. typedef struct HashJoin
  593. {
  594. Join join;
  595. List *hashclauses;
  596. } HashJoin;
  597. /* ----------------
  598. * materialization node
  599. * ----------------
  600. */
  601. typedef struct Material
  602. {
  603. Plan plan;
  604. } Material;
  605. /* ----------------
  606. * sort node
  607. * ----------------
  608. */
  609. typedef struct Sort
  610. {
  611. Plan plan;
  612. int numCols; /* number of sort-key columns */
  613. AttrNumber *sortColIdx; /* their indexes in the target list */
  614. Oid *sortOperators; /* OIDs of operators to sort them by */
  615. Oid *collations; /* OIDs of collations */
  616. bool *nullsFirst; /* NULLS FIRST/LAST directions */
  617. } Sort;
  618. /* ---------------
  619. * group node -
  620. * Used for queries with GROUP BY (but no aggregates) specified.
  621. * The input must be presorted according to the grouping columns.
  622. * ---------------
  623. */
  624. typedef struct Group
  625. {
  626. Plan plan;
  627. int numCols; /* number of grouping columns */
  628. AttrNumber *grpColIdx; /* their indexes in the target list */
  629. Oid *grpOperators; /* equality operators to compare with */
  630. } Group;
  631. /* ---------------
  632. * aggregate node
  633. *
  634. * An Agg node implements plain or grouped aggregation. For grouped
  635. * aggregation, we can work with presorted input or unsorted input;
  636. * the latter strategy uses an internal hashtable.
  637. *
  638. * Notice the lack of any direct info about the aggregate functions to be
  639. * computed. They are found by scanning the node's tlist and quals during
  640. * executor startup. (It is possible that there are no aggregate functions;
  641. * this could happen if they get optimized away by constant-folding, or if
  642. * we are using the Agg node to implement hash-based grouping.)
  643. * ---------------
  644. */
  645. typedef struct Agg
  646. {
  647. Plan plan;
  648. AggStrategy aggstrategy; /* basic strategy, see nodes.h */
  649. AggSplit aggsplit; /* agg-splitting mode, see nodes.h */
  650. int numCols; /* number of grouping columns */
  651. AttrNumber *grpColIdx; /* their indexes in the target list */
  652. Oid *grpOperators; /* equality operators to compare with */
  653. long numGroups; /* estimated number of groups in input */
  654. Bitmapset *aggParams; /* IDs of Params used in Aggref inputs */
  655. /* Note: planner provides numGroups & aggParams only in AGG_HASHED case */
  656. List *groupingSets; /* grouping sets to use */
  657. List *chain; /* chained Agg/Sort nodes */
  658. } Agg;
  659. /* ----------------
  660. * window aggregate node
  661. * ----------------
  662. */
  663. typedef struct WindowAgg
  664. {
  665. Plan plan;
  666. Index winref; /* ID referenced by window functions */
  667. int partNumCols; /* number of columns in partition clause */
  668. AttrNumber *partColIdx; /* their indexes in the target list */
  669. Oid *partOperators; /* equality operators for partition columns */
  670. int ordNumCols; /* number of columns in ordering clause */
  671. AttrNumber *ordColIdx; /* their indexes in the target list */
  672. Oid *ordOperators; /* equality operators for ordering columns */
  673. int frameOptions; /* frame_clause options, see WindowDef */
  674. Node *startOffset; /* expression for starting bound, if any */
  675. Node *endOffset; /* expression for ending bound, if any */
  676. } WindowAgg;
  677. /* ----------------
  678. * unique node
  679. * ----------------
  680. */
  681. typedef struct Unique
  682. {
  683. Plan plan;
  684. int numCols; /* number of columns to check for uniqueness */
  685. AttrNumber *uniqColIdx; /* their indexes in the target list */
  686. Oid *uniqOperators; /* equality operators to compare with */
  687. } Unique;
  688. /* ------------
  689. * gather node
  690. * ------------
  691. */
  692. typedef struct Gather
  693. {
  694. Plan plan;
  695. int num_workers;
  696. bool single_copy;
  697. bool invisible; /* suppress EXPLAIN display (for testing)? */
  698. } Gather;
  699. /* ----------------
  700. * hash build node
  701. *
  702. * If the executor is supposed to try to apply skew join optimization, then
  703. * skewTable/skewColumn/skewInherit identify the outer relation's join key
  704. * column, from which the relevant MCV statistics can be fetched. Also, its
  705. * type information is provided to save a lookup.
  706. * ----------------
  707. */
  708. typedef struct Hash
  709. {
  710. Plan plan;
  711. Oid skewTable; /* outer join key's table OID, or InvalidOid */
  712. AttrNumber skewColumn; /* outer join key's column #, or zero */
  713. bool skewInherit; /* is outer join rel an inheritance tree? */
  714. Oid skewColType; /* datatype of the outer key column */
  715. int32 skewColTypmod; /* typmod of the outer key column */
  716. /* all other info is in the parent HashJoin node */
  717. } Hash;
  718. /* ----------------
  719. * setop node
  720. * ----------------
  721. */
  722. typedef struct SetOp
  723. {
  724. Plan plan;
  725. SetOpCmd cmd; /* what to do, see nodes.h */
  726. SetOpStrategy strategy; /* how to do it, see nodes.h */
  727. int numCols; /* number of columns to check for
  728. * duplicate-ness */
  729. AttrNumber *dupColIdx; /* their indexes in the target list */
  730. Oid *dupOperators; /* equality operators to compare with */
  731. AttrNumber flagColIdx; /* where is the flag column, if any */
  732. int firstFlag; /* flag value for first input relation */
  733. long numGroups; /* estimated number of groups in input */
  734. } SetOp;
  735. /* ----------------
  736. * lock-rows node
  737. *
  738. * rowMarks identifies the rels to be locked by this node; it should be
  739. * a subset of the rowMarks listed in the top-level PlannedStmt.
  740. * epqParam is a Param that all scan nodes below this one must depend on.
  741. * It is used to force re-evaluation of the plan during EvalPlanQual.
  742. * ----------------
  743. */
  744. typedef struct LockRows
  745. {
  746. Plan plan;
  747. List *rowMarks; /* a list of PlanRowMark's */
  748. int epqParam; /* ID of Param for EvalPlanQual re-eval */
  749. } LockRows;
  750. /* ----------------
  751. * limit node
  752. *
  753. * Note: as of Postgres 8.2, the offset and count expressions are expected
  754. * to yield int8, rather than int4 as before.
  755. * ----------------
  756. */
  757. typedef struct Limit
  758. {
  759. Plan plan;
  760. Node *limitOffset; /* OFFSET parameter, or NULL if none */
  761. Node *limitCount; /* COUNT parameter, or NULL if none */
  762. } Limit;
  763. /*
  764. * RowMarkType -
  765. * enums for types of row-marking operations
  766. *
  767. * The first four of these values represent different lock strengths that
  768. * we can take on tuples according to SELECT FOR [KEY] UPDATE/SHARE requests.
  769. * We support these on regular tables, as well as on foreign tables whose FDWs
  770. * report support for late locking. For other foreign tables, any locking
  771. * that might be done for such requests must happen during the initial row
  772. * fetch; their FDWs provide no mechanism for going back to lock a row later.
  773. * This means that the semantics will be a bit different than for a local
  774. * table; in particular we are likely to lock more rows than would be locked
  775. * locally, since remote rows will be locked even if they then fail
  776. * locally-checked restriction or join quals. However, the prospect of
  777. * doing a separate remote query to lock each selected row is usually pretty
  778. * unappealing, so early locking remains a credible design choice for FDWs.
  779. *
  780. * When doing UPDATE, DELETE, or SELECT FOR UPDATE/SHARE, we have to uniquely
  781. * identify all the source rows, not only those from the target relations, so
  782. * that we can perform EvalPlanQual rechecking at need. For plain tables we
  783. * can just fetch the TID, much as for a target relation; this case is
  784. * represented by ROW_MARK_REFERENCE. Otherwise (for example for VALUES or
  785. * FUNCTION scans) we have to copy the whole row value. ROW_MARK_COPY is
  786. * pretty inefficient, since most of the time we'll never need the data; but
  787. * fortunately the overhead is usually not performance-critical in practice.
  788. * By default we use ROW_MARK_COPY for foreign tables, but if the FDW has
  789. * a concept of rowid it can request to use ROW_MARK_REFERENCE instead.
  790. * (Again, this probably doesn't make sense if a physical remote fetch is
  791. * needed, but for FDWs that map to local storage it might be credible.)
  792. */
  793. typedef enum RowMarkType
  794. {
  795. ROW_MARK_EXCLUSIVE, /* obtain exclusive tuple lock */
  796. ROW_MARK_NOKEYEXCLUSIVE, /* obtain no-key exclusive tuple lock */
  797. ROW_MARK_SHARE, /* obtain shared tuple lock */
  798. ROW_MARK_KEYSHARE, /* obtain keyshare tuple lock */
  799. ROW_MARK_REFERENCE, /* just fetch the TID, don't lock it */
  800. ROW_MARK_COPY /* physically copy the row value */
  801. } RowMarkType;
  802. #define RowMarkRequiresRowShareLock(marktype) ((marktype) <= ROW_MARK_KEYSHARE)
  803. /*
  804. * PlanRowMark -
  805. * plan-time representation of FOR [KEY] UPDATE/SHARE clauses
  806. *
  807. * When doing UPDATE, DELETE, or SELECT FOR UPDATE/SHARE, we create a separate
  808. * PlanRowMark node for each non-target relation in the query. Relations that
  809. * are not specified as FOR UPDATE/SHARE are marked ROW_MARK_REFERENCE (if
  810. * regular tables or supported foreign tables) or ROW_MARK_COPY (if not).
  811. *
  812. * Initially all PlanRowMarks have rti == prti and isParent == false.
  813. * When the planner discovers that a relation is the root of an inheritance
  814. * tree, it sets isParent true, and adds an additional PlanRowMark to the
  815. * list for each child relation (including the target rel itself in its role
  816. * as a child). The child entries have rti == child rel's RT index and
  817. * prti == parent's RT index, and can therefore be recognized as children by
  818. * the fact that prti != rti. The parent's allMarkTypes field gets the OR
  819. * of (1<<markType) across all its children (this definition allows children
  820. * to use different markTypes).
  821. *
  822. * The planner also adds resjunk output columns to the plan that carry
  823. * information sufficient to identify the locked or fetched rows. When
  824. * markType != ROW_MARK_COPY, these columns are named
  825. * tableoid%u OID of table
  826. * ctid%u TID of row
  827. * The tableoid column is only present for an inheritance hierarchy.
  828. * When markType == ROW_MARK_COPY, there is instead a single column named
  829. * wholerow%u whole-row value of relation
  830. * (An inheritance hierarchy could have all three resjunk output columns,
  831. * if some children use a different markType than others.)
  832. * In all three cases, %u represents the rowmark ID number (rowmarkId).
  833. * This number is unique within a plan tree, except that child relation
  834. * entries copy their parent's rowmarkId. (Assigning unique numbers
  835. * means we needn't renumber rowmarkIds when flattening subqueries, which
  836. * would require finding and renaming the resjunk columns as well.)
  837. * Note this means that all tables in an inheritance hierarchy share the
  838. * same resjunk column names. However, in an inherited UPDATE/DELETE the
  839. * columns could have different physical column numbers in each subplan.
  840. */
  841. typedef struct PlanRowMark
  842. {
  843. NodeTag type;
  844. Index rti; /* range table index of markable relation */
  845. Index prti; /* range table index of parent relation */
  846. Index rowmarkId; /* unique identifier for resjunk columns */
  847. RowMarkType markType; /* see enum above */
  848. int allMarkTypes; /* OR of (1<<markType) for all children */
  849. LockClauseStrength strength; /* LockingClause's strength, or LCS_NONE */
  850. LockWaitPolicy waitPolicy; /* NOWAIT and SKIP LOCKED options */
  851. bool isParent; /* true if this is a "dummy" parent entry */
  852. } PlanRowMark;
  853. /*
  854. * Plan invalidation info
  855. *
  856. * We track the objects on which a PlannedStmt depends in two ways:
  857. * relations are recorded as a simple list of OIDs, and everything else
  858. * is represented as a list of PlanInvalItems. A PlanInvalItem is designed
  859. * to be used with the syscache invalidation mechanism, so it identifies a
  860. * system catalog entry by cache ID and hash value.
  861. */
  862. typedef struct PlanInvalItem
  863. {
  864. NodeTag type;
  865. int cacheId; /* a syscache ID, see utils/syscache.h */
  866. uint32 hashValue; /* hash value of object's cache lookup key */
  867. } PlanInvalItem;
  868. #endif /* PLANNODES_H */