From f2e403803fe6deb8cff59ea09dff42c6163b2110 Mon Sep 17 00:00:00 2001 From: Alexander Korotkov Date: Sun, 10 Mar 2019 11:36:47 +0300 Subject: Support for INCLUDE attributes in GiST indexes Similarly to B-tree, GiST index access method gets support of INCLUDE attributes. These attributes aren't used for tree navigation and aren't present in non-leaf pages. But they are present in leaf pages and can be fetched during index-only scan. The point of having INCLUDE attributes in GiST indexes is slightly different from the point of having them in B-tree. The main point of INCLUDE attributes in B-tree is to define UNIQUE constraint over part of attributes enabled for index-only scan. In GiST the main point of INCLUDE attributes is to use index-only scan for attributes, whose data types don't have GiST opclasses. Discussion: https://postgr.es/m/73A1A452-AD5F-40D4-BD61-978622FF75C1%40yandex-team.ru Author: Andrey Borodin, with small changes by me Reviewed-by: Andreas Karlsson --- src/backend/access/gist/gistscan.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (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 78a8ede7949..893d7765b6c 100644 --- a/src/backend/access/gist/gistscan.c +++ b/src/backend/access/gist/gistscan.c @@ -158,6 +158,7 @@ gistrescan(IndexScanDesc scan, ScanKey key, int nkeys, if (scan->xs_want_itup && !scan->xs_hitupdesc) { int natts; + int nkeyatts; int attno; /* @@ -167,13 +168,23 @@ gistrescan(IndexScanDesc scan, ScanKey key, int nkeys, * types. */ natts = RelationGetNumberOfAttributes(scan->indexRelation); + nkeyatts = IndexRelationGetNumberOfKeyAttributes(scan->indexRelation); so->giststate->fetchTupdesc = CreateTemplateTupleDesc(natts); - for (attno = 1; attno <= natts; attno++) + for (attno = 1; attno <= nkeyatts; attno++) { TupleDescInitEntry(so->giststate->fetchTupdesc, attno, NULL, scan->indexRelation->rd_opcintype[attno - 1], -1, 0); } + + for (; attno <= natts; attno++) + { + /* taking opcintype from giststate->tupdesc */ + TupleDescInitEntry(so->giststate->fetchTupdesc, attno, NULL, + TupleDescAttr(so->giststate->leafTupdesc, + attno - 1)->atttypid, + -1, 0); + } scan->xs_hitupdesc = so->giststate->fetchTupdesc; /* Also create a memory context that will hold the returned tuples */ -- cgit v1.2.3