v2-0007-BitmapHeapScan-scan-desc-counts-lossy-and-exact-p.patch
text/x-patch
Filename: v2-0007-BitmapHeapScan-scan-desc-counts-lossy-and-exact-p.patch
Type: text/x-patch
Part: 5
Patch
Format: format-patch
Series: patch v2-0007
Subject: BitmapHeapScan scan desc counts lossy and exact pages
| File | + | − |
|---|---|---|
| src/backend/access/heap/heapam_handler.c | 9 | 0 |
| src/backend/executor/nodeBitmapHeapscan.c | 14 | 5 |
| src/include/access/relscan.h | 4 | 0 |
| src/include/access/tableam.h | 5 | 1 |
From 224a7e4e8eb7106c1e7159df8ca3d7ede6732be8 Mon Sep 17 00:00:00 2001
From: Melanie Plageman <melanieplageman@gmail.com>
Date: Tue, 13 Feb 2024 10:05:04 -0500
Subject: [PATCH v2 07/13] BitmapHeapScan scan desc counts lossy and exact
pages
Future commits will remove the TBMIterateResult from BitmapHeapNext(),
pushing it into the table AM-specific code. So we will have to keep
track of the number of lossy and exact pages in the scan descriptor.
Doing this change to lossy/exact page counting in a separate commit just
simplifies the diff.
---
src/backend/access/heap/heapam_handler.c | 9 +++++++++
src/backend/executor/nodeBitmapHeapscan.c | 19 ++++++++++++++-----
src/include/access/relscan.h | 4 ++++
src/include/access/tableam.h | 6 +++++-
4 files changed, 32 insertions(+), 6 deletions(-)
diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c
index d775756fa53..3af9466b9ca 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -2242,6 +2242,15 @@ heapam_scan_bitmap_next_block(TableScanDesc scan,
Assert(ntup <= MaxHeapTuplesPerPage);
hscan->rs_ntuples = ntup;
+ /* Only count exact and lossy pages with visible tuples */
+ if (ntup > 0)
+ {
+ if (tbmres->ntuples >= 0)
+ scan->exact_pages++;
+ else
+ scan->lossy_pages++;
+ }
+
return ntup > 0;
}
diff --git a/src/backend/executor/nodeBitmapHeapscan.c b/src/backend/executor/nodeBitmapHeapscan.c
index c884771e826..3b89e7e6c63 100644
--- a/src/backend/executor/nodeBitmapHeapscan.c
+++ b/src/backend/executor/nodeBitmapHeapscan.c
@@ -53,6 +53,8 @@
#include "utils/spccache.h"
static TupleTableSlot *BitmapHeapNext(BitmapHeapScanState *node);
+static inline void BitmapAccumCounters(BitmapHeapScanState *node,
+ TableScanDesc scan);
static inline void BitmapDoneInitializingSharedState(ParallelBitmapHeapState *pstate);
static inline void BitmapAdjustPrefetchIterator(BitmapHeapScanState *node,
BlockNumber blockno);
@@ -246,11 +248,6 @@ BitmapHeapNext(BitmapHeapScanState *node)
continue;
}
- if (tbmres->ntuples >= 0)
- node->exact_pages++;
- else
- node->lossy_pages++;
-
/* Adjust the prefetch target */
BitmapAdjustPrefetchTarget(node);
}
@@ -321,15 +318,27 @@ BitmapHeapNext(BitmapHeapScanState *node)
}
/* OK to return this tuple */
+ BitmapAccumCounters(node, scan);
return slot;
}
/*
* if we get here it means we are at the end of the scan..
*/
+ BitmapAccumCounters(node, scan);
return ExecClearTuple(slot);
}
+static inline void
+BitmapAccumCounters(BitmapHeapScanState *node,
+ TableScanDesc scan)
+{
+ node->exact_pages += scan->exact_pages;
+ scan->exact_pages = 0;
+ node->lossy_pages += scan->lossy_pages;
+ scan->lossy_pages = 0;
+}
+
/*
* BitmapDoneInitializingSharedState - Shared state is initialized
*
diff --git a/src/include/access/relscan.h b/src/include/access/relscan.h
index 521043304ab..b74e08dd745 100644
--- a/src/include/access/relscan.h
+++ b/src/include/access/relscan.h
@@ -40,6 +40,10 @@ typedef struct TableScanDescData
ItemPointerData rs_mintid;
ItemPointerData rs_maxtid;
+ /* Only used for Bitmap table scans */
+ long exact_pages;
+ long lossy_pages;
+
/*
* Information about type and behaviour of the scan, a bitmask of members
* of the ScanOptions enum (see tableam.h).
diff --git a/src/include/access/tableam.h b/src/include/access/tableam.h
index b5d65a9528c..a3e30c4eda7 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -942,9 +942,13 @@ table_beginscan_bm(Relation rel, Snapshot snapshot,
int nkeys, struct ScanKeyData *key,
uint32 extra_flags)
{
+ TableScanDesc result;
uint32 flags = SO_TYPE_BITMAPSCAN | SO_ALLOW_PAGEMODE | extra_flags;
- return rel->rd_tableam->scan_begin(rel, snapshot, nkeys, key, NULL, flags);
+ result = rel->rd_tableam->scan_begin(rel, snapshot, nkeys, key, NULL, flags);
+ result->lossy_pages = 0;
+ result->exact_pages = 0;
+ return result;
}
/*
--
2.37.2