Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 0960ae1

Browse files
committed
Fix EXPLAIN Bitmap heap scan to count pages with no visible tuples
Previously, bitmap heap scans only counted lossy and exact pages for explain when there was at least one visible tuple on the page. heapam_scan_bitmap_next_block() returned true only if there was a "valid" page with tuples to be processed. However, the lossy and exact page counters in EXPLAIN should count the number of pages represented in a lossy or non-lossy way in the constructed bitmap, regardless of whether or not the pages ultimately contained visible tuples. Backpatch to all supported versions. Author: Melanie Plageman Discussion: https://www.postgresql.org/message-id/CAAKRu_ZwCwWFeL_H3ia26bP2e7HiKLWt0ZmGXPVwPO6uXq0vaA@mail.gmail.com Discussion: https://www.postgresql.org/message-id/CAAKRu_bxrXeZ2rCnY8LyeC2Ls88KpjWrQ%2BopUrXDRXdcfwFZGA@mail.gmail.com
1 parent 48018f1 commit 0960ae1

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/backend/executor/nodeBitmapHeapscan.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,11 @@ BitmapHeapNext(BitmapHeapScanState *node)
204204

205205
BitmapAdjustPrefetchIterator(node, tbmres);
206206

207+
if (tbmres->ntuples >= 0)
208+
node->exact_pages++;
209+
else
210+
node->lossy_pages++;
211+
207212
/*
208213
* We can skip fetching the heap page if we don't need any fields
209214
* from the heap, and the bitmap entries don't need rechecking,
@@ -235,11 +240,6 @@ BitmapHeapNext(BitmapHeapScanState *node)
235240
continue;
236241
}
237242

238-
if (tbmres->ntuples >= 0)
239-
node->exact_pages++;
240-
else
241-
node->lossy_pages++;
242-
243243
/* Adjust the prefetch target */
244244
BitmapAdjustPrefetchTarget(node);
245245
}

src/test/regress/expected/partition_prune.out

+3-1
Original file line numberDiff line numberDiff line change
@@ -2848,6 +2848,7 @@ update ab_a1 set b = 3 from ab where ab.a = 1 and ab.a = ab_a1.a;
28482848
Index Cond: (a = 1)
28492849
-> Bitmap Heap Scan on ab_a1_b3 ab_a1_3 (actual rows=0 loops=1)
28502850
Recheck Cond: (a = 1)
2851+
Heap Blocks: exact=1
28512852
-> Bitmap Index Scan on ab_a1_b3_a_idx (actual rows=1 loops=1)
28522853
Index Cond: (a = 1)
28532854
-> Materialize (actual rows=1 loops=1)
@@ -2863,9 +2864,10 @@ update ab_a1 set b = 3 from ab where ab.a = 1 and ab.a = ab_a1.a;
28632864
Index Cond: (a = 1)
28642865
-> Bitmap Heap Scan on ab_a1_b3 ab_3 (actual rows=0 loops=1)
28652866
Recheck Cond: (a = 1)
2867+
Heap Blocks: exact=1
28662868
-> Bitmap Index Scan on ab_a1_b3_a_idx (actual rows=1 loops=1)
28672869
Index Cond: (a = 1)
2868-
(34 rows)
2870+
(36 rows)
28692871

28702872
table ab;
28712873
a | b

0 commit comments

Comments
 (0)