Eneboo - Documentación para desarrolladores
src/libpq/include/nodes/relation.h
Ir a la documentación de este archivo.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * relation.h
00004  *        Definitions for planner's internal data structures.
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/relation.h,v 1.119.2.1 2005/11/14 23:54:36 tgl Exp $
00011  *
00012  *-------------------------------------------------------------------------
00013  */
00014 #ifndef RELATION_H
00015 #define RELATION_H
00016 
00017 #include "access/sdir.h"
00018 #include "nodes/bitmapset.h"
00019 #include "nodes/parsenodes.h"
00020 #include "storage/block.h"
00021 
00022 
00023 /*
00024  * Relids
00025  *              Set of relation identifiers (indexes into the rangetable).
00026  */
00027 typedef Bitmapset *Relids;
00028 
00029 /*
00030  * When looking for a "cheapest path", this enum specifies whether we want
00031  * cheapest startup cost or cheapest total cost.
00032  */
00033 typedef enum CostSelector
00034 {
00035         STARTUP_COST, TOTAL_COST
00036 } CostSelector;
00037 
00038 /*
00039  * The cost estimate produced by cost_qual_eval() includes both a one-time
00040  * (startup) cost, and a per-tuple cost.
00041  */
00042 typedef struct QualCost
00043 {
00044         Cost            startup;                /* one-time cost */
00045         Cost            per_tuple;              /* per-evaluation cost */
00046 } QualCost;
00047 
00048 
00049 /*----------
00050  * PlannerInfo
00051  *              Per-query information for planning/optimization
00052  *
00053  * This struct is conventionally called "root" in all the planner routines.
00054  * It holds links to all of the planner's working state, in addition to the
00055  * original Query.      Note that at present the planner extensively manipulates
00056  * the passed-in Query data structure; someday that should stop.
00057  *----------
00058  */
00059 typedef struct PlannerInfo
00060 {
00061         NodeTag         type;
00062 
00063         Query      *parse;                      /* the Query being planned */
00064 
00065         /*
00066          * base_rel_array holds pointers to "base rels" and "other rels" (see
00067          * comments for RelOptInfo for more info).      It is indexed by rangetable
00068          * index (so entry 0 is always wasted).  Entries can be NULL when an RTE
00069          * does not correspond to a base relation.      Note that the array may be
00070          * enlarged on-the-fly.
00071          */
00072         struct RelOptInfo **base_rel_array; /* All one-relation RelOptInfos */
00073         int                     base_rel_array_size;    /* current allocated array len */
00074 
00075         /*
00076          * join_rel_list is a list of all join-relation RelOptInfos we have
00077          * considered in this planning run.  For small problems we just scan the
00078          * list to do lookups, but when there are many join relations we build a
00079          * hash table for faster lookups.  The hash table is present and valid
00080          * when join_rel_hash is not NULL.      Note that we still maintain the list
00081          * even when using the hash table for lookups; this simplifies life for
00082          * GEQO.
00083          */
00084         List       *join_rel_list;      /* list of join-relation RelOptInfos */
00085         struct HTAB *join_rel_hash; /* optional hashtable for join relations */
00086 
00087         List       *equi_key_list;      /* list of lists of equijoined PathKeyItems */
00088 
00089         List       *left_join_clauses;          /* list of RestrictInfos for outer
00090                                                                                  * join clauses w/nonnullable var on
00091                                                                                  * left */
00092 
00093         List       *right_join_clauses;         /* list of RestrictInfos for outer
00094                                                                                  * join clauses w/nonnullable var on
00095                                                                                  * right */
00096 
00097         List       *full_join_clauses;          /* list of RestrictInfos for full
00098                                                                                  * outer join clauses */
00099 
00100         List       *in_info_list;       /* list of InClauseInfos */
00101 
00102         List       *query_pathkeys; /* desired pathkeys for query_planner(), and
00103                                                                  * actual pathkeys afterwards */
00104 
00105         List       *group_pathkeys; /* groupClause pathkeys, if any */
00106         List       *sort_pathkeys;      /* sortClause pathkeys, if any */
00107 
00108         double          tuple_fraction; /* tuple_fraction passed to query_planner */
00109 
00110         bool            hasJoinRTEs;    /* true if any RTEs are RTE_JOIN kind */
00111         bool            hasOuterJoins;  /* true if any RTEs are outer joins */
00112         bool            hasHavingQual;  /* true if havingQual was non-null */
00113 } PlannerInfo;
00114 
00115 
00116 /*----------
00117  * RelOptInfo
00118  *              Per-relation information for planning/optimization
00119  *
00120  * For planning purposes, a "base rel" is either a plain relation (a table)
00121  * or the output of a sub-SELECT or function that appears in the range table.
00122  * In either case it is uniquely identified by an RT index.  A "joinrel"
00123  * is the joining of two or more base rels.  A joinrel is identified by
00124  * the set of RT indexes for its component baserels.  We create RelOptInfo
00125  * nodes for each baserel and joinrel, and store them in the PlannerInfo's
00126  * base_rel_array and join_rel_list respectively.
00127  *
00128  * Note that there is only one joinrel for any given set of component
00129  * baserels, no matter what order we assemble them in; so an unordered
00130  * set is the right datatype to identify it with.
00131  *
00132  * We also have "other rels", which are like base rels in that they refer to
00133  * single RT indexes; but they are not part of the join tree, and are given
00134  * a different RelOptKind to identify them.
00135  *
00136  * Currently the only kind of otherrels are those made for child relations
00137  * of an inheritance scan (SELECT FROM foo*).  The parent table's RTE and
00138  * corresponding baserel represent the whole result of the inheritance scan.
00139  * The planner creates separate RTEs and associated RelOptInfos for each child
00140  * table (including the parent table, in its capacity as a member of the
00141  * inheritance set).  These RelOptInfos are physically identical to baserels,
00142  * but are otherrels because they are not in the main join tree.  These added
00143  * RTEs and otherrels are used to plan the scans of the individual tables in
00144  * the inheritance set; then the parent baserel is given an Append plan
00145  * comprising the best plans for the individual child tables.
00146  *
00147  * At one time we also made otherrels to represent join RTEs, for use in
00148  * handling join alias Vars.  Currently this is not needed because all join
00149  * alias Vars are expanded to non-aliased form during preprocess_expression.
00150  *
00151  * Parts of this data structure are specific to various scan and join
00152  * mechanisms.  It didn't seem worth creating new node types for them.
00153  *
00154  *              relids - Set of base-relation identifiers; it is a base relation
00155  *                              if there is just one, a join relation if more than one
00156  *              rows - estimated number of tuples in the relation after restriction
00157  *                         clauses have been applied (ie, output rows of a plan for it)
00158  *              width - avg. number of bytes per tuple in the relation after the
00159  *                              appropriate projections have been done (ie, output width)
00160  *              reltargetlist - List of Var nodes for the attributes we need to
00161  *                                              output from this relation (in no particular order)
00162  *                                              NOTE: in a child relation, may contain RowExprs
00163  *              pathlist - List of Path nodes, one for each potentially useful
00164  *                                 method of generating the relation
00165  *              cheapest_startup_path - the pathlist member with lowest startup cost
00166  *                                                              (regardless of its ordering)
00167  *              cheapest_total_path - the pathlist member with lowest total cost
00168  *                                                        (regardless of its ordering)
00169  *              cheapest_unique_path - for caching cheapest path to produce unique
00170  *                                                         (no duplicates) output from relation
00171  *
00172  * If the relation is a base relation it will have these fields set:
00173  *
00174  *              relid - RTE index (this is redundant with the relids field, but
00175  *                              is provided for convenience of access)
00176  *              rtekind - distinguishes plain relation, subquery, or function RTE
00177  *              min_attr, max_attr - range of valid AttrNumbers for rel
00178  *              attr_needed - array of bitmapsets indicating the highest joinrel
00179  *                              in which each attribute is needed; if bit 0 is set then
00180  *                              the attribute is needed as part of final targetlist
00181  *              attr_widths - cache space for per-attribute width estimates;
00182  *                                        zero means not computed yet
00183  *              indexlist - list of IndexOptInfo nodes for relation's indexes
00184  *                                      (always NIL if it's not a table)
00185  *              pages - number of disk pages in relation (zero if not a table)
00186  *              tuples - number of tuples in relation (not considering restrictions)
00187  *              subplan - plan for subquery (NULL if it's not a subquery)
00188  *
00189  *              Note: for a subquery, tuples and subplan are not set immediately
00190  *              upon creation of the RelOptInfo object; they are filled in when
00191  *              set_base_rel_pathlist processes the object.
00192  *
00193  *              For otherrels that are inheritance children, these fields are filled
00194  *              in just as for a baserel.
00195  *
00196  * The presence of the remaining fields depends on the restrictions
00197  * and joins that the relation participates in:
00198  *
00199  *              baserestrictinfo - List of RestrictInfo nodes, containing info about
00200  *                                      each non-join qualification clause in which this relation
00201  *                                      participates (only used for base rels)
00202  *              baserestrictcost - Estimated cost of evaluating the baserestrictinfo
00203  *                                      clauses at a single tuple (only used for base rels)
00204  *              outerjoinset - For a base rel: if the rel appears within the nullable
00205  *                                      side of an outer join, the set of all relids
00206  *                                      participating in the highest such outer join; else NULL.
00207  *                                      Otherwise, unused.
00208  *              joininfo  - List of RestrictInfo nodes, containing info about each
00209  *                                      join clause in which this relation participates
00210  *              index_outer_relids - only used for base rels; set of outer relids
00211  *                                      that participate in indexable joinclauses for this rel
00212  *              index_inner_paths - only used for base rels; list of InnerIndexscanInfo
00213  *                                      nodes showing best indexpaths for various subsets of
00214  *                                      index_outer_relids.
00215  *
00216  * Note: Keeping a restrictinfo list in the RelOptInfo is useful only for
00217  * base rels, because for a join rel the set of clauses that are treated as
00218  * restrict clauses varies depending on which sub-relations we choose to join.
00219  * (For example, in a 3-base-rel join, a clause relating rels 1 and 2 must be
00220  * treated as a restrictclause if we join {1} and {2 3} to make {1 2 3}; but
00221  * if we join {1 2} and {3} then that clause will be a restrictclause in {1 2}
00222  * and should not be processed again at the level of {1 2 3}.)  Therefore,
00223  * the restrictinfo list in the join case appears in individual JoinPaths
00224  * (field joinrestrictinfo), not in the parent relation.  But it's OK for
00225  * the RelOptInfo to store the joininfo list, because that is the same
00226  * for a given rel no matter how we form it.
00227  *
00228  * We store baserestrictcost in the RelOptInfo (for base relations) because
00229  * we know we will need it at least once (to price the sequential scan)
00230  * and may need it multiple times to price index scans.
00231  *
00232  * outerjoinset is used to ensure correct placement of WHERE clauses that
00233  * apply to outer-joined relations; we must not apply such WHERE clauses
00234  * until after the outer join is performed.
00235  *----------
00236  */
00237 typedef enum RelOptKind
00238 {
00239         RELOPT_BASEREL,
00240         RELOPT_JOINREL,
00241         RELOPT_OTHER_CHILD_REL
00242 } RelOptKind;
00243 
00244 typedef struct RelOptInfo
00245 {
00246         NodeTag         type;
00247 
00248         RelOptKind      reloptkind;
00249 
00250         /* all relations included in this RelOptInfo */
00251         Relids          relids;                 /* set of base relids (rangetable indexes) */
00252 
00253         /* size estimates generated by planner */
00254         double          rows;                   /* estimated number of result tuples */
00255         int                     width;                  /* estimated avg width of result tuples */
00256 
00257         /* materialization information */
00258         List       *reltargetlist;      /* needed Vars */
00259         List       *pathlist;           /* Path structures */
00260         struct Path *cheapest_startup_path;
00261         struct Path *cheapest_total_path;
00262         struct Path *cheapest_unique_path;
00263 
00264         /* information about a base rel (not set for join rels!) */
00265         Index           relid;
00266         RTEKind         rtekind;                /* RELATION, SUBQUERY, or FUNCTION */
00267         AttrNumber      min_attr;               /* smallest attrno of rel (often <0) */
00268         AttrNumber      max_attr;               /* largest attrno of rel */
00269         Relids     *attr_needed;        /* array indexed [min_attr .. max_attr] */
00270         int32      *attr_widths;        /* array indexed [min_attr .. max_attr] */
00271         List       *indexlist;
00272         BlockNumber pages;
00273         double          tuples;
00274         struct Plan *subplan;           /* if subquery */
00275 
00276         /* used by various scans and joins: */
00277         List       *baserestrictinfo;           /* RestrictInfo structures (if base
00278                                                                                  * rel) */
00279         QualCost        baserestrictcost;               /* cost of evaluating the above */
00280         Relids          outerjoinset;   /* set of base relids */
00281         List       *joininfo;           /* RestrictInfo structures for join clauses
00282                                                                  * involving this rel */
00283 
00284         /* cached info about inner indexscan paths for relation: */
00285         Relids          index_outer_relids;             /* other relids in indexable join
00286                                                                                  * clauses */
00287         List       *index_inner_paths;          /* InnerIndexscanInfo nodes */
00288 
00289         /*
00290          * Inner indexscans are not in the main pathlist because they are not
00291          * usable except in specific join contexts.  We use the index_inner_paths
00292          * list just to avoid recomputing the best inner indexscan repeatedly for
00293          * similar outer relations.  See comments for InnerIndexscanInfo.
00294          */
00295 } RelOptInfo;
00296 
00297 /*
00298  * IndexOptInfo
00299  *              Per-index information for planning/optimization
00300  *
00301  *              Prior to Postgres 7.0, RelOptInfo was used to describe both relations
00302  *              and indexes, but that created confusion without actually doing anything
00303  *              useful.  So now we have a separate IndexOptInfo struct for indexes.
00304  *
00305  *              classlist[], indexkeys[], and ordering[] have ncolumns entries.
00306  *              Zeroes in the indexkeys[] array indicate index columns that are
00307  *              expressions; there is one element in indexprs for each such column.
00308  *
00309  *              Note: for historical reasons, the classlist and ordering arrays have
00310  *              an extra entry that is always zero.  Some code scans until it sees a
00311  *              zero entry, rather than looking at ncolumns.
00312  *
00313  *              The indexprs and indpred expressions have been run through
00314  *              prepqual.c and eval_const_expressions() for ease of matching to
00315  *              WHERE clauses.  indpred is in implicit-AND form.
00316  */
00317 
00318 typedef struct IndexOptInfo
00319 {
00320         NodeTag         type;
00321 
00322         Oid                     indexoid;               /* OID of the index relation */
00323         RelOptInfo *rel;                        /* back-link to index's table */
00324 
00325         /* statistics from pg_class */
00326         BlockNumber pages;                      /* number of disk pages in index */
00327         double          tuples;                 /* number of index tuples in index */
00328 
00329         /* index descriptor information */
00330         int                     ncolumns;               /* number of columns in index */
00331         Oid                *classlist;          /* OIDs of operator classes for columns */
00332         int                *indexkeys;          /* column numbers of index's keys, or 0 */
00333         Oid                *ordering;           /* OIDs of sort operators for each column */
00334         Oid                     relam;                  /* OID of the access method (in pg_am) */
00335 
00336         RegProcedure amcostestimate;    /* OID of the access method's cost fcn */
00337 
00338         List       *indexprs;           /* expressions for non-simple index columns */
00339         List       *indpred;            /* predicate if a partial index, else NIL */
00340 
00341         bool            predOK;                 /* true if predicate matches query */
00342         bool            unique;                 /* true if a unique index */
00343         bool            amoptionalkey;  /* can query omit key for the first column? */
00344 } IndexOptInfo;
00345 
00346 
00347 /*
00348  * PathKeys
00349  *
00350  *      The sort ordering of a path is represented by a list of sublists of
00351  *      PathKeyItem nodes.      An empty list implies no known ordering.  Otherwise
00352  *      the first sublist represents the primary sort key, the second the
00353  *      first secondary sort key, etc.  Each sublist contains one or more
00354  *      PathKeyItem nodes, each of which can be taken as the attribute that
00355  *      appears at that sort position.  (See optimizer/README for more
00356  *      information.)
00357  */
00358 
00359 typedef struct PathKeyItem
00360 {
00361         NodeTag         type;
00362 
00363         Node       *key;                        /* the item that is ordered */
00364         Oid                     sortop;                 /* the ordering operator ('<' op) */
00365 
00366         /*
00367          * key typically points to a Var node, ie a relation attribute, but it can
00368          * also point to an arbitrary expression representing the value indexed by
00369          * an index expression.
00370          */
00371 } PathKeyItem;
00372 
00373 /*
00374  * Type "Path" is used as-is for sequential-scan paths.  For other
00375  * path types it is the first component of a larger struct.
00376  *
00377  * Note: "pathtype" is the NodeTag of the Plan node we could build from this
00378  * Path.  It is partially redundant with the Path's NodeTag, but allows us
00379  * to use the same Path type for multiple Plan types where there is no need
00380  * to distinguish the Plan type during path processing.
00381  */
00382 
00383 typedef struct Path
00384 {
00385         NodeTag         type;
00386 
00387         NodeTag         pathtype;               /* tag identifying scan/join method */
00388 
00389         RelOptInfo *parent;                     /* the relation this path can build */
00390 
00391         /* estimated execution costs for path (see costsize.c for more info) */
00392         Cost            startup_cost;   /* cost expended before fetching any tuples */
00393         Cost            total_cost;             /* total cost (assuming all tuples fetched) */
00394 
00395         List       *pathkeys;           /* sort ordering of path's output */
00396         /* pathkeys is a List of Lists of PathKeyItem nodes; see above */
00397 } Path;
00398 
00399 /*----------
00400  * IndexPath represents an index scan over a single index.
00401  *
00402  * 'indexinfo' is the index to be scanned.
00403  *
00404  * 'indexclauses' is a list of index qualification clauses, with implicit
00405  * AND semantics across the list.  Each clause is a RestrictInfo node from
00406  * the query's WHERE or JOIN conditions.
00407  *
00408  * 'indexquals' has the same structure as 'indexclauses', but it contains
00409  * the actual indexqual conditions that can be used with the index.
00410  * In simple cases this is identical to 'indexclauses', but when special
00411  * indexable operators appear in 'indexclauses', they are replaced by the
00412  * derived indexscannable conditions in 'indexquals'.
00413  *
00414  * 'isjoininner' is TRUE if the path is a nestloop inner scan (that is,
00415  * some of the index conditions are join rather than restriction clauses).
00416  *
00417  * 'indexscandir' is one of:
00418  *              ForwardScanDirection: forward scan of an ordered index
00419  *              BackwardScanDirection: backward scan of an ordered index
00420  *              NoMovementScanDirection: scan of an unordered index, or don't care
00421  * (The executor doesn't care whether it gets ForwardScanDirection or
00422  * NoMovementScanDirection for an indexscan, but the planner wants to
00423  * distinguish ordered from unordered indexes for building pathkeys.)
00424  *
00425  * 'indextotalcost' and 'indexselectivity' are saved in the IndexPath so that
00426  * we need not recompute them when considering using the same index in a
00427  * bitmap index/heap scan (see BitmapHeapPath).  The costs of the IndexPath
00428  * itself represent the costs of an IndexScan plan type.
00429  *
00430  * 'rows' is the estimated result tuple count for the indexscan.  This
00431  * is the same as path.parent->rows for a simple indexscan, but it is
00432  * different for a nestloop inner scan, because the additional indexquals
00433  * coming from join clauses make the scan more selective than the parent
00434  * rel's restrict clauses alone would do.
00435  *----------
00436  */
00437 typedef struct IndexPath
00438 {
00439         Path            path;
00440         IndexOptInfo *indexinfo;
00441         List       *indexclauses;
00442         List       *indexquals;
00443         bool            isjoininner;
00444         ScanDirection indexscandir;
00445         Cost            indextotalcost;
00446         Selectivity indexselectivity;
00447         double          rows;                   /* estimated number of result tuples */
00448 } IndexPath;
00449 
00450 /*
00451  * BitmapHeapPath represents one or more indexscans that generate TID bitmaps
00452  * instead of directly accessing the heap, followed by AND/OR combinations
00453  * to produce a single bitmap, followed by a heap scan that uses the bitmap.
00454  * Note that the output is always considered unordered, since it will come
00455  * out in physical heap order no matter what the underlying indexes did.
00456  *
00457  * The individual indexscans are represented by IndexPath nodes, and any
00458  * logic on top of them is represented by a tree of BitmapAndPath and
00459  * BitmapOrPath nodes.  Notice that we can use the same IndexPath node both
00460  * to represent a regular IndexScan plan, and as the child of a BitmapHeapPath
00461  * that represents scanning the same index using a BitmapIndexScan.  The
00462  * startup_cost and total_cost figures of an IndexPath always represent the
00463  * costs to use it as a regular IndexScan.      The costs of a BitmapIndexScan
00464  * can be computed using the IndexPath's indextotalcost and indexselectivity.
00465  *
00466  * BitmapHeapPaths can be nestloop inner indexscans.  The isjoininner and
00467  * rows fields serve the same purpose as for plain IndexPaths.
00468  */
00469 typedef struct BitmapHeapPath
00470 {
00471         Path            path;
00472         Path       *bitmapqual;         /* IndexPath, BitmapAndPath, BitmapOrPath */
00473         bool            isjoininner;    /* T if it's a nestloop inner scan */
00474         double          rows;                   /* estimated number of result tuples */
00475 } BitmapHeapPath;
00476 
00477 /*
00478  * BitmapAndPath represents a BitmapAnd plan node; it can only appear as
00479  * part of the substructure of a BitmapHeapPath.  The Path structure is
00480  * a bit more heavyweight than we really need for this, but for simplicity
00481  * we make it a derivative of Path anyway.
00482  */
00483 typedef struct BitmapAndPath
00484 {
00485         Path            path;
00486         List       *bitmapquals;        /* IndexPaths and BitmapOrPaths */
00487         Selectivity bitmapselectivity;
00488 } BitmapAndPath;
00489 
00490 /*
00491  * BitmapOrPath represents a BitmapOr plan node; it can only appear as
00492  * part of the substructure of a BitmapHeapPath.  The Path structure is
00493  * a bit more heavyweight than we really need for this, but for simplicity
00494  * we make it a derivative of Path anyway.
00495  */
00496 typedef struct BitmapOrPath
00497 {
00498         Path            path;
00499         List       *bitmapquals;        /* IndexPaths and BitmapAndPaths */
00500         Selectivity bitmapselectivity;
00501 } BitmapOrPath;
00502 
00503 /*
00504  * TidPath represents a scan by TID
00505  *
00506  * tideval is an implicitly OR'ed list of quals of the form CTID = something.
00507  * Note they are bare quals, not RestrictInfos.
00508  */
00509 typedef struct TidPath
00510 {
00511         Path            path;
00512         List       *tideval;            /* qual(s) involving CTID = something */
00513 } TidPath;
00514 
00515 /*
00516  * AppendPath represents an Append plan, ie, successive execution of
00517  * several member plans.  Currently it is only used to handle expansion
00518  * of inheritance trees.
00519  *
00520  * Note: it is possible for "subpaths" to contain only one, or even no,
00521  * elements.  These cases are optimized during create_append_plan.
00522  */
00523 typedef struct AppendPath
00524 {
00525         Path            path;
00526         List       *subpaths;           /* list of component Paths */
00527 } AppendPath;
00528 
00529 /*
00530  * ResultPath represents use of a Result plan node.  There are several
00531  * applications for this:
00532  *      * To compute a variable-free targetlist (a "SELECT expressions" query).
00533  *        In this case subpath and path.parent will both be NULL.  constantqual
00534  *        might or might not be empty ("SELECT expressions WHERE something").
00535  *      * To gate execution of a subplan with a one-time (variable-free) qual
00536  *        condition.  path.parent is copied from the subpath.
00537  *      * To substitute for a scan plan when we have proven that no rows in
00538  *        a table will satisfy the query.  subpath is NULL but path.parent
00539  *        references the not-to-be-scanned relation, and constantqual is
00540  *        a constant FALSE.
00541  *
00542  * Note that constantqual is a list of bare clauses, not RestrictInfos.
00543  */
00544 typedef struct ResultPath
00545 {
00546         Path            path;
00547         Path       *subpath;
00548         List       *constantqual;
00549 } ResultPath;
00550 
00551 /*
00552  * MaterialPath represents use of a Material plan node, i.e., caching of
00553  * the output of its subpath.  This is used when the subpath is expensive
00554  * and needs to be scanned repeatedly, or when we need mark/restore ability
00555  * and the subpath doesn't have it.
00556  */
00557 typedef struct MaterialPath
00558 {
00559         Path            path;
00560         Path       *subpath;
00561 } MaterialPath;
00562 
00563 /*
00564  * UniquePath represents elimination of distinct rows from the output of
00565  * its subpath.
00566  *
00567  * This is unlike the other Path nodes in that it can actually generate
00568  * different plans: either hash-based or sort-based implementation, or a
00569  * no-op if the input path can be proven distinct already.      The decision
00570  * is sufficiently localized that it's not worth having separate Path node
00571  * types.  (Note: in the no-op case, we could eliminate the UniquePath node
00572  * entirely and just return the subpath; but it's convenient to have a
00573  * UniquePath in the path tree to signal upper-level routines that the input
00574  * is known distinct.)
00575  */
00576 typedef enum
00577 {
00578         UNIQUE_PATH_NOOP,                       /* input is known unique already */
00579         UNIQUE_PATH_HASH,                       /* use hashing */
00580         UNIQUE_PATH_SORT                        /* use sorting */
00581 } UniquePathMethod;
00582 
00583 typedef struct UniquePath
00584 {
00585         Path            path;
00586         Path       *subpath;
00587         UniquePathMethod umethod;
00588         double          rows;                   /* estimated number of result tuples */
00589 } UniquePath;
00590 
00591 /*
00592  * All join-type paths share these fields.
00593  */
00594 
00595 typedef struct JoinPath
00596 {
00597         Path            path;
00598 
00599         JoinType        jointype;
00600 
00601         Path       *outerjoinpath;      /* path for the outer side of the join */
00602         Path       *innerjoinpath;      /* path for the inner side of the join */
00603 
00604         List       *joinrestrictinfo;           /* RestrictInfos to apply to join */
00605 
00606         /*
00607          * See the notes for RelOptInfo to understand why joinrestrictinfo is
00608          * needed in JoinPath, and can't be merged into the parent RelOptInfo.
00609          */
00610 } JoinPath;
00611 
00612 /*
00613  * A nested-loop path needs no special fields.
00614  */
00615 
00616 typedef JoinPath NestPath;
00617 
00618 /*
00619  * A mergejoin path has these fields.
00620  *
00621  * path_mergeclauses lists the clauses (in the form of RestrictInfos)
00622  * that will be used in the merge.
00623  *
00624  * Note that the mergeclauses are a subset of the parent relation's
00625  * restriction-clause list.  Any join clauses that are not mergejoinable
00626  * appear only in the parent's restrict list, and must be checked by a
00627  * qpqual at execution time.
00628  *
00629  * outersortkeys (resp. innersortkeys) is NIL if the outer path
00630  * (resp. inner path) is already ordered appropriately for the
00631  * mergejoin.  If it is not NIL then it is a PathKeys list describing
00632  * the ordering that must be created by an explicit sort step.
00633  */
00634 
00635 typedef struct MergePath
00636 {
00637         JoinPath        jpath;
00638         List       *path_mergeclauses;          /* join clauses to be used for merge */
00639         List       *outersortkeys;      /* keys for explicit sort, if any */
00640         List       *innersortkeys;      /* keys for explicit sort, if any */
00641 } MergePath;
00642 
00643 /*
00644  * A hashjoin path has these fields.
00645  *
00646  * The remarks above for mergeclauses apply for hashclauses as well.
00647  *
00648  * Hashjoin does not care what order its inputs appear in, so we have
00649  * no need for sortkeys.
00650  */
00651 
00652 typedef struct HashPath
00653 {
00654         JoinPath        jpath;
00655         List       *path_hashclauses;           /* join clauses used for hashing */
00656 } HashPath;
00657 
00658 /*
00659  * Restriction clause info.
00660  *
00661  * We create one of these for each AND sub-clause of a restriction condition
00662  * (WHERE or JOIN/ON clause).  Since the restriction clauses are logically
00663  * ANDed, we can use any one of them or any subset of them to filter out
00664  * tuples, without having to evaluate the rest.  The RestrictInfo node itself
00665  * stores data used by the optimizer while choosing the best query plan.
00666  *
00667  * If a restriction clause references a single base relation, it will appear
00668  * in the baserestrictinfo list of the RelOptInfo for that base rel.
00669  *
00670  * If a restriction clause references more than one base rel, it will
00671  * appear in the joininfo list of every RelOptInfo that describes a strict
00672  * subset of the base rels mentioned in the clause.  The joininfo lists are
00673  * used to drive join tree building by selecting plausible join candidates.
00674  * The clause cannot actually be applied until we have built a join rel
00675  * containing all the base rels it references, however.
00676  *
00677  * When we construct a join rel that includes all the base rels referenced
00678  * in a multi-relation restriction clause, we place that clause into the
00679  * joinrestrictinfo lists of paths for the join rel, if neither left nor
00680  * right sub-path includes all base rels referenced in the clause.      The clause
00681  * will be applied at that join level, and will not propagate any further up
00682  * the join tree.  (Note: the "predicate migration" code was once intended to
00683  * push restriction clauses up and down the plan tree based on evaluation
00684  * costs, but it's dead code and is unlikely to be resurrected in the
00685  * foreseeable future.)
00686  *
00687  * Note that in the presence of more than two rels, a multi-rel restriction
00688  * might reach different heights in the join tree depending on the join
00689  * sequence we use.  So, these clauses cannot be associated directly with
00690  * the join RelOptInfo, but must be kept track of on a per-join-path basis.
00691  *
00692  * When dealing with outer joins we have to be very careful about pushing qual
00693  * clauses up and down the tree.  An outer join's own JOIN/ON conditions must
00694  * be evaluated exactly at that join node, and any quals appearing in WHERE or
00695  * in a JOIN above the outer join cannot be pushed down below the outer join.
00696  * Otherwise the outer join will produce wrong results because it will see the
00697  * wrong sets of input rows.  All quals are stored as RestrictInfo nodes
00698  * during planning, but there's a flag to indicate whether a qual has been
00699  * pushed down to a lower level than its original syntactic placement in the
00700  * join tree would suggest.  If an outer join prevents us from pushing a qual
00701  * down to its "natural" semantic level (the level associated with just the
00702  * base rels used in the qual) then we mark the qual with a "required_relids"
00703  * value including more than just the base rels it actually uses.  By
00704  * pretending that the qual references all the rels appearing in the outer
00705  * join, we prevent it from being evaluated below the outer join's joinrel.
00706  * When we do form the outer join's joinrel, we still need to distinguish
00707  * those quals that are actually in that join's JOIN/ON condition from those
00708  * that appeared higher in the tree and were pushed down to the join rel
00709  * because they used no other rels.  That's what the is_pushed_down flag is
00710  * for; it tells us that a qual came from a point above the join of the
00711  * set of base rels listed in required_relids.  A clause that originally came
00712  * from WHERE will *always* have its is_pushed_down flag set; a clause that
00713  * came from an INNER JOIN condition, but doesn't use all the rels being
00714  * joined, will also have is_pushed_down set because it will get attached to
00715  * some lower joinrel.
00716  *
00717  * When application of a qual must be delayed by outer join, we also mark it
00718  * with outerjoin_delayed = true.  This isn't redundant with required_relids
00719  * because that might equal clause_relids whether or not it's an outer-join
00720  * clause.
00721  *
00722  * In general, the referenced clause might be arbitrarily complex.      The
00723  * kinds of clauses we can handle as indexscan quals, mergejoin clauses,
00724  * or hashjoin clauses are fairly limited --- the code for each kind of
00725  * path is responsible for identifying the restrict clauses it can use
00726  * and ignoring the rest.  Clauses not implemented by an indexscan,
00727  * mergejoin, or hashjoin will be placed in the plan qual or joinqual field
00728  * of the finished Plan node, where they will be enforced by general-purpose
00729  * qual-expression-evaluation code.  (But we are still entitled to count
00730  * their selectivity when estimating the result tuple count, if we
00731  * can guess what it is...)
00732  *
00733  * When the referenced clause is an OR clause, we generate a modified copy
00734  * in which additional RestrictInfo nodes are inserted below the top-level
00735  * OR/AND structure.  This is a convenience for OR indexscan processing:
00736  * indexquals taken from either the top level or an OR subclause will have
00737  * associated RestrictInfo nodes.
00738  */
00739 
00740 typedef struct RestrictInfo
00741 {
00742         NodeTag         type;
00743 
00744         Expr       *clause;                     /* the represented clause of WHERE or JOIN */
00745 
00746         bool            is_pushed_down; /* TRUE if clause was pushed down in level */
00747 
00748         bool            outerjoin_delayed;              /* TRUE if delayed by outer join */
00749 
00750         /*
00751          * This flag is set true if the clause looks potentially useful as a merge
00752          * or hash join clause, that is if it is a binary opclause with
00753          * nonoverlapping sets of relids referenced in the left and right sides.
00754          * (Whether the operator is actually merge or hash joinable isn't checked,
00755          * however.)
00756          */
00757         bool            can_join;
00758 
00759         /* The set of relids (varnos) actually referenced in the clause: */
00760         Relids          clause_relids;
00761 
00762         /* The set of relids required to evaluate the clause: */
00763         Relids          required_relids;
00764 
00765         /* These fields are set for any binary opclause: */
00766         Relids          left_relids;    /* relids in left side of clause */
00767         Relids          right_relids;   /* relids in right side of clause */
00768 
00769         /* This field is NULL unless clause is an OR clause: */
00770         Expr       *orclause;           /* modified clause with RestrictInfos */
00771 
00772         /* cache space for cost and selectivity */
00773         QualCost        eval_cost;              /* eval cost of clause; -1 if not yet set */
00774         Selectivity this_selec;         /* selectivity; -1 if not yet set */
00775 
00776         /* valid if clause is mergejoinable, else InvalidOid: */
00777         Oid                     mergejoinoperator;              /* copy of clause operator */
00778         Oid                     left_sortop;    /* leftside sortop needed for mergejoin */
00779         Oid                     right_sortop;   /* rightside sortop needed for mergejoin */
00780 
00781         /* cache space for mergeclause processing; NIL if not yet set */
00782         List       *left_pathkey;       /* canonical pathkey for left side */
00783         List       *right_pathkey;      /* canonical pathkey for right side */
00784 
00785         /* cache space for mergeclause processing; -1 if not yet set */
00786         Selectivity left_mergescansel;          /* fraction of left side to scan */
00787         Selectivity right_mergescansel;         /* fraction of right side to scan */
00788 
00789         /* valid if clause is hashjoinable, else InvalidOid: */
00790         Oid                     hashjoinoperator;               /* copy of clause operator */
00791 
00792         /* cache space for hashclause processing; -1 if not yet set */
00793         Selectivity left_bucketsize;    /* avg bucketsize of left side */
00794         Selectivity right_bucketsize;           /* avg bucketsize of right side */
00795 } RestrictInfo;
00796 
00797 /*
00798  * Inner indexscan info.
00799  *
00800  * An inner indexscan is one that uses one or more joinclauses as index
00801  * conditions (perhaps in addition to plain restriction clauses).  So it
00802  * can only be used as the inner path of a nestloop join where the outer
00803  * relation includes all other relids appearing in those joinclauses.
00804  * The set of usable joinclauses, and thus the best inner indexscan,
00805  * thus varies depending on which outer relation we consider; so we have
00806  * to recompute the best such path for every join.      To avoid lots of
00807  * redundant computation, we cache the results of such searches.  For
00808  * each relation we compute the set of possible otherrelids (all relids
00809  * appearing in joinquals that could become indexquals for this table).
00810  * Two outer relations whose relids have the same intersection with this
00811  * set will have the same set of available joinclauses and thus the same
00812  * best inner indexscan for the inner relation.  By taking the intersection
00813  * before scanning the cache, we avoid recomputing when considering
00814  * join rels that differ only by the inclusion of irrelevant other rels.
00815  *
00816  * The search key also includes a bool showing whether the join being
00817  * considered is an outer join.  Since we constrain the join order for
00818  * outer joins, I believe that this bool can only have one possible value
00819  * for any particular base relation; but store it anyway to avoid confusion.
00820  */
00821 
00822 typedef struct InnerIndexscanInfo
00823 {
00824         NodeTag         type;
00825         /* The lookup key: */
00826         Relids          other_relids;   /* a set of relevant other relids */
00827         bool            isouterjoin;    /* true if join is outer */
00828         /* Best path for this lookup key: */
00829         Path       *best_innerpath; /* best inner indexscan, or NULL if none */
00830 } InnerIndexscanInfo;
00831 
00832 /*
00833  * IN clause info.
00834  *
00835  * When we convert top-level IN quals into join operations, we must restrict
00836  * the order of joining and use special join methods at some join points.
00837  * We record information about each such IN clause in an InClauseInfo struct.
00838  * These structs are kept in the PlannerInfo node's in_info_list.
00839  */
00840 
00841 typedef struct InClauseInfo
00842 {
00843         NodeTag         type;
00844         Relids          lefthand;               /* base relids in lefthand expressions */
00845         Relids          righthand;              /* base relids coming from the subselect */
00846         List       *sub_targetlist; /* targetlist of original RHS subquery */
00847 
00848         /*
00849          * Note: sub_targetlist is just a list of Vars or expressions; it does not
00850          * contain TargetEntry nodes.
00851          */
00852 } InClauseInfo;
00853 
00854 #endif   /* RELATION_H */
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'