diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2011-10-11 15:00:30 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2011-10-11 15:00:30 -0400 |
commit | 600d3206d1b3f8b540397b79905486a536ac7f78 (patch) | |
tree | bc0ab15d1c29bf3af7bb3fdb2150ee7769a92560 /src | |
parent | a0185461dd94c8d31d8d55a7f2839b0d2f172ab9 (diff) | |
download | postgresql-600d3206d1b3f8b540397b79905486a536ac7f78.tar.gz postgresql-600d3206d1b3f8b540397b79905486a536ac7f78.zip |
Consider index-only scans even when there is no matching qual or ORDER BY.
By popular demand.
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/optimizer/path/indxpath.c | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c index 9ab146a1f74..ece326d8850 100644 --- a/src/backend/optimizer/path/indxpath.c +++ b/src/backend/optimizer/path/indxpath.c @@ -317,8 +317,7 @@ find_usable_indexes(PlannerInfo *root, RelOptInfo *rel, bool useful_predicate; bool found_clause; bool index_is_ordered; - bool index_only_scan = false; - bool checked_index_only = false; + bool index_only_scan; /* * Check that index supports the desired scan type(s) @@ -436,17 +435,20 @@ find_usable_indexes(PlannerInfo *root, RelOptInfo *rel, } /* - * 3. Generate an indexscan path if there are relevant restriction + * 3. Check if an index-only scan is possible. + */ + index_only_scan = check_index_only(rel, index); + + /* + * 4. Generate an indexscan path if there are relevant restriction * clauses in the current clauses, OR the index ordering is * potentially useful for later merging or final output ordering, OR - * the index has a predicate that was proven by the current clauses. + * the index has a predicate that was proven by the current clauses, + * OR an index-only scan is possible. */ - if (found_clause || useful_pathkeys != NIL || useful_predicate) + if (found_clause || useful_pathkeys != NIL || useful_predicate || + index_only_scan) { - /* First, detect whether index-only scan is possible */ - index_only_scan = check_index_only(rel, index); - checked_index_only = true; - ipath = create_index_path(root, index, restrictclauses, orderbyclauses, @@ -460,7 +462,7 @@ find_usable_indexes(PlannerInfo *root, RelOptInfo *rel, } /* - * 4. If the index is ordered, a backwards scan might be interesting. + * 5. If the index is ordered, a backwards scan might be interesting. * Again, this is only interesting at top level. */ if (index_is_ordered && possibly_useful_pathkeys && @@ -472,9 +474,6 @@ find_usable_indexes(PlannerInfo *root, RelOptInfo *rel, index_pathkeys); if (useful_pathkeys != NIL) { - if (!checked_index_only) - index_only_scan = check_index_only(rel, index); - ipath = create_index_path(root, index, restrictclauses, NIL, |