00001 /*------------------------------------------------------------------------- 00002 * 00003 * plannodes.h 00004 * definitions for query plan nodes 00005 * 00006 * 00007 * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group 00008 * Portions Copyright (c) 1994, Regents of the University of California 00009 * 00010 * src/include/nodes/plannodes.h 00011 * 00012 *------------------------------------------------------------------------- 00013 */ 00014 #ifndef PLANNODES_H 00015 #define PLANNODES_H 00016 00017 #include "access/sdir.h" 00018 #include "nodes/bitmapset.h" 00019 #include "nodes/primnodes.h" 00020 00021 00022 /* ---------------------------------------------------------------- 00023 * node definitions 00024 * ---------------------------------------------------------------- 00025 */ 00026 00027 /* ---------------- 00028 * PlannedStmt node 00029 * 00030 * The output of the planner is a Plan tree headed by a PlannedStmt node. 00031 * PlannedStmt holds the "one time" information needed by the executor. 00032 * ---------------- 00033 */ 00034 typedef struct PlannedStmt 00035 { 00036 NodeTag type; 00037 00038 CmdType commandType; /* select|insert|update|delete */ 00039 00040 uint32 queryId; /* query identifier (copied from Query) */ 00041 00042 bool hasReturning; /* is it insert|update|delete RETURNING? */ 00043 00044 bool hasModifyingCTE; /* has insert|update|delete in WITH? */ 00045 00046 bool canSetTag; /* do I set the command result tag? */ 00047 00048 bool transientPlan; /* redo plan when TransactionXmin changes? */ 00049 00050 struct Plan *planTree; /* tree of Plan nodes */ 00051 00052 List *rtable; /* list of RangeTblEntry nodes */ 00053 00054 /* rtable indexes of target relations for INSERT/UPDATE/DELETE */ 00055 List *resultRelations; /* integer list of RT indexes, or NIL */ 00056 00057 Node *utilityStmt; /* non-null if this is DECLARE CURSOR */ 00058 00059 List *subplans; /* Plan trees for SubPlan expressions */ 00060 00061 Bitmapset *rewindPlanIDs; /* indices of subplans that require REWIND */ 00062 00063 List *rowMarks; /* a list of PlanRowMark's */ 00064 00065 List *relationOids; /* OIDs of relations the plan depends on */ 00066 00067 List *invalItems; /* other dependencies, as PlanInvalItems */ 00068 00069 int nParamExec; /* number of PARAM_EXEC Params used */ 00070 } PlannedStmt; 00071 00072 /* macro for fetching the Plan associated with a SubPlan node */ 00073 #define exec_subplan_get_plan(plannedstmt, subplan) \ 00074 ((Plan *) list_nth((plannedstmt)->subplans, (subplan)->plan_id - 1)) 00075 00076 00077 /* ---------------- 00078 * Plan node 00079 * 00080 * All plan nodes "derive" from the Plan structure by having the 00081 * Plan structure as the first field. This ensures that everything works 00082 * when nodes are cast to Plan's. (node pointers are frequently cast to Plan* 00083 * when passed around generically in the executor) 00084 * 00085 * We never actually instantiate any Plan nodes; this is just the common 00086 * abstract superclass for all Plan-type nodes. 00087 * ---------------- 00088 */ 00089 typedef struct Plan 00090 { 00091 NodeTag type; 00092 00093 /* 00094 * estimated execution costs for plan (see costsize.c for more info) 00095 */ 00096 Cost startup_cost; /* cost expended before fetching any tuples */ 00097 Cost total_cost; /* total cost (assuming all tuples fetched) */ 00098 00099 /* 00100 * planner's estimate of result size of this plan step 00101 */ 00102 double plan_rows; /* number of rows plan is expected to emit */ 00103 int plan_width; /* average row width in bytes */ 00104 00105 /* 00106 * Common structural data for all Plan types. 00107 */ 00108 List *targetlist; /* target list to be computed at this node */ 00109 List *qual; /* implicitly-ANDed qual conditions */ 00110 struct Plan *lefttree; /* input plan tree(s) */ 00111 struct Plan *righttree; 00112 List *initPlan; /* Init Plan nodes (un-correlated expr 00113 * subselects) */ 00114 00115 /* 00116 * Information for management of parameter-change-driven rescanning 00117 * 00118 * extParam includes the paramIDs of all external PARAM_EXEC params 00119 * affecting this plan node or its children. setParam params from the 00120 * node's initPlans are not included, but their extParams are. 00121 * 00122 * allParam includes all the extParam paramIDs, plus the IDs of local 00123 * params that affect the node (i.e., the setParams of its initplans). 00124 * These are _all_ the PARAM_EXEC params that affect this node. 00125 */ 00126 Bitmapset *extParam; 00127 Bitmapset *allParam; 00128 } Plan; 00129 00130 /* ---------------- 00131 * these are defined to avoid confusion problems with "left" 00132 * and "right" and "inner" and "outer". The convention is that 00133 * the "left" plan is the "outer" plan and the "right" plan is 00134 * the inner plan, but these make the code more readable. 00135 * ---------------- 00136 */ 00137 #define innerPlan(node) (((Plan *)(node))->righttree) 00138 #define outerPlan(node) (((Plan *)(node))->lefttree) 00139 00140 00141 /* ---------------- 00142 * Result node - 00143 * If no outer plan, evaluate a variable-free targetlist. 00144 * If outer plan, return tuples from outer plan (after a level of 00145 * projection as shown by targetlist). 00146 * 00147 * If resconstantqual isn't NULL, it represents a one-time qualification 00148 * test (i.e., one that doesn't depend on any variables from the outer plan, 00149 * so needs to be evaluated only once). 00150 * ---------------- 00151 */ 00152 typedef struct Result 00153 { 00154 Plan plan; 00155 Node *resconstantqual; 00156 } Result; 00157 00158 /* ---------------- 00159 * ModifyTable node - 00160 * Apply rows produced by subplan(s) to result table(s), 00161 * by inserting, updating, or deleting. 00162 * 00163 * Note that rowMarks and epqParam are presumed to be valid for all the 00164 * subplan(s); they can't contain any info that varies across subplans. 00165 * ---------------- 00166 */ 00167 typedef struct ModifyTable 00168 { 00169 Plan plan; 00170 CmdType operation; /* INSERT, UPDATE, or DELETE */ 00171 bool canSetTag; /* do we set the command tag/es_processed? */ 00172 List *resultRelations; /* integer list of RT indexes */ 00173 int resultRelIndex; /* index of first resultRel in plan's list */ 00174 List *plans; /* plan(s) producing source data */ 00175 List *returningLists; /* per-target-table RETURNING tlists */ 00176 List *fdwPrivLists; /* per-target-table FDW private data lists */ 00177 List *rowMarks; /* PlanRowMarks (non-locking only) */ 00178 int epqParam; /* ID of Param for EvalPlanQual re-eval */ 00179 } ModifyTable; 00180 00181 /* ---------------- 00182 * Append node - 00183 * Generate the concatenation of the results of sub-plans. 00184 * ---------------- 00185 */ 00186 typedef struct Append 00187 { 00188 Plan plan; 00189 List *appendplans; 00190 } Append; 00191 00192 /* ---------------- 00193 * MergeAppend node - 00194 * Merge the results of pre-sorted sub-plans to preserve the ordering. 00195 * ---------------- 00196 */ 00197 typedef struct MergeAppend 00198 { 00199 Plan plan; 00200 List *mergeplans; 00201 /* remaining fields are just like the sort-key info in struct Sort */ 00202 int numCols; /* number of sort-key columns */ 00203 AttrNumber *sortColIdx; /* their indexes in the target list */ 00204 Oid *sortOperators; /* OIDs of operators to sort them by */ 00205 Oid *collations; /* OIDs of collations */ 00206 bool *nullsFirst; /* NULLS FIRST/LAST directions */ 00207 } MergeAppend; 00208 00209 /* ---------------- 00210 * RecursiveUnion node - 00211 * Generate a recursive union of two subplans. 00212 * 00213 * The "outer" subplan is always the non-recursive term, and the "inner" 00214 * subplan is the recursive term. 00215 * ---------------- 00216 */ 00217 typedef struct RecursiveUnion 00218 { 00219 Plan plan; 00220 int wtParam; /* ID of Param representing work table */ 00221 /* Remaining fields are zero/null in UNION ALL case */ 00222 int numCols; /* number of columns to check for 00223 * duplicate-ness */ 00224 AttrNumber *dupColIdx; /* their indexes in the target list */ 00225 Oid *dupOperators; /* equality operators to compare with */ 00226 long numGroups; /* estimated number of groups in input */ 00227 } RecursiveUnion; 00228 00229 /* ---------------- 00230 * BitmapAnd node - 00231 * Generate the intersection of the results of sub-plans. 00232 * 00233 * The subplans must be of types that yield tuple bitmaps. The targetlist 00234 * and qual fields of the plan are unused and are always NIL. 00235 * ---------------- 00236 */ 00237 typedef struct BitmapAnd 00238 { 00239 Plan plan; 00240 List *bitmapplans; 00241 } BitmapAnd; 00242 00243 /* ---------------- 00244 * BitmapOr node - 00245 * Generate the union of the results of sub-plans. 00246 * 00247 * The subplans must be of types that yield tuple bitmaps. The targetlist 00248 * and qual fields of the plan are unused and are always NIL. 00249 * ---------------- 00250 */ 00251 typedef struct BitmapOr 00252 { 00253 Plan plan; 00254 List *bitmapplans; 00255 } BitmapOr; 00256 00257 /* 00258 * ========== 00259 * Scan nodes 00260 * ========== 00261 */ 00262 typedef struct Scan 00263 { 00264 Plan plan; 00265 Index scanrelid; /* relid is index into the range table */ 00266 } Scan; 00267 00268 /* ---------------- 00269 * sequential scan node 00270 * ---------------- 00271 */ 00272 typedef Scan SeqScan; 00273 00274 /* ---------------- 00275 * index scan node 00276 * 00277 * indexqualorig is an implicitly-ANDed list of index qual expressions, each 00278 * in the same form it appeared in the query WHERE condition. Each should 00279 * be of the form (indexkey OP comparisonval) or (comparisonval OP indexkey). 00280 * The indexkey is a Var or expression referencing column(s) of the index's 00281 * base table. The comparisonval might be any expression, but it won't use 00282 * any columns of the base table. The expressions are ordered by index 00283 * column position (but items referencing the same index column can appear 00284 * in any order). indexqualorig is used at runtime only if we have to recheck 00285 * a lossy indexqual. 00286 * 00287 * indexqual has the same form, but the expressions have been commuted if 00288 * necessary to put the indexkeys on the left, and the indexkeys are replaced 00289 * by Var nodes identifying the index columns (their varno is INDEX_VAR and 00290 * their varattno is the index column number). 00291 * 00292 * indexorderbyorig is similarly the original form of any ORDER BY expressions 00293 * that are being implemented by the index, while indexorderby is modified to 00294 * have index column Vars on the left-hand side. Here, multiple expressions 00295 * must appear in exactly the ORDER BY order, and this is not necessarily the 00296 * index column order. Only the expressions are provided, not the auxiliary 00297 * sort-order information from the ORDER BY SortGroupClauses; it's assumed 00298 * that the sort ordering is fully determinable from the top-level operators. 00299 * indexorderbyorig is unused at run time, but is needed for EXPLAIN. 00300 * (Note these fields are used for amcanorderbyop cases, not amcanorder cases.) 00301 * 00302 * indexorderdir specifies the scan ordering, for indexscans on amcanorder 00303 * indexes (for other indexes it should be "don't care"). 00304 * ---------------- 00305 */ 00306 typedef struct IndexScan 00307 { 00308 Scan scan; 00309 Oid indexid; /* OID of index to scan */ 00310 List *indexqual; /* list of index quals (usually OpExprs) */ 00311 List *indexqualorig; /* the same in original form */ 00312 List *indexorderby; /* list of index ORDER BY exprs */ 00313 List *indexorderbyorig; /* the same in original form */ 00314 ScanDirection indexorderdir; /* forward or backward or don't care */ 00315 } IndexScan; 00316 00317 /* ---------------- 00318 * index-only scan node 00319 * 00320 * IndexOnlyScan is very similar to IndexScan, but it specifies an 00321 * index-only scan, in which the data comes from the index not the heap. 00322 * Because of this, *all* Vars in the plan node's targetlist, qual, and 00323 * index expressions reference index columns and have varno = INDEX_VAR. 00324 * Hence we do not need separate indexqualorig and indexorderbyorig lists, 00325 * since their contents would be equivalent to indexqual and indexorderby. 00326 * 00327 * To help EXPLAIN interpret the index Vars for display, we provide 00328 * indextlist, which represents the contents of the index as a targetlist 00329 * with one TLE per index column. Vars appearing in this list reference 00330 * the base table, and this is the only field in the plan node that may 00331 * contain such Vars. 00332 * ---------------- 00333 */ 00334 typedef struct IndexOnlyScan 00335 { 00336 Scan scan; 00337 Oid indexid; /* OID of index to scan */ 00338 List *indexqual; /* list of index quals (usually OpExprs) */ 00339 List *indexorderby; /* list of index ORDER BY exprs */ 00340 List *indextlist; /* TargetEntry list describing index's cols */ 00341 ScanDirection indexorderdir; /* forward or backward or don't care */ 00342 } IndexOnlyScan; 00343 00344 /* ---------------- 00345 * bitmap index scan node 00346 * 00347 * BitmapIndexScan delivers a bitmap of potential tuple locations; 00348 * it does not access the heap itself. The bitmap is used by an 00349 * ancestor BitmapHeapScan node, possibly after passing through 00350 * intermediate BitmapAnd and/or BitmapOr nodes to combine it with 00351 * the results of other BitmapIndexScans. 00352 * 00353 * The fields have the same meanings as for IndexScan, except we don't 00354 * store a direction flag because direction is uninteresting. 00355 * 00356 * In a BitmapIndexScan plan node, the targetlist and qual fields are 00357 * not used and are always NIL. The indexqualorig field is unused at 00358 * run time too, but is saved for the benefit of EXPLAIN. 00359 * ---------------- 00360 */ 00361 typedef struct BitmapIndexScan 00362 { 00363 Scan scan; 00364 Oid indexid; /* OID of index to scan */ 00365 List *indexqual; /* list of index quals (OpExprs) */ 00366 List *indexqualorig; /* the same in original form */ 00367 } BitmapIndexScan; 00368 00369 /* ---------------- 00370 * bitmap sequential scan node 00371 * 00372 * This needs a copy of the qual conditions being used by the input index 00373 * scans because there are various cases where we need to recheck the quals; 00374 * for example, when the bitmap is lossy about the specific rows on a page 00375 * that meet the index condition. 00376 * ---------------- 00377 */ 00378 typedef struct BitmapHeapScan 00379 { 00380 Scan scan; 00381 List *bitmapqualorig; /* index quals, in standard expr form */ 00382 } BitmapHeapScan; 00383 00384 /* ---------------- 00385 * tid scan node 00386 * 00387 * tidquals is an implicitly OR'ed list of qual expressions of the form 00388 * "CTID = pseudoconstant" or "CTID = ANY(pseudoconstant_array)". 00389 * ---------------- 00390 */ 00391 typedef struct TidScan 00392 { 00393 Scan scan; 00394 List *tidquals; /* qual(s) involving CTID = something */ 00395 } TidScan; 00396 00397 /* ---------------- 00398 * subquery scan node 00399 * 00400 * SubqueryScan is for scanning the output of a sub-query in the range table. 00401 * We often need an extra plan node above the sub-query's plan to perform 00402 * expression evaluations (which we can't push into the sub-query without 00403 * risking changing its semantics). Although we are not scanning a physical 00404 * relation, we make this a descendant of Scan anyway for code-sharing 00405 * purposes. 00406 * 00407 * Note: we store the sub-plan in the type-specific subplan field, not in 00408 * the generic lefttree field as you might expect. This is because we do 00409 * not want plan-tree-traversal routines to recurse into the subplan without 00410 * knowing that they are changing Query contexts. 00411 * ---------------- 00412 */ 00413 typedef struct SubqueryScan 00414 { 00415 Scan scan; 00416 Plan *subplan; 00417 } SubqueryScan; 00418 00419 /* ---------------- 00420 * FunctionScan node 00421 * ---------------- 00422 */ 00423 typedef struct FunctionScan 00424 { 00425 Scan scan; 00426 Node *funcexpr; /* expression tree for func call */ 00427 List *funccolnames; /* output column names (string Value nodes) */ 00428 List *funccoltypes; /* OID list of column type OIDs */ 00429 List *funccoltypmods; /* integer list of column typmods */ 00430 List *funccolcollations; /* OID list of column collation OIDs */ 00431 } FunctionScan; 00432 00433 /* ---------------- 00434 * ValuesScan node 00435 * ---------------- 00436 */ 00437 typedef struct ValuesScan 00438 { 00439 Scan scan; 00440 List *values_lists; /* list of expression lists */ 00441 } ValuesScan; 00442 00443 /* ---------------- 00444 * CteScan node 00445 * ---------------- 00446 */ 00447 typedef struct CteScan 00448 { 00449 Scan scan; 00450 int ctePlanId; /* ID of init SubPlan for CTE */ 00451 int cteParam; /* ID of Param representing CTE output */ 00452 } CteScan; 00453 00454 /* ---------------- 00455 * WorkTableScan node 00456 * ---------------- 00457 */ 00458 typedef struct WorkTableScan 00459 { 00460 Scan scan; 00461 int wtParam; /* ID of Param representing work table */ 00462 } WorkTableScan; 00463 00464 /* ---------------- 00465 * ForeignScan node 00466 * 00467 * fdw_exprs and fdw_private are both under the control of the foreign-data 00468 * wrapper, but fdw_exprs is presumed to contain expression trees and will 00469 * be post-processed accordingly by the planner; fdw_private won't be. 00470 * Note that everything in both lists must be copiable by copyObject(). 00471 * One way to store an arbitrary blob of bytes is to represent it as a bytea 00472 * Const. Usually, though, you'll be better off choosing a representation 00473 * that can be dumped usefully by nodeToString(). 00474 * ---------------- 00475 */ 00476 typedef struct ForeignScan 00477 { 00478 Scan scan; 00479 List *fdw_exprs; /* expressions that FDW may evaluate */ 00480 List *fdw_private; /* private data for FDW */ 00481 bool fsSystemCol; /* true if any "system column" is needed */ 00482 } ForeignScan; 00483 00484 00485 /* 00486 * ========== 00487 * Join nodes 00488 * ========== 00489 */ 00490 00491 /* ---------------- 00492 * Join node 00493 * 00494 * jointype: rule for joining tuples from left and right subtrees 00495 * joinqual: qual conditions that came from JOIN/ON or JOIN/USING 00496 * (plan.qual contains conditions that came from WHERE) 00497 * 00498 * When jointype is INNER, joinqual and plan.qual are semantically 00499 * interchangeable. For OUTER jointypes, the two are *not* interchangeable; 00500 * only joinqual is used to determine whether a match has been found for 00501 * the purpose of deciding whether to generate null-extended tuples. 00502 * (But plan.qual is still applied before actually returning a tuple.) 00503 * For an outer join, only joinquals are allowed to be used as the merge 00504 * or hash condition of a merge or hash join. 00505 * ---------------- 00506 */ 00507 typedef struct Join 00508 { 00509 Plan plan; 00510 JoinType jointype; 00511 List *joinqual; /* JOIN quals (in addition to plan.qual) */ 00512 } Join; 00513 00514 /* ---------------- 00515 * nest loop join node 00516 * 00517 * The nestParams list identifies any executor Params that must be passed 00518 * into execution of the inner subplan carrying values from the current row 00519 * of the outer subplan. Currently we restrict these values to be simple 00520 * Vars, but perhaps someday that'd be worth relaxing. (Note: during plan 00521 * creation, the paramval can actually be a PlaceHolderVar expression; but it 00522 * must be a Var with varno OUTER_VAR by the time it gets to the executor.) 00523 * ---------------- 00524 */ 00525 typedef struct NestLoop 00526 { 00527 Join join; 00528 List *nestParams; /* list of NestLoopParam nodes */ 00529 } NestLoop; 00530 00531 typedef struct NestLoopParam 00532 { 00533 NodeTag type; 00534 int paramno; /* number of the PARAM_EXEC Param to set */ 00535 Var *paramval; /* outer-relation Var to assign to Param */ 00536 } NestLoopParam; 00537 00538 /* ---------------- 00539 * merge join node 00540 * 00541 * The expected ordering of each mergeable column is described by a btree 00542 * opfamily OID, a collation OID, a direction (BTLessStrategyNumber or 00543 * BTGreaterStrategyNumber) and a nulls-first flag. Note that the two sides 00544 * of each mergeclause may be of different datatypes, but they are ordered the 00545 * same way according to the common opfamily and collation. The operator in 00546 * each mergeclause must be an equality operator of the indicated opfamily. 00547 * ---------------- 00548 */ 00549 typedef struct MergeJoin 00550 { 00551 Join join; 00552 List *mergeclauses; /* mergeclauses as expression trees */ 00553 /* these are arrays, but have the same length as the mergeclauses list: */ 00554 Oid *mergeFamilies; /* per-clause OIDs of btree opfamilies */ 00555 Oid *mergeCollations; /* per-clause OIDs of collations */ 00556 int *mergeStrategies; /* per-clause ordering (ASC or DESC) */ 00557 bool *mergeNullsFirst; /* per-clause nulls ordering */ 00558 } MergeJoin; 00559 00560 /* ---------------- 00561 * hash join node 00562 * ---------------- 00563 */ 00564 typedef struct HashJoin 00565 { 00566 Join join; 00567 List *hashclauses; 00568 } HashJoin; 00569 00570 /* ---------------- 00571 * materialization node 00572 * ---------------- 00573 */ 00574 typedef struct Material 00575 { 00576 Plan plan; 00577 } Material; 00578 00579 /* ---------------- 00580 * sort node 00581 * ---------------- 00582 */ 00583 typedef struct Sort 00584 { 00585 Plan plan; 00586 int numCols; /* number of sort-key columns */ 00587 AttrNumber *sortColIdx; /* their indexes in the target list */ 00588 Oid *sortOperators; /* OIDs of operators to sort them by */ 00589 Oid *collations; /* OIDs of collations */ 00590 bool *nullsFirst; /* NULLS FIRST/LAST directions */ 00591 } Sort; 00592 00593 /* --------------- 00594 * group node - 00595 * Used for queries with GROUP BY (but no aggregates) specified. 00596 * The input must be presorted according to the grouping columns. 00597 * --------------- 00598 */ 00599 typedef struct Group 00600 { 00601 Plan plan; 00602 int numCols; /* number of grouping columns */ 00603 AttrNumber *grpColIdx; /* their indexes in the target list */ 00604 Oid *grpOperators; /* equality operators to compare with */ 00605 } Group; 00606 00607 /* --------------- 00608 * aggregate node 00609 * 00610 * An Agg node implements plain or grouped aggregation. For grouped 00611 * aggregation, we can work with presorted input or unsorted input; 00612 * the latter strategy uses an internal hashtable. 00613 * 00614 * Notice the lack of any direct info about the aggregate functions to be 00615 * computed. They are found by scanning the node's tlist and quals during 00616 * executor startup. (It is possible that there are no aggregate functions; 00617 * this could happen if they get optimized away by constant-folding, or if 00618 * we are using the Agg node to implement hash-based grouping.) 00619 * --------------- 00620 */ 00621 typedef enum AggStrategy 00622 { 00623 AGG_PLAIN, /* simple agg across all input rows */ 00624 AGG_SORTED, /* grouped agg, input must be sorted */ 00625 AGG_HASHED /* grouped agg, use internal hashtable */ 00626 } AggStrategy; 00627 00628 typedef struct Agg 00629 { 00630 Plan plan; 00631 AggStrategy aggstrategy; 00632 int numCols; /* number of grouping columns */ 00633 AttrNumber *grpColIdx; /* their indexes in the target list */ 00634 Oid *grpOperators; /* equality operators to compare with */ 00635 long numGroups; /* estimated number of groups in input */ 00636 } Agg; 00637 00638 /* ---------------- 00639 * window aggregate node 00640 * ---------------- 00641 */ 00642 typedef struct WindowAgg 00643 { 00644 Plan plan; 00645 Index winref; /* ID referenced by window functions */ 00646 int partNumCols; /* number of columns in partition clause */ 00647 AttrNumber *partColIdx; /* their indexes in the target list */ 00648 Oid *partOperators; /* equality operators for partition columns */ 00649 int ordNumCols; /* number of columns in ordering clause */ 00650 AttrNumber *ordColIdx; /* their indexes in the target list */ 00651 Oid *ordOperators; /* equality operators for ordering columns */ 00652 int frameOptions; /* frame_clause options, see WindowDef */ 00653 Node *startOffset; /* expression for starting bound, if any */ 00654 Node *endOffset; /* expression for ending bound, if any */ 00655 } WindowAgg; 00656 00657 /* ---------------- 00658 * unique node 00659 * ---------------- 00660 */ 00661 typedef struct Unique 00662 { 00663 Plan plan; 00664 int numCols; /* number of columns to check for uniqueness */ 00665 AttrNumber *uniqColIdx; /* their indexes in the target list */ 00666 Oid *uniqOperators; /* equality operators to compare with */ 00667 } Unique; 00668 00669 /* ---------------- 00670 * hash build node 00671 * 00672 * If the executor is supposed to try to apply skew join optimization, then 00673 * skewTable/skewColumn/skewInherit identify the outer relation's join key 00674 * column, from which the relevant MCV statistics can be fetched. Also, its 00675 * type information is provided to save a lookup. 00676 * ---------------- 00677 */ 00678 typedef struct Hash 00679 { 00680 Plan plan; 00681 Oid skewTable; /* outer join key's table OID, or InvalidOid */ 00682 AttrNumber skewColumn; /* outer join key's column #, or zero */ 00683 bool skewInherit; /* is outer join rel an inheritance tree? */ 00684 Oid skewColType; /* datatype of the outer key column */ 00685 int32 skewColTypmod; /* typmod of the outer key column */ 00686 /* all other info is in the parent HashJoin node */ 00687 } Hash; 00688 00689 /* ---------------- 00690 * setop node 00691 * ---------------- 00692 */ 00693 typedef enum SetOpCmd 00694 { 00695 SETOPCMD_INTERSECT, 00696 SETOPCMD_INTERSECT_ALL, 00697 SETOPCMD_EXCEPT, 00698 SETOPCMD_EXCEPT_ALL 00699 } SetOpCmd; 00700 00701 typedef enum SetOpStrategy 00702 { 00703 SETOP_SORTED, /* input must be sorted */ 00704 SETOP_HASHED /* use internal hashtable */ 00705 } SetOpStrategy; 00706 00707 typedef struct SetOp 00708 { 00709 Plan plan; 00710 SetOpCmd cmd; /* what to do */ 00711 SetOpStrategy strategy; /* how to do it */ 00712 int numCols; /* number of columns to check for 00713 * duplicate-ness */ 00714 AttrNumber *dupColIdx; /* their indexes in the target list */ 00715 Oid *dupOperators; /* equality operators to compare with */ 00716 AttrNumber flagColIdx; /* where is the flag column, if any */ 00717 int firstFlag; /* flag value for first input relation */ 00718 long numGroups; /* estimated number of groups in input */ 00719 } SetOp; 00720 00721 /* ---------------- 00722 * lock-rows node 00723 * 00724 * rowMarks identifies the rels to be locked by this node; it should be 00725 * a subset of the rowMarks listed in the top-level PlannedStmt. 00726 * epqParam is a Param that all scan nodes below this one must depend on. 00727 * It is used to force re-evaluation of the plan during EvalPlanQual. 00728 * ---------------- 00729 */ 00730 typedef struct LockRows 00731 { 00732 Plan plan; 00733 List *rowMarks; /* a list of PlanRowMark's */ 00734 int epqParam; /* ID of Param for EvalPlanQual re-eval */ 00735 } LockRows; 00736 00737 /* ---------------- 00738 * limit node 00739 * 00740 * Note: as of Postgres 8.2, the offset and count expressions are expected 00741 * to yield int8, rather than int4 as before. 00742 * ---------------- 00743 */ 00744 typedef struct Limit 00745 { 00746 Plan plan; 00747 Node *limitOffset; /* OFFSET parameter, or NULL if none */ 00748 Node *limitCount; /* COUNT parameter, or NULL if none */ 00749 } Limit; 00750 00751 00752 /* 00753 * RowMarkType - 00754 * enums for types of row-marking operations 00755 * 00756 * The first four of these values represent different lock strengths that 00757 * we can take on tuples according to SELECT FOR [KEY] UPDATE/SHARE requests. 00758 * We only support these on regular tables. For foreign tables, any locking 00759 * that might be done for these requests must happen during the initial row 00760 * fetch; there is no mechanism for going back to lock a row later (and thus 00761 * no need for EvalPlanQual machinery during updates of foreign tables). 00762 * This means that the semantics will be a bit different than for a local 00763 * table; in particular we are likely to lock more rows than would be locked 00764 * locally, since remote rows will be locked even if they then fail 00765 * locally-checked restriction or join quals. However, the alternative of 00766 * doing a separate remote query to lock each selected row is extremely 00767 * unappealing, so let's do it like this for now. 00768 * 00769 * When doing UPDATE, DELETE, or SELECT FOR UPDATE/SHARE, we have to uniquely 00770 * identify all the source rows, not only those from the target relations, so 00771 * that we can perform EvalPlanQual rechecking at need. For plain tables we 00772 * can just fetch the TID, much as for a target relation; this case is 00773 * represented by ROW_MARK_REFERENCE. Otherwise (for example for VALUES or 00774 * FUNCTION scans) we have to copy the whole row value. ROW_MARK_COPY is 00775 * pretty inefficient, since most of the time we'll never need the data; but 00776 * fortunately the case is not performance-critical in practice. Note that 00777 * we use ROW_MARK_COPY for non-target foreign tables, even if the FDW has a 00778 * concept of rowid and so could theoretically support some form of 00779 * ROW_MARK_REFERENCE. Although copying the whole row value is inefficient, 00780 * it's probably still faster than doing a second remote fetch, so it doesn't 00781 * seem worth the extra complexity to permit ROW_MARK_REFERENCE. 00782 */ 00783 typedef enum RowMarkType 00784 { 00785 ROW_MARK_EXCLUSIVE, /* obtain exclusive tuple lock */ 00786 ROW_MARK_NOKEYEXCLUSIVE, /* obtain no-key exclusive tuple lock */ 00787 ROW_MARK_SHARE, /* obtain shared tuple lock */ 00788 ROW_MARK_KEYSHARE, /* obtain keyshare tuple lock */ 00789 ROW_MARK_REFERENCE, /* just fetch the TID */ 00790 ROW_MARK_COPY /* physically copy the row value */ 00791 } RowMarkType; 00792 00793 #define RowMarkRequiresRowShareLock(marktype) ((marktype) <= ROW_MARK_KEYSHARE) 00794 00795 /* 00796 * PlanRowMark - 00797 * plan-time representation of FOR [KEY] UPDATE/SHARE clauses 00798 * 00799 * When doing UPDATE, DELETE, or SELECT FOR UPDATE/SHARE, we create a separate 00800 * PlanRowMark node for each non-target relation in the query. Relations that 00801 * are not specified as FOR UPDATE/SHARE are marked ROW_MARK_REFERENCE (if 00802 * regular tables) or ROW_MARK_COPY (if not). 00803 * 00804 * Initially all PlanRowMarks have rti == prti and isParent == false. 00805 * When the planner discovers that a relation is the root of an inheritance 00806 * tree, it sets isParent true, and adds an additional PlanRowMark to the 00807 * list for each child relation (including the target rel itself in its role 00808 * as a child). The child entries have rti == child rel's RT index and 00809 * prti == parent's RT index, and can therefore be recognized as children by 00810 * the fact that prti != rti. 00811 * 00812 * The planner also adds resjunk output columns to the plan that carry 00813 * information sufficient to identify the locked or fetched rows. For 00814 * regular tables (markType != ROW_MARK_COPY), these columns are named 00815 * tableoid%u OID of table 00816 * ctid%u TID of row 00817 * The tableoid column is only present for an inheritance hierarchy. 00818 * When markType == ROW_MARK_COPY, there is instead a single column named 00819 * wholerow%u whole-row value of relation 00820 * In all three cases, %u represents the rowmark ID number (rowmarkId). 00821 * This number is unique within a plan tree, except that child relation 00822 * entries copy their parent's rowmarkId. (Assigning unique numbers 00823 * means we needn't renumber rowmarkIds when flattening subqueries, which 00824 * would require finding and renaming the resjunk columns as well.) 00825 * Note this means that all tables in an inheritance hierarchy share the 00826 * same resjunk column names. However, in an inherited UPDATE/DELETE the 00827 * columns could have different physical column numbers in each subplan. 00828 */ 00829 typedef struct PlanRowMark 00830 { 00831 NodeTag type; 00832 Index rti; /* range table index of markable relation */ 00833 Index prti; /* range table index of parent relation */ 00834 Index rowmarkId; /* unique identifier for resjunk columns */ 00835 RowMarkType markType; /* see enum above */ 00836 bool noWait; /* NOWAIT option */ 00837 bool isParent; /* true if this is a "dummy" parent entry */ 00838 } PlanRowMark; 00839 00840 00841 /* 00842 * Plan invalidation info 00843 * 00844 * We track the objects on which a PlannedStmt depends in two ways: 00845 * relations are recorded as a simple list of OIDs, and everything else 00846 * is represented as a list of PlanInvalItems. A PlanInvalItem is designed 00847 * to be used with the syscache invalidation mechanism, so it identifies a 00848 * system catalog entry by cache ID and hash value. 00849 */ 00850 typedef struct PlanInvalItem 00851 { 00852 NodeTag type; 00853 int cacheId; /* a syscache ID, see utils/syscache.h */ 00854 uint32 hashValue; /* hash value of object's cache lookup key */ 00855 } PlanInvalItem; 00856 00857 #endif /* PLANNODES_H */