Skip to content

Commit 32373aa

Browse files
committed
Fix aoco_relation_size() using wrong snapshot to read pg_aocsseg
aoco_relation_size() used GetLatestSnapshot() to read pg_aocsseg catalog metadata. During ALTER TABLE SET DISTRIBUTED BY on AOCO tables, the reader gang's GetLatestSnapshot() cannot see pg_aocsseg rows written by the writer gang within the same distributed transaction (uncommitted local xid), causing the function to return 0 bytes. This led to relpages=0 being passed to vac_update_relstats() alongside a non-zero totalrows from sampling (which correctly uses GetCatalogSnapshot()), triggering an assertion failure: FailedAssertion: "Gp_role == GP_ROLE_UTILITY", vacuum.c:1738 Fix by passing NULL to GetAllAOCSFileSegInfo() so that systable_beginscan() uses GetCatalogSnapshot() internally, consistent with appendonly_relation_size() for AO row tables.
1 parent 0efd878 commit 32373aa

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/backend/access/aocs/aocsam_handler.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2044,15 +2044,25 @@ static uint64
20442044
aoco_relation_size(Relation rel, ForkNumber forkNumber)
20452045
{
20462046
AOCSFileSegInfo **allseg;
2047-
Snapshot snapshot;
20482047
uint64 totalbytes = 0;
20492048
int totalseg;
20502049

20512050
if (forkNumber != MAIN_FORKNUM)
20522051
return totalbytes;
20532052

2054-
snapshot = RegisterSnapshot(GetLatestSnapshot());
2055-
allseg = GetAllAOCSFileSegInfo(rel, snapshot, &totalseg, NULL);
2053+
/*
2054+
* Pass NULL as snapshot so that GetAllAOCSFileSegInfo -> systable_beginscan
2055+
* uses GetCatalogSnapshot() internally. This is consistent with
2056+
* appendonly_relation_size() for AO row tables and ensures pg_aocsseg
2057+
* entries are visible even when called within the same transaction that
2058+
* populated them (e.g. ALTER TABLE SET DISTRIBUTED BY).
2059+
*
2060+
* Using GetLatestSnapshot() here previously caused the metadata to be
2061+
* invisible on QE segments during in-transaction redistribution, leading
2062+
* to a zero return value and a subsequent assertion failure in
2063+
* vac_update_relstats().
2064+
*/
2065+
allseg = GetAllAOCSFileSegInfo(rel, NULL, &totalseg, NULL);
20562066
for (int seg = 0; seg < totalseg; seg++)
20572067
{
20582068
for (int attr = 0; attr < RelationGetNumberOfAttributes(rel); attr++)
@@ -2079,7 +2089,6 @@ aoco_relation_size(Relation rel, ForkNumber forkNumber)
20792089
FreeAllAOCSSegFileInfo(allseg, totalseg);
20802090
pfree(allseg);
20812091
}
2082-
UnregisterSnapshot(snapshot);
20832092

20842093
return totalbytes;
20852094
}

0 commit comments

Comments
 (0)