📄 relation.h
字号:
* clauses */ List *index_inner_paths; /* InnerIndexscanInfo nodes */ /* * Inner indexscans are not in the main pathlist because they are not * usable except in specific join contexts. We use the index_inner_paths * list just to avoid recomputing the best inner indexscan repeatedly for * similar outer relations. See comments for InnerIndexscanInfo. */} RelOptInfo;/* * IndexOptInfo * Per-index information for planning/optimization * * Prior to Postgres 7.0, RelOptInfo was used to describe both relations * and indexes, but that created confusion without actually doing anything * useful. So now we have a separate IndexOptInfo struct for indexes. * * classlist[], indexkeys[], and ordering[] have ncolumns entries. * Zeroes in the indexkeys[] array indicate index columns that are * expressions; there is one element in indexprs for each such column. * * Note: for historical reasons, the classlist and ordering arrays have * an extra entry that is always zero. Some code scans until it sees a * zero entry, rather than looking at ncolumns. * * The indexprs and indpred expressions have been run through * prepqual.c and eval_const_expressions() for ease of matching to * WHERE clauses. indpred is in implicit-AND form. */typedef struct IndexOptInfo{ NodeTag type; Oid indexoid; /* OID of the index relation */ RelOptInfo *rel; /* back-link to index's table */ /* statistics from pg_class */ BlockNumber pages; /* number of disk pages in index */ double tuples; /* number of index tuples in index */ /* index descriptor information */ int ncolumns; /* number of columns in index */ Oid *classlist; /* OIDs of operator classes for columns */ int *indexkeys; /* column numbers of index's keys, or 0 */ Oid *ordering; /* OIDs of sort operators for each column */ Oid relam; /* OID of the access method (in pg_am) */ RegProcedure amcostestimate; /* OID of the access method's cost fcn */ List *indexprs; /* expressions for non-simple index columns */ List *indpred; /* predicate if a partial index, else NIL */ bool predOK; /* true if predicate matches query */ bool unique; /* true if a unique index */ bool amoptionalkey; /* can query omit key for the first column? */} IndexOptInfo;/* * PathKeys * * The sort ordering of a path is represented by a list of sublists of * PathKeyItem nodes. An empty list implies no known ordering. Otherwise * the first sublist represents the primary sort key, the second the * first secondary sort key, etc. Each sublist contains one or more * PathKeyItem nodes, each of which can be taken as the attribute that * appears at that sort position. (See optimizer/README for more * information.) */typedef struct PathKeyItem{ NodeTag type; Node *key; /* the item that is ordered */ Oid sortop; /* the ordering operator ('<' op) */ /* * key typically points to a Var node, ie a relation attribute, but it can * also point to an arbitrary expression representing the value indexed by * an index expression. */} PathKeyItem;/* * Type "Path" is used as-is for sequential-scan paths. For other * path types it is the first component of a larger struct. * * Note: "pathtype" is the NodeTag of the Plan node we could build from this * Path. It is partially redundant with the Path's NodeTag, but allows us * to use the same Path type for multiple Plan types where there is no need * to distinguish the Plan type during path processing. */typedef struct Path{ NodeTag type; NodeTag pathtype; /* tag identifying scan/join method */ RelOptInfo *parent; /* the relation this path can build */ /* estimated execution costs for path (see costsize.c for more info) */ Cost startup_cost; /* cost expended before fetching any tuples */ Cost total_cost; /* total cost (assuming all tuples fetched) */ List *pathkeys; /* sort ordering of path's output */ /* pathkeys is a List of Lists of PathKeyItem nodes; see above */} Path;/*---------- * IndexPath represents an index scan over a single index. * * 'indexinfo' is the index to be scanned. * * 'indexclauses' is a list of index qualification clauses, with implicit * AND semantics across the list. Each clause is a RestrictInfo node from * the query's WHERE or JOIN conditions. * * 'indexquals' has the same structure as 'indexclauses', but it contains * the actual indexqual conditions that can be used with the index. * In simple cases this is identical to 'indexclauses', but when special * indexable operators appear in 'indexclauses', they are replaced by the * derived indexscannable conditions in 'indexquals'. * * 'isjoininner' is TRUE if the path is a nestloop inner scan (that is, * some of the index conditions are join rather than restriction clauses). * * 'indexscandir' is one of: * ForwardScanDirection: forward scan of an ordered index * BackwardScanDirection: backward scan of an ordered index * NoMovementScanDirection: scan of an unordered index, or don't care * (The executor doesn't care whether it gets ForwardScanDirection or * NoMovementScanDirection for an indexscan, but the planner wants to * distinguish ordered from unordered indexes for building pathkeys.) * * 'indextotalcost' and 'indexselectivity' are saved in the IndexPath so that * we need not recompute them when considering using the same index in a * bitmap index/heap scan (see BitmapHeapPath). The costs of the IndexPath * itself represent the costs of an IndexScan plan type. * * 'rows' is the estimated result tuple count for the indexscan. This * is the same as path.parent->rows for a simple indexscan, but it is * different for a nestloop inner scan, because the additional indexquals * coming from join clauses make the scan more selective than the parent * rel's restrict clauses alone would do. *---------- */typedef struct IndexPath{ Path path; IndexOptInfo *indexinfo; List *indexclauses; List *indexquals; bool isjoininner; ScanDirection indexscandir; Cost indextotalcost; Selectivity indexselectivity; double rows; /* estimated number of result tuples */} IndexPath;/* * BitmapHeapPath represents one or more indexscans that generate TID bitmaps * instead of directly accessing the heap, followed by AND/OR combinations * to produce a single bitmap, followed by a heap scan that uses the bitmap. * Note that the output is always considered unordered, since it will come * out in physical heap order no matter what the underlying indexes did. * * The individual indexscans are represented by IndexPath nodes, and any * logic on top of them is represented by a tree of BitmapAndPath and * BitmapOrPath nodes. Notice that we can use the same IndexPath node both * to represent a regular IndexScan plan, and as the child of a BitmapHeapPath * that represents scanning the same index using a BitmapIndexScan. The * startup_cost and total_cost figures of an IndexPath always represent the * costs to use it as a regular IndexScan. The costs of a BitmapIndexScan * can be computed using the IndexPath's indextotalcost and indexselectivity. * * BitmapHeapPaths can be nestloop inner indexscans. The isjoininner and * rows fields serve the same purpose as for plain IndexPaths. */typedef struct BitmapHeapPath{ Path path; Path *bitmapqual; /* IndexPath, BitmapAndPath, BitmapOrPath */ bool isjoininner; /* T if it's a nestloop inner scan */ double rows; /* estimated number of result tuples */} BitmapHeapPath;/* * BitmapAndPath represents a BitmapAnd plan node; it can only appear as * part of the substructure of a BitmapHeapPath. The Path structure is * a bit more heavyweight than we really need for this, but for simplicity * we make it a derivative of Path anyway. */typedef struct BitmapAndPath{ Path path; List *bitmapquals; /* IndexPaths and BitmapOrPaths */ Selectivity bitmapselectivity;} BitmapAndPath;/* * BitmapOrPath represents a BitmapOr plan node; it can only appear as * part of the substructure of a BitmapHeapPath. The Path structure is * a bit more heavyweight than we really need for this, but for simplicity * we make it a derivative of Path anyway. */typedef struct BitmapOrPath{ Path path; List *bitmapquals; /* IndexPaths and BitmapAndPaths */ Selectivity bitmapselectivity;} BitmapOrPath;/* * TidPath represents a scan by TID * * tideval is an implicitly OR'ed list of quals of the form CTID = something. * Note they are bare quals, not RestrictInfos. */typedef struct TidPath{ Path path; List *tideval; /* qual(s) involving CTID = something */} TidPath;/* * AppendPath represents an Append plan, ie, successive execution of * several member plans. Currently it is only used to handle expansion * of inheritance trees. * * Note: it is possible for "subpaths" to contain only one, or even no, * elements. These cases are optimized during create_append_plan. */typedef struct AppendPath{ Path path; List *subpaths; /* list of component Paths */} AppendPath;/* * ResultPath represents use of a Result plan node. There are several * applications for this: * * To compute a variable-free targetlist (a "SELECT expressions" query). * In this case subpath and path.parent will both be NULL. constantqual * might or might not be empty ("SELECT expressions WHERE something"). * * To gate execution of a subplan with a one-time (variable-free) qual * condition. path.parent is copied from the subpath. * * To substitute for a scan plan when we have proven that no rows in * a table will satisfy the query. subpath is NULL but path.parent * references the not-to-be-scanned relation, and constantqual is * a constant FALSE. * * Note that constantqual is a list of bare clauses, not RestrictInfos. */typedef struct ResultPath{ Path path; Path *subpath; List *constantqual;} ResultPath;/* * MaterialPath represents use of a Material plan node, i.e., caching of * the output of its subpath. This is used when the subpath is expensive * and needs to be scanned repeatedly, or when we need mark/restore ability * and the subpath doesn't have it. */typedef struct MaterialPath{ Path path; Path *subpath;} MaterialPath;/* * UniquePath represents elimination of distinct rows from the output of * its subpath. * * This is unlike the other Path nodes in that it can actually generate * different plans: either hash-based or sort-based implementation, or a * no-op if the input path can be proven distinct already. The decision * is sufficiently localized that it's not worth having separate Path node
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -