From b738aa5ef69b8e686525cca48bc5d2f9ac82bda2 Mon Sep 17 00:00:00 2001
From: Peter Geoghegan <pg@bowt.ie>
Date: Tue, 18 Aug 2026 15:50:56 -0400
Subject: [PATCH] Backpatch

---
 src/backend/access/gist/gistscan.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/backend/access/gist/gistscan.c b/src/backend/access/gist/gistscan.c
index e05801e2f..ae00b943c 100644
--- a/src/backend/access/gist/gistscan.c
+++ b/src/backend/access/gist/gistscan.c
@@ -135,6 +135,9 @@ gistrescan(IndexScanDesc scan, ScanKey key, int nkeys,
 
 	/* rescan an existing indexscan --- reset state */
 
+	/* invalidate any killed items still pending */
+	so->numKilled = 0;
+
 	/*
 	 * The first time through, we create the search queue in the scanCxt.
 	 * Subsequent times through, we create the queue in a separate queueCxt,
@@ -350,6 +353,9 @@ gistendscan(IndexScanDesc scan)
 {
 	GISTScanOpaque so = (GISTScanOpaque) scan->opaque;
 
+	/* invalidate any killed items still pending */
+	so->numKilled = 0;
+
 	/*
 	 * freeGISTstate is enough to clean up everything made by gistbeginscan,
 	 * as well as the queueCxt if there is a separate context for it.
-- 
2.53.0

