From fbcce08046bc553901ccbcf1ea6cf82f61968970 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sun, 5 Apr 2009 19:59:40 +0000 Subject: Change EXPLAIN output so that subplans and initplans (particularly CTEs) are individually labeled, rather than just grouped under an "InitPlan" or "SubPlan" heading. This in turn makes it possible for decompilation of a subplan reference to usefully identify which subplan it's referencing. I also made InitPlans identify which parameter symbol(s) they compute, so that references to those parameters elsewhere in the plan tree can be connected to the initplan that will be executed. Per a gripe from Robert Haas about EXPLAIN output of a WITH query being inadequate, plus some longstanding pet peeves of my own. --- src/backend/utils/adt/ruleutils.c | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) (limited to 'src/backend/utils/adt/ruleutils.c') diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index f05e6a2cb93..8d06f54e479 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.296 2009/02/25 18:00:01 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.297 2009/04/05 19:59:40 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -4404,20 +4404,42 @@ get_rule_expr(Node *node, deparse_context *context, case T_SubPlan: { + SubPlan *subplan = (SubPlan *) node; + /* * We cannot see an already-planned subplan in rule deparsing, - * only while EXPLAINing a query plan. For now, just punt. + * only while EXPLAINing a query plan. We don't try to + * reconstruct the original SQL, just reference the subplan + * that appears elsewhere in EXPLAIN's result. */ - if (((SubPlan *) node)->useHashTable) - appendStringInfo(buf, "(hashed subplan)"); + if (subplan->useHashTable) + appendStringInfo(buf, "(hashed %s)", subplan->plan_name); else - appendStringInfo(buf, "(subplan)"); + appendStringInfo(buf, "(%s)", subplan->plan_name); } break; case T_AlternativeSubPlan: - /* As above, just punt */ - appendStringInfo(buf, "(alternative subplans)"); + { + AlternativeSubPlan *asplan = (AlternativeSubPlan *) node; + ListCell *lc; + + /* As above, this can only happen during EXPLAIN */ + appendStringInfo(buf, "(alternatives: "); + foreach(lc, asplan->subplans) + { + SubPlan *splan = (SubPlan *) lfirst(lc); + + Assert(IsA(splan, SubPlan)); + if (splan->useHashTable) + appendStringInfo(buf, "hashed %s", splan->plan_name); + else + appendStringInfo(buf, "%s", splan->plan_name); + if (lnext(lc)) + appendStringInfo(buf, " or "); + } + appendStringInfo(buf, ")"); + } break; case T_FieldSelect: -- cgit v1.2.3