From 524f4b2d1064d482ba968d46afb081563e97a653 Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Wed, 21 Oct 1998 16:21:29 +0000 Subject: The patch does 2 things: Fixes a bug in the rule system that caused a crashing backend when a join-view with calculated column is used in subselect. Modifies EXPLAIN to explain rewritten queries instead of the plain SeqScan on a view. Rules can produce very deep MORE Jan. --- src/backend/commands/explain.c | 52 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 9 deletions(-) (limited to 'src/backend/commands/explain.c') diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c index 63534050f1c..1b861c96204 100644 --- a/src/backend/commands/explain.c +++ b/src/backend/commands/explain.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/explain.c,v 1.24 1998/09/01 04:27:53 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/explain.c,v 1.25 1998/10/21 16:21:20 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -26,6 +26,7 @@ #include #include #include +#include typedef struct ExplainState { @@ -37,6 +38,8 @@ typedef struct ExplainState } ExplainState; static char *Explain_PlanToString(Plan *plan, ExplainState *es); +static void ExplainOneQuery(Query *query, bool verbose, CommandDest dest); + /* * ExplainQuery - @@ -46,11 +49,8 @@ static char *Explain_PlanToString(Plan *plan, ExplainState *es); void ExplainQuery(Query *query, bool verbose, CommandDest dest) { - char *s = NULL, - *s2; - Plan *plan; - ExplainState *es; - int len; + List *rewritten; + List *l; if (IsAbortedTransactionBlockState()) { @@ -64,6 +64,35 @@ ExplainQuery(Query *query, bool verbose, CommandDest dest) return; } + /* Rewrite through rule system */ + rewritten = QueryRewrite(query); + + /* In the case of an INSTEAD NOTHING, tell at least that */ + if (rewritten == NIL) + { + elog(NOTICE, "query rewrites to nothing"); + return; + } + + /* Explain every plan */ + foreach(l, rewritten) + ExplainOneQuery(lfirst(l), verbose, dest); +} + +/* + * ExplainOneQuery - + * print out the execution plan for one query + * + */ +static void +ExplainOneQuery(Query *query, bool verbose, CommandDest dest) +{ + char *s = NULL, + *s2; + Plan *plan; + ExplainState *es; + int len; + /* plan the queries (XXX we've ignored rewrite!!) */ plan = planner(query); @@ -202,8 +231,13 @@ explain_outNode(StringInfo str, Plan *plan, int indent, ExplainState *es) { RangeTblEntry *rte = nth(((Scan *) plan)->scanrelid - 1, es->rtable); - sprintf(buf, " on %s", rte->refname); - appendStringInfo(str, buf); + appendStringInfo(str, " on "); + if (strcmp(rte->refname, rte->relname) != 0) + { + sprintf(buf, "%s ", rte->relname); + appendStringInfo(str, buf); + } + appendStringInfo(str, rte->refname); } break; default: @@ -232,7 +266,7 @@ explain_outNode(StringInfo str, Plan *plan, int indent, ExplainState *es) for (i = 0; i < indent; i++) appendStringInfo(str, " "); appendStringInfo(str, " -> "); - explain_outNode(str, ((SubPlan *) lfirst(lst))->plan, indent + 4, es); + explain_outNode(str, ((SubPlan *) lfirst(lst))->plan, indent + 2, es); } es->rtable = saved_rtable; } -- cgit v1.2.3