1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-30 21:42:05 +03:00

Show Parallel Bitmap Heap Scan worker stats in EXPLAIN ANALYZE

Nodes like Memoize report the cache stats for each parallel worker, so it
makes sense to show the exact and lossy pages in Parallel Bitmap Heap Scan
in a similar way.  Likewise, Sort shows the method and memory used for
each worker.

There was some discussion on whether the leader stats should include the
totals for each parallel worker or not.  I did some analysis on this to
see what other parallel node types do and it seems only Parallel Hash does
anything like this.  All the rest, per what's supported by
ExecParallelRetrieveInstrumentation() are consistent with each other.

Author: David Geier <geidav.pg@gmail.com>
Author: Heikki Linnakangas <hlinnaka@iki.fi>
Author: Donghang Lin <donghanglin@gmail.com>
Author: Alena Rybakina <lena.ribackina@yandex.ru>
Author: David Rowley <dgrowleyml@gmail.com>
Reviewed-by: Dmitry Dolgov <9erthalion6@gmail.com>
Reviewed-by: Michael Christofides <michael@pgmustard.com>
Reviewed-by: Robert Haas <robertmhaas@gmail.com>
Reviewed-by: Dilip Kumar <dilipbalaut@gmail.com>
Reviewed-by: Tomas Vondra <tomas.vondra@enterprisedb.com>
Reviewed-by: Melanie Plageman <melanieplageman@gmail.com>
Reviewed-by: Donghang Lin <donghanglin@gmail.com>
Reviewed-by: Masahiro Ikeda <Masahiro.Ikeda@nttdata.com>
Discussion: https://postgr.es/m/b3d80961-c2e5-38cc-6a32-61886cdf766d%40gmail.com
This commit is contained in:
David Rowley
2024-07-09 12:15:47 +12:00
parent e41f713097
commit 5a1e6df3b8
6 changed files with 181 additions and 23 deletions

View File

@ -2010,8 +2010,7 @@ ExplainNode(PlanState *planstate, List *ancestors,
if (plan->qual)
show_instrumentation_count("Rows Removed by Filter", 1,
planstate, es);
if (es->analyze)
show_tidbitmap_info((BitmapHeapScanState *) planstate, es);
show_tidbitmap_info((BitmapHeapScanState *) planstate, es);
break;
case T_SampleScan:
show_tablesample(((SampleScan *) plan)->tablesample,
@ -3628,31 +3627,70 @@ show_hashagg_info(AggState *aggstate, ExplainState *es)
}
/*
* If it's EXPLAIN ANALYZE, show exact/lossy pages for a BitmapHeapScan node
* Show exact/lossy pages for a BitmapHeapScan node
*/
static void
show_tidbitmap_info(BitmapHeapScanState *planstate, ExplainState *es)
{
if (!es->analyze)
return;
if (es->format != EXPLAIN_FORMAT_TEXT)
{
ExplainPropertyUInteger("Exact Heap Blocks", NULL,
planstate->exact_pages, es);
planstate->stats.exact_pages, es);
ExplainPropertyUInteger("Lossy Heap Blocks", NULL,
planstate->lossy_pages, es);
planstate->stats.lossy_pages, es);
}
else
{
if (planstate->exact_pages > 0 || planstate->lossy_pages > 0)
if (planstate->stats.exact_pages > 0 || planstate->stats.lossy_pages > 0)
{
ExplainIndentText(es);
appendStringInfoString(es->str, "Heap Blocks:");
if (planstate->exact_pages > 0)
appendStringInfo(es->str, " exact=" UINT64_FORMAT, planstate->exact_pages);
if (planstate->lossy_pages > 0)
appendStringInfo(es->str, " lossy=" UINT64_FORMAT, planstate->lossy_pages);
if (planstate->stats.exact_pages > 0)
appendStringInfo(es->str, " exact=" UINT64_FORMAT, planstate->stats.exact_pages);
if (planstate->stats.lossy_pages > 0)
appendStringInfo(es->str, " lossy=" UINT64_FORMAT, planstate->stats.lossy_pages);
appendStringInfoChar(es->str, '\n');
}
}
/* Display stats for each parallel worker */
if (planstate->pstate != NULL)
{
for (int n = 0; n < planstate->sinstrument->num_workers; n++)
{
BitmapHeapScanInstrumentation *si = &planstate->sinstrument->sinstrument[n];
if (si->exact_pages == 0 && si->lossy_pages == 0)
continue;
if (es->workers_state)
ExplainOpenWorker(n, es);
if (es->format == EXPLAIN_FORMAT_TEXT)
{
ExplainIndentText(es);
appendStringInfoString(es->str, "Heap Blocks:");
if (si->exact_pages > 0)
appendStringInfo(es->str, " exact=" UINT64_FORMAT, si->exact_pages);
if (si->lossy_pages > 0)
appendStringInfo(es->str, " lossy=" UINT64_FORMAT, si->lossy_pages);
appendStringInfoChar(es->str, '\n');
}
else
{
ExplainPropertyUInteger("Exact Heap Blocks", NULL,
si->exact_pages, es);
ExplainPropertyUInteger("Lossy Heap Blocks", NULL,
si->lossy_pages, es);
}
if (es->workers_state)
ExplainCloseWorker(n, es);
}
}
}
/*