]> 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 0d129f38ea1375d2793c756f0873a8c0bada3c53..91114fb03b76d54eaee381b1d5de8998fa5afad8 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/nodes/relation.h,v 1.88 2003/12/30 23:53:15 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/nodes/relation.h,v 1.95 2004/06/01 03:03:05 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -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;
@@ -271,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 */
@@ -319,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) */
@@ -327,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;
@@ -342,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
@@ -379,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
 {
@@ -410,6 +414,8 @@ 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
 {
@@ -435,15 +441,26 @@ typedef struct MaterialPath
  * 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;
 
@@ -478,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
@@ -568,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,
@@ -586,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
@@ -594,7 +619,9 @@ typedef struct RestrictInfo
 
        Expr       *clause;                     /* the represented clause of WHERE or JOIN */
 
-       bool            ispusheddown;   /* TRUE if clause was pushed down in level */
+       bool            is_pushed_down; /* TRUE if clause was pushed down in level */
+
+       bool            valid_everywhere;       /* TRUE if valid on every level */
 
        /*
         * This flag is set true if the clause looks potentially useful as a
@@ -603,17 +630,19 @@ typedef struct RestrictInfo
         * (Whether the operator is actually merge or hash joinable isn't
         * checked, however.)
         */
-       bool            canjoin;
+       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 */
 
-       /* only used if clause is an OR clause: */
-       List       *subclauseindices;           /* indexes matching subclauses */
-       /* subclauseindices is a List of Lists of IndexOptInfos */
+       /* This field is NULL unless clause is an OR clause: */
+       Expr       *orclause;           /* modified clause with RestrictInfos */
 
-       /* cache space for costs (currently only used for join clauses) */
+       /* 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 */