From c5f52325414d57022f66500c29fe091e4a39c77b Mon Sep 17 00:00:00 2001
From: Tomas Vondra <tomas@vondra.me>
Date: Wed, 23 Apr 2025 22:21:51 +0200
Subject: [PATCH v20250501 4/7] fix: update moreRight/moreLeft in btgetbatch

---
 src/backend/access/nbtree/nbtree.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/src/backend/access/nbtree/nbtree.c b/src/backend/access/nbtree/nbtree.c
index 405c601d3ff..6ea1dfcc52c 100644
--- a/src/backend/access/nbtree/nbtree.c
+++ b/src/backend/access/nbtree/nbtree.c
@@ -308,6 +308,11 @@ btgetbatch(IndexScanDesc scan, ScanDirection dir)
 	{
 		IndexScanBatch batch = INDEX_SCAN_BATCH(scan, scan->xs_batches->nextBatch-1);
 		pos = (BTBatchScanPos) batch->opaque;
+
+		if (ScanDirectionIsForward(scan->xs_batches->direction))
+			pos->moreRight = true;
+		else
+			pos->moreLeft = true;
 	}
 
 	/* Each loop iteration performs another primitive index scan */
@@ -322,6 +327,12 @@ btgetbatch(IndexScanDesc scan, ScanDirection dir)
 			res = _bt_first_batch(scan, dir);
 		else
 		{
+			if (so->numArrayKeys)
+			{
+				_bt_start_array_keys(scan, so->currPos.dir);
+				so->needPrimScan = false;
+			}
+
 			/*
 			 * Now continue the scan.
 			 */
-- 
2.49.0

