2
0

plannodes.h 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349
  1. /*-------------------------------------------------------------------------
  2. *
  3. * plannodes.h
  4. * definitions for query plan nodes
  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/nodes/plannodes.h
  11. *
  12. *-------------------------------------------------------------------------
  13. */
  14. #ifndef PLANNODES_H
  15. #define PLANNODES_H
  16. #include "access/sdir.h"
  17. #include "access/stratnum.h"
  18. #include "lib/stringinfo.h"
  19. #include "nodes/bitmapset.h"
  20. #include "nodes/lockoptions.h"
  21. #include "nodes/parsenodes.h"
  22. #include "nodes/primnodes.h"
  23. /* ----------------------------------------------------------------
  24. * node definitions
  25. * ----------------------------------------------------------------
  26. */
  27. /* ----------------
  28. * PlannedStmt node
  29. *
  30. * The output of the planner is a Plan tree headed by a PlannedStmt node.
  31. * PlannedStmt holds the "one time" information needed by the executor.
  32. *
  33. * For simplicity in APIs, we also wrap utility statements in PlannedStmt
  34. * nodes; in such cases, commandType == CMD_UTILITY, the statement itself
  35. * is in the utilityStmt field, and the rest of the struct is mostly dummy.
  36. * (We do use canSetTag, stmt_location, stmt_len, and possibly queryId.)
  37. * ----------------
  38. */
  39. typedef struct PlannedStmt
  40. {
  41. NodeTag type;
  42. CmdType commandType; /* select|insert|update|delete|merge|utility */
  43. uint64 queryId; /* query identifier (copied from Query) */
  44. bool hasReturning; /* is it insert|update|delete RETURNING? */
  45. bool hasModifyingCTE; /* has insert|update|delete in WITH? */
  46. bool canSetTag; /* do I set the command result tag? */
  47. bool transientPlan; /* redo plan when TransactionXmin changes? */
  48. bool dependsOnRole; /* is plan specific to current role? */
  49. bool parallelModeNeeded; /* parallel mode required to execute? */
  50. int jitFlags; /* which forms of JIT should be performed */
  51. struct Plan *planTree; /* tree of Plan nodes */
  52. List *rtable; /* list of RangeTblEntry nodes */
  53. /* rtable indexes of target relations for INSERT/UPDATE/DELETE/MERGE */
  54. List *resultRelations; /* integer list of RT indexes, or NIL */
  55. List *appendRelations; /* list of AppendRelInfo nodes */
  56. List *subplans; /* Plan trees for SubPlan expressions; note
  57. * that some could be NULL */
  58. Bitmapset *rewindPlanIDs; /* indices of subplans that require REWIND */
  59. List *rowMarks; /* a list of PlanRowMark's */
  60. List *relationOids; /* OIDs of relations the plan depends on */
  61. List *invalItems; /* other dependencies, as PlanInvalItems */
  62. List *paramExecTypes; /* type OIDs for PARAM_EXEC Params */
  63. Node *utilityStmt; /* non-null if this is utility stmt */
  64. /* statement location in source string (copied from Query) */
  65. int stmt_location; /* start location, or -1 if unknown */
  66. int stmt_len; /* length in bytes; 0 means "rest of string" */
  67. } PlannedStmt;
  68. /* macro for fetching the Plan associated with a SubPlan node */
  69. #define exec_subplan_get_plan(plannedstmt, subplan) \
  70. ((Plan *) list_nth((plannedstmt)->subplans, (subplan)->plan_id - 1))
  71. /* ----------------
  72. * Plan node
  73. *
  74. * All plan nodes "derive" from the Plan structure by having the
  75. * Plan structure as the first field. This ensures that everything works
  76. * when nodes are cast to Plan's. (node pointers are frequently cast to Plan*
  77. * when passed around generically in the executor)
  78. *
  79. * We never actually instantiate any Plan nodes; this is just the common
  80. * abstract superclass for all Plan-type nodes.
  81. * ----------------
  82. */
  83. typedef struct Plan
  84. {
  85. NodeTag type;
  86. /*
  87. * estimated execution costs for plan (see costsize.c for more info)
  88. */
  89. Cost startup_cost; /* cost expended before fetching any tuples */
  90. Cost total_cost; /* total cost (assuming all tuples fetched) */
  91. /*
  92. * planner's estimate of result size of this plan step
  93. */
  94. Cardinality plan_rows; /* number of rows plan is expected to emit */
  95. int plan_width; /* average row width in bytes */
  96. /*
  97. * information needed for parallel query
  98. */
  99. bool parallel_aware; /* engage parallel-aware logic? */
  100. bool parallel_safe; /* OK to use as part of parallel plan? */
  101. /*
  102. * information needed for asynchronous execution
  103. */
  104. bool async_capable; /* engage asynchronous-capable logic? */
  105. /*
  106. * Common structural data for all Plan types.
  107. */
  108. int plan_node_id; /* unique across entire final plan tree */
  109. List *targetlist; /* target list to be computed at this node */
  110. List *qual; /* implicitly-ANDed qual conditions */
  111. struct Plan *lefttree; /* input plan tree(s) */
  112. struct Plan *righttree;
  113. List *initPlan; /* Init Plan nodes (un-correlated expr
  114. * subselects) */
  115. /*
  116. * Information for management of parameter-change-driven rescanning
  117. *
  118. * extParam includes the paramIDs of all external PARAM_EXEC params
  119. * affecting this plan node or its children. setParam params from the
  120. * node's initPlans are not included, but their extParams are.
  121. *
  122. * allParam includes all the extParam paramIDs, plus the IDs of local
  123. * params that affect the node (i.e., the setParams of its initplans).
  124. * These are _all_ the PARAM_EXEC params that affect this node.
  125. */
  126. Bitmapset *extParam;
  127. Bitmapset *allParam;
  128. } Plan;
  129. /* ----------------
  130. * these are defined to avoid confusion problems with "left"
  131. * and "right" and "inner" and "outer". The convention is that
  132. * the "left" plan is the "outer" plan and the "right" plan is
  133. * the inner plan, but these make the code more readable.
  134. * ----------------
  135. */
  136. #define innerPlan(node) (((Plan *)(node))->righttree)
  137. #define outerPlan(node) (((Plan *)(node))->lefttree)
  138. /* ----------------
  139. * Result node -
  140. * If no outer plan, evaluate a variable-free targetlist.
  141. * If outer plan, return tuples from outer plan (after a level of
  142. * projection as shown by targetlist).
  143. *
  144. * If resconstantqual isn't NULL, it represents a one-time qualification
  145. * test (i.e., one that doesn't depend on any variables from the outer plan,
  146. * so needs to be evaluated only once).
  147. * ----------------
  148. */
  149. typedef struct Result
  150. {
  151. Plan plan;
  152. Node *resconstantqual;
  153. } Result;
  154. /* ----------------
  155. * ProjectSet node -
  156. * Apply a projection that includes set-returning functions to the
  157. * output tuples of the outer plan.
  158. * ----------------
  159. */
  160. typedef struct ProjectSet
  161. {
  162. Plan plan;
  163. } ProjectSet;
  164. /* ----------------
  165. * ModifyTable node -
  166. * Apply rows produced by outer plan to result table(s),
  167. * by inserting, updating, or deleting.
  168. *
  169. * If the originally named target table is a partitioned table, both
  170. * nominalRelation and rootRelation contain the RT index of the partition
  171. * root, which is not otherwise mentioned in the plan. Otherwise rootRelation
  172. * is zero. However, nominalRelation will always be set, as it's the rel that
  173. * EXPLAIN should claim is the INSERT/UPDATE/DELETE/MERGE target.
  174. *
  175. * Note that rowMarks and epqParam are presumed to be valid for all the
  176. * table(s); they can't contain any info that varies across tables.
  177. * ----------------
  178. */
  179. typedef struct ModifyTable
  180. {
  181. Plan plan;
  182. CmdType operation; /* INSERT, UPDATE, DELETE, or MERGE */
  183. bool canSetTag; /* do we set the command tag/es_processed? */
  184. Index nominalRelation; /* Parent RT index for use of EXPLAIN */
  185. Index rootRelation; /* Root RT index, if target is partitioned */
  186. bool partColsUpdated; /* some part key in hierarchy updated? */
  187. List *resultRelations; /* integer list of RT indexes */
  188. List *updateColnosLists; /* per-target-table update_colnos lists */
  189. List *withCheckOptionLists; /* per-target-table WCO lists */
  190. List *returningLists; /* per-target-table RETURNING tlists */
  191. List *fdwPrivLists; /* per-target-table FDW private data lists */
  192. Bitmapset *fdwDirectModifyPlans; /* indices of FDW DM plans */
  193. List *rowMarks; /* PlanRowMarks (non-locking only) */
  194. int epqParam; /* ID of Param for EvalPlanQual re-eval */
  195. OnConflictAction onConflictAction; /* ON CONFLICT action */
  196. List *arbiterIndexes; /* List of ON CONFLICT arbiter index OIDs */
  197. List *onConflictSet; /* INSERT ON CONFLICT DO UPDATE targetlist */
  198. List *onConflictCols; /* target column numbers for onConflictSet */
  199. Node *onConflictWhere; /* WHERE for ON CONFLICT UPDATE */
  200. Index exclRelRTI; /* RTI of the EXCLUDED pseudo relation */
  201. List *exclRelTlist; /* tlist of the EXCLUDED pseudo relation */
  202. List *mergeActionLists; /* per-target-table lists of actions for
  203. * MERGE */
  204. } ModifyTable;
  205. struct PartitionPruneInfo; /* forward reference to struct below */
  206. /* ----------------
  207. * Append node -
  208. * Generate the concatenation of the results of sub-plans.
  209. * ----------------
  210. */
  211. typedef struct Append
  212. {
  213. Plan plan;
  214. Bitmapset *apprelids; /* RTIs of appendrel(s) formed by this node */
  215. List *appendplans;
  216. int nasyncplans; /* # of asynchronous plans */
  217. /*
  218. * All 'appendplans' preceding this index are non-partial plans. All
  219. * 'appendplans' from this index onwards are partial plans.
  220. */
  221. int first_partial_plan;
  222. /* Info for run-time subplan pruning; NULL if we're not doing that */
  223. struct PartitionPruneInfo *part_prune_info;
  224. } Append;
  225. /* ----------------
  226. * MergeAppend node -
  227. * Merge the results of pre-sorted sub-plans to preserve the ordering.
  228. * ----------------
  229. */
  230. typedef struct MergeAppend
  231. {
  232. Plan plan;
  233. Bitmapset *apprelids; /* RTIs of appendrel(s) formed by this node */
  234. List *mergeplans;
  235. /* these fields are just like the sort-key info in struct Sort: */
  236. int numCols; /* number of sort-key columns */
  237. AttrNumber *sortColIdx; /* their indexes in the target list */
  238. Oid *sortOperators; /* OIDs of operators to sort them by */
  239. Oid *collations; /* OIDs of collations */
  240. bool *nullsFirst; /* NULLS FIRST/LAST directions */
  241. /* Info for run-time subplan pruning; NULL if we're not doing that */
  242. struct PartitionPruneInfo *part_prune_info;
  243. } MergeAppend;
  244. /* ----------------
  245. * RecursiveUnion node -
  246. * Generate a recursive union of two subplans.
  247. *
  248. * The "outer" subplan is always the non-recursive term, and the "inner"
  249. * subplan is the recursive term.
  250. * ----------------
  251. */
  252. typedef struct RecursiveUnion
  253. {
  254. Plan plan;
  255. int wtParam; /* ID of Param representing work table */
  256. /* Remaining fields are zero/null in UNION ALL case */
  257. int numCols; /* number of columns to check for
  258. * duplicate-ness */
  259. AttrNumber *dupColIdx; /* their indexes in the target list */
  260. Oid *dupOperators; /* equality operators to compare with */
  261. Oid *dupCollations;
  262. long numGroups; /* estimated number of groups in input */
  263. } RecursiveUnion;
  264. /* ----------------
  265. * BitmapAnd node -
  266. * Generate the intersection of the results of sub-plans.
  267. *
  268. * The subplans must be of types that yield tuple bitmaps. The targetlist
  269. * and qual fields of the plan are unused and are always NIL.
  270. * ----------------
  271. */
  272. typedef struct BitmapAnd
  273. {
  274. Plan plan;
  275. List *bitmapplans;
  276. } BitmapAnd;
  277. /* ----------------
  278. * BitmapOr node -
  279. * Generate the union of the results of sub-plans.
  280. *
  281. * The subplans must be of types that yield tuple bitmaps. The targetlist
  282. * and qual fields of the plan are unused and are always NIL.
  283. * ----------------
  284. */
  285. typedef struct BitmapOr
  286. {
  287. Plan plan;
  288. bool isshared;
  289. List *bitmapplans;
  290. } BitmapOr;
  291. /*
  292. * ==========
  293. * Scan nodes
  294. * ==========
  295. */
  296. typedef struct Scan
  297. {
  298. Plan plan;
  299. Index scanrelid; /* relid is index into the range table */
  300. } Scan;
  301. /* ----------------
  302. * sequential scan node
  303. * ----------------
  304. */
  305. typedef struct SeqScan
  306. {
  307. Scan scan;
  308. } SeqScan;
  309. /* ----------------
  310. * table sample scan node
  311. * ----------------
  312. */
  313. typedef struct SampleScan
  314. {
  315. Scan scan;
  316. /* use struct pointer to avoid including parsenodes.h here */
  317. struct TableSampleClause *tablesample;
  318. } SampleScan;
  319. /* ----------------
  320. * index scan node
  321. *
  322. * indexqualorig is an implicitly-ANDed list of index qual expressions, each
  323. * in the same form it appeared in the query WHERE condition. Each should
  324. * be of the form (indexkey OP comparisonval) or (comparisonval OP indexkey).
  325. * The indexkey is a Var or expression referencing column(s) of the index's
  326. * base table. The comparisonval might be any expression, but it won't use
  327. * any columns of the base table. The expressions are ordered by index
  328. * column position (but items referencing the same index column can appear
  329. * in any order). indexqualorig is used at runtime only if we have to recheck
  330. * a lossy indexqual.
  331. *
  332. * indexqual has the same form, but the expressions have been commuted if
  333. * necessary to put the indexkeys on the left, and the indexkeys are replaced
  334. * by Var nodes identifying the index columns (their varno is INDEX_VAR and
  335. * their varattno is the index column number).
  336. *
  337. * indexorderbyorig is similarly the original form of any ORDER BY expressions
  338. * that are being implemented by the index, while indexorderby is modified to
  339. * have index column Vars on the left-hand side. Here, multiple expressions
  340. * must appear in exactly the ORDER BY order, and this is not necessarily the
  341. * index column order. Only the expressions are provided, not the auxiliary
  342. * sort-order information from the ORDER BY SortGroupClauses; it's assumed
  343. * that the sort ordering is fully determinable from the top-level operators.
  344. * indexorderbyorig is used at runtime to recheck the ordering, if the index
  345. * cannot calculate an accurate ordering. It is also needed for EXPLAIN.
  346. *
  347. * indexorderbyops is a list of the OIDs of the operators used to sort the
  348. * ORDER BY expressions. This is used together with indexorderbyorig to
  349. * recheck ordering at run time. (Note that indexorderby, indexorderbyorig,
  350. * and indexorderbyops are used for amcanorderbyop cases, not amcanorder.)
  351. *
  352. * indexorderdir specifies the scan ordering, for indexscans on amcanorder
  353. * indexes (for other indexes it should be "don't care").
  354. * ----------------
  355. */
  356. typedef struct IndexScan
  357. {
  358. Scan scan;
  359. Oid indexid; /* OID of index to scan */
  360. List *indexqual; /* list of index quals (usually OpExprs) */
  361. List *indexqualorig; /* the same in original form */
  362. List *indexorderby; /* list of index ORDER BY exprs */
  363. List *indexorderbyorig; /* the same in original form */
  364. List *indexorderbyops; /* OIDs of sort ops for ORDER BY exprs */
  365. ScanDirection indexorderdir; /* forward or backward or don't care */
  366. } IndexScan;
  367. /* ----------------
  368. * index-only scan node
  369. *
  370. * IndexOnlyScan is very similar to IndexScan, but it specifies an
  371. * index-only scan, in which the data comes from the index not the heap.
  372. * Because of this, *all* Vars in the plan node's targetlist, qual, and
  373. * index expressions reference index columns and have varno = INDEX_VAR.
  374. *
  375. * We could almost use indexqual directly against the index's output tuple
  376. * when rechecking lossy index operators, but that won't work for quals on
  377. * index columns that are not retrievable. Hence, recheckqual is needed
  378. * for rechecks: it expresses the same condition as indexqual, but using
  379. * only index columns that are retrievable. (We will not generate an
  380. * index-only scan if this is not possible. An example is that if an
  381. * index has table column "x" in a retrievable index column "ind1", plus
  382. * an expression f(x) in a non-retrievable column "ind2", an indexable
  383. * query on f(x) will use "ind2" in indexqual and f(ind1) in recheckqual.
  384. * Without the "ind1" column, an index-only scan would be disallowed.)
  385. *
  386. * We don't currently need a recheckable equivalent of indexorderby,
  387. * because we don't support lossy operators in index ORDER BY.
  388. *
  389. * To help EXPLAIN interpret the index Vars for display, we provide
  390. * indextlist, which represents the contents of the index as a targetlist
  391. * with one TLE per index column. Vars appearing in this list reference
  392. * the base table, and this is the only field in the plan node that may
  393. * contain such Vars. Also, for the convenience of setrefs.c, TLEs in
  394. * indextlist are marked as resjunk if they correspond to columns that
  395. * the index AM cannot reconstruct.
  396. * ----------------
  397. */
  398. typedef struct IndexOnlyScan
  399. {
  400. Scan scan;
  401. Oid indexid; /* OID of index to scan */
  402. List *indexqual; /* list of index quals (usually OpExprs) */
  403. List *recheckqual; /* index quals in recheckable form */
  404. List *indexorderby; /* list of index ORDER BY exprs */
  405. List *indextlist; /* TargetEntry list describing index's cols */
  406. ScanDirection indexorderdir; /* forward or backward or don't care */
  407. } IndexOnlyScan;
  408. /* ----------------
  409. * bitmap index scan node
  410. *
  411. * BitmapIndexScan delivers a bitmap of potential tuple locations;
  412. * it does not access the heap itself. The bitmap is used by an
  413. * ancestor BitmapHeapScan node, possibly after passing through
  414. * intermediate BitmapAnd and/or BitmapOr nodes to combine it with
  415. * the results of other BitmapIndexScans.
  416. *
  417. * The fields have the same meanings as for IndexScan, except we don't
  418. * store a direction flag because direction is uninteresting.
  419. *
  420. * In a BitmapIndexScan plan node, the targetlist and qual fields are
  421. * not used and are always NIL. The indexqualorig field is unused at
  422. * run time too, but is saved for the benefit of EXPLAIN.
  423. * ----------------
  424. */
  425. typedef struct BitmapIndexScan
  426. {
  427. Scan scan;
  428. Oid indexid; /* OID of index to scan */
  429. bool isshared; /* Create shared bitmap if set */
  430. List *indexqual; /* list of index quals (OpExprs) */
  431. List *indexqualorig; /* the same in original form */
  432. } BitmapIndexScan;
  433. /* ----------------
  434. * bitmap sequential scan node
  435. *
  436. * This needs a copy of the qual conditions being used by the input index
  437. * scans because there are various cases where we need to recheck the quals;
  438. * for example, when the bitmap is lossy about the specific rows on a page
  439. * that meet the index condition.
  440. * ----------------
  441. */
  442. typedef struct BitmapHeapScan
  443. {
  444. Scan scan;
  445. List *bitmapqualorig; /* index quals, in standard expr form */
  446. } BitmapHeapScan;
  447. /* ----------------
  448. * tid scan node
  449. *
  450. * tidquals is an implicitly OR'ed list of qual expressions of the form
  451. * "CTID = pseudoconstant", or "CTID = ANY(pseudoconstant_array)",
  452. * or a CurrentOfExpr for the relation.
  453. * ----------------
  454. */
  455. typedef struct TidScan
  456. {
  457. Scan scan;
  458. List *tidquals; /* qual(s) involving CTID = something */
  459. } TidScan;
  460. /* ----------------
  461. * tid range scan node
  462. *
  463. * tidrangequals is an implicitly AND'ed list of qual expressions of the form
  464. * "CTID relop pseudoconstant", where relop is one of >,>=,<,<=.
  465. * ----------------
  466. */
  467. typedef struct TidRangeScan
  468. {
  469. Scan scan;
  470. List *tidrangequals; /* qual(s) involving CTID op something */
  471. } TidRangeScan;
  472. /* ----------------
  473. * subquery scan node
  474. *
  475. * SubqueryScan is for scanning the output of a sub-query in the range table.
  476. * We often need an extra plan node above the sub-query's plan to perform
  477. * expression evaluations (which we can't push into the sub-query without
  478. * risking changing its semantics). Although we are not scanning a physical
  479. * relation, we make this a descendant of Scan anyway for code-sharing
  480. * purposes.
  481. *
  482. * SubqueryScanStatus caches the trivial_subqueryscan property of the node.
  483. * SUBQUERY_SCAN_UNKNOWN means not yet determined. This is only used during
  484. * planning.
  485. *
  486. * Note: we store the sub-plan in the type-specific subplan field, not in
  487. * the generic lefttree field as you might expect. This is because we do
  488. * not want plan-tree-traversal routines to recurse into the subplan without
  489. * knowing that they are changing Query contexts.
  490. * ----------------
  491. */
  492. typedef enum SubqueryScanStatus
  493. {
  494. SUBQUERY_SCAN_UNKNOWN,
  495. SUBQUERY_SCAN_TRIVIAL,
  496. SUBQUERY_SCAN_NONTRIVIAL
  497. } SubqueryScanStatus;
  498. typedef struct SubqueryScan
  499. {
  500. Scan scan;
  501. Plan *subplan;
  502. SubqueryScanStatus scanstatus;
  503. } SubqueryScan;
  504. /* ----------------
  505. * FunctionScan node
  506. * ----------------
  507. */
  508. typedef struct FunctionScan
  509. {
  510. Scan scan;
  511. List *functions; /* list of RangeTblFunction nodes */
  512. bool funcordinality; /* WITH ORDINALITY */
  513. } FunctionScan;
  514. /* ----------------
  515. * ValuesScan node
  516. * ----------------
  517. */
  518. typedef struct ValuesScan
  519. {
  520. Scan scan;
  521. List *values_lists; /* list of expression lists */
  522. } ValuesScan;
  523. /* ----------------
  524. * TableFunc scan node
  525. * ----------------
  526. */
  527. typedef struct TableFuncScan
  528. {
  529. Scan scan;
  530. TableFunc *tablefunc; /* table function node */
  531. } TableFuncScan;
  532. /* ----------------
  533. * CteScan node
  534. * ----------------
  535. */
  536. typedef struct CteScan
  537. {
  538. Scan scan;
  539. int ctePlanId; /* ID of init SubPlan for CTE */
  540. int cteParam; /* ID of Param representing CTE output */
  541. } CteScan;
  542. /* ----------------
  543. * NamedTuplestoreScan node
  544. * ----------------
  545. */
  546. typedef struct NamedTuplestoreScan
  547. {
  548. Scan scan;
  549. char *enrname; /* Name given to Ephemeral Named Relation */
  550. } NamedTuplestoreScan;
  551. /* ----------------
  552. * WorkTableScan node
  553. * ----------------
  554. */
  555. typedef struct WorkTableScan
  556. {
  557. Scan scan;
  558. int wtParam; /* ID of Param representing work table */
  559. } WorkTableScan;
  560. /* ----------------
  561. * ForeignScan node
  562. *
  563. * fdw_exprs and fdw_private are both under the control of the foreign-data
  564. * wrapper, but fdw_exprs is presumed to contain expression trees and will
  565. * be post-processed accordingly by the planner; fdw_private won't be.
  566. * Note that everything in both lists must be copiable by copyObject().
  567. * One way to store an arbitrary blob of bytes is to represent it as a bytea
  568. * Const. Usually, though, you'll be better off choosing a representation
  569. * that can be dumped usefully by nodeToString().
  570. *
  571. * fdw_scan_tlist is a targetlist describing the contents of the scan tuple
  572. * returned by the FDW; it can be NIL if the scan tuple matches the declared
  573. * rowtype of the foreign table, which is the normal case for a simple foreign
  574. * table scan. (If the plan node represents a foreign join, fdw_scan_tlist
  575. * is required since there is no rowtype available from the system catalogs.)
  576. * When fdw_scan_tlist is provided, Vars in the node's tlist and quals must
  577. * have varno INDEX_VAR, and their varattnos correspond to resnos in the
  578. * fdw_scan_tlist (which are also column numbers in the actual scan tuple).
  579. * fdw_scan_tlist is never actually executed; it just holds expression trees
  580. * describing what is in the scan tuple's columns.
  581. *
  582. * fdw_recheck_quals should contain any quals which the core system passed to
  583. * the FDW but which were not added to scan.plan.qual; that is, it should
  584. * contain the quals being checked remotely. This is needed for correct
  585. * behavior during EvalPlanQual rechecks.
  586. *
  587. * When the plan node represents a foreign join, scan.scanrelid is zero and
  588. * fs_relids must be consulted to identify the join relation. (fs_relids
  589. * is valid for simple scans as well, but will always match scan.scanrelid.)
  590. *
  591. * If the FDW's PlanDirectModify() callback decides to repurpose a ForeignScan
  592. * node to perform the UPDATE or DELETE operation directly in the remote
  593. * server, it sets 'operation' and 'resultRelation' to identify the operation
  594. * type and target relation. Note that these fields are only set if the
  595. * modification is performed *fully* remotely; otherwise, the modification is
  596. * driven by a local ModifyTable node and 'operation' is left to CMD_SELECT.
  597. * ----------------
  598. */
  599. typedef struct ForeignScan
  600. {
  601. Scan scan;
  602. CmdType operation; /* SELECT/INSERT/UPDATE/DELETE */
  603. Index resultRelation; /* direct modification target's RT index */
  604. Oid fs_server; /* OID of foreign server */
  605. List *fdw_exprs; /* expressions that FDW may evaluate */
  606. List *fdw_private; /* private data for FDW */
  607. List *fdw_scan_tlist; /* optional tlist describing scan tuple */
  608. List *fdw_recheck_quals; /* original quals not in scan.plan.qual */
  609. Bitmapset *fs_relids; /* RTIs generated by this scan */
  610. bool fsSystemCol; /* true if any "system column" is needed */
  611. } ForeignScan;
  612. /* ----------------
  613. * CustomScan node
  614. *
  615. * The comments for ForeignScan's fdw_exprs, fdw_private, fdw_scan_tlist,
  616. * and fs_relids fields apply equally to CustomScan's custom_exprs,
  617. * custom_private, custom_scan_tlist, and custom_relids fields. The
  618. * convention of setting scan.scanrelid to zero for joins applies as well.
  619. *
  620. * Note that since Plan trees can be copied, custom scan providers *must*
  621. * fit all plan data they need into those fields; embedding CustomScan in
  622. * a larger struct will not work.
  623. * ----------------
  624. */
  625. struct CustomScanMethods;
  626. typedef struct CustomScan
  627. {
  628. Scan scan;
  629. uint32 flags; /* mask of CUSTOMPATH_* flags, see
  630. * nodes/extensible.h */
  631. List *custom_plans; /* list of Plan nodes, if any */
  632. List *custom_exprs; /* expressions that custom code may evaluate */
  633. List *custom_private; /* private data for custom code */
  634. List *custom_scan_tlist; /* optional tlist describing scan tuple */
  635. Bitmapset *custom_relids; /* RTIs generated by this scan */
  636. const struct CustomScanMethods *methods;
  637. } CustomScan;
  638. /*
  639. * ==========
  640. * Join nodes
  641. * ==========
  642. */
  643. /* ----------------
  644. * Join node
  645. *
  646. * jointype: rule for joining tuples from left and right subtrees
  647. * inner_unique each outer tuple can match to no more than one inner tuple
  648. * joinqual: qual conditions that came from JOIN/ON or JOIN/USING
  649. * (plan.qual contains conditions that came from WHERE)
  650. *
  651. * When jointype is INNER, joinqual and plan.qual are semantically
  652. * interchangeable. For OUTER jointypes, the two are *not* interchangeable;
  653. * only joinqual is used to determine whether a match has been found for
  654. * the purpose of deciding whether to generate null-extended tuples.
  655. * (But plan.qual is still applied before actually returning a tuple.)
  656. * For an outer join, only joinquals are allowed to be used as the merge
  657. * or hash condition of a merge or hash join.
  658. *
  659. * inner_unique is set if the joinquals are such that no more than one inner
  660. * tuple could match any given outer tuple. This allows the executor to
  661. * skip searching for additional matches. (This must be provable from just
  662. * the joinquals, ignoring plan.qual, due to where the executor tests it.)
  663. * ----------------
  664. */
  665. typedef struct Join
  666. {
  667. Plan plan;
  668. JoinType jointype;
  669. bool inner_unique;
  670. List *joinqual; /* JOIN quals (in addition to plan.qual) */
  671. } Join;
  672. /* ----------------
  673. * nest loop join node
  674. *
  675. * The nestParams list identifies any executor Params that must be passed
  676. * into execution of the inner subplan carrying values from the current row
  677. * of the outer subplan. Currently we restrict these values to be simple
  678. * Vars, but perhaps someday that'd be worth relaxing. (Note: during plan
  679. * creation, the paramval can actually be a PlaceHolderVar expression; but it
  680. * must be a Var with varno OUTER_VAR by the time it gets to the executor.)
  681. * ----------------
  682. */
  683. typedef struct NestLoop
  684. {
  685. Join join;
  686. List *nestParams; /* list of NestLoopParam nodes */
  687. } NestLoop;
  688. typedef struct NestLoopParam
  689. {
  690. NodeTag type;
  691. int paramno; /* number of the PARAM_EXEC Param to set */
  692. Var *paramval; /* outer-relation Var to assign to Param */
  693. } NestLoopParam;
  694. /* ----------------
  695. * merge join node
  696. *
  697. * The expected ordering of each mergeable column is described by a btree
  698. * opfamily OID, a collation OID, a direction (BTLessStrategyNumber or
  699. * BTGreaterStrategyNumber) and a nulls-first flag. Note that the two sides
  700. * of each mergeclause may be of different datatypes, but they are ordered the
  701. * same way according to the common opfamily and collation. The operator in
  702. * each mergeclause must be an equality operator of the indicated opfamily.
  703. * ----------------
  704. */
  705. typedef struct MergeJoin
  706. {
  707. Join join;
  708. bool skip_mark_restore; /* Can we skip mark/restore calls? */
  709. List *mergeclauses; /* mergeclauses as expression trees */
  710. /* these are arrays, but have the same length as the mergeclauses list: */
  711. Oid *mergeFamilies; /* per-clause OIDs of btree opfamilies */
  712. Oid *mergeCollations; /* per-clause OIDs of collations */
  713. int *mergeStrategies; /* per-clause ordering (ASC or DESC) */
  714. bool *mergeNullsFirst; /* per-clause nulls ordering */
  715. } MergeJoin;
  716. /* ----------------
  717. * hash join node
  718. * ----------------
  719. */
  720. typedef struct HashJoin
  721. {
  722. Join join;
  723. List *hashclauses;
  724. List *hashoperators;
  725. List *hashcollations;
  726. /*
  727. * List of expressions to be hashed for tuples from the outer plan, to
  728. * perform lookups in the hashtable over the inner plan.
  729. */
  730. List *hashkeys;
  731. } HashJoin;
  732. /* ----------------
  733. * materialization node
  734. * ----------------
  735. */
  736. typedef struct Material
  737. {
  738. Plan plan;
  739. } Material;
  740. /* ----------------
  741. * memoize node
  742. * ----------------
  743. */
  744. typedef struct Memoize
  745. {
  746. Plan plan;
  747. int numKeys; /* size of the two arrays below */
  748. Oid *hashOperators; /* hash operators for each key */
  749. Oid *collations; /* collations for each key */
  750. List *param_exprs; /* cache keys in the form of exprs containing
  751. * parameters */
  752. bool singlerow; /* true if the cache entry should be marked as
  753. * complete after we store the first tuple in
  754. * it. */
  755. bool binary_mode; /* true when cache key should be compared bit
  756. * by bit, false when using hash equality ops */
  757. uint32 est_entries; /* The maximum number of entries that the
  758. * planner expects will fit in the cache, or 0
  759. * if unknown */
  760. Bitmapset *keyparamids; /* paramids from param_exprs */
  761. } Memoize;
  762. /* ----------------
  763. * sort node
  764. * ----------------
  765. */
  766. typedef struct Sort
  767. {
  768. Plan plan;
  769. int numCols; /* number of sort-key columns */
  770. AttrNumber *sortColIdx; /* their indexes in the target list */
  771. Oid *sortOperators; /* OIDs of operators to sort them by */
  772. Oid *collations; /* OIDs of collations */
  773. bool *nullsFirst; /* NULLS FIRST/LAST directions */
  774. } Sort;
  775. /* ----------------
  776. * incremental sort node
  777. * ----------------
  778. */
  779. typedef struct IncrementalSort
  780. {
  781. Sort sort;
  782. int nPresortedCols; /* number of presorted columns */
  783. } IncrementalSort;
  784. /* ---------------
  785. * group node -
  786. * Used for queries with GROUP BY (but no aggregates) specified.
  787. * The input must be presorted according to the grouping columns.
  788. * ---------------
  789. */
  790. typedef struct Group
  791. {
  792. Plan plan;
  793. int numCols; /* number of grouping columns */
  794. AttrNumber *grpColIdx; /* their indexes in the target list */
  795. Oid *grpOperators; /* equality operators to compare with */
  796. Oid *grpCollations;
  797. } Group;
  798. /* ---------------
  799. * aggregate node
  800. *
  801. * An Agg node implements plain or grouped aggregation. For grouped
  802. * aggregation, we can work with presorted input or unsorted input;
  803. * the latter strategy uses an internal hashtable.
  804. *
  805. * Notice the lack of any direct info about the aggregate functions to be
  806. * computed. They are found by scanning the node's tlist and quals during
  807. * executor startup. (It is possible that there are no aggregate functions;
  808. * this could happen if they get optimized away by constant-folding, or if
  809. * we are using the Agg node to implement hash-based grouping.)
  810. * ---------------
  811. */
  812. typedef struct Agg
  813. {
  814. Plan plan;
  815. AggStrategy aggstrategy; /* basic strategy, see nodes.h */
  816. AggSplit aggsplit; /* agg-splitting mode, see nodes.h */
  817. int numCols; /* number of grouping columns */
  818. AttrNumber *grpColIdx; /* their indexes in the target list */
  819. Oid *grpOperators; /* equality operators to compare with */
  820. Oid *grpCollations;
  821. long numGroups; /* estimated number of groups in input */
  822. uint64 transitionSpace; /* for pass-by-ref transition data */
  823. Bitmapset *aggParams; /* IDs of Params used in Aggref inputs */
  824. /* Note: planner provides numGroups & aggParams only in HASHED/MIXED case */
  825. List *groupingSets; /* grouping sets to use */
  826. List *chain; /* chained Agg/Sort nodes */
  827. } Agg;
  828. /* ----------------
  829. * window aggregate node
  830. * ----------------
  831. */
  832. typedef struct WindowAgg
  833. {
  834. Plan plan;
  835. Index winref; /* ID referenced by window functions */
  836. int partNumCols; /* number of columns in partition clause */
  837. AttrNumber *partColIdx; /* their indexes in the target list */
  838. Oid *partOperators; /* equality operators for partition columns */
  839. Oid *partCollations; /* collations for partition columns */
  840. int ordNumCols; /* number of columns in ordering clause */
  841. AttrNumber *ordColIdx; /* their indexes in the target list */
  842. Oid *ordOperators; /* equality operators for ordering columns */
  843. Oid *ordCollations; /* collations for ordering columns */
  844. int frameOptions; /* frame_clause options, see WindowDef */
  845. Node *startOffset; /* expression for starting bound, if any */
  846. Node *endOffset; /* expression for ending bound, if any */
  847. List *runCondition; /* qual to help short-circuit execution */
  848. List *runConditionOrig; /* runCondition for display in EXPLAIN */
  849. /* these fields are used with RANGE offset PRECEDING/FOLLOWING: */
  850. Oid startInRangeFunc; /* in_range function for startOffset */
  851. Oid endInRangeFunc; /* in_range function for endOffset */
  852. Oid inRangeColl; /* collation for in_range tests */
  853. bool inRangeAsc; /* use ASC sort order for in_range tests? */
  854. bool inRangeNullsFirst; /* nulls sort first for in_range tests? */
  855. bool topWindow; /* false for all apart from the WindowAgg
  856. * that's closest to the root of the plan */
  857. } WindowAgg;
  858. /* ----------------
  859. * unique node
  860. * ----------------
  861. */
  862. typedef struct Unique
  863. {
  864. Plan plan;
  865. int numCols; /* number of columns to check for uniqueness */
  866. AttrNumber *uniqColIdx; /* their indexes in the target list */
  867. Oid *uniqOperators; /* equality operators to compare with */
  868. Oid *uniqCollations; /* collations for equality comparisons */
  869. } Unique;
  870. /* ------------
  871. * gather node
  872. *
  873. * Note: rescan_param is the ID of a PARAM_EXEC parameter slot. That slot
  874. * will never actually contain a value, but the Gather node must flag it as
  875. * having changed whenever it is rescanned. The child parallel-aware scan
  876. * nodes are marked as depending on that parameter, so that the rescan
  877. * machinery is aware that their output is likely to change across rescans.
  878. * In some cases we don't need a rescan Param, so rescan_param is set to -1.
  879. * ------------
  880. */
  881. typedef struct Gather
  882. {
  883. Plan plan;
  884. int num_workers; /* planned number of worker processes */
  885. int rescan_param; /* ID of Param that signals a rescan, or -1 */
  886. bool single_copy; /* don't execute plan more than once */
  887. bool invisible; /* suppress EXPLAIN display (for testing)? */
  888. Bitmapset *initParam; /* param id's of initplans which are referred
  889. * at gather or one of it's child node */
  890. } Gather;
  891. /* ------------
  892. * gather merge node
  893. * ------------
  894. */
  895. typedef struct GatherMerge
  896. {
  897. Plan plan;
  898. int num_workers; /* planned number of worker processes */
  899. int rescan_param; /* ID of Param that signals a rescan, or -1 */
  900. /* remaining fields are just like the sort-key info in struct Sort */
  901. int numCols; /* number of sort-key columns */
  902. AttrNumber *sortColIdx; /* their indexes in the target list */
  903. Oid *sortOperators; /* OIDs of operators to sort them by */
  904. Oid *collations; /* OIDs of collations */
  905. bool *nullsFirst; /* NULLS FIRST/LAST directions */
  906. Bitmapset *initParam; /* param id's of initplans which are referred
  907. * at gather merge or one of it's child node */
  908. } GatherMerge;
  909. /* ----------------
  910. * hash build node
  911. *
  912. * If the executor is supposed to try to apply skew join optimization, then
  913. * skewTable/skewColumn/skewInherit identify the outer relation's join key
  914. * column, from which the relevant MCV statistics can be fetched.
  915. * ----------------
  916. */
  917. typedef struct Hash
  918. {
  919. Plan plan;
  920. /*
  921. * List of expressions to be hashed for tuples from Hash's outer plan,
  922. * needed to put them into the hashtable.
  923. */
  924. List *hashkeys; /* hash keys for the hashjoin condition */
  925. Oid skewTable; /* outer join key's table OID, or InvalidOid */
  926. AttrNumber skewColumn; /* outer join key's column #, or zero */
  927. bool skewInherit; /* is outer join rel an inheritance tree? */
  928. /* all other info is in the parent HashJoin node */
  929. Cardinality rows_total; /* estimate total rows if parallel_aware */
  930. } Hash;
  931. /* ----------------
  932. * setop node
  933. * ----------------
  934. */
  935. typedef struct SetOp
  936. {
  937. Plan plan;
  938. SetOpCmd cmd; /* what to do, see nodes.h */
  939. SetOpStrategy strategy; /* how to do it, see nodes.h */
  940. int numCols; /* number of columns to check for
  941. * duplicate-ness */
  942. AttrNumber *dupColIdx; /* their indexes in the target list */
  943. Oid *dupOperators; /* equality operators to compare with */
  944. Oid *dupCollations;
  945. AttrNumber flagColIdx; /* where is the flag column, if any */
  946. int firstFlag; /* flag value for first input relation */
  947. long numGroups; /* estimated number of groups in input */
  948. } SetOp;
  949. /* ----------------
  950. * lock-rows node
  951. *
  952. * rowMarks identifies the rels to be locked by this node; it should be
  953. * a subset of the rowMarks listed in the top-level PlannedStmt.
  954. * epqParam is a Param that all scan nodes below this one must depend on.
  955. * It is used to force re-evaluation of the plan during EvalPlanQual.
  956. * ----------------
  957. */
  958. typedef struct LockRows
  959. {
  960. Plan plan;
  961. List *rowMarks; /* a list of PlanRowMark's */
  962. int epqParam; /* ID of Param for EvalPlanQual re-eval */
  963. } LockRows;
  964. /* ----------------
  965. * limit node
  966. *
  967. * Note: as of Postgres 8.2, the offset and count expressions are expected
  968. * to yield int8, rather than int4 as before.
  969. * ----------------
  970. */
  971. typedef struct Limit
  972. {
  973. Plan plan;
  974. Node *limitOffset; /* OFFSET parameter, or NULL if none */
  975. Node *limitCount; /* COUNT parameter, or NULL if none */
  976. LimitOption limitOption; /* limit type */
  977. int uniqNumCols; /* number of columns to check for similarity */
  978. AttrNumber *uniqColIdx; /* their indexes in the target list */
  979. Oid *uniqOperators; /* equality operators to compare with */
  980. Oid *uniqCollations; /* collations for equality comparisons */
  981. } Limit;
  982. /*
  983. * RowMarkType -
  984. * enums for types of row-marking operations
  985. *
  986. * The first four of these values represent different lock strengths that
  987. * we can take on tuples according to SELECT FOR [KEY] UPDATE/SHARE requests.
  988. * We support these on regular tables, as well as on foreign tables whose FDWs
  989. * report support for late locking. For other foreign tables, any locking
  990. * that might be done for such requests must happen during the initial row
  991. * fetch; their FDWs provide no mechanism for going back to lock a row later.
  992. * This means that the semantics will be a bit different than for a local
  993. * table; in particular we are likely to lock more rows than would be locked
  994. * locally, since remote rows will be locked even if they then fail
  995. * locally-checked restriction or join quals. However, the prospect of
  996. * doing a separate remote query to lock each selected row is usually pretty
  997. * unappealing, so early locking remains a credible design choice for FDWs.
  998. *
  999. * When doing UPDATE, DELETE, or SELECT FOR UPDATE/SHARE, we have to uniquely
  1000. * identify all the source rows, not only those from the target relations, so
  1001. * that we can perform EvalPlanQual rechecking at need. For plain tables we
  1002. * can just fetch the TID, much as for a target relation; this case is
  1003. * represented by ROW_MARK_REFERENCE. Otherwise (for example for VALUES or
  1004. * FUNCTION scans) we have to copy the whole row value. ROW_MARK_COPY is
  1005. * pretty inefficient, since most of the time we'll never need the data; but
  1006. * fortunately the overhead is usually not performance-critical in practice.
  1007. * By default we use ROW_MARK_COPY for foreign tables, but if the FDW has
  1008. * a concept of rowid it can request to use ROW_MARK_REFERENCE instead.
  1009. * (Again, this probably doesn't make sense if a physical remote fetch is
  1010. * needed, but for FDWs that map to local storage it might be credible.)
  1011. */
  1012. typedef enum RowMarkType
  1013. {
  1014. ROW_MARK_EXCLUSIVE, /* obtain exclusive tuple lock */
  1015. ROW_MARK_NOKEYEXCLUSIVE, /* obtain no-key exclusive tuple lock */
  1016. ROW_MARK_SHARE, /* obtain shared tuple lock */
  1017. ROW_MARK_KEYSHARE, /* obtain keyshare tuple lock */
  1018. ROW_MARK_REFERENCE, /* just fetch the TID, don't lock it */
  1019. ROW_MARK_COPY /* physically copy the row value */
  1020. } RowMarkType;
  1021. #define RowMarkRequiresRowShareLock(marktype) ((marktype) <= ROW_MARK_KEYSHARE)
  1022. /*
  1023. * PlanRowMark -
  1024. * plan-time representation of FOR [KEY] UPDATE/SHARE clauses
  1025. *
  1026. * When doing UPDATE, DELETE, or SELECT FOR UPDATE/SHARE, we create a separate
  1027. * PlanRowMark node for each non-target relation in the query. Relations that
  1028. * are not specified as FOR UPDATE/SHARE are marked ROW_MARK_REFERENCE (if
  1029. * regular tables or supported foreign tables) or ROW_MARK_COPY (if not).
  1030. *
  1031. * Initially all PlanRowMarks have rti == prti and isParent == false.
  1032. * When the planner discovers that a relation is the root of an inheritance
  1033. * tree, it sets isParent true, and adds an additional PlanRowMark to the
  1034. * list for each child relation (including the target rel itself in its role
  1035. * as a child, if it is not a partitioned table). Any non-leaf partitioned
  1036. * child relations will also have entries with isParent = true. The child
  1037. * entries have rti == child rel's RT index and prti == top parent's RT index,
  1038. * and can therefore be recognized as children by the fact that prti != rti.
  1039. * The parent's allMarkTypes field gets the OR of (1<<markType) across all
  1040. * its children (this definition allows children to use different markTypes).
  1041. *
  1042. * The planner also adds resjunk output columns to the plan that carry
  1043. * information sufficient to identify the locked or fetched rows. When
  1044. * markType != ROW_MARK_COPY, these columns are named
  1045. * tableoid%u OID of table
  1046. * ctid%u TID of row
  1047. * The tableoid column is only present for an inheritance hierarchy.
  1048. * When markType == ROW_MARK_COPY, there is instead a single column named
  1049. * wholerow%u whole-row value of relation
  1050. * (An inheritance hierarchy could have all three resjunk output columns,
  1051. * if some children use a different markType than others.)
  1052. * In all three cases, %u represents the rowmark ID number (rowmarkId).
  1053. * This number is unique within a plan tree, except that child relation
  1054. * entries copy their parent's rowmarkId. (Assigning unique numbers
  1055. * means we needn't renumber rowmarkIds when flattening subqueries, which
  1056. * would require finding and renaming the resjunk columns as well.)
  1057. * Note this means that all tables in an inheritance hierarchy share the
  1058. * same resjunk column names.
  1059. */
  1060. typedef struct PlanRowMark
  1061. {
  1062. NodeTag type;
  1063. Index rti; /* range table index of markable relation */
  1064. Index prti; /* range table index of parent relation */
  1065. Index rowmarkId; /* unique identifier for resjunk columns */
  1066. RowMarkType markType; /* see enum above */
  1067. int allMarkTypes; /* OR of (1<<markType) for all children */
  1068. LockClauseStrength strength; /* LockingClause's strength, or LCS_NONE */
  1069. LockWaitPolicy waitPolicy; /* NOWAIT and SKIP LOCKED options */
  1070. bool isParent; /* true if this is a "dummy" parent entry */
  1071. } PlanRowMark;
  1072. /*
  1073. * Node types to represent partition pruning information.
  1074. */
  1075. /*
  1076. * PartitionPruneInfo - Details required to allow the executor to prune
  1077. * partitions.
  1078. *
  1079. * Here we store mapping details to allow translation of a partitioned table's
  1080. * index as returned by the partition pruning code into subplan indexes for
  1081. * plan types which support arbitrary numbers of subplans, such as Append.
  1082. * We also store various details to tell the executor when it should be
  1083. * performing partition pruning.
  1084. *
  1085. * Each PartitionedRelPruneInfo describes the partitioning rules for a single
  1086. * partitioned table (a/k/a level of partitioning). Since a partitioning
  1087. * hierarchy could contain multiple levels, we represent it by a List of
  1088. * PartitionedRelPruneInfos, where the first entry represents the topmost
  1089. * partitioned table and additional entries represent non-leaf child
  1090. * partitions, ordered such that parents appear before their children.
  1091. * Then, since an Append-type node could have multiple partitioning
  1092. * hierarchies among its children, we have an unordered List of those Lists.
  1093. *
  1094. * prune_infos List of Lists containing PartitionedRelPruneInfo nodes,
  1095. * one sublist per run-time-prunable partition hierarchy
  1096. * appearing in the parent plan node's subplans.
  1097. * other_subplans Indexes of any subplans that are not accounted for
  1098. * by any of the PartitionedRelPruneInfo nodes in
  1099. * "prune_infos". These subplans must not be pruned.
  1100. */
  1101. typedef struct PartitionPruneInfo
  1102. {
  1103. NodeTag type;
  1104. List *prune_infos;
  1105. Bitmapset *other_subplans;
  1106. } PartitionPruneInfo;
  1107. /*
  1108. * PartitionedRelPruneInfo - Details required to allow the executor to prune
  1109. * partitions for a single partitioned table.
  1110. *
  1111. * subplan_map[] and subpart_map[] are indexed by partition index of the
  1112. * partitioned table referenced by 'rtindex', the partition index being the
  1113. * order that the partitions are defined in the table's PartitionDesc. For a
  1114. * leaf partition p, subplan_map[p] contains the zero-based index of the
  1115. * partition's subplan in the parent plan's subplan list; it is -1 if the
  1116. * partition is non-leaf or has been pruned. For a non-leaf partition p,
  1117. * subpart_map[p] contains the zero-based index of that sub-partition's
  1118. * PartitionedRelPruneInfo in the hierarchy's PartitionedRelPruneInfo list;
  1119. * it is -1 if the partition is a leaf or has been pruned. Note that subplan
  1120. * indexes, as stored in 'subplan_map', are global across the parent plan
  1121. * node, but partition indexes are valid only within a particular hierarchy.
  1122. * relid_map[p] contains the partition's OID, or 0 if the partition was pruned.
  1123. */
  1124. typedef struct PartitionedRelPruneInfo
  1125. {
  1126. NodeTag type;
  1127. Index rtindex; /* RT index of partition rel for this level */
  1128. Bitmapset *present_parts; /* Indexes of all partitions which subplans or
  1129. * subparts are present for */
  1130. int nparts; /* Length of the following arrays: */
  1131. int *subplan_map; /* subplan index by partition index, or -1 */
  1132. int *subpart_map; /* subpart index by partition index, or -1 */
  1133. Oid *relid_map; /* relation OID by partition index, or 0 */
  1134. /*
  1135. * initial_pruning_steps shows how to prune during executor startup (i.e.,
  1136. * without use of any PARAM_EXEC Params); it is NIL if no startup pruning
  1137. * is required. exec_pruning_steps shows how to prune with PARAM_EXEC
  1138. * Params; it is NIL if no per-scan pruning is required.
  1139. */
  1140. List *initial_pruning_steps; /* List of PartitionPruneStep */
  1141. List *exec_pruning_steps; /* List of PartitionPruneStep */
  1142. Bitmapset *execparamids; /* All PARAM_EXEC Param IDs in
  1143. * exec_pruning_steps */
  1144. } PartitionedRelPruneInfo;
  1145. /*
  1146. * Abstract Node type for partition pruning steps (there are no concrete
  1147. * Nodes of this type).
  1148. *
  1149. * step_id is the global identifier of the step within its pruning context.
  1150. */
  1151. typedef struct PartitionPruneStep
  1152. {
  1153. NodeTag type;
  1154. int step_id;
  1155. } PartitionPruneStep;
  1156. /*
  1157. * PartitionPruneStepOp - Information to prune using a set of mutually ANDed
  1158. * OpExpr clauses
  1159. *
  1160. * This contains information extracted from up to partnatts OpExpr clauses,
  1161. * where partnatts is the number of partition key columns. 'opstrategy' is the
  1162. * strategy of the operator in the clause matched to the last partition key.
  1163. * 'exprs' contains expressions which comprise the lookup key to be passed to
  1164. * the partition bound search function. 'cmpfns' contains the OIDs of
  1165. * comparison functions used to compare aforementioned expressions with
  1166. * partition bounds. Both 'exprs' and 'cmpfns' contain the same number of
  1167. * items, up to partnatts items.
  1168. *
  1169. * Once we find the offset of a partition bound using the lookup key, we
  1170. * determine which partitions to include in the result based on the value of
  1171. * 'opstrategy'. For example, if it were equality, we'd return just the
  1172. * partition that would contain that key or a set of partitions if the key
  1173. * didn't consist of all partitioning columns. For non-equality strategies,
  1174. * we'd need to include other partitions as appropriate.
  1175. *
  1176. * 'nullkeys' is the set containing the offset of the partition keys (0 to
  1177. * partnatts - 1) that were matched to an IS NULL clause. This is only
  1178. * considered for hash partitioning as we need to pass which keys are null
  1179. * to the hash partition bound search function. It is never possible to
  1180. * have an expression be present in 'exprs' for a given partition key and
  1181. * the corresponding bit set in 'nullkeys'.
  1182. */
  1183. typedef struct PartitionPruneStepOp
  1184. {
  1185. PartitionPruneStep step;
  1186. StrategyNumber opstrategy;
  1187. List *exprs;
  1188. List *cmpfns;
  1189. Bitmapset *nullkeys;
  1190. } PartitionPruneStepOp;
  1191. /*
  1192. * PartitionPruneStepCombine - Information to prune using a BoolExpr clause
  1193. *
  1194. * For BoolExpr clauses, we combine the set of partitions determined for each
  1195. * of the argument clauses.
  1196. */
  1197. typedef enum PartitionPruneCombineOp
  1198. {
  1199. PARTPRUNE_COMBINE_UNION,
  1200. PARTPRUNE_COMBINE_INTERSECT
  1201. } PartitionPruneCombineOp;
  1202. typedef struct PartitionPruneStepCombine
  1203. {
  1204. PartitionPruneStep step;
  1205. PartitionPruneCombineOp combineOp;
  1206. List *source_stepids;
  1207. } PartitionPruneStepCombine;
  1208. /*
  1209. * Plan invalidation info
  1210. *
  1211. * We track the objects on which a PlannedStmt depends in two ways:
  1212. * relations are recorded as a simple list of OIDs, and everything else
  1213. * is represented as a list of PlanInvalItems. A PlanInvalItem is designed
  1214. * to be used with the syscache invalidation mechanism, so it identifies a
  1215. * system catalog entry by cache ID and hash value.
  1216. */
  1217. typedef struct PlanInvalItem
  1218. {
  1219. NodeTag type;
  1220. int cacheId; /* a syscache ID, see utils/syscache.h */
  1221. uint32 hashValue; /* hash value of object's cache lookup key */
  1222. } PlanInvalItem;
  1223. /*
  1224. * MonotonicFunction
  1225. *
  1226. * Allows the planner to track monotonic properties of functions. A function
  1227. * is monotonically increasing if a subsequent call cannot yield a lower value
  1228. * than the previous call. A monotonically decreasing function cannot yield a
  1229. * higher value on subsequent calls, and a function which is both must return
  1230. * the same value on each call.
  1231. */
  1232. typedef enum MonotonicFunction
  1233. {
  1234. MONOTONICFUNC_NONE = 0,
  1235. MONOTONICFUNC_INCREASING = (1 << 0),
  1236. MONOTONICFUNC_DECREASING = (1 << 1),
  1237. MONOTONICFUNC_BOTH = MONOTONICFUNC_INCREASING | MONOTONICFUNC_DECREASING
  1238. } MonotonicFunction;
  1239. #endif /* PLANNODES_H */