This is an automated email from the ASF dual-hosted git repository.
yjhjstz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
The following commit(s) were added to refs/heads/main by this push:
new 32373aa26c1 Fix aoco_relation_size() using wrong snapshot to read
pg_aocsseg
32373aa26c1 is described below
commit 32373aa26c1659faf6bcf71aa604d397bc8f6feb
Author: Jianghua Yang <[email protected]>
AuthorDate: Wed Apr 8 22:47:38 2026 +0800
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.
---
src/backend/access/aocs/aocsam_handler.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/src/backend/access/aocs/aocsam_handler.c
b/src/backend/access/aocs/aocsam_handler.c
index c2faa538e10..4b3cd2a52ef 100644
--- a/src/backend/access/aocs/aocsam_handler.c
+++ b/src/backend/access/aocs/aocsam_handler.c
@@ -2044,15 +2044,25 @@ static uint64
aoco_relation_size(Relation rel, ForkNumber forkNumber)
{
AOCSFileSegInfo **allseg;
- Snapshot snapshot;
uint64 totalbytes = 0;
int totalseg;
if (forkNumber != MAIN_FORKNUM)
return totalbytes;
- snapshot = RegisterSnapshot(GetLatestSnapshot());
- allseg = GetAllAOCSFileSegInfo(rel, snapshot, &totalseg, NULL);
+ /*
+ * Pass NULL as snapshot so that GetAllAOCSFileSegInfo ->
systable_beginscan
+ * uses GetCatalogSnapshot() internally. This is consistent with
+ * appendonly_relation_size() for AO row tables and ensures pg_aocsseg
+ * entries are visible even when called within the same transaction that
+ * populated them (e.g. ALTER TABLE SET DISTRIBUTED BY).
+ *
+ * Using GetLatestSnapshot() here previously caused the metadata to be
+ * invisible on QE segments during in-transaction redistribution,
leading
+ * to a zero return value and a subsequent assertion failure in
+ * vac_update_relstats().
+ */
+ allseg = GetAllAOCSFileSegInfo(rel, NULL, &totalseg, NULL);
for (int seg = 0; seg < totalseg; seg++)
{
for (int attr = 0; attr < RelationGetNumberOfAttributes(rel);
attr++)
@@ -2079,7 +2089,6 @@ aoco_relation_size(Relation rel, ForkNumber forkNumber)
FreeAllAOCSSegFileInfo(allseg, totalseg);
pfree(allseg);
}
- UnregisterSnapshot(snapshot);
return totalbytes;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]