From b570b3d593f1eede3d79c03417bd0be5157cd717 Mon Sep 17 00:00:00 2001 From: liushengsong Date: Tue, 8 Aug 2023 11:43:14 +0800 Subject: [PATCH] FIX: constraint check exception with snapshot memory leak in AO/AOCS. _bt_check_unique(DirtySnapshot is created here) -> table_index_fetch_tuple_check -> ... -> AppendOnlyVisimapStore_Init -> RegisterSnapshot(snapshot) UnregisterSnapshot is called in AppendOnlyVisimapStore_Finish. If transaction aborts, there is no chance to call AppendOnlyVisimapStore_Finish. In order to solve this problem, we directly delete the RegisterSnapshot in AppendOnlyVisimapStore_Init which is useless and at the same time delete the UnregisterSnapshot. --- src/backend/access/appendonly/appendonly_visimap_store.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/backend/access/appendonly/appendonly_visimap_store.c b/src/backend/access/appendonly/appendonly_visimap_store.c index d7b9906d0f2..c0c1917a213 100644 --- a/src/backend/access/appendonly/appendonly_visimap_store.c +++ b/src/backend/access/appendonly/appendonly_visimap_store.c @@ -43,7 +43,6 @@ AppendOnlyVisimapStore_Finish(AppendOnlyVisimapStore *visiMapStore, visiMapStore->scanKeys = NULL; } - UnregisterSnapshot(visiMapStore->snapshot); index_close(visiMapStore->visimapIndex, lockmode); table_close(visiMapStore->visimapRelation, lockmode); } @@ -71,7 +70,7 @@ AppendOnlyVisimapStore_Init(AppendOnlyVisimapStore *visiMapStore, Assert(OidIsValid(visimapRelid)); Assert(OidIsValid(visimapIdxid)); - visiMapStore->snapshot = RegisterSnapshot(snapshot); + visiMapStore->snapshot = snapshot; visiMapStore->memoryContext = memoryContext; visiMapStore->visimapRelation = table_open(visimapRelid, lockmode);