aboutsummaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2004-01-05 23:39:54 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2004-01-05 23:39:54 +0000
commitfa559a86eec2ae90fd63fd7e6563e42f7dc619e0 (patch)
treea43de4df13060be5df59c38d7b3b9a5e47069e05 /src/include
parent5d472f64647346a44af6ab2ab9ca70cadf9fe788 (diff)
downloadpostgresql-fa559a86eec2ae90fd63fd7e6563e42f7dc619e0.tar.gz
postgresql-fa559a86eec2ae90fd63fd7e6563e42f7dc619e0.zip
Adjust indexscan planning logic to keep RestrictInfo nodes associated
with index qual clauses in the Path representation. This saves a little work during createplan and (probably more importantly) allows reuse of cached selectivity estimates during indexscan planning. Also fix latent bug: wrong plan would have been generated for a 'special operator' used in a nestloop-inner-indexscan join qual, because the special operator would not have gotten into the list of quals to recheck. This bug is only latent because at present the special-operator code could never trigger on a join qual, but sooner or later someone will want to do it.
Diffstat (limited to 'src/include')
-rw-r--r--src/include/nodes/relation.h40
-rw-r--r--src/include/optimizer/paths.h4
-rw-r--r--src/include/optimizer/restrictinfo.h5
3 files changed, 28 insertions, 21 deletions
diff --git a/src/include/nodes/relation.h b/src/include/nodes/relation.h
index 166f1242b0e..460679416f1 100644
--- a/src/include/nodes/relation.h
+++ b/src/include/nodes/relation.h
@@ -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.92 2004/01/05 18:04:39 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/nodes/relation.h,v 1.93 2004/01/05 23:39:54 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -344,23 +344,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
@@ -381,8 +382,9 @@ 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;
diff --git a/src/include/optimizer/paths.h b/src/include/optimizer/paths.h
index e1a46bcb3f8..40f7206fac3 100644
--- a/src/include/optimizer/paths.h
+++ b/src/include/optimizer/paths.h
@@ -8,7 +8,7 @@
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/optimizer/paths.h,v 1.72 2004/01/05 05:07:36 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/optimizer/paths.h,v 1.73 2004/01/05 23:39:54 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -44,6 +44,8 @@ extern List *group_clauses_by_indexkey_for_or(RelOptInfo *rel,
extern List *expand_indexqual_conditions(IndexOptInfo *index,
List *clausegroups);
extern void check_partial_indexes(Query *root, RelOptInfo *rel);
+extern List *flatten_clausegroups_list(List *clausegroups);
+extern Expr *make_expr_from_indexclauses(List *indexclauses);
/*
* orindxpath.c
diff --git a/src/include/optimizer/restrictinfo.h b/src/include/optimizer/restrictinfo.h
index 022bfa253a3..dfb6e71e319 100644
--- a/src/include/optimizer/restrictinfo.h
+++ b/src/include/optimizer/restrictinfo.h
@@ -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/optimizer/restrictinfo.h,v 1.22 2004/01/05 05:07:36 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/optimizer/restrictinfo.h,v 1.23 2004/01/05 23:39:54 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -18,6 +18,9 @@
extern RestrictInfo *make_restrictinfo(Expr *clause, bool is_pushed_down,
bool valid_everywhere);
+extern List *make_restrictinfo_from_indexclauses(List *indexclauses,
+ bool is_pushed_down,
+ bool valid_everywhere);
extern bool restriction_is_or_clause(RestrictInfo *restrictinfo);
extern List *get_actual_clauses(List *restrictinfo_list);
extern void get_actual_join_clauses(List *restrictinfo_list,