From 4ba6b8cda0bce3a68f68c39f45864a6fcb148b45 Mon Sep 17 00:00:00 2001
From: Melanie Plageman <melanieplageman@gmail.com>
Date: Sat, 6 Apr 2024 14:43:04 -0400
Subject: [PATCH v19 13/21] BitmapHeapScan: rescan in BitmapHeapNext

Instead of rescanning in ExecReScanBitmapHeapScan(), do so in
BitmapHeapNext(). This has no functional impact, but it is a step toward
creating the iterators in the table rescan function itself.

Author: Melanie Plageman
Discussion: https://postgr.es/m/CAAKRu_ZwCwWFeL_H3ia26bP2e7HiKLWt0ZmGXPVwPO6uXq0vaA%40mail.gmail.com
---
 src/backend/executor/nodeBitmapHeapscan.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/src/backend/executor/nodeBitmapHeapscan.c b/src/backend/executor/nodeBitmapHeapscan.c
index cd76d5e46ad..1fe50348c6f 100644
--- a/src/backend/executor/nodeBitmapHeapscan.c
+++ b/src/backend/executor/nodeBitmapHeapscan.c
@@ -164,6 +164,8 @@ BitmapHeapNext(BitmapHeapScanState *node)
 			node->ss.ss_currentScanDesc = scan;
 		}
 
+		/* rescan to release any page pin */
+		table_rescan(scan, NULL);
 		unified_tbm_begin_iterate(&scan->rs_bhs_iterator, tbm, dsa,
 								  pstate ?
 								  pstate->tbmiterator :
@@ -541,10 +543,6 @@ ExecReScanBitmapHeapScan(BitmapHeapScanState *node)
 {
 	PlanState  *outerPlan = outerPlanState(node);
 
-	/* rescan to release any page pin */
-	if (node->ss.ss_currentScanDesc)
-		table_rescan(node->ss.ss_currentScanDesc, NULL);
-
 	/* release bitmaps and buffers if any */
 	if (node->prefetch_iterator.exhausted)
 		unified_tbm_end_iterate(&node->prefetch_iterator);
-- 
2.40.1

