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 ed02e55db..6dfe6cbc9 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 @@ -687,7 +687,10 @@ GetRenameShardIndexCommand(Oid indexOid, uint64 shardId) static void RenameShardRelationStatistics(Oid shardRelationId, uint64 shardId) { - List *statsOidList = GetExplicitStatisticsIdList(shardRelationId); + Relation shardRelation = RelationIdGetRelation(shardRelationId); + List *statsOidList = RelationGetStatExtList(shardRelation); + RelationClose(shardRelation); + List *statsCommandList = GetRenameStatsCommandList(statsOidList, shardId); char *command = NULL; diff --git a/src/backend/distributed/commands/statistics.c b/src/backend/distributed/commands/statistics.c index 3eed687d9..9b0323442 100644 --- a/src/backend/distributed/commands/statistics.c +++ b/src/backend/distributed/commands/statistics.c @@ -425,16 +425,18 @@ PreprocessAlterStatisticsOwnerStmt(Node *node, const char *queryString, * GetExplicitStatisticsCommandList returns the list of DDL commands to create * or alter statistics that are explicitly created for the table with relationId. * This function gets called when distributing the table with relationId. - * See comment of GetExplicitStatisticsIdList function. */ List * GetExplicitStatisticsCommandList(Oid relationId) { List *explicitStatisticsCommandList = NIL; - PushOverrideEmptySearchPath(CurrentMemoryContext); + Relation relation = RelationIdGetRelation(relationId); + List *statisticsIdList = RelationGetStatExtList(relation); + RelationClose(relation); - List *statisticsIdList = GetExplicitStatisticsIdList(relationId); + /* generate fully-qualified names */ + PushOverrideEmptySearchPath(CurrentMemoryContext); Oid statisticsId = InvalidOid; foreach_oid(statisticsId, statisticsIdList) @@ -567,48 +569,6 @@ GetAlterIndexStatisticsCommands(Oid indexOid) } -/* - * GetExplicitStatisticsIdList returns a list of OIDs corresponding to the statistics - * that are explicitly created on the relation with relationId. That means, - * this function discards internal statistics implicitly created by postgres. - */ -List * -GetExplicitStatisticsIdList(Oid relationId) -{ - List *statisticsIdList = NIL; - - Relation pgStatistics = table_open(StatisticExtRelationId, AccessShareLock); - - 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)) - { - FormData_pg_statistic_ext *statisticsForm = - (FormData_pg_statistic_ext *) GETSTRUCT(heapTuple); - Oid statisticsId = statisticsForm->oid; - statisticsIdList = lappend_oid(statisticsIdList, statisticsId); - - heapTuple = systable_getnext(scanDescriptor); - } - - systable_endscan(scanDescriptor); - table_close(pgStatistics, NoLock); - - return statisticsIdList; -} - - /* * GenerateAlterIndexColumnSetStatsCommand returns a string in form of 'ALTER INDEX .. * ALTER COLUMN .. SET STATISTICS ..' which will be used to create a DDL command to diff --git a/src/include/distributed/commands.h b/src/include/distributed/commands.h index 178014669..7accc064e 100644 --- a/src/include/distributed/commands.h +++ b/src/include/distributed/commands.h @@ -388,7 +388,6 @@ extern List * PreprocessAlterStatisticsOwnerStmt(Node *node, const char *querySt extern List * GetExplicitStatisticsCommandList(Oid relationId); extern List * GetExplicitStatisticsSchemaIdList(Oid relationId); extern List * GetAlterIndexStatisticsCommands(Oid indexOid); -extern List * GetExplicitStatisticsIdList(Oid relationId); /* subscription.c - forward declarations */ extern Node * ProcessCreateSubscriptionStmt(CreateSubscriptionStmt *createSubStmt);