Subject: [PATCH 5/6] Remove 'numEmptyPages'. it's not really needed.

From: Heikki Linnakangas <[email-masked]>
Date: Mon, 11 Mar 2019 15:41:07 +0200

---
 src/backend/access/gist/gistvacuum.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/src/backend/access/gist/gistvacuum.c b/src/backend/access/gist/gistvacuum.c
index b95e755406e..bf0b9d54f69 100644
--- a/src/backend/access/gist/gistvacuum.c
+++ b/src/backend/access/gist/gistvacuum.c
@@ -28,7 +28,6 @@ typedef struct
 	IndexBulkDeleteResult stats;
 
 	IndexVacuumInfo *info;
-	BlockNumber numEmptyPages;
 	BlockSet	internalPagesMap;
 	BlockSet	emptyLeafPagesMap;
 } GistBulkDeleteResult;
@@ -349,7 +348,6 @@ restart:
 		if (nremain == 0)
 		{
 			stats->emptyLeafPagesMap = blockset_set(stats->emptyLeafPagesMap, blkno);
-			stats->numEmptyPages++;
 		}
 		else
 			stats->stats.num_index_tuples += nremain;
@@ -408,13 +406,15 @@ gistvacuum_recycle_pages(GistBulkDeleteResult *stats)
 	BlockNumber	x;
 
 	/* quick exit if no empty pages */
-	if (stats->numEmptyPages > 0)
-		gistvacuum_recycle_pages(stats);
+	/* HEIKKI: I'm assuming the blockset is always NULL if it's empty. That's true
+	 * for the current usage. But add comments, and maybe a blockset_isempty() macro
+	 * for clarity */
+	if (stats->emptyLeafPagesMap == NULL)
+		return;
 
 	/* rescan all inner pages to find those that have empty child pages */
 	x = InvalidBlockNumber;
-	while (stats->numEmptyPages > 0 &&
-		   (x = blockset_next(stats->internalPagesMap, x)) != InvalidBlockNumber)
+	while ((x = blockset_next(stats->internalPagesMap, x)) != InvalidBlockNumber)
 	{
 		Buffer		buffer;
 		Page		page;
@@ -442,7 +442,9 @@ gistvacuum_recycle_pages(GistBulkDeleteResult *stats)
 
 		maxoff = PageGetMaxOffsetNumber(page);
 		/* Check that leafs are still empty and decide what to delete */
-		for (off = FirstOffsetNumber; off <= maxoff && ntodelete < maxoff-1; off = OffsetNumberNext(off))
+		for (off = FirstOffsetNumber;
+			 off <= maxoff && ntodelete < maxoff-1;
+			 off = OffsetNumberNext(off))
 		{
 			Buffer		leafBuffer;
 			Page		leafPage;
@@ -569,7 +571,6 @@ gistvacuum_recycle_pages(GistBulkDeleteResult *stats)
 				GistPageSetDeleted(leafPage);
 				MarkBufferDirty(buftodelete[i]);
 				stats->stats.pages_deleted++;
-				stats->numEmptyPages--;
 
 				MarkBufferDirty(buffer);
 				/* Offsets are changed as long as we delete tuples from internal page */
-- 
2.20.1

--------------AF9416BC788B4CF5E4BF929D
Content-Type: text/x-patch;
 name="0006-Misc-cleanup.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename="0006-Misc-cleanup.patch"