Use RelationGetStatExtList instead of GetExplicitStatisticsIdList

pull/5192/head
Onur Tirtir 2021-08-18 01:28:33 +03:00
parent 91544d0191
commit 4b03195c06
3 changed files with 9 additions and 47 deletions

View File

@ -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;

View File

@ -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

View File

@ -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);