Bug #73306 Manual does not explain what privileges are needed for EXPLAIN explainable_stmt

Submitted: 17 Jul 2014 7:35 Modified: 15 May 2017 12:37
Reporter: Valeriy Kravchuk Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Documentation Severity:S3 (Non-critical)
Version:5.5, 5.6, 5.7 OS:Any
Assigned to: Paul DuBois CPU Architecture:Any
Tags: explain, missing manual, privilege, show view

[17 Jul 2014 7:35] Valeriy Kravchuk
Description:
Manual (http://dev.mysql.com/doc/refman/5.6/en/explain.html) says literally nothing about privileges needed to run 

EXPLAIN explainable_stmt

successfully, while in some cases you need more privileges for that than to run the statement itself. Look:

mysql> show grants;
+-------------------------------------------------------------------------------
----------------------------+
| Grants for uv@localhost
                            |
+-------------------------------------------------------------------------------
----------------------------+
| GRANT USAGE ON *.* TO 'uv'@'localhost' IDENTIFIED BY PASSWORD '*B436DA7205F6DA
66C21ED96ECF6ECF9EAD82AA5A' |
| GRANT SELECT ON `db1`.`t` TO 'uv'@'localhost'
                            |
| GRANT SELECT ON `db1`.`vt` TO 'uv'@'localhost'
                            |
+-------------------------------------------------------------------------------
----------------------------+
3 rows in set (0.00 sec)

mysql> select * from vt;
Empty set (0.00 sec)

mysql> desc vt;
+-------+---------+------+-----+---------+-------+
| Field | Type    | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| c1    | int(11) | YES  |     | NULL    |       |
+-------+---------+------+-----+---------+-------+
1 row in set (0.02 sec)

mysql> explain select * from vt;
ERROR 1345 (HY000): EXPLAIN/SHOW can not be issued; lacking privileges for under
lying table

So, if one guesses that vt is a view and grant SHOW VIEW on top:

C:\Program Files\MySQL\MySQL Server 5.6\bin>mysql -uroot -proot -P3314 test
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 26
Server version: 5.6.19-log MySQL Community Server (GPL)

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> grant show view on db1.vt to uv@localhost;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye

C:\Program Files\MySQL\MySQL Server 5.6\bin>mysql -uuv -puv -P3314 db1
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 27
Server version: 5.6.19-log MySQL Community Server (GPL)

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> explain select * from vt;
+----+-------------+-------+------+---------------+------+---------+------+-----
-+-------+
| id | select_type | table | type | possible_keys | key  | key_len | ref  | rows
 | Extra |
+----+-------------+-------+------+---------------+------+---------+------+-----
-+-------+
|  1 | SIMPLE      | t     | ALL  | NULL          | NULL | NULL    | NULL |    1
 | NULL  |
+----+-------------+-------+------+---------------+------+---------+------+-----
-+-------+
1 row in set (0.00 sec)

mysql> show grants;
+-------------------------------------------------------------------------------
----------------------------+
| Grants for uv@localhost
                            |
+-------------------------------------------------------------------------------
----------------------------+
| GRANT USAGE ON *.* TO 'uv'@'localhost' IDENTIFIED BY PASSWORD '*B436DA7205F6DA
66C21ED96ECF6ECF9EAD82AA5A' |
| GRANT SELECT ON `db1`.`t` TO 'uv'@'localhost'
                            |
| GRANT SELECT, SHOW VIEW ON `db1`.`vt` TO 'uv'@'localhost'
                            |
+-------------------------------------------------------------------------------
----------------------------+
3 rows in set (0.00 sec)

EXPLAIN finally works. This must be explicitly documented.

How to repeat:
See bug #73305 for more details about the test case.

Suggested fix:
Explicitly document ALL privileges that may be required for EXPLAIN in all cases.
[18 Jul 2014 9:48] MySQL Verification Team
Hello Valeriy,

Thank you for the bug report and test case.
Verified as described.

Thanks,
Umesh
[15 May 2017 12:37] Paul DuBois
Posted by developer:
 
EXPLAIN requires the SELECT privilege for any tables or views accessed, including any underlying tables of views. For views, EXPLAIN also requires the SHOW VIEW privilege.

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.055 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.