Eneboo - Documentación para desarrolladores
|
00001 /*------------------------------------------------------------------------- 00002 * 00003 * plannodes.h 00004 * definitions for query plan nodes 00005 * 00006 * 00007 * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group 00008 * Portions Copyright (c) 1994, Regents of the University of California 00009 * 00010 * $PostgreSQL: pgsql/src/include/nodes/plannodes.h,v 1.80.2.1 2005/11/22 18:23:28 momjian Exp $ 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 * Plan node 00029 * 00030 * All plan nodes "derive" from the Plan structure by having the 00031 * Plan structure as the first field. This ensures that everything works 00032 * when nodes are cast to Plan's. (node pointers are frequently cast to Plan* 00033 * when passed around generically in the executor) 00034 * 00035 * We never actually instantiate any Plan nodes; this is just the common 00036 * abstract superclass for all Plan-type nodes. 00037 * ---------------- 00038 */ 00039 typedef struct Plan 00040 { 00041 NodeTag type; 00042 00043 /* 00044 * estimated execution costs for plan (see costsize.c for more info) 00045 */ 00046 Cost startup_cost; /* cost expended before fetching any tuples */ 00047 Cost total_cost; /* total cost (assuming all tuples fetched) */ 00048 00049 /* 00050 * planner's estimate of result size of this plan step 00051 */ 00052 double plan_rows; /* number of rows plan is expected to emit */ 00053 int plan_width; /* average row width in bytes */ 00054 00055 /* 00056 * Common structural data for all Plan types. 00057 */ 00058 List *targetlist; /* target list to be computed at this node */ 00059 List *qual; /* implicitly-ANDed qual conditions */ 00060 struct Plan *lefttree; /* input plan tree(s) */ 00061 struct Plan *righttree; 00062 List *initPlan; /* Init Plan nodes (un-correlated expr 00063 * subselects) */ 00064 00065 /* 00066 * Information for management of parameter-change-driven rescanning 00067 * 00068 * extParam includes the paramIDs of all external PARAM_EXEC params 00069 * affecting this plan node or its children. setParam params from the 00070 * node's initPlans are not included, but their extParams are. 00071 * 00072 * allParam includes all the extParam paramIDs, plus the IDs of local 00073 * params that affect the node (i.e., the setParams of its initplans). 00074 * These are _all_ the PARAM_EXEC params that affect this node. 00075 */ 00076 Bitmapset *extParam; 00077 Bitmapset *allParam; 00078 00079 /* 00080 * We really need in some TopPlan node to store range table and 00081 * resultRelation from Query there and get rid of Query itself from 00082 * Executor. Some other stuff like below could be put there, too. 00083 */ 00084 int nParamExec; /* Number of them in entire query. This is to 00085 * get Executor know about how many PARAM_EXEC 00086 * there are in query plan. */ 00087 } Plan; 00088 00089 /* ---------------- 00090 * these are are defined to avoid confusion problems with "left" 00091 * and "right" and "inner" and "outer". The convention is that 00092 * the "left" plan is the "outer" plan and the "right" plan is 00093 * the inner plan, but these make the code more readable. 00094 * ---------------- 00095 */ 00096 #define innerPlan(node) (((Plan *)(node))->righttree) 00097 #define outerPlan(node) (((Plan *)(node))->lefttree) 00098 00099 00100 /* ---------------- 00101 * Result node - 00102 * If no outer plan, evaluate a variable-free targetlist. 00103 * If outer plan, return tuples from outer plan (after a level of 00104 * projection as shown by targetlist). 00105 * 00106 * If resconstantqual isn't NULL, it represents a one-time qualification 00107 * test (i.e., one that doesn't depend on any variables from the outer plan, 00108 * so needs to be evaluated only once). 00109 * ---------------- 00110 */ 00111 typedef struct Result 00112 { 00113 Plan plan; 00114 Node *resconstantqual; 00115 } Result; 00116 00117 /* ---------------- 00118 * Append node - 00119 * Generate the concatenation of the results of sub-plans. 00120 * 00121 * Append nodes are sometimes used to switch between several result relations 00122 * (when the target of an UPDATE or DELETE is an inheritance set). Such a 00123 * node will have isTarget true. The Append executor is then responsible 00124 * for updating the executor state to point at the correct target relation 00125 * whenever it switches subplans. 00126 * ---------------- 00127 */ 00128 typedef struct Append 00129 { 00130 Plan plan; 00131 List *appendplans; 00132 bool isTarget; 00133 } Append; 00134 00135 /* ---------------- 00136 * BitmapAnd node - 00137 * Generate the intersection of the results of sub-plans. 00138 * 00139 * The subplans must be of types that yield tuple bitmaps. The targetlist 00140 * and qual fields of the plan are unused and are always NIL. 00141 * ---------------- 00142 */ 00143 typedef struct BitmapAnd 00144 { 00145 Plan plan; 00146 List *bitmapplans; 00147 } BitmapAnd; 00148 00149 /* ---------------- 00150 * BitmapOr node - 00151 * Generate the union of the results of sub-plans. 00152 * 00153 * The subplans must be of types that yield tuple bitmaps. The targetlist 00154 * and qual fields of the plan are unused and are always NIL. 00155 * ---------------- 00156 */ 00157 typedef struct BitmapOr 00158 { 00159 Plan plan; 00160 List *bitmapplans; 00161 } BitmapOr; 00162 00163 /* 00164 * ========== 00165 * Scan nodes 00166 * ========== 00167 */ 00168 typedef struct Scan 00169 { 00170 Plan plan; 00171 Index scanrelid; /* relid is index into the range table */ 00172 } Scan; 00173 00174 /* ---------------- 00175 * sequential scan node 00176 * ---------------- 00177 */ 00178 typedef Scan SeqScan; 00179 00180 /* ---------------- 00181 * index scan node 00182 * 00183 * indexqualorig is an implicitly-ANDed list of index qual expressions, each 00184 * in the same form it appeared in the query WHERE condition. Each should 00185 * be of the form (indexkey OP comparisonval) or (comparisonval OP indexkey). 00186 * The indexkey is a Var or expression referencing column(s) of the index's 00187 * base table. The comparisonval might be any expression, but it won't use 00188 * any columns of the base table. 00189 * 00190 * indexqual has the same form, but the expressions have been commuted if 00191 * necessary to put the indexkeys on the left, and the indexkeys are replaced 00192 * by Var nodes identifying the index columns (varattno is the index column 00193 * position, not the base table's column, even though varno is for the base 00194 * table). This is a bit hokey ... would be cleaner to use a special-purpose 00195 * node type that could not be mistaken for a regular Var. But it will do 00196 * for now. 00197 * 00198 * indexstrategy and indexsubtype are lists corresponding one-to-one with 00199 * indexqual; they give information about the indexable operators that appear 00200 * at the top of each indexqual. 00201 * ---------------- 00202 */ 00203 typedef struct IndexScan 00204 { 00205 Scan scan; 00206 Oid indexid; /* OID of index to scan */ 00207 List *indexqual; /* list of index quals (OpExprs) */ 00208 List *indexqualorig; /* the same in original form */ 00209 List *indexstrategy; /* integer list of strategy numbers */ 00210 List *indexsubtype; /* OID list of strategy subtypes */ 00211 ScanDirection indexorderdir; /* forward or backward or don't care */ 00212 } IndexScan; 00213 00214 /* ---------------- 00215 * bitmap index scan node 00216 * 00217 * BitmapIndexScan delivers a bitmap of potential tuple locations; 00218 * it does not access the heap itself. The bitmap is used by an 00219 * ancestor BitmapHeapScan node, possibly after passing through 00220 * intermediate BitmapAnd and/or BitmapOr nodes to combine it with 00221 * the results of other BitmapIndexScans. 00222 * 00223 * The fields have the same meanings as for IndexScan, except we don't 00224 * store a direction flag because direction is uninteresting. 00225 * 00226 * In a BitmapIndexScan plan node, the targetlist and qual fields are 00227 * not used and are always NIL. The indexqualorig field is unused at 00228 * run time too, but is saved for the benefit of EXPLAIN. 00229 * ---------------- 00230 */ 00231 typedef struct BitmapIndexScan 00232 { 00233 Scan scan; 00234 Oid indexid; /* OID of index to scan */ 00235 List *indexqual; /* list of index quals (OpExprs) */ 00236 List *indexqualorig; /* the same in original form */ 00237 List *indexstrategy; /* integer list of strategy numbers */ 00238 List *indexsubtype; /* OID list of strategy subtypes */ 00239 } BitmapIndexScan; 00240 00241 /* ---------------- 00242 * bitmap sequential scan node 00243 * 00244 * This needs a copy of the qual conditions being used by the input index 00245 * scans because there are various cases where we need to recheck the quals; 00246 * for example, when the bitmap is lossy about the specific rows on a page 00247 * that meet the index condition. 00248 * ---------------- 00249 */ 00250 typedef struct BitmapHeapScan 00251 { 00252 Scan scan; 00253 List *bitmapqualorig; /* index quals, in standard expr form */ 00254 } BitmapHeapScan; 00255 00256 /* ---------------- 00257 * tid scan node 00258 * ---------------- 00259 */ 00260 typedef struct TidScan 00261 { 00262 Scan scan; 00263 List *tideval; 00264 } TidScan; 00265 00266 /* ---------------- 00267 * subquery scan node 00268 * 00269 * SubqueryScan is for scanning the output of a sub-query in the range table. 00270 * We need a special plan node above the sub-query's plan as a place to switch 00271 * execution contexts. Although we are not scanning a physical relation, 00272 * we make this a descendant of Scan anyway for code-sharing purposes. 00273 * 00274 * Note: we store the sub-plan in the type-specific subplan field, not in 00275 * the generic lefttree field as you might expect. This is because we do 00276 * not want plan-tree-traversal routines to recurse into the subplan without 00277 * knowing that they are changing Query contexts. 00278 * ---------------- 00279 */ 00280 typedef struct SubqueryScan 00281 { 00282 Scan scan; 00283 Plan *subplan; 00284 } SubqueryScan; 00285 00286 /* ---------------- 00287 * FunctionScan node 00288 * ---------------- 00289 */ 00290 typedef struct FunctionScan 00291 { 00292 Scan scan; 00293 /* no other fields needed at present */ 00294 } FunctionScan; 00295 00296 /* 00297 * ========== 00298 * Join nodes 00299 * ========== 00300 */ 00301 00302 /* ---------------- 00303 * Join node 00304 * 00305 * jointype: rule for joining tuples from left and right subtrees 00306 * joinqual: qual conditions that came from JOIN/ON or JOIN/USING 00307 * (plan.qual contains conditions that came from WHERE) 00308 * 00309 * When jointype is INNER, joinqual and plan.qual are semantically 00310 * interchangeable. For OUTER jointypes, the two are *not* interchangeable; 00311 * only joinqual is used to determine whether a match has been found for 00312 * the purpose of deciding whether to generate null-extended tuples. 00313 * (But plan.qual is still applied before actually returning a tuple.) 00314 * For an outer join, only joinquals are allowed to be used as the merge 00315 * or hash condition of a merge or hash join. 00316 * ---------------- 00317 */ 00318 typedef struct Join 00319 { 00320 Plan plan; 00321 JoinType jointype; 00322 List *joinqual; /* JOIN quals (in addition to plan.qual) */ 00323 } Join; 00324 00325 /* ---------------- 00326 * nest loop join node 00327 * ---------------- 00328 */ 00329 typedef struct NestLoop 00330 { 00331 Join join; 00332 } NestLoop; 00333 00334 /* ---------------- 00335 * merge join node 00336 * ---------------- 00337 */ 00338 typedef struct MergeJoin 00339 { 00340 Join join; 00341 List *mergeclauses; 00342 } MergeJoin; 00343 00344 /* ---------------- 00345 * hash join (probe) node 00346 * ---------------- 00347 */ 00348 typedef struct HashJoin 00349 { 00350 Join join; 00351 List *hashclauses; 00352 } HashJoin; 00353 00354 /* ---------------- 00355 * materialization node 00356 * ---------------- 00357 */ 00358 typedef struct Material 00359 { 00360 Plan plan; 00361 } Material; 00362 00363 /* ---------------- 00364 * sort node 00365 * ---------------- 00366 */ 00367 typedef struct Sort 00368 { 00369 Plan plan; 00370 int numCols; /* number of sort-key columns */ 00371 AttrNumber *sortColIdx; /* their indexes in the target list */ 00372 Oid *sortOperators; /* OIDs of operators to sort them by */ 00373 } Sort; 00374 00375 /* --------------- 00376 * group node - 00377 * Used for queries with GROUP BY (but no aggregates) specified. 00378 * The input must be presorted according to the grouping columns. 00379 * --------------- 00380 */ 00381 typedef struct Group 00382 { 00383 Plan plan; 00384 int numCols; /* number of grouping columns */ 00385 AttrNumber *grpColIdx; /* their indexes in the target list */ 00386 } Group; 00387 00388 /* --------------- 00389 * aggregate node 00390 * 00391 * An Agg node implements plain or grouped aggregation. For grouped 00392 * aggregation, we can work with presorted input or unsorted input; 00393 * the latter strategy uses an internal hashtable. 00394 * 00395 * Notice the lack of any direct info about the aggregate functions to be 00396 * computed. They are found by scanning the node's tlist and quals during 00397 * executor startup. (It is possible that there are no aggregate functions; 00398 * this could happen if they get optimized away by constant-folding, or if 00399 * we are using the Agg node to implement hash-based grouping.) 00400 * --------------- 00401 */ 00402 typedef enum AggStrategy 00403 { 00404 AGG_PLAIN, /* simple agg across all input rows */ 00405 AGG_SORTED, /* grouped agg, input must be sorted */ 00406 AGG_HASHED /* grouped agg, use internal hashtable */ 00407 } AggStrategy; 00408 00409 typedef struct Agg 00410 { 00411 Plan plan; 00412 AggStrategy aggstrategy; 00413 int numCols; /* number of grouping columns */ 00414 AttrNumber *grpColIdx; /* their indexes in the target list */ 00415 long numGroups; /* estimated number of groups in input */ 00416 } Agg; 00417 00418 /* ---------------- 00419 * unique node 00420 * ---------------- 00421 */ 00422 typedef struct Unique 00423 { 00424 Plan plan; 00425 int numCols; /* number of columns to check for uniqueness */ 00426 AttrNumber *uniqColIdx; /* indexes into the target list */ 00427 } Unique; 00428 00429 /* ---------------- 00430 * hash build node 00431 * ---------------- 00432 */ 00433 typedef struct Hash 00434 { 00435 Plan plan; 00436 /* all other info is in the parent HashJoin node */ 00437 } Hash; 00438 00439 /* ---------------- 00440 * setop node 00441 * ---------------- 00442 */ 00443 typedef enum SetOpCmd 00444 { 00445 SETOPCMD_INTERSECT, 00446 SETOPCMD_INTERSECT_ALL, 00447 SETOPCMD_EXCEPT, 00448 SETOPCMD_EXCEPT_ALL 00449 } SetOpCmd; 00450 00451 typedef struct SetOp 00452 { 00453 Plan plan; 00454 SetOpCmd cmd; /* what to do */ 00455 int numCols; /* number of columns to check for 00456 * duplicate-ness */ 00457 AttrNumber *dupColIdx; /* indexes into the target list */ 00458 AttrNumber flagColIdx; 00459 } SetOp; 00460 00461 /* ---------------- 00462 * limit node 00463 * ---------------- 00464 */ 00465 typedef struct Limit 00466 { 00467 Plan plan; 00468 Node *limitOffset; /* OFFSET parameter, or NULL if none */ 00469 Node *limitCount; /* COUNT parameter, or NULL if none */ 00470 } Limit; 00471 00472 #endif /* PLANNODES_H */