Use PGIndexProcessor infra to find explicitly created indexes

pull/5192/head
Onur Tirtir 2021-08-18 01:20:52 +03:00
parent 549ca4de6d
commit 91544d0191
1 changed files with 18 additions and 41 deletions

View File

@ -69,6 +69,9 @@ static char * GetRenameShardTriggerCommand(Oid shardRelationId, char *triggerNam
static void DropRelationTruncateTriggers(Oid relationId); static void DropRelationTruncateTriggers(Oid relationId);
static char * GetDropTriggerCommand(Oid relationId, char *triggerName); static char * GetDropTriggerCommand(Oid relationId, char *triggerName);
static List * GetRenameStatsCommandList(List *statsOidList, uint64 shardId); static List * GetRenameStatsCommandList(List *statsOidList, uint64 shardId);
static void AppendExplicitIndexIdsToList(Form_pg_index indexForm,
List **explicitIndexIdList,
int flags);
static void DropDefaultExpressionsAndMoveOwnedSequenceOwnerships(Oid sourceRelationId, static void DropDefaultExpressionsAndMoveOwnedSequenceOwnerships(Oid sourceRelationId,
Oid targetRelationId); Oid targetRelationId);
static void DropDefaultColumnDefinition(Oid relationId, char *columnName); static void DropDefaultColumnDefinition(Oid relationId, char *columnName);
@ -834,51 +837,25 @@ GetDropTriggerCommand(Oid relationId, char *triggerName)
List * List *
GetExplicitIndexOidList(Oid relationId) GetExplicitIndexOidList(Oid relationId)
{ {
int scanKeyCount = 1; /* flags are not applicable for AppendExplicitIndexIdsToList */
ScanKeyData scanKey[1]; int flags = 0;
return ExecuteFunctionOnEachTableIndex(relationId, AppendExplicitIndexIdsToList,
flags);
}
PushOverrideEmptySearchPath(CurrentMemoryContext);
Relation pgIndex = table_open(IndexRelationId, AccessShareLock); /*
* AppendExplicitIndexIdsToList adds the given index oid if it is
ScanKeyInit(&scanKey[0], Anum_pg_index_indrelid, * explicitly created on its relation.
BTEqualStrategyNumber, F_OIDEQ, relationId); */
static void
bool useIndex = true; AppendExplicitIndexIdsToList(Form_pg_index indexForm, List **explicitIndexIdList,
SysScanDesc scanDescriptor = systable_beginscan(pgIndex, IndexIndrelidIndexId, int flags)
useIndex, NULL, scanKeyCount, {
scanKey); if (!IndexImpliedByAConstraint(indexForm))
List *indexOidList = NIL;
HeapTuple heapTuple = systable_getnext(scanDescriptor);
while (HeapTupleIsValid(heapTuple))
{ {
Form_pg_index indexForm = (Form_pg_index) GETSTRUCT(heapTuple); *explicitIndexIdList = lappend_oid(*explicitIndexIdList, indexForm->indexrelid);
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);
} }
systable_endscan(scanDescriptor);
table_close(pgIndex, NoLock);
/* revert back to original search_path */
PopOverrideSearchPath();
return indexOidList;
} }