Commit 9347baa5 authored by Robert Haas's avatar Robert Haas

Include planning time in EXPLAIN ANALYZE output.

This doesn't work for prepared queries, but it's not too easy to get
the information in that case and there's some debate as to exactly
what the right thing to measure is, so just do this for now.

Andreas Karlsson, with slight doc changes by me.
parent 5264d915
...@@ -89,6 +89,7 @@ EXPLAIN SELECT * FROM tenk1; ...@@ -89,6 +89,7 @@ EXPLAIN SELECT * FROM tenk1;
QUERY PLAN QUERY PLAN
------------------------------------------------------------- -------------------------------------------------------------
Seq Scan on tenk1 (cost=0.00..458.00 rows=10000 width=244) Seq Scan on tenk1 (cost=0.00..458.00 rows=10000 width=244)
Planning time: 0.113 ms
</screen> </screen>
</para> </para>
...@@ -161,6 +162,12 @@ EXPLAIN SELECT * FROM tenk1; ...@@ -161,6 +162,12 @@ EXPLAIN SELECT * FROM tenk1;
actually returned, updated, or deleted by the query. actually returned, updated, or deleted by the query.
</para> </para>
<para>
The <literal>Planning time</literal> shown is the time it took to generate
the query plan from the parsed query and optimize it. It does not include
rewriting and parsing.
</para>
<para> <para>
Returning to our example: Returning to our example:
...@@ -170,6 +177,7 @@ EXPLAIN SELECT * FROM tenk1; ...@@ -170,6 +177,7 @@ EXPLAIN SELECT * FROM tenk1;
QUERY PLAN QUERY PLAN
------------------------------------------------------------- -------------------------------------------------------------
Seq Scan on tenk1 (cost=0.00..458.00 rows=10000 width=244) Seq Scan on tenk1 (cost=0.00..458.00 rows=10000 width=244)
Planning time: 0.113 ms
</screen> </screen>
</para> </para>
...@@ -198,6 +206,7 @@ EXPLAIN SELECT * FROM tenk1 WHERE unique1 &lt; 7000; ...@@ -198,6 +206,7 @@ EXPLAIN SELECT * FROM tenk1 WHERE unique1 &lt; 7000;
------------------------------------------------------------ ------------------------------------------------------------
Seq Scan on tenk1 (cost=0.00..483.00 rows=7001 width=244) Seq Scan on tenk1 (cost=0.00..483.00 rows=7001 width=244)
Filter: (unique1 &lt; 7000) Filter: (unique1 &lt; 7000)
Planning time: 0.104 ms
</screen> </screen>
Notice that the <command>EXPLAIN</> output shows the <literal>WHERE</> Notice that the <command>EXPLAIN</> output shows the <literal>WHERE</>
...@@ -234,6 +243,7 @@ EXPLAIN SELECT * FROM tenk1 WHERE unique1 &lt; 100; ...@@ -234,6 +243,7 @@ EXPLAIN SELECT * FROM tenk1 WHERE unique1 &lt; 100;
Recheck Cond: (unique1 &lt; 100) Recheck Cond: (unique1 &lt; 100)
-&gt; Bitmap Index Scan on tenk1_unique1 (cost=0.00..5.04 rows=101 width=0) -&gt; Bitmap Index Scan on tenk1_unique1 (cost=0.00..5.04 rows=101 width=0)
Index Cond: (unique1 &lt; 100) Index Cond: (unique1 &lt; 100)
Planning time: 0.093 ms
</screen> </screen>
Here the planner has decided to use a two-step plan: the child plan Here the planner has decided to use a two-step plan: the child plan
...@@ -262,6 +272,7 @@ EXPLAIN SELECT * FROM tenk1 WHERE unique1 &lt; 100 AND stringu1 = 'xxx'; ...@@ -262,6 +272,7 @@ EXPLAIN SELECT * FROM tenk1 WHERE unique1 &lt; 100 AND stringu1 = 'xxx';
Filter: (stringu1 = 'xxx'::name) Filter: (stringu1 = 'xxx'::name)
-&gt; Bitmap Index Scan on tenk1_unique1 (cost=0.00..5.04 rows=101 width=0) -&gt; Bitmap Index Scan on tenk1_unique1 (cost=0.00..5.04 rows=101 width=0)
Index Cond: (unique1 &lt; 100) Index Cond: (unique1 &lt; 100)
Planning time: 0.089 ms
</screen> </screen>
The added condition <literal>stringu1 = 'xxx'</literal> reduces the The added condition <literal>stringu1 = 'xxx'</literal> reduces the
...@@ -283,6 +294,7 @@ EXPLAIN SELECT * FROM tenk1 WHERE unique1 = 42; ...@@ -283,6 +294,7 @@ EXPLAIN SELECT * FROM tenk1 WHERE unique1 = 42;
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
Index Scan using tenk1_unique1 on tenk1 (cost=0.29..8.30 rows=1 width=244) Index Scan using tenk1_unique1 on tenk1 (cost=0.29..8.30 rows=1 width=244)
Index Cond: (unique1 = 42) Index Cond: (unique1 = 42)
Planning time: 0.076 ms
</screen> </screen>
In this type of plan the table rows are fetched in index order, which In this type of plan the table rows are fetched in index order, which
...@@ -311,6 +323,7 @@ EXPLAIN SELECT * FROM tenk1 WHERE unique1 &lt; 100 AND unique2 &gt; 9000; ...@@ -311,6 +323,7 @@ EXPLAIN SELECT * FROM tenk1 WHERE unique1 &lt; 100 AND unique2 &gt; 9000;
Index Cond: (unique1 &lt; 100) Index Cond: (unique1 &lt; 100)
-&gt; Bitmap Index Scan on tenk1_unique2 (cost=0.00..19.78 rows=999 width=0) -&gt; Bitmap Index Scan on tenk1_unique2 (cost=0.00..19.78 rows=999 width=0)
Index Cond: (unique2 &gt; 9000) Index Cond: (unique2 &gt; 9000)
Planning time: 0.094 ms
</screen> </screen>
But this requires visiting both indexes, so it's not necessarily a win But this requires visiting both indexes, so it's not necessarily a win
...@@ -331,6 +344,7 @@ EXPLAIN SELECT * FROM tenk1 WHERE unique1 &lt; 100 AND unique2 &gt; 9000 LIMIT 2 ...@@ -331,6 +344,7 @@ EXPLAIN SELECT * FROM tenk1 WHERE unique1 &lt; 100 AND unique2 &gt; 9000 LIMIT 2
-&gt; Index Scan using tenk1_unique2 on tenk1 (cost=0.29..71.27 rows=10 width=244) -&gt; Index Scan using tenk1_unique2 on tenk1 (cost=0.29..71.27 rows=10 width=244)
Index Cond: (unique2 &gt; 9000) Index Cond: (unique2 &gt; 9000)
Filter: (unique1 &lt; 100) Filter: (unique1 &lt; 100)
Planning time: 0.087 ms
</screen> </screen>
</para> </para>
...@@ -364,6 +378,7 @@ WHERE t1.unique1 &lt; 10 AND t1.unique2 = t2.unique2; ...@@ -364,6 +378,7 @@ WHERE t1.unique1 &lt; 10 AND t1.unique2 = t2.unique2;
Index Cond: (unique1 &lt; 10) Index Cond: (unique1 &lt; 10)
-&gt; Index Scan using tenk2_unique2 on tenk2 t2 (cost=0.29..7.91 rows=1 width=244) -&gt; Index Scan using tenk2_unique2 on tenk2 t2 (cost=0.29..7.91 rows=1 width=244)
Index Cond: (unique2 = t1.unique2) Index Cond: (unique2 = t1.unique2)
Planning time: 0.117 ms
</screen> </screen>
</para> </para>
...@@ -415,6 +430,7 @@ WHERE t1.unique1 &lt; 10 AND t2.unique2 &lt; 10 AND t1.hundred &lt; t2.hundred; ...@@ -415,6 +430,7 @@ WHERE t1.unique1 &lt; 10 AND t2.unique2 &lt; 10 AND t1.hundred &lt; t2.hundred;
-&gt; Materialize (cost=0.29..8.51 rows=10 width=244) -&gt; Materialize (cost=0.29..8.51 rows=10 width=244)
-&gt; Index Scan using tenk2_unique2 on tenk2 t2 (cost=0.29..8.46 rows=10 width=244) -&gt; Index Scan using tenk2_unique2 on tenk2 t2 (cost=0.29..8.46 rows=10 width=244)
Index Cond: (unique2 &lt; 10) Index Cond: (unique2 &lt; 10)
Planning time: 0.119 ms
</screen> </screen>
The condition <literal>t1.hundred &lt; t2.hundred</literal> can't be The condition <literal>t1.hundred &lt; t2.hundred</literal> can't be
...@@ -462,6 +478,7 @@ WHERE t1.unique1 &lt; 100 AND t1.unique2 = t2.unique2; ...@@ -462,6 +478,7 @@ WHERE t1.unique1 &lt; 100 AND t1.unique2 = t2.unique2;
Recheck Cond: (unique1 &lt; 100) Recheck Cond: (unique1 &lt; 100)
-&gt; Bitmap Index Scan on tenk1_unique1 (cost=0.00..5.04 rows=101 width=0) -&gt; Bitmap Index Scan on tenk1_unique1 (cost=0.00..5.04 rows=101 width=0)
Index Cond: (unique1 &lt; 100) Index Cond: (unique1 &lt; 100)
Planning time: 0.182 ms
</screen> </screen>
</para> </para>
...@@ -492,6 +509,7 @@ WHERE t1.unique1 &lt; 100 AND t1.unique2 = t2.unique2; ...@@ -492,6 +509,7 @@ WHERE t1.unique1 &lt; 100 AND t1.unique2 = t2.unique2;
-&gt; Sort (cost=197.83..200.33 rows=1000 width=244) -&gt; Sort (cost=197.83..200.33 rows=1000 width=244)
Sort Key: t2.unique2 Sort Key: t2.unique2
-&gt; Seq Scan on onek t2 (cost=0.00..148.00 rows=1000 width=244) -&gt; Seq Scan on onek t2 (cost=0.00..148.00 rows=1000 width=244)
Planning time: 0.195 ms
</screen> </screen>
</para> </para>
...@@ -528,6 +546,7 @@ WHERE t1.unique1 &lt; 100 AND t1.unique2 = t2.unique2; ...@@ -528,6 +546,7 @@ WHERE t1.unique1 &lt; 100 AND t1.unique2 = t2.unique2;
-&gt; Index Scan using tenk1_unique2 on tenk1 t1 (cost=0.29..656.28 rows=101 width=244) -&gt; Index Scan using tenk1_unique2 on tenk1 t1 (cost=0.29..656.28 rows=101 width=244)
Filter: (unique1 &lt; 100) Filter: (unique1 &lt; 100)
-&gt; Index Scan using onek_unique2 on onek t2 (cost=0.28..224.79 rows=1000 width=244) -&gt; Index Scan using onek_unique2 on onek t2 (cost=0.28..224.79 rows=1000 width=244)
Planning time: 0.176 ms
</screen> </screen>
which shows that the planner thinks that sorting <literal>onek</> by which shows that the planner thinks that sorting <literal>onek</> by
...@@ -564,6 +583,7 @@ WHERE t1.unique1 &lt; 10 AND t1.unique2 = t2.unique2; ...@@ -564,6 +583,7 @@ WHERE t1.unique1 &lt; 10 AND t1.unique2 = t2.unique2;
Index Cond: (unique1 &lt; 10) Index Cond: (unique1 &lt; 10)
-&gt; Index Scan using tenk2_unique2 on tenk2 t2 (cost=0.29..7.91 rows=1 width=244) (actual time=0.021..0.022 rows=1 loops=10) -&gt; Index Scan using tenk2_unique2 on tenk2 t2 (cost=0.29..7.91 rows=1 width=244) (actual time=0.021..0.022 rows=1 loops=10)
Index Cond: (unique2 = t1.unique2) Index Cond: (unique2 = t1.unique2)
Planning time: 0.181 ms
Total runtime: 0.501 ms Total runtime: 0.501 ms
</screen> </screen>
...@@ -612,6 +632,7 @@ WHERE t1.unique1 &lt; 100 AND t1.unique2 = t2.unique2 ORDER BY t1.fivethous; ...@@ -612,6 +632,7 @@ WHERE t1.unique1 &lt; 100 AND t1.unique2 = t2.unique2 ORDER BY t1.fivethous;
Recheck Cond: (unique1 &lt; 100) Recheck Cond: (unique1 &lt; 100)
-&gt; Bitmap Index Scan on tenk1_unique1 (cost=0.00..5.04 rows=101 width=0) (actual time=0.049..0.049 rows=100 loops=1) -&gt; Bitmap Index Scan on tenk1_unique1 (cost=0.00..5.04 rows=101 width=0) (actual time=0.049..0.049 rows=100 loops=1)
Index Cond: (unique1 &lt; 100) Index Cond: (unique1 &lt; 100)
Planning time: 0.194 ms
Total runtime: 8.008 ms Total runtime: 8.008 ms
</screen> </screen>
...@@ -635,6 +656,7 @@ EXPLAIN ANALYZE SELECT * FROM tenk1 WHERE ten &lt; 7; ...@@ -635,6 +656,7 @@ EXPLAIN ANALYZE SELECT * FROM tenk1 WHERE ten &lt; 7;
Seq Scan on tenk1 (cost=0.00..483.00 rows=7000 width=244) (actual time=0.016..5.107 rows=7000 loops=1) Seq Scan on tenk1 (cost=0.00..483.00 rows=7000 width=244) (actual time=0.016..5.107 rows=7000 loops=1)
Filter: (ten &lt; 7) Filter: (ten &lt; 7)
Rows Removed by Filter: 3000 Rows Removed by Filter: 3000
Planning time: 0.083 ms
Total runtime: 5.905 ms Total runtime: 5.905 ms
</screen> </screen>
...@@ -657,6 +679,7 @@ EXPLAIN ANALYZE SELECT * FROM polygon_tbl WHERE f1 @&gt; polygon '(0.5,2.0)'; ...@@ -657,6 +679,7 @@ EXPLAIN ANALYZE SELECT * FROM polygon_tbl WHERE f1 @&gt; polygon '(0.5,2.0)';
Seq Scan on polygon_tbl (cost=0.00..1.05 rows=1 width=32) (actual time=0.044..0.044 rows=0 loops=1) Seq Scan on polygon_tbl (cost=0.00..1.05 rows=1 width=32) (actual time=0.044..0.044 rows=0 loops=1)
Filter: (f1 @&gt; '((0.5,2))'::polygon) Filter: (f1 @&gt; '((0.5,2))'::polygon)
Rows Removed by Filter: 4 Rows Removed by Filter: 4
Planning time: 0.040 ms
Total runtime: 0.083 ms Total runtime: 0.083 ms
</screen> </screen>
...@@ -675,6 +698,7 @@ EXPLAIN ANALYZE SELECT * FROM polygon_tbl WHERE f1 @&gt; polygon '(0.5,2.0)'; ...@@ -675,6 +698,7 @@ EXPLAIN ANALYZE SELECT * FROM polygon_tbl WHERE f1 @&gt; polygon '(0.5,2.0)';
Index Scan using gpolygonind on polygon_tbl (cost=0.13..8.15 rows=1 width=32) (actual time=0.062..0.062 rows=0 loops=1) Index Scan using gpolygonind on polygon_tbl (cost=0.13..8.15 rows=1 width=32) (actual time=0.062..0.062 rows=0 loops=1)
Index Cond: (f1 @&gt; '((0.5,2))'::polygon) Index Cond: (f1 @&gt; '((0.5,2))'::polygon)
Rows Removed by Index Recheck: 1 Rows Removed by Index Recheck: 1
Planning time: 0.034 ms
Total runtime: 0.144 ms Total runtime: 0.144 ms
</screen> </screen>
...@@ -705,6 +729,7 @@ EXPLAIN (ANALYZE, BUFFERS) SELECT * FROM tenk1 WHERE unique1 &lt; 100 AND unique ...@@ -705,6 +729,7 @@ EXPLAIN (ANALYZE, BUFFERS) SELECT * FROM tenk1 WHERE unique1 &lt; 100 AND unique
-&gt; Bitmap Index Scan on tenk1_unique2 (cost=0.00..19.78 rows=999 width=0) (actual time=0.227..0.227 rows=999 loops=1) -&gt; Bitmap Index Scan on tenk1_unique2 (cost=0.00..19.78 rows=999 width=0) (actual time=0.227..0.227 rows=999 loops=1)
Index Cond: (unique2 &gt; 9000) Index Cond: (unique2 &gt; 9000)
Buffers: shared hit=5 Buffers: shared hit=5
Planning time: 0.088 ms
Total runtime: 0.423 ms Total runtime: 0.423 ms
</screen> </screen>
...@@ -732,6 +757,7 @@ EXPLAIN ANALYZE UPDATE tenk1 SET hundred = hundred + 1 WHERE unique1 &lt; 100; ...@@ -732,6 +757,7 @@ EXPLAIN ANALYZE UPDATE tenk1 SET hundred = hundred + 1 WHERE unique1 &lt; 100;
Recheck Cond: (unique1 &lt; 100) Recheck Cond: (unique1 &lt; 100)
-&gt; Bitmap Index Scan on tenk1_unique1 (cost=0.00..5.04 rows=101 width=0) (actual time=0.043..0.043 rows=100 loops=1) -&gt; Bitmap Index Scan on tenk1_unique1 (cost=0.00..5.04 rows=101 width=0) (actual time=0.043..0.043 rows=100 loops=1)
Index Cond: (unique1 &lt; 100) Index Cond: (unique1 &lt; 100)
Planning time: 0.079 ms
Total runtime: 14.727 ms Total runtime: 14.727 ms
ROLLBACK; ROLLBACK;
...@@ -817,6 +843,7 @@ EXPLAIN ANALYZE SELECT * FROM tenk1 WHERE unique1 &lt; 100 AND unique2 &gt; 9000 ...@@ -817,6 +843,7 @@ EXPLAIN ANALYZE SELECT * FROM tenk1 WHERE unique1 &lt; 100 AND unique2 &gt; 9000
Index Cond: (unique2 &gt; 9000) Index Cond: (unique2 &gt; 9000)
Filter: (unique1 &lt; 100) Filter: (unique1 &lt; 100)
Rows Removed by Filter: 287 Rows Removed by Filter: 287
Planning time: 0.096 ms
Total runtime: 0.336 ms Total runtime: 0.336 ms
</screen> </screen>
......
...@@ -145,7 +145,8 @@ ROLLBACK; ...@@ -145,7 +145,8 @@ ROLLBACK;
<para> <para>
Include information on the estimated startup and total cost of each Include information on the estimated startup and total cost of each
plan node, as well as the estimated number of rows and the estimated plan node, as well as the estimated number of rows and the estimated
width of each row. This parameter defaults to <literal>TRUE</literal>. width of each row. Also, include the time spent planning the query,
if available. This parameter defaults to <literal>TRUE</literal>.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -289,7 +290,8 @@ EXPLAIN SELECT * FROM foo; ...@@ -289,7 +290,8 @@ EXPLAIN SELECT * FROM foo;
QUERY PLAN QUERY PLAN
--------------------------------------------------------- ---------------------------------------------------------
Seq Scan on foo (cost=0.00..155.00 rows=10000 width=4) Seq Scan on foo (cost=0.00..155.00 rows=10000 width=4)
(1 row) Planning time: 0.114 ms
(2 rows)
</programlisting> </programlisting>
</para> </para>
...@@ -309,7 +311,8 @@ EXPLAIN (FORMAT JSON) SELECT * FROM foo; ...@@ -309,7 +311,8 @@ EXPLAIN (FORMAT JSON) SELECT * FROM foo;
"Total Cost": 155.00, + "Total Cost": 155.00, +
"Plan Rows": 10000, + "Plan Rows": 10000, +
"Plan Width": 4 + "Plan Width": 4 +
} + }. +
"Planning Time": 0.114 +
} + } +
] ]
(1 row) (1 row)
...@@ -328,7 +331,8 @@ EXPLAIN SELECT * FROM foo WHERE i = 4; ...@@ -328,7 +331,8 @@ EXPLAIN SELECT * FROM foo WHERE i = 4;
-------------------------------------------------------------- --------------------------------------------------------------
Index Scan using fi on foo (cost=0.00..5.98 rows=1 width=4) Index Scan using fi on foo (cost=0.00..5.98 rows=1 width=4)
Index Cond: (i = 4) Index Cond: (i = 4)
(2 rows) Planning time: 0.073 ms
(3 rows)
</programlisting> </programlisting>
</para> </para>
...@@ -348,7 +352,8 @@ EXPLAIN (FORMAT YAML) SELECT * FROM foo WHERE i='4'; ...@@ -348,7 +352,8 @@ EXPLAIN (FORMAT YAML) SELECT * FROM foo WHERE i='4';
Total Cost: 5.98 + Total Cost: 5.98 +
Plan Rows: 1 + Plan Rows: 1 +
Plan Width: 4 + Plan Width: 4 +
Index Cond: "(i = 4)" Index Cond: "(i = 4)" +
Planning Time: 0.073
(1 row) (1 row)
</programlisting> </programlisting>
...@@ -380,6 +385,7 @@ EXPLAIN SELECT sum(i) FROM foo WHERE i &lt; 10; ...@@ -380,6 +385,7 @@ EXPLAIN SELECT sum(i) FROM foo WHERE i &lt; 10;
Aggregate (cost=23.93..23.93 rows=1 width=4) Aggregate (cost=23.93..23.93 rows=1 width=4)
-&gt; Index Scan using fi on foo (cost=0.00..23.92 rows=6 width=4) -&gt; Index Scan using fi on foo (cost=0.00..23.92 rows=6 width=4)
Index Cond: (i &lt; 10) Index Cond: (i &lt; 10)
Planning time: 0.088 ms
(3 rows) (3 rows)
</programlisting> </programlisting>
</para> </para>
...@@ -401,6 +407,7 @@ EXPLAIN ANALYZE EXECUTE query(100, 200); ...@@ -401,6 +407,7 @@ EXPLAIN ANALYZE EXECUTE query(100, 200);
Group Key: foo Group Key: foo
-&gt; Index Scan using test_pkey on test (cost=0.29..9.29 rows=50 width=8) (actual time=0.039..0.091 rows=99 loops=1) -&gt; Index Scan using test_pkey on test (cost=0.29..9.29 rows=50 width=8) (actual time=0.039..0.091 rows=99 loops=1)
Index Cond: ((id &gt; $1) AND (id &lt; $2)) Index Cond: ((id &gt; $1) AND (id &lt; $2))
Planning time: 0.197 ms
Total runtime: 0.225 ms Total runtime: 0.225 ms
(5 rows) (5 rows)
</programlisting> </programlisting>
......
...@@ -320,13 +320,19 @@ ExplainOneQuery(Query *query, IntoClause *into, ExplainState *es, ...@@ -320,13 +320,19 @@ ExplainOneQuery(Query *query, IntoClause *into, ExplainState *es,
(*ExplainOneQuery_hook) (query, into, es, queryString, params); (*ExplainOneQuery_hook) (query, into, es, queryString, params);
else else
{ {
PlannedStmt *plan; PlannedStmt *plan;
instr_time planstart, planduration;
INSTR_TIME_SET_CURRENT(planstart);
/* plan the query */ /* plan the query */
plan = pg_plan_query(query, 0, params); plan = pg_plan_query(query, 0, params);
INSTR_TIME_SET_CURRENT(planduration);
INSTR_TIME_SUBTRACT(planduration, planstart);
/* run it (if needed) and produce output */ /* run it (if needed) and produce output */
ExplainOnePlan(plan, into, es, queryString, params); ExplainOnePlan(plan, into, es, queryString, params, &planduration);
} }
} }
...@@ -403,7 +409,8 @@ ExplainOneUtility(Node *utilityStmt, IntoClause *into, ExplainState *es, ...@@ -403,7 +409,8 @@ ExplainOneUtility(Node *utilityStmt, IntoClause *into, ExplainState *es,
*/ */
void void
ExplainOnePlan(PlannedStmt *plannedstmt, IntoClause *into, ExplainState *es, ExplainOnePlan(PlannedStmt *plannedstmt, IntoClause *into, ExplainState *es,
const char *queryString, ParamListInfo params) const char *queryString, ParamListInfo params,
const instr_time *planduration)
{ {
DestReceiver *dest; DestReceiver *dest;
QueryDesc *queryDesc; QueryDesc *queryDesc;
...@@ -484,6 +491,17 @@ ExplainOnePlan(PlannedStmt *plannedstmt, IntoClause *into, ExplainState *es, ...@@ -484,6 +491,17 @@ ExplainOnePlan(PlannedStmt *plannedstmt, IntoClause *into, ExplainState *es,
/* Create textual dump of plan tree */ /* Create textual dump of plan tree */
ExplainPrintPlan(es, queryDesc); ExplainPrintPlan(es, queryDesc);
if (es->costs && planduration)
{
double plantime = INSTR_TIME_GET_DOUBLE(*planduration);
if (es->format == EXPLAIN_FORMAT_TEXT)
appendStringInfo(es->str, "Planning time: %.3f ms\n",
1000.0 * plantime);
else
ExplainPropertyFloat("Planning Time", 1000.0 * plantime, 3, es);
}
/* Print info about runtime of triggers */ /* Print info about runtime of triggers */
if (es->analyze) if (es->analyze)
ExplainPrintTriggers(es, queryDesc); ExplainPrintTriggers(es, queryDesc);
......
...@@ -665,7 +665,7 @@ ExplainExecuteQuery(ExecuteStmt *execstmt, IntoClause *into, ExplainState *es, ...@@ -665,7 +665,7 @@ ExplainExecuteQuery(ExecuteStmt *execstmt, IntoClause *into, ExplainState *es,
PlannedStmt *pstmt = (PlannedStmt *) lfirst(p); PlannedStmt *pstmt = (PlannedStmt *) lfirst(p);
if (IsA(pstmt, PlannedStmt)) if (IsA(pstmt, PlannedStmt))
ExplainOnePlan(pstmt, into, es, query_string, paramLI); ExplainOnePlan(pstmt, into, es, query_string, paramLI, NULL);
else else
ExplainOneUtility((Node *) pstmt, into, es, query_string, paramLI); ExplainOneUtility((Node *) pstmt, into, es, query_string, paramLI);
......
...@@ -67,8 +67,8 @@ extern void ExplainOneUtility(Node *utilityStmt, IntoClause *into, ...@@ -67,8 +67,8 @@ extern void ExplainOneUtility(Node *utilityStmt, IntoClause *into,
const char *queryString, ParamListInfo params); const char *queryString, ParamListInfo params);
extern void ExplainOnePlan(PlannedStmt *plannedstmt, IntoClause *into, extern void ExplainOnePlan(PlannedStmt *plannedstmt, IntoClause *into,
ExplainState *es, ExplainState *es, const char *queryString,
const char *queryString, ParamListInfo params); ParamListInfo params, const instr_time *planduration);
extern void ExplainPrintPlan(ExplainState *es, QueryDesc *queryDesc); extern void ExplainPrintPlan(ExplainState *es, QueryDesc *queryDesc);
extern void ExplainPrintTriggers(ExplainState *es, QueryDesc *queryDesc); extern void ExplainPrintTriggers(ExplainState *es, QueryDesc *queryDesc);
......
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