aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/explain.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2008-11-19 01:10:24 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2008-11-19 01:10:24 +0000
commitcd35e9d7468e8f86dd5a7d928707f4ba8cdae44d (patch)
tree0871bc92bd00e622cc567d29edf3d9a7c9b9adff /src/backend/commands/explain.c
parent667685ca7da3b895fe362863c3da00b010543399 (diff)
downloadpostgresql-cd35e9d7468e8f86dd5a7d928707f4ba8cdae44d.tar.gz
postgresql-cd35e9d7468e8f86dd5a7d928707f4ba8cdae44d.zip
Some infrastructure changes for the upcoming auto-explain contrib module:
* Refactor explain.c slightly to export a convenient-to-use subroutine for printing EXPLAIN results. * Provide hooks for plugins to get control at ExecutorStart and ExecutorEnd as well as ExecutorRun. * Add some minimal support for tracking the total runtime of ExecutorRun. This code won't actually do anything unless a plugin prods it to. * Change the API of the DefineCustomXXXVariable functions to allow nonzero "flags" to be specified for a custom GUC variable. While at it, also make the "bootstrap" default value for custom GUCs be explicitly specified as a parameter to these functions. This is to eliminate confusion over where the default comes from, as has been expressed in the past by some users of the custom-variable facility. * Refactor GUC code a bit to ensure that a custom variable gets initialized to something valid (like its default value) even if the placeholder value was invalid.
Diffstat (limited to 'src/backend/commands/explain.c')
-rw-r--r--src/backend/commands/explain.c46
1 files changed, 32 insertions, 14 deletions
diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c
index 300dc5f3fa4..e5f1b313076 100644
--- a/src/backend/commands/explain.c
+++ b/src/backend/commands/explain.c
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994-5, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/explain.c,v 1.180 2008/10/06 20:29:38 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/explain.c,v 1.181 2008/11/19 01:10:23 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -224,7 +224,6 @@ ExplainOnePlan(PlannedStmt *plannedstmt, ParamListInfo params,
QueryDesc *queryDesc;
instr_time starttime;
double totaltime = 0;
- ExplainState *es;
StringInfoData buf;
int eflags;
@@ -265,17 +264,9 @@ ExplainOnePlan(PlannedStmt *plannedstmt, ParamListInfo params,
totaltime += elapsed_time(&starttime);
}
- es = (ExplainState *) palloc0(sizeof(ExplainState));
-
- es->printTList = stmt->verbose;
- es->printAnalyze = stmt->analyze;
- es->pstmt = queryDesc->plannedstmt;
- es->rtable = queryDesc->plannedstmt->rtable;
-
+ /* Create textual dump of plan tree */
initStringInfo(&buf);
- explain_outNode(&buf,
- queryDesc->plannedstmt->planTree, queryDesc->planstate,
- NULL, 0, es);
+ ExplainPrintPlan(&buf, queryDesc, stmt->analyze, stmt->verbose);
/*
* If we ran the command, run any AFTER triggers it queued. (Note this
@@ -290,7 +281,7 @@ ExplainOnePlan(PlannedStmt *plannedstmt, ParamListInfo params,
}
/* Print info about runtime of triggers */
- if (es->printAnalyze)
+ if (stmt->analyze)
{
ResultRelInfo *rInfo;
bool show_relname;
@@ -335,7 +326,34 @@ ExplainOnePlan(PlannedStmt *plannedstmt, ParamListInfo params,
do_text_output_multiline(tstate, buf.data);
pfree(buf.data);
- pfree(es);
+}
+
+/*
+ * ExplainPrintPlan -
+ * convert a QueryDesc's plan tree to text and append it to 'str'
+ *
+ * 'analyze' means to include runtime instrumentation results
+ * 'verbose' means a verbose printout (currently, it shows targetlists)
+ *
+ * NB: will not work on utility statements
+ */
+void
+ExplainPrintPlan(StringInfo str, QueryDesc *queryDesc,
+ bool analyze, bool verbose)
+{
+ ExplainState es;
+
+ Assert(queryDesc->plannedstmt != NULL);
+
+ memset(&es, 0, sizeof(es));
+ es.printTList = verbose;
+ es.printAnalyze = analyze;
+ es.pstmt = queryDesc->plannedstmt;
+ es.rtable = queryDesc->plannedstmt->rtable;
+
+ explain_outNode(str,
+ queryDesc->plannedstmt->planTree, queryDesc->planstate,
+ NULL, 0, &es);
}
/*