pg_explain_plan_time_v3.patch
application/x-download
Filename: pg_explain_plan_time_v3.patch
Type: application/x-download
Part: 1
Patch
Format: unified
Series: patch v3
| File | + | − |
|---|---|---|
| doc/src/sgml/ref/explain.sgml | 13 | 0 |
| src/backend/commands/explain.c | 14 | 3 |
diff --git a/doc/src/sgml/ref/explain.sgml b/doc/src/sgml/ref/explain.sgml
index f14a58d..4d83359 100644
--- a/doc/src/sgml/ref/explain.sgml
+++ b/doc/src/sgml/ref/explain.sgml
@@ -41,6 +41,7 @@ EXPLAIN [ ANALYZE ] [ VERBOSE ] <replaceable class="parameter">statement</replac
COSTS [ <replaceable class="parameter">boolean</replaceable> ]
BUFFERS [ <replaceable class="parameter">boolean</replaceable> ]
TIMING [ <replaceable class="parameter">boolean</replaceable> ]
+ SUMMARY [ <replaceable class="parameter">boolean</replaceable> ]
FORMAT { TEXT | XML | JSON | YAML }
</synopsis>
</refsynopsisdiv>
@@ -197,6 +198,18 @@ ROLLBACK;
</varlistentry>
<varlistentry>
+ <term><literal>SUMMARY</literal></term>
+ <listitem>
+ <para>
+ Include planning time and execution time. Execution time is included
+ when <literal>ANALYZE</literal> is enabled.
+ It defaults to <literal>TRUE</literal> when <literal>ANALYZE</literal>
+ is enabled. Otherwise it defaults to <literal>FALSE</literal>.
+ </para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
<term><literal>FORMAT</literal></term>
<listitem>
<para>
diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c
index 0a669d9..7ae8378 100644
--- a/src/backend/commands/explain.c
+++ b/src/backend/commands/explain.c
@@ -148,6 +148,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)
@@ -167,6 +168,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);
@@ -208,8 +214,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
@@ -550,7 +556,12 @@ ExplainOnePlan(PlannedStmt *plannedstmt, IntoClause *into, ExplainState *es,
totaltime += elapsed_time(&starttime);
- if (es->summary)
+ /*
+ * Execution time matters only when analyze is requested. If user has
+ * explicitly requested not to report summary, don't report total execution
+ * time.
+ */
+ if (es->summary && es->analyze)
{
if (es->format == EXPLAIN_FORMAT_TEXT)
appendStringInfo(es->str, "Execution time: %.3f ms\n",