From 2371aaa1483051fc8b81256a271e45ac4c5c472e Mon Sep 17 00:00:00 2001
From: Hayato Kuroda <kuroda.hayato@fujitsu.com>
Date: Wed, 18 Nov 2026 22:02:54 +0900
Subject: [PATCH vnocfbot] simplify hash_xlog_squeeze_page

---
 src/backend/access/hash/hash_xlog.c | 36 +++++++++++------------------
 1 file changed, 14 insertions(+), 22 deletions(-)

diff --git a/src/backend/access/hash/hash_xlog.c b/src/backend/access/hash/hash_xlog.c
index 37ea8099f23..f4816486618 100644
--- a/src/backend/access/hash/hash_xlog.c
+++ b/src/backend/access/hash/hash_xlog.c
@@ -641,6 +641,7 @@ hash_xlog_squeeze_page(XLogReaderState *record)
 	Buffer		prevbuf = InvalidBuffer;
 	Buffer		mapbuf;
 	XLogRedoAction action;
+	bool		writebuf_registered;
 
 	/*
 	 * Ensure we have a cleanup lock on primary bucket page before we start
@@ -648,31 +649,22 @@ hash_xlog_squeeze_page(XLogReaderState *record)
 	 * scan can start nor a scan can be already-in-progress during the replay
 	 * of this operation.  If we allow scans during this operation, then they
 	 * can miss some records or show the same record multiple times.
+	 *
+	 * A modified write page is registered as block 0.  If it is also the
+	 * primary bucket page, its cleanup lock protects scans; otherwise, lock
+	 * the primary bucket page separately.
 	 */
-	if (xldata->is_prim_bucket_same_wrt)
-	{
-		/*
-		 * If the primary bucket page is modified, it is registered as block
-		 * 0 and read for redo.  Otherwise, acquire its cleanup lock
-		 * separately.
-		 */
-		if (XLogRecHasBlockRef(record, 0))
-			action = XLogReadBufferForRedoExtended(record, 0, RBM_NORMAL, true, &writebuf);
-		else
-		{
-			bucketbuf = hash_xlog_lock_primary_bucket(record, 1, SizeOfHashSqueezePage);
-			action = BLK_NOTFOUND;
-		}
-	}
-	else
-	{
+	writebuf_registered = XLogRecHasBlockRef(record, 0);
+
+	if (!(xldata->is_prim_bucket_same_wrt && writebuf_registered))
 		bucketbuf = hash_xlog_lock_primary_bucket(record, 1, SizeOfHashSqueezePage);
 
-		if (xldata->ntups > 0 || xldata->is_prev_bucket_same_wrt)
-			action = XLogReadBufferForRedo(record, 0, &writebuf);
-		else
-			action = BLK_NOTFOUND;
-	}
+	if (writebuf_registered)
+		action = XLogReadBufferForRedoExtended(record, 0, RBM_NORMAL,
+											   xldata->is_prim_bucket_same_wrt,
+											   &writebuf);
+	else
+		action = BLK_NOTFOUND;
 
 	/* replay the record for adding entries in overflow buffer */
 	if (action == BLK_NEEDS_REDO)
-- 
2.52.0

