v1-0001-Unity-NULL-snapshot-hadling.patch
application/octet-stream
Filename: v1-0001-Unity-NULL-snapshot-hadling.patch
Type: application/octet-stream
Part: 0
From 358dda1591ca96bf8c6b9dbdc463148461d2709b Mon Sep 17 00:00:00 2001
From: reshke <reshke@double.cloud>
Date: Fri, 19 Dec 2025 21:23:38 +0000
Subject: [PATCH v1] Unity NULL snapshot hadling.
UnregisterSnapshot and UnregisterSnapshotFromOwner are ready to
accept NULL snapshot. However, there are places in code where we
call this function only for non-NULL argumnet. Remove this
unneccessary check to simplify coding.
---
contrib/amcheck/verify_nbtree.c | 7 ++++---
src/backend/access/index/genam.c | 9 +++++----
src/backend/access/index/indexam.c | 4 ++--
src/backend/libpq/be-fsstubs.c | 4 ++--
src/backend/utils/cache/relcache.c | 4 ++--
src/backend/utils/mmgr/portalmem.c | 8 ++++----
src/backend/utils/time/snapmgr.c | 4 ++--
7 files changed, 21 insertions(+), 19 deletions(-)
diff --git a/contrib/amcheck/verify_nbtree.c b/contrib/amcheck/verify_nbtree.c
index f91392a3a49..40a2dc8d69b 100644
--- a/contrib/amcheck/verify_nbtree.c
+++ b/contrib/amcheck/verify_nbtree.c
@@ -594,9 +594,10 @@ bt_check_every_level(Relation rel, Relation heaprel, bool heapkeyspace,
bloom_free(state->filter);
}
- /* Be tidy: */
- if (state->snapshot != InvalidSnapshot)
- UnregisterSnapshot(state->snapshot);
+ /* Be tidy. Dont worry about snapshot being NULL here,
+ * as UnregisterSnapshot is ready to handle it. */
+ UnregisterSnapshot(state->snapshot);
+
MemoryContextDelete(state->targetcontext);
}
diff --git a/src/backend/access/index/genam.c b/src/backend/access/index/genam.c
index b7f10a1aed0..59607e2a160 100644
--- a/src/backend/access/index/genam.c
+++ b/src/backend/access/index/genam.c
@@ -616,8 +616,8 @@ systable_endscan(SysScanDesc sysscan)
else
table_endscan(sysscan->scan);
- if (sysscan->snapshot)
- UnregisterSnapshot(sysscan->snapshot);
+ /* Be tidy, unregister snaphot, if any. */
+ UnregisterSnapshot(sysscan->snapshot);
/*
* Reset the bsysscan flag at the end of the systable scan. See detailed
@@ -764,8 +764,9 @@ systable_endscan_ordered(SysScanDesc sysscan)
Assert(sysscan->irel);
index_endscan(sysscan->iscan);
- if (sysscan->snapshot)
- UnregisterSnapshot(sysscan->snapshot);
+
+ /* Be tidy, unregister snaphot, if any. */
+ UnregisterSnapshot(sysscan->snapshot);
/*
* Reset the bsysscan flag at the end of the systable scan. See detailed
diff --git a/src/backend/access/index/indexam.c b/src/backend/access/index/indexam.c
index 0492d92d23b..6727bcf8565 100644
--- a/src/backend/access/index/indexam.c
+++ b/src/backend/access/index/indexam.c
@@ -407,8 +407,8 @@ index_endscan(IndexScanDesc scan)
/* Release index refcount acquired by index_beginscan */
RelationDecrementReferenceCount(scan->indexRelation);
- if (scan->xs_temp_snap)
- UnregisterSnapshot(scan->xs_snapshot);
+ /* Be tidy, unregister snaphot, if any. */
+ UnregisterSnapshot(scan->xs_snapshot);
/* Release the scan data structure itself */
IndexScanEnd(scan);
diff --git a/src/backend/libpq/be-fsstubs.c b/src/backend/libpq/be-fsstubs.c
index e5a34c61931..3015683f51e 100644
--- a/src/backend/libpq/be-fsstubs.c
+++ b/src/backend/libpq/be-fsstubs.c
@@ -729,8 +729,8 @@ closeLOfd(int fd)
lobj = cookies[fd];
cookies[fd] = NULL;
- if (lobj->snapshot)
- UnregisterSnapshotFromOwner(lobj->snapshot,
+ /* Be tidy, unregister snaphot, if any. */
+ UnregisterSnapshotFromOwner(lobj->snapshot,
TopTransactionResourceOwner);
inv_close(lobj);
}
diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c
index 2d0cb7bcfd4..ef3707488b4 100644
--- a/src/backend/utils/cache/relcache.c
+++ b/src/backend/utils/cache/relcache.c
@@ -395,8 +395,8 @@ ScanPgRelation(Oid targetRelId, bool indexOK, bool force_non_historic)
/* all done */
systable_endscan(pg_class_scan);
- if (snapshot)
- UnregisterSnapshot(snapshot);
+ /* Be tidy, unregister snaphot, if any. */
+ UnregisterSnapshot(snapshot);
table_close(pg_class_desc, AccessShareLock);
diff --git a/src/backend/utils/mmgr/portalmem.c b/src/backend/utils/mmgr/portalmem.c
index 1f2a423f38a..5d4c565b4af 100644
--- a/src/backend/utils/mmgr/portalmem.c
+++ b/src/backend/utils/mmgr/portalmem.c
@@ -525,8 +525,8 @@ PortalDrop(Portal portal, bool isTopCommit)
*/
if (portal->holdSnapshot)
{
- if (portal->resowner)
- UnregisterSnapshotFromOwner(portal->holdSnapshot,
+ /* Be tidy, unregister snaphot, if any. */
+ UnregisterSnapshotFromOwner(portal->holdSnapshot,
portal->resowner);
portal->holdSnapshot = NULL;
}
@@ -708,8 +708,8 @@ PreCommit_Portals(bool isPrepare)
{
if (portal->holdSnapshot)
{
- if (portal->resowner)
- UnregisterSnapshotFromOwner(portal->holdSnapshot,
+ /* Be tidy, unregister snaphot, if any. */
+ UnregisterSnapshotFromOwner(portal->holdSnapshot,
portal->resowner);
portal->holdSnapshot = NULL;
}
diff --git a/src/backend/utils/time/snapmgr.c b/src/backend/utils/time/snapmgr.c
index 5af8326d5e8..1350b21efa7 100644
--- a/src/backend/utils/time/snapmgr.c
+++ b/src/backend/utils/time/snapmgr.c
@@ -865,7 +865,7 @@ RegisterSnapshotOnOwner(Snapshot snapshot, ResourceOwner owner)
void
UnregisterSnapshot(Snapshot snapshot)
{
- if (snapshot == NULL)
+ if (snapshot == InvalidSnapshot)
return;
UnregisterSnapshotFromOwner(snapshot, CurrentResourceOwner);
@@ -878,7 +878,7 @@ UnregisterSnapshot(Snapshot snapshot)
void
UnregisterSnapshotFromOwner(Snapshot snapshot, ResourceOwner owner)
{
- if (snapshot == NULL)
+ if (snapshot == InvalidSnapshot)
return;
ResourceOwnerForgetSnapshot(owner, snapshot);
--
2.43.0