From d1b1ce71c88a04e3c5a2480827bd3af3ffbe1372 Mon Sep 17 00:00:00 2001
From: Melanie Plageman <melanieplageman@gmail.com>
Date: Mon, 18 Mar 2024 19:01:17 -0400
Subject: [PATCH v4 01/19] Reorganize heap_page_prune() function comment

heap_page_prune()'s function header comment didn't explain the
parameters in the same order they appear in the function. Fix that.

While we are at it, move some parts of the initial function body
comments around so they are in more relevant locations.
---
 src/backend/access/heap/pruneheap.c | 30 ++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/src/backend/access/heap/pruneheap.c b/src/backend/access/heap/pruneheap.c
index 4f12413b8b1..b5895406ec2 100644
--- a/src/backend/access/heap/pruneheap.c
+++ b/src/backend/access/heap/pruneheap.c
@@ -193,22 +193,26 @@ heap_page_prune_opt(Relation relation, Buffer buffer)
  *
  * Caller must have pin and buffer cleanup lock on the page.  Note that we
  * don't update the FSM information for page on caller's behalf.  Caller might
- * also need to account for a reduction in the length of the line pointer
- * array following array truncation by us.
+ * also need to account for a reduction in the length of the line pointer array
+ * following array truncation by us.
  *
- * vistest is used to distinguish whether tuples are DEAD or RECENTLY_DEAD
- * (see heap_prune_satisfies_vacuum and
- * HeapTupleSatisfiesVacuum).
+ * Our strategy is to scan the page and make lists of items to change, then
+ * apply the changes within a critical section.  This keeps as much logic as
+ * possible out of the critical section, and also ensures that WAL replay will
+ * work the same as the normal case.
  *
- * mark_unused_now indicates whether or not dead items can be set LP_UNUSED during
- * pruning.
+ * vistest is used to distinguish whether tuples are DEAD or RECENTLY_DEAD (see
+ * heap_prune_satisfies_vacuum and HeapTupleSatisfiesVacuum).
  *
- * off_loc is the offset location required by the caller to use in error
- * callback.
+ * mark_unused_now indicates whether or not dead items can be set LP_UNUSED
+ * during pruning.
  *
  * presult contains output parameters needed by callers such as the number of
  * tuples removed and the number of line pointers newly marked LP_DEAD.
  * heap_page_prune() is responsible for initializing it.
+ *
+ * off_loc is the offset location required by the caller to use in error
+ * callback.
  */
 void
 heap_page_prune(Relation relation, Buffer buffer,
@@ -225,11 +229,6 @@ heap_page_prune(Relation relation, Buffer buffer,
 	HeapTupleData tup;
 
 	/*
-	 * Our strategy is to scan the page and make lists of items to change,
-	 * then apply the changes within a critical section.  This keeps as much
-	 * logic as possible out of the critical section, and also ensures that
-	 * WAL replay will work the same as the normal case.
-	 *
 	 * First, initialize the new pd_prune_xid value to zero (indicating no
 	 * prunable tuples).  If we find any tuples which may soon become
 	 * prunable, we will save the lowest relevant XID in new_prune_xid. Also
@@ -241,12 +240,13 @@ heap_page_prune(Relation relation, Buffer buffer,
 	prstate.mark_unused_now = mark_unused_now;
 	prstate.snapshotConflictHorizon = InvalidTransactionId;
 	prstate.nredirected = prstate.ndead = prstate.nunused = 0;
-	memset(prstate.marked, 0, sizeof(prstate.marked));
 
 	/*
 	 * 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.
 	 */
+	memset(prstate.marked, 0, sizeof(prstate.marked));
+
 	presult->ndeleted = 0;
 	presult->nnewlpdead = 0;
 
-- 
2.40.1

