diff options
author | Alexander Korotkov <akorotkov@postgresql.org> | 2019-09-09 13:50:12 +0300 |
---|---|---|
committer | Alexander Korotkov <akorotkov@postgresql.org> | 2019-09-09 13:50:12 +0300 |
commit | 7e04160390464cd39690d36054e0ac5e4f1bf227 (patch) | |
tree | a44f736dbfe1bd4e85f1a85b13acad7fae0171f4 /src | |
parent | 89b160c32045dd85cc6f9ae6248e34a72931ac67 (diff) | |
download | postgresql-7e04160390464cd39690d36054e0ac5e4f1bf227.tar.gz postgresql-7e04160390464cd39690d36054e0ac5e4f1bf227.zip |
Fix handling of non-key columns get_index_column_opclass()
f2e40380 introduces support of non-key attributes in GiST indexes. Then if
get_index_column_opclass() is asked by gistproperty() to get an opclass of
non-key column, it returns garbage past oidvector value. This commit fixes
that by making get_index_column_opclass() return InvalidOid in this case.
Discussion: https://postgr.es/m/20190902231948.GA5343%40alvherre.pgsql
Author: Nikita Glukhov, Alexander Korotkov
Backpatch-through: 12
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/utils/cache/lsyscache.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index c13c08a97b4..27602fa49c6 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -3157,7 +3157,8 @@ get_range_subtype(Oid rangeOid) * * Given the index OID and column number, * return opclass of the index column - * or InvalidOid if the index was not found. + * or InvalidOid if the index was not found + * or column is non-key one. */ Oid get_index_column_opclass(Oid index_oid, int attno) @@ -3180,11 +3181,20 @@ get_index_column_opclass(Oid index_oid, int attno) /* caller is supposed to guarantee this */ Assert(attno > 0 && attno <= rd_index->indnatts); + /* Non-key attributes don't have an opclass */ + if (attno > rd_index->indnkeyatts) + { + ReleaseSysCache(tuple); + return InvalidOid; + } + datum = SysCacheGetAttr(INDEXRELID, tuple, Anum_pg_index_indclass, &isnull); Assert(!isnull); indclass = ((oidvector *) DatumGetPointer(datum)); + + Assert(attno <= indclass->dim1); opclass = indclass->values[attno - 1]; ReleaseSysCache(tuple); |