From 1eff8279d494b96f0073df78abc74954a2f6ee54 Mon Sep 17 00:00:00 2001 From: David Rowley Date: Fri, 5 Jul 2024 14:05:08 +1200 Subject: Add memory/disk usage for Material nodes in EXPLAIN Up until now, there was no ability to easily determine if a Material node caused the underlying tuplestore to spill to disk or even see how much memory the tuplestore used if it didn't. Here we add some new functions to tuplestore.c to query this information and add some additional output in EXPLAIN ANALYZE to display this information for the Material node. There are a few other executor node types that use tuplestores, so we could also consider adding these details to the EXPLAIN ANALYZE for those nodes too. Let's consider those independently from this. Having the tuplestore.c infrastructure in to allow that is step 1. Author: David Rowley Reviewed-by: Matthias van de Meent, Dmitry Dolgov Discussion: https://postgr.es/m/CAApHDvp5Py9g4Rjq7_inL3-MCK1Co2CRt_YWFwTU2zfQix0p4A@mail.gmail.com --- src/backend/commands/explain.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src/backend/commands/explain.c') diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c index 30de9de9d4f..1b5ab503898 100644 --- a/src/backend/commands/explain.c +++ b/src/backend/commands/explain.c @@ -125,6 +125,7 @@ static void show_sort_info(SortState *sortstate, ExplainState *es); static void show_incremental_sort_info(IncrementalSortState *incrsortstate, ExplainState *es); static void show_hash_info(HashState *hashstate, ExplainState *es); +static void show_material_info(MaterialState *mstate, ExplainState *es); static void show_memoize_info(MemoizeState *mstate, List *ancestors, ExplainState *es); static void show_hashagg_info(AggState *aggstate, ExplainState *es); @@ -2251,6 +2252,9 @@ ExplainNode(PlanState *planstate, List *ancestors, case T_Hash: show_hash_info(castNode(HashState, planstate), es); break; + case T_Material: + show_material_info(castNode(MaterialState, planstate), es); + break; case T_Memoize: show_memoize_info(castNode(MemoizeState, planstate), ancestors, es); @@ -3322,6 +3326,39 @@ show_hash_info(HashState *hashstate, ExplainState *es) } } +/* + * Show information on material node, storage method and maximum memory/disk + * space used. + */ +static void +show_material_info(MaterialState *mstate, ExplainState *es) +{ + Tuplestorestate *tupstore; + const char *storageType; + int64 spaceUsedKB; + + if (!es->analyze) + return; + + tupstore = mstate->tuplestorestate; + storageType = tuplestore_storage_type_name(tupstore); + spaceUsedKB = BYTES_TO_KILOBYTES(tuplestore_space_used(tupstore)); + + if (es->format != EXPLAIN_FORMAT_TEXT) + { + ExplainPropertyText("Storage", storageType, es); + ExplainPropertyInteger("Maximum Storage", "kB", spaceUsedKB, es); + } + else + { + ExplainIndentText(es); + appendStringInfo(es->str, + "Storage: %s Maximum Storage: " INT64_FORMAT "kB\n", + storageType, + spaceUsedKB); + } +} + /* * Show information on memoize hits/misses/evictions and memory usage. */ -- cgit v1.2.3