From a854b2760f66cc640bf2fe71683b0e4595dfbdde Mon Sep 17 00:00:00 2001 From: Sven Klemm Date: Wed, 8 Mar 2023 13:27:13 +0100 Subject: [PATCH] Simplify ts_indexing_relation_has_primary_or_unique_index Rely on postgres functionality for index column tracking instead of rolling our own. --- src/indexing.c | 29 +++-------------------------- 1 file changed, 3 insertions(+), 26 deletions(-) diff --git a/src/indexing.c b/src/indexing.c index f0e67f157..7cdf7ee82 100644 --- a/src/indexing.c +++ b/src/indexing.c @@ -273,33 +273,10 @@ indexing_create_and_verify_hypertable_indexes(const Hypertable *ht, bool create_ bool ts_indexing_relation_has_primary_or_unique_index(Relation htrel) { - List *indexoidlist = RelationGetIndexList(htrel); - ListCell *lc; - bool result = false; + Bitmapset *key_attrs = RelationGetIndexAttrBitmap(htrel, INDEX_ATTR_BITMAP_KEY); + bool result = bms_num_members(key_attrs) > 0; - if (OidIsValid(htrel->rd_pkindex)) - return true; - - foreach (lc, indexoidlist) - { - Oid indexoid = lfirst_oid(lc); - HeapTuple index_tuple; - Form_pg_index index; - - index_tuple = SearchSysCache1(INDEXRELID, ObjectIdGetDatum(indexoid)); - if (!HeapTupleIsValid(index_tuple)) /* should not happen */ - elog(ERROR, - "cache lookup failed for index %u in \"%s\" ", - indexoid, - RelationGetRelationName(htrel)); - index = (Form_pg_index) GETSTRUCT(index_tuple); - result = index->indisunique; - ReleaseSysCache(index_tuple); - if (result) - break; - } - - list_free(indexoidlist); + bms_free(key_attrs); return result; }