mirror of https://github.com/citusdata/citus.git
Use RelationGetIndexList instead of scanning pg_index
parent
fa9933daf3
commit
549ca4de6d
|
@ -306,37 +306,25 @@ ExecuteFunctionOnEachTableIndex(Oid relationId, PGIndexProcessor pgIndexProcesso
|
||||||
int indexFlags)
|
int indexFlags)
|
||||||
{
|
{
|
||||||
List *result = NIL;
|
List *result = NIL;
|
||||||
ScanKeyData scanKey[1];
|
|
||||||
int scanKeyCount = 1;
|
|
||||||
|
|
||||||
PushOverrideEmptySearchPath(CurrentMemoryContext);
|
Relation relation = RelationIdGetRelation(relationId);
|
||||||
|
List *indexIdList = RelationGetIndexList(relation);
|
||||||
/* open system catalog and scan all indexes that belong to this table */
|
Oid indexId = InvalidOid;
|
||||||
Relation pgIndex = table_open(IndexRelationId, AccessShareLock);
|
foreach_oid(indexId, indexIdList)
|
||||||
|
|
||||||
ScanKeyInit(&scanKey[0], Anum_pg_index_indrelid,
|
|
||||||
BTEqualStrategyNumber, F_OIDEQ, relationId);
|
|
||||||
|
|
||||||
SysScanDesc scanDescriptor = systable_beginscan(pgIndex,
|
|
||||||
IndexIndrelidIndexId, true, /* indexOK */
|
|
||||||
NULL, scanKeyCount, scanKey);
|
|
||||||
|
|
||||||
HeapTuple heapTuple = systable_getnext(scanDescriptor);
|
|
||||||
while (HeapTupleIsValid(heapTuple))
|
|
||||||
{
|
{
|
||||||
Form_pg_index indexForm = (Form_pg_index) GETSTRUCT(heapTuple);
|
HeapTuple indexTuple = SearchSysCache1(INDEXRELID, ObjectIdGetDatum(indexId));
|
||||||
pgIndexProcessor(indexForm, &result, indexFlags);
|
if (!HeapTupleIsValid(indexTuple))
|
||||||
|
{
|
||||||
heapTuple = systable_getnext(scanDescriptor);
|
ereport(ERROR, (errmsg("cache lookup failed for index with oid %u",
|
||||||
|
indexId)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* clean up scan and close system catalog */
|
Form_pg_index indexForm = (Form_pg_index) GETSTRUCT(indexTuple);
|
||||||
systable_endscan(scanDescriptor);
|
pgIndexProcessor(indexForm, &result, indexFlags);
|
||||||
table_close(pgIndex, AccessShareLock);
|
ReleaseSysCache(indexTuple);
|
||||||
|
}
|
||||||
/* revert back to original search_path */
|
|
||||||
PopOverrideSearchPath();
|
|
||||||
|
|
||||||
|
RelationClose(relation);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -798,6 +798,9 @@ void
|
||||||
GatherIndexAndConstraintDefinitionList(Form_pg_index indexForm, List **indexDDLEventList,
|
GatherIndexAndConstraintDefinitionList(Form_pg_index indexForm, List **indexDDLEventList,
|
||||||
int indexFlags)
|
int indexFlags)
|
||||||
{
|
{
|
||||||
|
/* generate fully-qualified names */
|
||||||
|
PushOverrideEmptySearchPath(CurrentMemoryContext);
|
||||||
|
|
||||||
Oid indexId = indexForm->indexrelid;
|
Oid indexId = indexForm->indexrelid;
|
||||||
bool indexImpliedByConstraint = IndexImpliedByAConstraint(indexForm);
|
bool indexImpliedByConstraint = IndexImpliedByAConstraint(indexForm);
|
||||||
|
|
||||||
|
@ -845,6 +848,9 @@ GatherIndexAndConstraintDefinitionList(Form_pg_index indexForm, List **indexDDLE
|
||||||
*indexDDLEventList = list_concat(*indexDDLEventList,
|
*indexDDLEventList = list_concat(*indexDDLEventList,
|
||||||
alterIndexStatisticsCommands);
|
alterIndexStatisticsCommands);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* revert back to original search_path */
|
||||||
|
PopOverrideSearchPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue