]> granicus.if.org Git - postgresql/blobdiff - src/include/nodes/relation.h
Desultory de-FastList-ification. RelOptInfo.reltargetlist is back to
[postgresql] / src / include / nodes / relation.h
index 158a23427cf69f60f973d40a0b54bf645fec96db..91114fb03b76d54eaee381b1d5de8998fa5afad8 100644 (file)
@@ -4,10 +4,10 @@
  *       Definitions for planner's internal data structures.
  *
  *
- * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: relation.h,v 1.83 2003/08/04 00:43:31 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/nodes/relation.h,v 1.95 2004/06/01 03:03:05 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -43,7 +43,7 @@ typedef struct QualCost
 {
        Cost            startup;                /* one-time cost */
        Cost            per_tuple;              /* per-evaluation cost */
-}      QualCost;
+} QualCost;
 
 /*----------
  * RelOptInfo
@@ -99,8 +99,6 @@ typedef struct QualCost
  *                                                       (regardless of its ordering)
  *             cheapest_unique_path - for caching cheapest path to produce unique
  *                                                        (no duplicates) output from relation
- *             pruneable - flag to let the planner know whether it can prune the
- *                                     pathlist of this RelOptInfo or not.
  *
  * If the relation is a base relation it will have these fields set:
  *
@@ -188,12 +186,11 @@ typedef struct RelOptInfo
        int                     width;                  /* estimated avg width of result tuples */
 
        /* materialization information */
-       FastList        reltargetlist;
+       List       *reltargetlist;      /* needed Vars */
        List       *pathlist;           /* Path structures */
        struct Path *cheapest_startup_path;
        struct Path *cheapest_total_path;
        struct Path *cheapest_unique_path;
-       bool            pruneable;
 
        /* information about a base rel (not set for join rels!) */
        Index           relid;
@@ -245,7 +242,8 @@ typedef struct RelOptInfo
  *             zero entry, rather than looking at ncolumns.
  *
  *             The indexprs and indpred expressions have been run through
- *             eval_const_expressions() for ease of matching to WHERE clauses.
+ *             prepqual.c and eval_const_expressions() for ease of matching to
+ *             WHERE clauses.  indpred is in implicit-AND form.
  */
 
 typedef struct IndexOptInfo
@@ -270,6 +268,8 @@ typedef struct IndexOptInfo
        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 */
 
        /* cached info about inner indexscan paths for index */
@@ -318,6 +318,8 @@ 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) */
@@ -326,8 +328,6 @@ typedef struct Path
        Cost            total_cost;             /* total cost (assuming all tuples
                                                                 * fetched) */
 
-       NodeTag         pathtype;               /* tag identifying scan/join method */
-
        List       *pathkeys;           /* sort ordering of path's output */
        /* pathkeys is a List of Lists of PathKeyItem nodes; see above */
 } Path;
@@ -341,23 +341,24 @@ typedef struct Path
  *
  * 'indexinfo' is a list of IndexOptInfo nodes, one per scan to be performed.
  *
- * 'indexqual' is a list of index qualifications, also one per scan.
- * Each entry in 'indexqual' is a sublist of qualification expressions with
- * implicit AND semantics across the sublist items.  Only expressions that
- * are usable as indexquals (as determined by indxpath.c) may appear here.
- * NOTE that the semantics of the top-level list in 'indexqual' is OR
+ * 'indexclauses' is a list of index qualifications, also one per scan.
+ * Each entry in 'indexclauses' is a sublist of qualification clauses to be
+ * used for that scan, with implicit AND semantics across the sublist items.
+ * NOTE that the semantics of the top-level list in 'indexclauses' is OR
  * combination, while the sublists are implicitly AND combinations!
- * Also note that indexquals lists do not contain RestrictInfo nodes,
- * just bare clause expressions.
- *
- * 'indexjoinclauses' is NIL for an ordinary indexpath (one that does not
- * use any join clauses in the index conditions).  For an innerjoin indexpath,
- * it has the same structure as 'indexqual', but references the RestrictInfo
- * nodes from which the indexqual was built, rather than the bare clause
- * expressions.  (Note: there isn't necessarily a one-to-one correspondence
- * between RestrictInfos and expressions, because of expansion of special
- * indexable operators.)  We need this so that we can eliminate redundant
- * join clauses when plans are built.
+ *
+ * 'indexquals' has the same structure as 'indexclauses', but it contains
+ * the actual indexqual conditions that can be used with the index(es).
+ * 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'.
+ *
+ * Both 'indexclauses' and 'indexquals' are lists of sublists of RestrictInfo
+ * nodes.  (Before 7.5, we kept bare operator expressions in these lists, but
+ * storing RestrictInfos is more efficient since selectivities can be cached.)
+ *
+ * '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
@@ -378,14 +379,18 @@ typedef struct IndexPath
 {
        Path            path;
        List       *indexinfo;
-       List       *indexqual;
-       List       *indexjoinclauses;
+       List       *indexclauses;
+       List       *indexquals;
+       bool            isjoininner;
        ScanDirection indexscandir;
        double          rows;                   /* estimated number of result tuples */
 } IndexPath;
 
 /*
  * 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
 {
@@ -409,13 +414,15 @@ typedef struct AppendPath
  * variable-free targetlist or to gate execution of a subplan with a
  * one-time (variable-free) qual condition.  Note that in the former case
  * path.parent will be NULL; in the latter case it is copied from the subpath.
+ *
+ * Note that constantqual is a list of bare clauses, not RestrictInfos.
  */
 typedef struct ResultPath
 {
        Path            path;
        Path       *subpath;
        List       *constantqual;
-}      ResultPath;
+} ResultPath;
 
 /*
  * MaterialPath represents use of a Material plan node, i.e., caching of
@@ -427,24 +434,35 @@ typedef struct MaterialPath
 {
        Path            path;
        Path       *subpath;
-}      MaterialPath;
+} 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
- * two different plans: either hash-based or sort-based implementation.
- * The decision is sufficiently localized that it's not worth having two
- * separate Path node types.
+ * 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
+ * types.  (Note: in the no-op case, we could eliminate the UniquePath node
+ * entirely and just return the subpath; but it's convenient to have a
+ * UniquePath in the path tree to signal upper-level routines that the input
+ * is known distinct.)
  */
+typedef enum
+{
+       UNIQUE_PATH_NOOP,                       /* input is known unique already */
+       UNIQUE_PATH_HASH,                       /* use hashing */
+       UNIQUE_PATH_SORT                        /* use sorting */
+} UniquePathMethod;
+
 typedef struct UniquePath
 {
        Path            path;
        Path       *subpath;
-       bool            use_hash;
+       UniquePathMethod umethod;
        double          rows;                   /* estimated number of result tuples */
-}      UniquePath;
+} UniquePath;
 
 /*
  * All join-type paths share these fields.
@@ -477,9 +495,7 @@ typedef JoinPath NestPath;
  * A mergejoin path has these fields.
  *
  * path_mergeclauses lists the clauses (in the form of RestrictInfos)
- * that will be used in the merge.     (Before 7.0, this was a list of bare
- * clause expressions, but we can save on list memory and cost_qual_eval
- * work by leaving it in the form of a RestrictInfo list.)
+ * that will be used in the merge.
  *
  * Note that the mergeclauses are a subset of the parent relation's
  * restriction-clause list.  Any join clauses that are not mergejoinable
@@ -567,13 +583,17 @@ typedef struct HashPath
  * When we do form the outer join's joinrel, we still need to distinguish
  * those quals that are actually in that join's JOIN/ON condition from those
  * that appeared higher in the tree and were pushed down to the join rel
- * because they used no other rels.  That's what the ispusheddown flag is for;
- * it tells us that a qual came from a point above the join of the specific
- * set of base rels that it uses (or that the JoinInfo structures claim it
- * uses).  A clause that originally came from WHERE will *always* have its
- * ispusheddown flag set; a clause that came from an INNER JOIN condition,
- * but doesn't use all the rels being joined, will also have ispusheddown set
- * because it will get attached to some lower joinrel.
+ * because they used no other rels.  That's what the is_pushed_down flag is
+ * for; it tells us that a qual came from a point above the join of the
+ * specific set of base rels that it uses (or that the JoinInfo structures
+ * claim it uses).  A clause that originally came from WHERE will *always*
+ * have its is_pushed_down flag set; a clause that came from an INNER JOIN
+ * condition, but doesn't use all the rels being joined, will also have
+ * is_pushed_down set because it will get attached to some lower joinrel.
+ *
+ * We also store a valid_everywhere flag, which says that the clause is not
+ * affected by any lower-level outer join, and therefore any conditions it
+ * asserts can be presumed true throughout the plan tree.
  *
  * In general, the referenced clause might be arbitrarily complex.     The
  * kinds of clauses we can handle as indexscan quals, mergejoin clauses,
@@ -585,6 +605,12 @@ typedef struct HashPath
  * qual-expression-evaluation code.  (But we are still entitled to count
  * their selectivity when estimating the result tuple count, if we
  * can guess what it is...)
+ *
+ * When the referenced clause is an OR clause, we generate a modified copy
+ * in which additional RestrictInfo nodes are inserted below the top-level
+ * OR/AND structure.  This is a convenience for OR indexscan processing:
+ * indexquals taken from either the top level or an OR subclause will have
+ * associated RestrictInfo nodes.
  */
 
 typedef struct RestrictInfo
@@ -593,24 +619,32 @@ typedef struct RestrictInfo
 
        Expr       *clause;                     /* the represented clause of WHERE or JOIN */
 
-       bool            ispusheddown;   /* TRUE if clause was pushed down in level */
-
-       /* only used if clause is an OR clause: */
-       List       *subclauseindices;           /* indexes matching subclauses */
-       /* subclauseindices is a List of Lists of IndexOptInfos */
+       bool            is_pushed_down; /* TRUE if clause was pushed down in level */
 
-       /* cache space for costs (currently only used for join clauses) */
-       QualCost        eval_cost;              /* eval cost of clause; -1 if not yet set */
-       Selectivity this_selec;         /* selectivity; -1 if not yet set */
+       bool            valid_everywhere;       /* TRUE if valid on every level */
 
        /*
-        * If the clause looks useful for joining --- that is, it is a binary
-        * opclause with nonoverlapping sets of relids referenced in the left
-        * and right sides --- then these two fields are set to sets of the
-        * referenced relids.  Otherwise they are both NULL.
+        * This flag is set true if the clause looks potentially useful as a
+        * merge or hash join clause, that is if it is a binary opclause with
+        * nonoverlapping sets of relids referenced in the left and right sides.
+        * (Whether the operator is actually merge or hash joinable isn't
+        * checked, however.)
         */
-       Relids          left_relids;    /* relids in left side of join clause */
-       Relids          right_relids;   /* relids in right side of join clause */
+       bool            can_join;
+
+       /* The set of relids (varnos) referenced in the clause: */
+       Relids          clause_relids;
+
+       /* These fields are set for any binary opclause: */
+       Relids          left_relids;    /* relids in left side of clause */
+       Relids          right_relids;   /* relids in right side of clause */
+
+       /* This field is NULL unless clause is an OR clause: */
+       Expr       *orclause;           /* modified clause with RestrictInfos */
+
+       /* cache space for cost and selectivity */
+       QualCost        eval_cost;              /* eval cost of clause; -1 if not yet set */
+       Selectivity this_selec;         /* selectivity; -1 if not yet set */
 
        /* valid if clause is mergejoinable, else InvalidOid: */
        Oid                     mergejoinoperator;              /* copy of clause operator */
@@ -690,7 +724,7 @@ typedef struct InnerIndexscanInfo
        bool            isouterjoin;    /* true if join is outer */
        /* Best path for this lookup key: */
        Path       *best_innerpath; /* best inner indexscan, or NULL if none */
-}      InnerIndexscanInfo;
+} InnerIndexscanInfo;
 
 /*
  * IN clause info.
@@ -712,6 +746,6 @@ typedef struct InClauseInfo
         * Note: sub_targetlist is just a list of Vars or expressions; it does
         * not contain TargetEntry nodes.
         */
-}      InClauseInfo;
+} InClauseInfo;
 
 #endif   /* RELATION_H */