Skip to content

Commit 2bb1f14

Browse files
committed
Make bitmap heap scans show exact/lossy block info in EXPLAIN ANALYZE.
Etsuro Fujita
1 parent c3ccc9e commit 2bb1f14

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

src/backend/commands/explain.c

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ static void show_sort_group_keys(PlanState *planstate, const char *qlabel,
8585
List *ancestors, ExplainState *es);
8686
static void show_sort_info(SortState *sortstate, ExplainState *es);
8787
static void show_hash_info(HashState *hashstate, ExplainState *es);
88+
static void show_tidbitmap_info(BitmapHeapScanState *planstate,
89+
ExplainState *es);
8890
static void show_instrumentation_count(const char *qlabel, int which,
8991
PlanState *planstate, ExplainState *es);
9092
static void show_foreignscan_info(ForeignScanState *fsstate, ExplainState *es);
@@ -1250,7 +1252,13 @@ ExplainNode(PlanState *planstate, List *ancestors,
12501252
if (((BitmapHeapScan *) plan)->bitmapqualorig)
12511253
show_instrumentation_count("Rows Removed by Index Recheck", 2,
12521254
planstate, es);
1253-
/* FALL THRU */
1255+
show_scan_qual(plan->qual, "Filter", planstate, ancestors, es);
1256+
if (plan->qual)
1257+
show_instrumentation_count("Rows Removed by Filter", 1,
1258+
planstate, es);
1259+
if (es->analyze)
1260+
show_tidbitmap_info((BitmapHeapScanState *) planstate, es);
1261+
break;
12541262
case T_SeqScan:
12551263
case T_ValuesScan:
12561264
case T_CteScan:
@@ -1878,6 +1886,29 @@ show_hash_info(HashState *hashstate, ExplainState *es)
18781886
}
18791887
}
18801888

1889+
/*
1890+
* If it's EXPLAIN ANALYZE, show exact/lossy pages for a BitmapHeapScan node
1891+
*/
1892+
static void
1893+
show_tidbitmap_info(BitmapHeapScanState *planstate, ExplainState *es)
1894+
{
1895+
if (es->format != EXPLAIN_FORMAT_TEXT)
1896+
{
1897+
ExplainPropertyLong("Exact Heap Blocks", planstate->exact_pages, es);
1898+
ExplainPropertyLong("Lossy Heap Blocks", planstate->lossy_pages, es);
1899+
}
1900+
else
1901+
{
1902+
appendStringInfoSpaces(es->str, es->indent * 2);
1903+
appendStringInfoString(es->str, "Heap Blocks:");
1904+
if (planstate->exact_pages > 0)
1905+
appendStringInfo(es->str, " exact=%ld", planstate->exact_pages);
1906+
if (planstate->lossy_pages > 0)
1907+
appendStringInfo(es->str, " lossy=%ld", planstate->lossy_pages);
1908+
appendStringInfoChar(es->str, '\n');
1909+
}
1910+
}
1911+
18811912
/*
18821913
* If it's EXPLAIN ANALYZE, show instrumentation information for a plan node
18831914
*

src/backend/executor/nodeBitmapHeapscan.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ BitmapHeapNext(BitmapHeapScanState *node)
170170
*/
171171
bitgetpage(scan, tbmres);
172172

173+
if (tbmres->ntuples >= 0)
174+
node->exact_pages++;
175+
else
176+
node->lossy_pages++;
177+
173178
/*
174179
* Set rs_cindex to first slot to examine
175180
*/
@@ -553,6 +558,8 @@ ExecInitBitmapHeapScan(BitmapHeapScan *node, EState *estate, int eflags)
553558
scanstate->tbm = NULL;
554559
scanstate->tbmiterator = NULL;
555560
scanstate->tbmres = NULL;
561+
scanstate->exact_pages = 0;
562+
scanstate->lossy_pages = 0;
556563
scanstate->prefetch_iterator = NULL;
557564
scanstate->prefetch_pages = 0;
558565
scanstate->prefetch_target = 0;

src/include/nodes/execnodes.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,6 +1338,8 @@ typedef struct BitmapIndexScanState
13381338
* tbm bitmap obtained from child index scan(s)
13391339
* tbmiterator iterator for scanning current pages
13401340
* tbmres current-page data
1341+
* exact_pages total number of exact pages retrieved
1342+
* lossy_pages total number of lossy pages retrieved
13411343
* prefetch_iterator iterator for prefetching ahead of current page
13421344
* prefetch_pages # pages prefetch iterator is ahead of current
13431345
* prefetch_target target prefetch distance
@@ -1350,6 +1352,8 @@ typedef struct BitmapHeapScanState
13501352
TIDBitmap *tbm;
13511353
TBMIterator *tbmiterator;
13521354
TBMIterateResult *tbmres;
1355+
long exact_pages;
1356+
long lossy_pages;
13531357
TBMIterator *prefetch_iterator;
13541358
int prefetch_pages;
13551359
int prefetch_target;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy