Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Fix EXPLAIN Bitmap heap scan to count pages with no visible tuples
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Mon, 18 Mar 2024 12:04:28 +0000 (14:04 +0200)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Mon, 18 Mar 2024 12:04:28 +0000 (14:04 +0200)
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

src/backend/executor/nodeBitmapHeapscan.c
src/test/regress/expected/partition_prune.out

index f62105f5284007ed2af0fb36c9feb0289b098a69..15abed130414d5034c488dad8109b6cb00f410f5 100644 (file)
@@ -208,6 +208,11 @@ BitmapHeapNext(BitmapHeapScanState *node)
 
            BitmapAdjustPrefetchIterator(node, tbmres);
 
+           if (tbmres->ntuples >= 0)
+               node->exact_pages++;
+           else
+               node->lossy_pages++;
+
            /*
             * We can skip fetching the heap page if we don't need any fields
             * from the heap, and the bitmap entries don't need rechecking,
@@ -239,11 +244,6 @@ BitmapHeapNext(BitmapHeapScanState *node)
                continue;
            }
 
-           if (tbmres->ntuples >= 0)
-               node->exact_pages++;
-           else
-               node->lossy_pages++;
-
            /* Adjust the prefetch target */
            BitmapAdjustPrefetchTarget(node);
        }
index 7fde46113ea87f48d4a150c9820923ee0bb749f3..d5b009077bbc98b33304b08d9479b3dec3c2ee2b 100644 (file)
@@ -2964,6 +2964,7 @@ update ab_a1 set b = 3 from ab where ab.a = 1 and ab.a = ab_a1.a;
                            Index Cond: (a = 1)
                ->  Bitmap Heap Scan on ab_a1_b3 ab_a1_b3_1 (actual rows=0 loops=1)
                      Recheck Cond: (a = 1)
+                     Heap Blocks: exact=1
                      ->  Bitmap Index Scan on ab_a1_b3_a_idx (actual rows=1 loops=1)
                            Index Cond: (a = 1)
          ->  Materialize (actual rows=1 loops=1)
@@ -2985,14 +2986,16 @@ update ab_a1 set b = 3 from ab where ab.a = 1 and ab.a = ab_a1.a;
                            Index Cond: (a = 1)
                ->  Bitmap Heap Scan on ab_a1_b3 ab_a1_b3_1 (actual rows=0 loops=1)
                      Recheck Cond: (a = 1)
+                     Heap Blocks: exact=1
                      ->  Bitmap Index Scan on ab_a1_b3_a_idx (actual rows=1 loops=1)
                            Index Cond: (a = 1)
          ->  Materialize (actual rows=0 loops=1)
                ->  Bitmap Heap Scan on ab_a1_b3 (actual rows=0 loops=1)
                      Recheck Cond: (a = 1)
+                     Heap Blocks: exact=1
                      ->  Bitmap Index Scan on ab_a1_b3_a_idx (actual rows=1 loops=1)
                            Index Cond: (a = 1)
-(65 rows)
+(68 rows)
 
 table ab;
  a | b