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

Commit 7bd7aa4

Browse files
Move EXPLAIN counter increment to heapam_scan_bitmap_next_block
Increment the lossy and exact page counters for EXPLAIN of bitmap heap scans in heapam_scan_bitmap_next_block(). Note that other table AMs will need to do this as well Pushing the counters into heapam_scan_bitmap_next_block() is required to be able to use the read stream API for bitmap heap scans. The bitmap iterator must be advanced from inside the read stream callback, so TBMIterateResults cannot be used as a flow control mechanism in BitmapHeapNext(). Author: Melanie Plageman Reviewed-by: Tomas Vondra, Heikki Linnakangas Discussion: https://postgr.es/m/063e4eb4-32d9-439e-a0b1-75565a9835a8%40iki.fi
1 parent 8e7e672 commit 7bd7aa4

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
lines changed

src/backend/access/heap/heapam_handler.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2115,7 +2115,8 @@ heapam_estimate_rel_size(Relation rel, int32 *attr_widths,
21152115

21162116
static bool
21172117
heapam_scan_bitmap_next_block(TableScanDesc scan,
2118-
TBMIterateResult *tbmres)
2118+
TBMIterateResult *tbmres,
2119+
uint64 *lossy_pages, uint64 *exact_pages)
21192120
{
21202121
HeapScanDesc hscan = (HeapScanDesc) scan;
21212122
BlockNumber block = tbmres->blockno;
@@ -2243,6 +2244,11 @@ heapam_scan_bitmap_next_block(TableScanDesc scan,
22432244
Assert(ntup <= MaxHeapTuplesPerPage);
22442245
hscan->rs_ntuples = ntup;
22452246

2247+
if (tbmres->ntuples >= 0)
2248+
(*exact_pages)++;
2249+
else
2250+
(*lossy_pages)++;
2251+
22462252
return ntup > 0;
22472253
}
22482254

src/backend/executor/nodeBitmapHeapscan.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,6 @@ BitmapHeapNext(BitmapHeapScanState *node)
212212

213213
for (;;)
214214
{
215-
bool valid_block;
216-
217215
CHECK_FOR_INTERRUPTS();
218216

219217
/*
@@ -233,14 +231,9 @@ BitmapHeapNext(BitmapHeapScanState *node)
233231

234232
BitmapAdjustPrefetchIterator(node, tbmres->blockno);
235233

236-
valid_block = table_scan_bitmap_next_block(scan, tbmres);
237-
238-
if (tbmres->ntuples >= 0)
239-
node->stats.exact_pages++;
240-
else
241-
node->stats.lossy_pages++;
242-
243-
if (!valid_block)
234+
if (!table_scan_bitmap_next_block(scan, tbmres,
235+
&node->stats.lossy_pages,
236+
&node->stats.exact_pages))
244237
{
245238
/* AM doesn't think this block is valid, skip */
246239
continue;

src/include/access/tableam.h

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,10 @@ typedef struct TableAmRoutine
796796
* on the page have to be returned, otherwise the tuples at offsets in
797797
* `tbmres->offsets` need to be returned.
798798
*
799+
* `lossy_pages` and `exact_pages` are EXPLAIN counters that can be
800+
* incremented by the table AM to indicate whether or not the block's
801+
* representation in the bitmap is lossy.
802+
*
799803
* XXX: Currently this may only be implemented if the AM uses md.c as its
800804
* storage manager, and uses ItemPointer->ip_blkid in a manner that maps
801805
* blockids directly to the underlying storage. nodeBitmapHeapscan.c
@@ -811,7 +815,9 @@ typedef struct TableAmRoutine
811815
* scan_bitmap_next_tuple need to exist, or neither.
812816
*/
813817
bool (*scan_bitmap_next_block) (TableScanDesc scan,
814-
struct TBMIterateResult *tbmres);
818+
struct TBMIterateResult *tbmres,
819+
uint64 *lossy_pages,
820+
uint64 *exact_pages);
815821

816822
/*
817823
* Fetch the next tuple of a bitmap table scan into `slot` and return true
@@ -1954,12 +1960,18 @@ table_relation_estimate_size(Relation rel, int32 *attr_widths,
19541960
* table_beginscan_bm(). Returns false if there are no tuples to be found on
19551961
* the page, true otherwise.
19561962
*
1963+
* `lossy_pages` and `exact_pages` are EXPLAIN counters that can be
1964+
* incremented by the table AM to indicate whether or not the block's
1965+
* representation in the bitmap is lossy.
1966+
*
19571967
* Note, this is an optionally implemented function, therefore should only be
19581968
* used after verifying the presence (at plan time or such).
19591969
*/
19601970
static inline bool
19611971
table_scan_bitmap_next_block(TableScanDesc scan,
1962-
struct TBMIterateResult *tbmres)
1972+
struct TBMIterateResult *tbmres,
1973+
uint64 *lossy_pages,
1974+
uint64 *exact_pages)
19631975
{
19641976
/*
19651977
* We don't expect direct calls to table_scan_bitmap_next_block with valid
@@ -1970,7 +1982,9 @@ table_scan_bitmap_next_block(TableScanDesc scan,
19701982
elog(ERROR, "unexpected table_scan_bitmap_next_block call during logical decoding");
19711983

19721984
return scan->rs_rd->rd_tableam->scan_bitmap_next_block(scan,
1973-
tbmres);
1985+
tbmres,
1986+
lossy_pages,
1987+
exact_pages);
19741988
}
19751989

19761990
/*

0 commit comments

Comments
 (0)