1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-19 04:21:08 +03:00

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
This commit is contained in:
Alexander Korotkov
2019-03-10 11:36:47 +03:00
parent a0b7626268
commit f2e403803f
16 changed files with 382 additions and 48 deletions

View File

@ -164,7 +164,7 @@ gistindex_keytest(IndexScanDesc scan,
datum = index_getattr(tuple,
key->sk_attno,
giststate->tupdesc,
giststate->leafTupdesc,
&isNull);
if (key->sk_flags & SK_ISNULL)
@ -244,7 +244,7 @@ gistindex_keytest(IndexScanDesc scan,
datum = index_getattr(tuple,
key->sk_attno,
giststate->tupdesc,
giststate->leafTupdesc,
&isNull);
if ((key->sk_flags & SK_ISNULL) || isNull)
@ -769,11 +769,13 @@ gistgetbitmap(IndexScanDesc scan, TIDBitmap *tbm)
*
* Opclasses that implement a fetch function support index-only scans.
* Opclasses without compression functions also support index-only scans.
* Included attributes always can be fetched for index-only scans.
*/
bool
gistcanreturn(Relation index, int attno)
{
if (OidIsValid(index_getprocid(index, attno, GIST_FETCH_PROC)) ||
if (attno > IndexRelationGetNumberOfKeyAttributes(index) ||
OidIsValid(index_getprocid(index, attno, GIST_FETCH_PROC)) ||
!OidIsValid(index_getprocid(index, attno, GIST_COMPRESS_PROC)))
return true;
else