aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/explain.c
diff options
context:
space:
mode:
authorTatsuo Ishii <ishii@postgresql.org>2024-09-17 14:38:53 +0900
committerTatsuo Ishii <ishii@postgresql.org>2024-09-17 14:38:53 +0900
commit95d6e9af07d2e5af2fdd272e72b5b552bad3ea0a (patch)
treec9103286d6a8eaf06751b11eaa38df7661d55af8 /src/backend/commands/explain.c
parent1bbf1e2f1a077905037272cd4767e952f34c02b3 (diff)
downloadpostgresql-95d6e9af07d2e5af2fdd272e72b5b552bad3ea0a.tar.gz
postgresql-95d6e9af07d2e5af2fdd272e72b5b552bad3ea0a.zip
Add memory/disk usage for Window aggregate nodes in EXPLAIN.
This commit is similar to 1eff8279d and expands the idea to Window aggregate nodes so that users can know how much memory or disk the tuplestore used. This commit uses newly introduced tuplestore_get_stats() to inquire this information and add some additional output in EXPLAIN ANALYZE to display the information for the Window aggregate node. Reviewed-by: David Rowley, Ashutosh Bapat, Maxim Orlov, Jian He Discussion: https://postgr.es/m/20240706.202254.89740021795421286.ishii%40postgresql.org
Diffstat (limited to 'src/backend/commands/explain.c')
-rw-r--r--src/backend/commands/explain.c68
1 files changed, 50 insertions, 18 deletions
diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c
index 2819e479f82..aaec439892c 100644
--- a/src/backend/commands/explain.c
+++ b/src/backend/commands/explain.c
@@ -120,6 +120,7 @@ static void show_sort_group_keys(PlanState *planstate, const char *qlabel,
List *ancestors, ExplainState *es);
static void show_sortorder_options(StringInfo buf, Node *sortexpr,
Oid sortOperator, Oid collation, bool nullsFirst);
+static void show_storage_info(Tuplestorestate *tupstore, ExplainState *es);
static void show_tablesample(TableSampleClause *tsc, PlanState *planstate,
List *ancestors, ExplainState *es);
static void show_sort_info(SortState *sortstate, ExplainState *es);
@@ -127,6 +128,7 @@ 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_windowagg_info(WindowAggState *winstate, ExplainState *es);
static void show_memoize_info(MemoizeState *mstate, List *ancestors,
ExplainState *es);
static void show_hashagg_info(AggState *aggstate, ExplainState *es);
@@ -2231,6 +2233,7 @@ ExplainNode(PlanState *planstate, List *ancestors,
planstate, es);
show_upper_qual(((WindowAgg *) plan)->runConditionOrig,
"Run Condition", planstate, ancestors, es);
+ show_windowagg_info(castNode(WindowAggState, planstate), es);
break;
case T_Group:
show_group_keys(castNode(GroupState, planstate), ancestors, es);
@@ -2895,6 +2898,34 @@ show_sortorder_options(StringInfo buf, Node *sortexpr,
}
/*
+ * Show information on storage method and maximum memory/disk space used.
+ */
+static void
+show_storage_info(Tuplestorestate *tupstore, ExplainState *es)
+{
+ char *maxStorageType;
+ int64 maxSpaceUsed,
+ maxSpaceUsedKB;
+
+ tuplestore_get_stats(tupstore, &maxStorageType, &maxSpaceUsed);
+ maxSpaceUsedKB = BYTES_TO_KILOBYTES(maxSpaceUsed);
+
+ if (es->format != EXPLAIN_FORMAT_TEXT)
+ {
+ ExplainPropertyText("Storage", maxStorageType, es);
+ ExplainPropertyInteger("Maximum Storage", "kB", maxSpaceUsedKB, es);
+ }
+ else
+ {
+ ExplainIndentText(es);
+ appendStringInfo(es->str,
+ "Storage: %s Maximum Storage: " INT64_FORMAT "kB\n",
+ maxStorageType,
+ maxSpaceUsedKB);
+ }
+}
+
+/*
* Show TABLESAMPLE properties
*/
static void
@@ -3350,9 +3381,6 @@ static void
show_material_info(MaterialState *mstate, ExplainState *es)
{
Tuplestorestate *tupstore = mstate->tuplestorestate;
- char *maxStorageType;
- int64 maxSpaceUsed,
- maxSpaceUsedKB;
/*
* Nothing to show if ANALYZE option wasn't used or if execution didn't
@@ -3361,22 +3389,26 @@ show_material_info(MaterialState *mstate, ExplainState *es)
if (!es->analyze || tupstore == NULL)
return;
- tuplestore_get_stats(tupstore, &maxStorageType, &maxSpaceUsed);
- maxSpaceUsedKB = BYTES_TO_KILOBYTES(maxSpaceUsed);
+ show_storage_info(tupstore, es);
+}
- if (es->format != EXPLAIN_FORMAT_TEXT)
- {
- ExplainPropertyText("Storage", maxStorageType, es);
- ExplainPropertyInteger("Maximum Storage", "kB", maxSpaceUsedKB, es);
- }
- else
- {
- ExplainIndentText(es);
- appendStringInfo(es->str,
- "Storage: %s Maximum Storage: " INT64_FORMAT "kB\n",
- maxStorageType,
- maxSpaceUsedKB);
- }
+/*
+ * Show information on WindowAgg node, storage method and maximum memory/disk
+ * space used.
+ */
+static void
+show_windowagg_info(WindowAggState *winstate, ExplainState *es)
+{
+ Tuplestorestate *tupstore = winstate->buffer;
+
+ /*
+ * Nothing to show if ANALYZE option wasn't used or if execution didn't
+ * get as far as creating the tuplestore.
+ */
+ if (!es->analyze || tupstore == NULL)
+ return;
+
+ show_storage_info(tupstore, es);
}
/*