From 9fba1ed2947382af213dfbfabfcd8898c89bf4ca Mon Sep 17 00:00:00 2001 From: David Rowley Date: Thu, 12 Sep 2024 16:02:01 +1200 Subject: Adjust tuplestore stats API 1eff8279d added an API to tuplestore.c to allow callers to obtain storage telemetry data. That API wasn't quite good enough for callers that perform tuplestore_clear() as the telemetry functions only accounted for the current state of the tuplestore, not the maximums before tuplestore_clear() was called. There's a pending patch that would like to add tuplestore telemetry output to EXPLAIN ANALYZE for WindowAgg. That node type uses tuplestore_clear() before moving to the next window partition and we want to show the maximum space used, not the space used for the final partition. Reviewed-by: Tatsuo Ishii, Ashutosh Bapat Discussion: https://postgres/m/CAApHDvoY8cibGcicLV0fNh=9JVx9PANcWvhkdjBnDCc9Quqytg@mail.gmail.com --- src/backend/commands/explain.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src/backend/commands/explain.c') diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c index 14cd36c87c5..2819e479f82 100644 --- a/src/backend/commands/explain.c +++ b/src/backend/commands/explain.c @@ -3350,8 +3350,9 @@ static void show_material_info(MaterialState *mstate, ExplainState *es) { Tuplestorestate *tupstore = mstate->tuplestorestate; - const char *storageType; - int64 spaceUsedKB; + char *maxStorageType; + int64 maxSpaceUsed, + maxSpaceUsedKB; /* * Nothing to show if ANALYZE option wasn't used or if execution didn't @@ -3360,21 +3361,21 @@ show_material_info(MaterialState *mstate, ExplainState *es) if (!es->analyze || tupstore == NULL) return; - storageType = tuplestore_storage_type_name(tupstore); - spaceUsedKB = BYTES_TO_KILOBYTES(tuplestore_space_used(tupstore)); + tuplestore_get_stats(tupstore, &maxStorageType, &maxSpaceUsed); + maxSpaceUsedKB = BYTES_TO_KILOBYTES(maxSpaceUsed); if (es->format != EXPLAIN_FORMAT_TEXT) { - ExplainPropertyText("Storage", storageType, es); - ExplainPropertyInteger("Maximum Storage", "kB", spaceUsedKB, es); + ExplainPropertyText("Storage", maxStorageType, es); + ExplainPropertyInteger("Maximum Storage", "kB", maxSpaceUsedKB, es); } else { ExplainIndentText(es); appendStringInfo(es->str, "Storage: %s Maximum Storage: " INT64_FORMAT "kB\n", - storageType, - spaceUsedKB); + maxStorageType, + maxSpaceUsedKB); } } -- cgit v1.2.3