From 6ad506879d8a754013b971197592fc9617850b7e Mon Sep 17 00:00:00 2001
From: Justin Pryzby <pryzbyj@telsasoft.com>
Date: Sat, 4 Jan 2020 10:25:12 -0600
Subject: [PATCH v1] allow disabling indexscans but not bitmap scans

---
 src/backend/optimizer/path/costsize.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/backend/optimizer/path/costsize.c b/src/backend/optimizer/path/costsize.c
index b5a0033..6f37386 100644
--- a/src/backend/optimizer/path/costsize.c
+++ b/src/backend/optimizer/path/costsize.c
@@ -972,7 +972,12 @@ cost_bitmap_heap_scan(Path *path, PlannerInfo *root, RelOptInfo *baserel,
 										 loop_count, &indexTotalCost,
 										 &tuples_fetched);
 
-	startup_cost += indexTotalCost;
+	if (indexTotalCost > disable_cost && enable_bitmapscan)
+		/* enable_indexscan=off no longer itself disables bitmap scans */
+		startup_cost += indexTotalCost - disable_cost;
+	else
+		startup_cost += indexTotalCost;
+
 	T = (baserel->pages > 1) ? (double) baserel->pages : 1.0;
 
 	/* Fetch estimated page costs for tablespace containing table. */
-- 
2.7.4

