From d04c8ed9044eccebce043143a930617e3998c005 Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Thu, 26 Mar 2015 19:12:00 +0200 Subject: 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. --- src/backend/access/gist/gistscan.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/backend/access/gist/gistscan.c') diff --git a/src/backend/access/gist/gistscan.c b/src/backend/access/gist/gistscan.c index 991858ff43f..3522d75a496 100644 --- a/src/backend/access/gist/gistscan.c +++ b/src/backend/access/gist/gistscan.c @@ -88,6 +88,13 @@ gistbeginscan(PG_FUNCTION_ARGS) scan->opaque = so; + /* + * All fields required for index-only scans are null until gistrescan. + * However, we set up scan->xs_itupdesc whether we'll need it or not, + * since that's cheap. + */ + scan->xs_itupdesc = RelationGetDescr(r); + MemoryContextSwitchTo(oldCxt); PG_RETURN_POINTER(scan); @@ -141,6 +148,17 @@ gistrescan(PG_FUNCTION_ARGS) first_time = false; } + /* + * If we're doing an index-only scan, also create a memory context to hold + * the returned tuples. + */ + if (scan->xs_want_itup && so->pageDataCxt == NULL) + so->pageDataCxt = AllocSetContextCreate(so->giststate->scanCxt, + "GiST page data context", + ALLOCSET_DEFAULT_MINSIZE, + ALLOCSET_DEFAULT_INITSIZE, + ALLOCSET_DEFAULT_MAXSIZE); + /* create new, empty RBTree for search queue */ oldCxt = MemoryContextSwitchTo(so->queueCxt); so->queue = pairingheap_allocate(pairingheap_GISTSearchItem_cmp, scan); -- cgit v1.2.3