diff options
author | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2015-03-26 19:12:00 +0200 |
---|---|---|
committer | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2015-03-26 19:12:00 +0200 |
commit | d04c8ed9044eccebce043143a930617e3998c005 (patch) | |
tree | e0167be995bb28dab91dfb92f1e18609e91a0d3e /src/backend/optimizer/path/indxpath.c | |
parent | 8fa393a6d739796d9f06a7fba91d7e1d0c354879 (diff) | |
download | postgresql-d04c8ed9044eccebce043143a930617e3998c005.tar.gz postgresql-d04c8ed9044eccebce043143a930617e3998c005.zip |
Add support for index-only scans in GiST.
This adds a new GiST opclass method, 'fetch', which is used to reconstruct
the original Datum from the value stored in the index. Also, the 'canreturn'
index AM interface function gains a new 'attno' argument. That makes it
possible to use index-only scans on a multi-column index where some of the
opclasses support index-only scans but some do not.
This patch adds support in the box and point opclasses. Other opclasses
can added later as follow-on patches (btree_gist would be particularly
interesting).
Anastasia Lubennikova, with additional fixes and modifications by me.
Diffstat (limited to 'src/backend/optimizer/path/indxpath.c')
-rw-r--r-- | src/backend/optimizer/path/indxpath.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c index 49ab3666b93..fdd6baba6c6 100644 --- a/src/backend/optimizer/path/indxpath.c +++ b/src/backend/optimizer/path/indxpath.c @@ -1786,15 +1786,13 @@ check_index_only(RelOptInfo *rel, IndexOptInfo *index) { bool result; Bitmapset *attrs_used = NULL; - Bitmapset *index_attrs = NULL; + Bitmapset *index_canreturn_attrs = NULL; ListCell *lc; int i; - /* Index-only scans must be enabled, and index must be capable of them */ + /* Index-only scans must be enabled */ if (!enable_indexonlyscan) return false; - if (!index->canreturn) - return false; /* * Check that all needed attributes of the relation are available from the @@ -1824,7 +1822,10 @@ check_index_only(RelOptInfo *rel, IndexOptInfo *index) pull_varattnos((Node *) rinfo->clause, rel->relid, &attrs_used); } - /* Construct a bitmapset of columns stored in the index. */ + /* + * Construct a bitmapset of columns that the index can return back in an + * index-only scan. + */ for (i = 0; i < index->ncolumns; i++) { int attno = index->indexkeys[i]; @@ -1836,16 +1837,17 @@ check_index_only(RelOptInfo *rel, IndexOptInfo *index) if (attno == 0) continue; - index_attrs = - bms_add_member(index_attrs, - attno - FirstLowInvalidHeapAttributeNumber); + if (index->canreturn[i]) + index_canreturn_attrs = + bms_add_member(index_canreturn_attrs, + attno - FirstLowInvalidHeapAttributeNumber); } /* Do we have all the necessary attributes? */ - result = bms_is_subset(attrs_used, index_attrs); + result = bms_is_subset(attrs_used, index_canreturn_attrs); bms_free(attrs_used); - bms_free(index_attrs); + bms_free(index_canreturn_attrs); return result; } |