From 91544d019111ae37d09ea0f8a8d4793cf057b96c Mon Sep 17 00:00:00 2001 From: Onur Tirtir Date: Wed, 18 Aug 2021 01:20:52 +0300 Subject: [PATCH] Use PGIndexProcessor infra to find explicitly created indexes --- .../citus_add_local_table_to_metadata.c | 59 ++++++------------- 1 file changed, 18 insertions(+), 41 deletions(-) diff --git a/src/backend/distributed/commands/citus_add_local_table_to_metadata.c b/src/backend/distributed/commands/citus_add_local_table_to_metadata.c index 75b7661dd..ed02e55db 100644 --- a/src/backend/distributed/commands/citus_add_local_table_to_metadata.c +++ b/src/backend/distributed/commands/citus_add_local_table_to_metadata.c @@ -69,6 +69,9 @@ static char * GetRenameShardTriggerCommand(Oid shardRelationId, char *triggerNam static void DropRelationTruncateTriggers(Oid relationId); static char * GetDropTriggerCommand(Oid relationId, char *triggerName); static List * GetRenameStatsCommandList(List *statsOidList, uint64 shardId); +static void AppendExplicitIndexIdsToList(Form_pg_index indexForm, + List **explicitIndexIdList, + int flags); static void DropDefaultExpressionsAndMoveOwnedSequenceOwnerships(Oid sourceRelationId, Oid targetRelationId); static void DropDefaultColumnDefinition(Oid relationId, char *columnName); @@ -834,51 +837,25 @@ GetDropTriggerCommand(Oid relationId, char *triggerName) List * GetExplicitIndexOidList(Oid relationId) { - int scanKeyCount = 1; - ScanKeyData scanKey[1]; + /* flags are not applicable for AppendExplicitIndexIdsToList */ + int flags = 0; + return ExecuteFunctionOnEachTableIndex(relationId, AppendExplicitIndexIdsToList, + flags); +} - PushOverrideEmptySearchPath(CurrentMemoryContext); - Relation pgIndex = table_open(IndexRelationId, AccessShareLock); - - ScanKeyInit(&scanKey[0], Anum_pg_index_indrelid, - BTEqualStrategyNumber, F_OIDEQ, relationId); - - bool useIndex = true; - SysScanDesc scanDescriptor = systable_beginscan(pgIndex, IndexIndrelidIndexId, - useIndex, NULL, scanKeyCount, - scanKey); - - List *indexOidList = NIL; - - HeapTuple heapTuple = systable_getnext(scanDescriptor); - while (HeapTupleIsValid(heapTuple)) +/* + * AppendExplicitIndexIdsToList adds the given index oid if it is + * explicitly created on its relation. + */ +static void +AppendExplicitIndexIdsToList(Form_pg_index indexForm, List **explicitIndexIdList, + int flags) +{ + if (!IndexImpliedByAConstraint(indexForm)) { - Form_pg_index indexForm = (Form_pg_index) GETSTRUCT(heapTuple); - - Oid indexId = indexForm->indexrelid; - - bool indexImpliedByConstraint = IndexImpliedByAConstraint(indexForm); - - /* - * Skip the indexes that are not implied by explicitly executing - * a CREATE INDEX command. - */ - if (!indexImpliedByConstraint) - { - indexOidList = lappend_oid(indexOidList, indexId); - } - - heapTuple = systable_getnext(scanDescriptor); + *explicitIndexIdList = lappend_oid(*explicitIndexIdList, indexForm->indexrelid); } - - systable_endscan(scanDescriptor); - table_close(pgIndex, NoLock); - - /* revert back to original search_path */ - PopOverrideSearchPath(); - - return indexOidList; }