Bug #97492 Print unit for timings in EXPLAIN ANALYZE
Submitted: 5 Nov 2019 9:08 Modified: 6 Nov 2019 14:41
Reporter: Georgi Sotirov Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Documentation Severity:S4 (Feature request)
Version:8.0.18 OS:Any
Assigned to: Jon Stephens CPU Architecture:Any

[5 Nov 2019 9:08] Georgi Sotirov
Description:
The user manual on EXPLAIN ANALYZE (see https://dev.mysql.com/doc/refman/8.0/en/explain.html#explain-analyze) does not specify the unit for timings printed in the output of the command. This becomes clear only from blog posts (e.g. see https://mysqlserverteam.com/mysql-explain-analyze/) and feature preview presentations (e.g. see https://www.slideshare.net/NorvaldRyeng/mysql-8018-latest-updates-hash-join-and-explain-an...). In this regard my first suggestion is to update the manual, so it's clear for all users what is the unit for timings.

However, I think it would be even better to print the unit in the output of the command, which is my second suggestion. For example, printing the abbreviation "ms" (see https://en.wikipedia.org/wiki/Millisecond) next to the timing values would make it explicitly clear what unit are these values in. It would also make it less confusing, because MySQL client for example prints query timings in seconds (and suffixes them with "sec").

How to repeat:
1. Execute EXPLAIN ANALYZE on an arbitrary query (that could be explained by the iterator executor of course). For example I use the following sample query over the dept_emp schema (see https://livesql.oracle.com/apex/livesql/file/content_O5AEB2HE08PYEPTGCFLZU9YCV.html):

EXPLAIN ANALYZE
SELECT E.ename, E.job, D.dname
  FROM dept D,
       emp  E
 WHERE E.deptno = D.deptno
   AND E.job    = 'CLERK';

Note: I have added 1 million random employees in emp table.

2. The result is:

+------------------------------------------------------------------------------------------+
| EXPLAIN                                                                                  |
+------------------------------------------------------------------------------------------+
| -> Nested loop inner join  (cost=144308.94 rows=442815)
       (actual time=5.904..3281.472 rows=333278 loops=1)
    -> Table scan on D  (cost=1.40 rows=4)
         (actual time=4.659..4.666 rows=4 loops=1)
    -> Filter: (e.job = 'CLERK')  (cost=5627.35 rows=110704)
         (actual time=1.016..811.246 rows=83320 loops=4)
        -> Index lookup on E using fk_deptno (deptno=d.deptno)  (cost=5627.35 rows=332171)
             (actual time=1.013..786.799 rows=250004 loops=4)                              |
+------------------------------------------------------------------------------------------+
1 row in set (3.3051 sec)

Note: Output is shortened (actual times and rows moved to next line) for better readability (i.e. shorter lines).

Suggested fix:
The expected output would be:

+------------------------------------------------------------------------------------------+
| EXPLAIN                                                                                  |
+------------------------------------------------------------------------------------------+
| -> Nested loop inner join  (cost=144308.94 rows=442815)
       (actual time=5.904..3281.472 ms rows=333278 loops=1)
    -> Table scan on D  (cost=1.40 rows=4)
         (actual time=4.659..4.666 ms rows=4 loops=1)
    -> Filter: (e.job = 'CLERK')  (cost=5627.35 rows=110704)
         (actual time=1.016..811.246 ms rows=83320 loops=4)
        -> Index lookup on E using fk_deptno (deptno=d.deptno)  (cost=5627.35 rows=332171)
             (actual time=1.013..786.799 ms rows=250004 loops=4)                           |
+------------------------------------------------------------------------------------------+
1 row in set (3.3051 sec)

Note: I'm not able to highlight in color, so note the "ms" after time=first..all strings.
[5 Nov 2019 17:23] Jon Stephens
Verified as a docs issue and assigned to myself for resolution.

Thanks for bringing this to our attention.
[6 Nov 2019 0:21] Jon Stephens
Fixed in mysqldoc rev 64107.

Closed.
[6 Nov 2019 5:07] Georgi Sotirov
Thanks for updating the manual, but what about my other suggestion? Do I need to open a new issue?
[6 Nov 2019 14:35] Norvald Ryeng
Hi Georgi,

No, you don't need to file a separate bug. We are considering your suggestion anyway.

Best regards,

Norvald
[6 Nov 2019 14:41] Georgi Sotirov
Thank you Norvald!