From e2b50f9b64f7e4255f4f764e2a348e1b446573dc Mon Sep 17 00:00:00 2001
From: Heikki Linnakangas <heikki.linnakangas@iki.fi>
Date: Wed, 20 Mar 2024 11:43:31 +0200
Subject: [PATCH v5 22/26] make 'all_visible_except_removable' local

The caller doesn't need it, so it doesn't belong in PruneFreezeResult
---
 src/backend/access/heap/pruneheap.c | 22 ++++++++++++----------
 src/include/access/heapam.h         |  1 -
 2 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/src/backend/access/heap/pruneheap.c b/src/backend/access/heap/pruneheap.c
index 3821f489aad..adf6406b880 100644
--- a/src/backend/access/heap/pruneheap.c
+++ b/src/backend/access/heap/pruneheap.c
@@ -245,6 +245,7 @@ heap_page_prune_and_freeze(Relation relation, Buffer buffer,
 	bool		do_hint;
 	bool		hint_bit_fpi;
 	int64		fpi_before = pgWalUsage.wal_fpi;
+	bool		all_visible_except_removable;
 
 	/*
 	 * Our strategy is to scan the page and make lists of items to change,
@@ -268,6 +269,7 @@ heap_page_prune_and_freeze(Relation relation, Buffer buffer,
 	 * presult->htsv is not initialized here because all ntuple spots in the
 	 * array will be set either to a valid HTSV_Result value or -1.
 	 */
+
 	presult->ndeleted = 0;
 	presult->nnewlpdead = 0;
 	presult->nfrozen = 0;
@@ -280,7 +282,6 @@ heap_page_prune_and_freeze(Relation relation, Buffer buffer,
 	 * all_visible is also set to true.
 	 */
 	presult->all_frozen = true;
-	presult->all_visible = true;
 	/* for recovery conflicts */
 	presult->frz_conflict_horizon = InvalidTransactionId;
 
@@ -311,6 +312,7 @@ heap_page_prune_and_freeze(Relation relation, Buffer buffer,
 	 * prefetching efficiency significantly / decreases the number of cache
 	 * misses.
 	 */
+	all_visible_except_removable = true;
 	for (offnum = maxoff;
 		 offnum >= FirstOffsetNumber;
 		 offnum = OffsetNumberPrev(offnum))
@@ -367,13 +369,13 @@ heap_page_prune_and_freeze(Relation relation, Buffer buffer,
 				 * asynchronously. See SetHintBits for more info. Check that
 				 * the tuple is hinted xmin-committed because of that.
 				 */
-				if (presult->all_visible)
+				if (all_visible_except_removable)
 				{
 					TransactionId xmin;
 
 					if (!HeapTupleHeaderXminCommitted(htup))
 					{
-						presult->all_visible = false;
+						all_visible_except_removable = false;
 						break;
 					}
 
@@ -389,7 +391,7 @@ heap_page_prune_and_freeze(Relation relation, Buffer buffer,
 					if (xmin != FrozenTransactionId &&
 						!GlobalVisTestIsRemovableXid(vistest, xmin))
 					{
-						presult->all_visible = false;
+						all_visible_except_removable = false;
 						break;
 					}
 
@@ -400,14 +402,14 @@ heap_page_prune_and_freeze(Relation relation, Buffer buffer,
 				}
 				break;
 			case HEAPTUPLE_RECENTLY_DEAD:
-				presult->all_visible = false;
+				all_visible_except_removable = false;
 				break;
 			case HEAPTUPLE_INSERT_IN_PROGRESS:
-				presult->all_visible = false;
+				all_visible_except_removable = false;
 				break;
 			case HEAPTUPLE_DELETE_IN_PROGRESS:
 				/* This is an expected case during concurrent vacuum */
-				presult->all_visible = false;
+				all_visible_except_removable = false;
 				break;
 			default:
 				elog(ERROR, "unexpected HeapTupleSatisfiesVacuum result");
@@ -460,7 +462,7 @@ heap_page_prune_and_freeze(Relation relation, Buffer buffer,
 	 * pruning and keep all_visible_except_removable to permit freezing if the
 	 * whole page will eventually become all visible after removing tuples.
 	 */
-	presult->all_visible_except_removable = presult->all_visible;
+	presult->all_visible = all_visible_except_removable;
 
 	/* Scan the page */
 	for (offnum = FirstOffsetNumber;
@@ -523,7 +525,7 @@ heap_page_prune_and_freeze(Relation relation, Buffer buffer,
 		bool		whole_page_freezable;
 
 		/* Is the whole page freezable? And is there something to freeze? */
-		whole_page_freezable = presult->all_visible_except_removable &&
+		whole_page_freezable = all_visible_except_removable &&
 			presult->all_frozen;
 
 		if (pagefrz->freeze_required)
@@ -613,7 +615,7 @@ heap_page_prune_and_freeze(Relation relation, Buffer buffer,
 			 * cutoff by stepping back from OldestXmin. This avoids false
 			 * conflicts when hot_standby_feedback is in use.
 			 */
-			if (!(presult->all_visible_except_removable && presult->all_frozen))
+			if (!(all_visible_except_removable && presult->all_frozen))
 			{
 				presult->frz_conflict_horizon = pagefrz->cutoffs->OldestXmin;
 				TransactionIdRetreat(presult->frz_conflict_horizon);
diff --git a/src/include/access/heapam.h b/src/include/access/heapam.h
index cfa4b07433b..7a5bc018088 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -201,7 +201,6 @@ typedef struct PruneFreezeResult
 	int			ndeleted;		/* Number of tuples deleted from the page */
 	int			nnewlpdead;		/* Number of newly LP_DEAD items */
 	bool		all_visible;	/* Whether or not the page is all visible */
-	bool		all_visible_except_removable;
 	/* Whether or not the page can be set all frozen in the VM */
 	bool		all_frozen;
 
-- 
2.39.2

