mirror of
https://github.com/timescale/timescaledb.git
synced 2025-05-15 01:53:41 +08:00
Simplify ts_indexing_relation_has_primary_or_unique_index
Rely on postgres functionality for index column tracking instead of rolling our own.
This commit is contained in:
parent
f54dd7b05d
commit
a854b2760f
@ -273,33 +273,10 @@ indexing_create_and_verify_hypertable_indexes(const Hypertable *ht, bool create_
|
|||||||
bool
|
bool
|
||||||
ts_indexing_relation_has_primary_or_unique_index(Relation htrel)
|
ts_indexing_relation_has_primary_or_unique_index(Relation htrel)
|
||||||
{
|
{
|
||||||
List *indexoidlist = RelationGetIndexList(htrel);
|
Bitmapset *key_attrs = RelationGetIndexAttrBitmap(htrel, INDEX_ATTR_BITMAP_KEY);
|
||||||
ListCell *lc;
|
bool result = bms_num_members(key_attrs) > 0;
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
if (OidIsValid(htrel->rd_pkindex))
|
bms_free(key_attrs);
|
||||||
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);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user