From 4e1201a33319c0dde87a63bac254c6bfd6a78cc2 Mon Sep 17 00:00:00 2001 From: Onur Tirtir Date: Wed, 18 Aug 2021 14:34:42 +0300 Subject: [PATCH] Use RelationGetStatExtList instead of scanning pg_stats_ext --- src/backend/distributed/commands/statistics.c | 31 +++++++------------ 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/src/backend/distributed/commands/statistics.c b/src/backend/distributed/commands/statistics.c index 9b0323442..fb5406786 100644 --- a/src/backend/distributed/commands/statistics.c +++ b/src/backend/distributed/commands/statistics.c @@ -490,23 +490,19 @@ GetExplicitStatisticsSchemaIdList(Oid relationId) { List *schemaIdList = NIL; - Relation pgStatistics = table_open(StatisticExtRelationId, AccessShareLock); + Relation relation = RelationIdGetRelation(relationId); + List *statsIdList = RelationGetStatExtList(relation); + RelationClose(relation); - int scanKeyCount = 1; - ScanKeyData scanKey[1]; - - ScanKeyInit(&scanKey[0], Anum_pg_statistic_ext_stxrelid, - BTEqualStrategyNumber, F_OIDEQ, relationId); - - bool useIndex = true; - SysScanDesc scanDescriptor = systable_beginscan(pgStatistics, - StatisticExtRelidIndexId, - useIndex, NULL, scanKeyCount, - scanKey); - - HeapTuple heapTuple = systable_getnext(scanDescriptor); - while (HeapTupleIsValid(heapTuple)) + Oid statsId = InvalidOid; + foreach_oid(statsId, statsIdList) { + HeapTuple heapTuple = SearchSysCache1(STATEXTOID, ObjectIdGetDatum(statsId)); + if (!HeapTupleIsValid(heapTuple)) + { + ereport(ERROR, (errmsg("cache lookup failed for statistics " + "object with oid %u", statsId))); + } FormData_pg_statistic_ext *statisticsForm = (FormData_pg_statistic_ext *) GETSTRUCT(heapTuple); @@ -515,12 +511,9 @@ GetExplicitStatisticsSchemaIdList(Oid relationId) { schemaIdList = lappend_oid(schemaIdList, schemaId); } - - heapTuple = systable_getnext(scanDescriptor); + ReleaseSysCache(heapTuple); } - systable_endscan(scanDescriptor); - table_close(pgStatistics, NoLock); return schemaIdList; }