diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2009-04-05 19:59:40 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2009-04-05 19:59:40 +0000 |
commit | fbcce08046bc553901ccbcf1ea6cf82f61968970 (patch) | |
tree | 8848ad80ceb71406bf111bb2c99b3c1240410f00 /src/backend/utils/adt/ruleutils.c | |
parent | 329a5322e9280bde04907f947ada2e2627ef41c2 (diff) | |
download | postgresql-fbcce08046bc553901ccbcf1ea6cf82f61968970.tar.gz postgresql-fbcce08046bc553901ccbcf1ea6cf82f61968970.zip |
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.
Diffstat (limited to 'src/backend/utils/adt/ruleutils.c')
-rw-r--r-- | src/backend/utils/adt/ruleutils.c | 36 |
1 files changed, 29 insertions, 7 deletions
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: |