From 1d1671b2fffd3e3a8050364aec5a7f5d5add8d73 Mon Sep 17 00:00:00 2001 From: Justin Pryzby Date: Sat, 15 Feb 2020 14:13:06 -0600 Subject: [PATCH v7 3/9] Gross hack to put hash stats of subplans in the right(?) place --- src/backend/commands/explain.c | 70 ++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 32 deletions(-) diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c index e3f05da464..4c92256646 100644 --- a/src/backend/commands/explain.c +++ b/src/backend/commands/explain.c @@ -66,7 +66,7 @@ static double elapsed_time(instr_time *starttime); static bool ExplainPreScanNode(PlanState *planstate, Bitmapset **rels_used); static void ExplainNode(PlanState *planstate, List *ancestors, const char *relationship, const char *plan_name, - ExplainState *es); + SubPlanState *subplanstate, ExplainState *es); static void show_plan_tlist(PlanState *planstate, List *ancestors, ExplainState *es); static void show_expression(Node *node, const char *qlabel, @@ -721,7 +721,7 @@ ExplainPrintPlan(ExplainState *es, QueryDesc *queryDesc) ps = outerPlanState(ps); es->hide_workers = true; } - ExplainNode(ps, NIL, NULL, NULL, es); + ExplainNode(ps, NIL, NULL, NULL, NULL, es); /* * If requested, include information about GUC parameters with values that @@ -1083,7 +1083,7 @@ ExplainPreScanNode(PlanState *planstate, Bitmapset **rels_used) static void ExplainNode(PlanState *planstate, List *ancestors, const char *relationship, const char *plan_name, - ExplainState *es) + SubPlanState *subplanstate, ExplainState *es) { Plan *plan = planstate->plan; const char *pname; /* node type name for text output */ @@ -1340,6 +1340,21 @@ ExplainNode(PlanState *planstate, List *ancestors, ExplainIndentText(es); appendStringInfo(es->str, "%s\n", plan_name); es->indent++; + + Assert(subplanstate != NULL); + /* Show hash stats for hashed subplan */ + if (subplanstate->hashtable) + { + ExplainIndentText(es); + appendStringInfoString(es->str, "Hashtable: "); + show_tuplehash_info(&subplanstate->hashtable->instrument, es); + } + if (subplanstate->hashnulls) + { + ExplainIndentText(es); + appendStringInfoString(es->str, "Null Hashtable: "); + show_tuplehash_info(&subplanstate->hashnulls->instrument, es); + } } if (es->indent) { @@ -1368,6 +1383,20 @@ ExplainNode(PlanState *planstate, List *ancestors, if (custom_name) ExplainPropertyText("Custom Plan Provider", custom_name, es); ExplainPropertyBool("Parallel Aware", plan->parallel_aware, es); + + if (subplanstate && subplanstate->hashtable) + { + ExplainOpenGroup("Hashtable", "Hashtable", true, es); + show_tuplehash_info(&subplanstate->hashtable->instrument, es); + ExplainCloseGroup("Hashtable", "Hashtable", true, es); + } + + if (subplanstate && subplanstate->hashnulls) + { + ExplainOpenGroup("Null Hashtable", "Null Hashtable", true, es); + show_tuplehash_info(&subplanstate->hashnulls->instrument, es); + ExplainCloseGroup("Null Hashtable", "Null Hashtable", true, es); + } } switch (nodeTag(plan)) @@ -2040,12 +2069,12 @@ ExplainNode(PlanState *planstate, List *ancestors, /* lefttree */ if (outerPlanState(planstate)) ExplainNode(outerPlanState(planstate), ancestors, - "Outer", NULL, es); + "Outer", NULL, NULL, es); /* righttree */ if (innerPlanState(planstate)) ExplainNode(innerPlanState(planstate), ancestors, - "Inner", NULL, es); + "Inner", NULL, NULL, es); /* special child plans */ switch (nodeTag(plan)) @@ -2077,7 +2106,7 @@ ExplainNode(PlanState *planstate, List *ancestors, break; case T_SubqueryScan: ExplainNode(((SubqueryScanState *) planstate)->subplan, ancestors, - "Subquery", NULL, es); + "Subquery", NULL, NULL, es); break; case T_CustomScan: ExplainCustomChildren((CustomScanState *) planstate, @@ -3480,7 +3509,7 @@ ExplainMemberNodes(PlanState **planstates, int nplans, for (j = 0; j < nplans; j++) ExplainNode(planstates[j], ancestors, - "Member", NULL, es); + "Member", NULL, NULL, es); } /* @@ -3538,30 +3567,7 @@ ExplainSubPlans(List *plans, List *ancestors, ancestors = lcons(sp, ancestors); ExplainNode(sps->planstate, ancestors, - relationship, sp->plan_name, es); - if (sps->hashtable) - { - ExplainOpenGroup("Hashtable", "Hashtable", true, es); - if (es->format == EXPLAIN_FORMAT_TEXT) - { - ExplainIndentText(es); - appendStringInfoString(es->str, "Hashtable: "); - } - show_tuplehash_info(&sps->hashtable->instrument, es); - ExplainCloseGroup("Hashtable", "Hashtable", true, es); - } - - if (sps->hashnulls) - { - ExplainOpenGroup("Null Hashtable", "Null Hashtable", true, es); - if (es->format == EXPLAIN_FORMAT_TEXT) - { - ExplainIndentText(es); - appendStringInfoString(es->str, "Null Hashtable: "); - } - show_tuplehash_info(&sps->hashnulls->instrument, es); - ExplainCloseGroup("Null Hashtable", "Null Hashtable", true, es); - } + relationship, sp->plan_name, sps, es); ancestors = list_delete_first(ancestors); } @@ -3578,7 +3584,7 @@ ExplainCustomChildren(CustomScanState *css, List *ancestors, ExplainState *es) (list_length(css->custom_ps) != 1 ? "children" : "child"); foreach(cell, css->custom_ps) - ExplainNode((PlanState *) lfirst(cell), ancestors, label, NULL, es); + ExplainNode((PlanState *) lfirst(cell), ancestors, label, NULL, NULL, es); } /* -- 2.17.0