Skip to content

Commit 9f4f0a0

Browse files
committed
Fix incorrect logic in HaveRegisteredOrActiveSnapshot().
This function gave the wrong answer when there's more than one RegisteredSnapshots entry, whether or not any of them is the CatalogSnapshot. This leads to assertion failure in some scenarios involving fetching toasted data using a cursor. (As per discussion, I'm dubious that this is the right contract to be enforcing at all; but it surely doesn't help to be enforcing it incorrectly.) Fetching toasted data using a cursor is evidently under-tested, so add a test case too. Per report from Erik Rijkers. This is new code, so no need for back-patch. Discussion: https://postgr.es/m/dc9dd229-ed30-6c62-4c41-d733ffff776b@xs4all.nl
1 parent a17fd67 commit 9f4f0a0

File tree

3 files changed

+52
-3
lines changed

3 files changed

+52
-3
lines changed

src/backend/utils/time/snapmgr.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,11 +1646,11 @@ HaveRegisteredOrActiveSnapshot(void)
16461646
* removed at any time due to invalidation processing. If explicitly
16471647
* registered more than one snapshot has to be in RegisteredSnapshots.
16481648
*/
1649-
if (pairingheap_is_empty(&RegisteredSnapshots) ||
1650-
!pairingheap_is_singular(&RegisteredSnapshots))
1649+
if (CatalogSnapshot != NULL &&
1650+
pairingheap_is_singular(&RegisteredSnapshots))
16511651
return false;
16521652

1653-
return CatalogSnapshot == NULL;
1653+
return !pairingheap_is_empty(&RegisteredSnapshots);
16541654
}
16551655

16561656

0 commit comments

Comments
 (0)