Commit 4415e481 authored by Bruce Momjian's avatar Bruce Momjian

Improved EXPLAIN option handling.

parent e981bcb0
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/explain.c,v 1.5 1996/12/03 05:50:11 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/explain.c,v 1.6 1996/12/29 00:53:20 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -43,7 +43,7 @@ static char *Explain_PlanToString(Plan *plan, ExplainState *es); ...@@ -43,7 +43,7 @@ static char *Explain_PlanToString(Plan *plan, ExplainState *es);
void void
ExplainQuery(Query *query, List *options, CommandDest dest) ExplainQuery(Query *query, List *options, CommandDest dest)
{ {
char *s; char *s = NULL, *s2;
Plan *plan; Plan *plan;
ExplainState *es; ExplainState *es;
int len; int len;
...@@ -69,21 +69,31 @@ ExplainQuery(Query *query, List *options, CommandDest dest) ...@@ -69,21 +69,31 @@ ExplainQuery(Query *query, List *options, CommandDest dest)
memset(es, 0, sizeof(ExplainState)); memset(es, 0, sizeof(ExplainState));
/* parse options */ /* parse options */
es->printCost = 1; /* default */
while (options) { while (options) {
char *ostr = strVal(lfirst(options)); char *ostr = strVal(lfirst(options));
if (!strcasecmp(ostr, "cost")) if (!strcasecmp(ostr, "cost"))
es->printCost = 1; es->printCost = 1;
else if (!strcasecmp(ostr, "full_plan")) else if (!strcasecmp(ostr, "full"))
es->printNodes = 1; es->printNodes = 1;
else
elog(WARN, "Unknown EXPLAIN option: %s", ostr);
options = lnext(options); options = lnext(options);
} }
es->rtable = query->rtable; es->rtable = query->rtable;
if (es->printNodes) { if (es->printNodes)
s = nodeToString(plan); s = nodeToString(plan);
} else {
s = Explain_PlanToString(plan, es); if (es->printCost) {
s2 = Explain_PlanToString(plan, es);
if (s == NULL)
s = s2;
else {
strcat(s, "\n\n");
strcat(s, s2);
}
} }
/* output the plan */ /* output the plan */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment