aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/explain.c
diff options
context:
space:
mode:
authorStephen Frost <sfrost@snowman.net>2017-03-08 15:14:03 -0500
committerStephen Frost <sfrost@snowman.net>2017-03-08 15:14:03 -0500
commitf9b1a0dd403ec0931213c66d5f979a3d3e8e7e30 (patch)
tree714d2629895708f66b731b6ccdb0d3a2677936d0 /src/backend/commands/explain.c
parent15d03e597662847e13428a8b3ce9dd59c38decf3 (diff)
downloadpostgresql-f9b1a0dd403ec0931213c66d5f979a3d3e8e7e30.tar.gz
postgresql-f9b1a0dd403ec0931213c66d5f979a3d3e8e7e30.zip
Expose explain's SUMMARY option
This exposes the existing explain summary option to users to allow them to choose if they wish to have the planning time and totalled run time included in the EXPLAIN result. The existing default behavior is retained if SUMMARY is not specified- running explain without analyze will not print the summary lines (just the planning time, currently) while running explain with analyze will include the summary lines (both the planning time and the totalled execution time). Users who wish to see the summary information for plain explain can now use: EXPLAIN (SUMMARY ON) query; Users who do not want to have the summary printed for an analyze run can use: EXPLAIN (ANALYZE ON, SUMMARY OFF) query; With this, we can now also have EXPLAIN ANALYZE queries included in our regression tests by using: EXPLAIN (ANALYZE ON, TIMING OFF, SUMMARY off) query; I went ahead and added an example of this, which will hopefully not make the buildfarm complain. Author: Ashutosh Bapat Discussion: https://postgr.es/m/CAFjFpReE5z2h98U2Vuia8hcEkpRRwrauRjHmyE44hNv8-xk+XA@mail.gmail.com
Diffstat (limited to 'src/backend/commands/explain.c')
-rw-r--r--src/backend/commands/explain.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c
index 7a8d36c8db1..6fd82e9d52f 100644
--- a/src/backend/commands/explain.c
+++ b/src/backend/commands/explain.c
@@ -149,6 +149,7 @@ ExplainQuery(ParseState *pstate, ExplainStmt *stmt, const char *queryString,
List *rewritten;
ListCell *lc;
bool timing_set = false;
+ bool summary_set = false;
/* Parse options list. */
foreach(lc, stmt->options)
@@ -168,6 +169,11 @@ ExplainQuery(ParseState *pstate, ExplainStmt *stmt, const char *queryString,
timing_set = true;
es->timing = defGetBoolean(opt);
}
+ else if (strcmp(opt->defname, "summary") == 0)
+ {
+ summary_set = true;
+ es->summary = defGetBoolean(opt);
+ }
else if (strcmp(opt->defname, "format") == 0)
{
char *p = defGetString(opt);
@@ -209,8 +215,8 @@ ExplainQuery(ParseState *pstate, ExplainStmt *stmt, const char *queryString,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("EXPLAIN option TIMING requires ANALYZE")));
- /* currently, summary option is not exposed to users; just set it */
- es->summary = es->analyze;
+ /* if the summary was not set explicitly, set default value */
+ es->summary = (summary_set) ? es->summary : es->analyze;
/*
* Parse analysis was done already, but we still have to run the rule
@@ -571,7 +577,13 @@ ExplainOnePlan(PlannedStmt *plannedstmt, IntoClause *into, ExplainState *es,
totaltime += elapsed_time(&starttime);
- if (es->summary)
+ /*
+ * We only report execution time if we actually ran the query (that is,
+ * the user specified ANALYZE), and if summary reporting is enabled (the
+ * user can set SUMMARY OFF to not have the timing information included in
+ * the output). By default, ANALYZE sets SUMMARY to true.
+ */
+ if (es->summary && es->analyze)
{
if (es->format == EXPLAIN_FORMAT_TEXT)
appendStringInfo(es->str, "Execution time: %.3f ms\n",