Skip to content

Commit 7e04160

Browse files
committed
Fix handling of non-key columns get_index_column_opclass()
f2e4038 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
1 parent 89b160c commit 7e04160

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/backend/utils/cache/lsyscache.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3157,7 +3157,8 @@ get_range_subtype(Oid rangeOid)
31573157
*
31583158
* Given the index OID and column number,
31593159
* return opclass of the index column
3160-
* or InvalidOid if the index was not found.
3160+
* or InvalidOid if the index was not found
3161+
* or column is non-key one.
31613162
*/
31623163
Oid
31633164
get_index_column_opclass(Oid index_oid, int attno)
@@ -3180,11 +3181,20 @@ get_index_column_opclass(Oid index_oid, int attno)
31803181
/* caller is supposed to guarantee this */
31813182
Assert(attno > 0 && attno <= rd_index->indnatts);
31823183

3184+
/* Non-key attributes don't have an opclass */
3185+
if (attno > rd_index->indnkeyatts)
3186+
{
3187+
ReleaseSysCache(tuple);
3188+
return InvalidOid;
3189+
}
3190+
31833191
datum = SysCacheGetAttr(INDEXRELID, tuple,
31843192
Anum_pg_index_indclass, &isnull);
31853193
Assert(!isnull);
31863194

31873195
indclass = ((oidvector *) DatumGetPointer(datum));
3196+
3197+
Assert(attno <= indclass->dim1);
31883198
opclass = indclass->values[attno - 1];
31893199

31903200
ReleaseSysCache(tuple);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy