Reporting planning time with EXPLAIN

From: Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Reporting planning time with EXPLAIN
Date: 2016-12-27 07:57:24
Message-ID: CAFjFpReE5z2h98U2Vuia8hcEkpRRwrauRjHmyE44hNv8-xk+XA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,
We report planning and execution time when EXPLAIN ANALYZE is issued.
We do not have facility to report planning time as part EXPLAIN
output. In order to get the planning time, one has to issue EXPLAIN
ANALYZE which involves executing the plan, which is unnecessary.

We report planning and execution times when es->summary is true. It is
set to true when es->analyze is true.
211 /* currently, summary option is not exposed to users; just set it */
212 es->summary = es->analyze;

The comment was introduced by commit

commit 90063a7612e2730f7757c2a80ba384bbe7e35c4b
Author: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Date: Wed Oct 15 18:50:13 2014 -0400

Print planning time only in EXPLAIN ANALYZE, not plain EXPLAIN.

We've gotten enough push-back on that change to make it clear that it
wasn't an especially good idea to do it like that. Revert plain EXPLAIN
to its previous behavior, but keep the extra output in EXPLAIN ANALYZE.
Per discussion.

Internally, I set this up as a separate flag ExplainState.summary that
controls printing of planning time and execution time. For now it's
just copied from the ANALYZE option, but we could consider exposing it
to users.

The discussion referred to seems to be [1]. Here's patch to expose the
"summary" option as mentioned in the last paragraph of above commit
message. Right now I have named it as "summary", but I am fine if we
want to change it to something meaningful. "timing" already has got
some other usage, so can't use it here.

One can use this option as
postgres=# explain (summary on) select * from pg_class c, pg_type t
where c.reltype = t.oid;
QUERY PLAN
--------------------------------------------------------------------------
Hash Join (cost=17.12..35.70 rows=319 width=511)
Hash Cond: (c.reltype = t.oid)
-> Seq Scan on pg_class c (cost=0.00..14.19 rows=319 width=259)
-> Hash (cost=12.61..12.61 rows=361 width=256)
-> Seq Scan on pg_type t (cost=0.00..12.61 rows=361 width=256)
Planning time: 48.823 ms
(6 rows)

When analyze is specified, summary is also set to ON. By default this
flag is OFF.

Suggestions welcome.

[1] https://www.postgresql.org/message-id/flat/1351f76f-69a4-4257-91c2-9382e2a6dc22%40email(dot)android(dot)com#1351f76f-69a4-4257-91c2-9382e2a6dc22(at)email(dot)android(dot)com

[2] https://www.postgresql.org/message-id/19766.1413129321%40sss.pgh.pa.us
--
Best Wishes,
Ashutosh Bapat
EnterpriseDB Corporation
The Postgres Database Company

Attachment Content-Type Size
pg_explain_plan_time.patch binary/octet-stream 1.9 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Pavel Stehule 2016-12-27 07:58:47 Re: merging some features from plpgsql2 project
Previous Message Pavel Stehule 2016-12-27 07:54:27 merging some features from plpgsql2 project