You are viewing an older version of this section. View current production version.
SHOW PLAN
Displays the EXPLAIN plan of a query as per the plan ID.
Syntax
SHOW PLAN [JSON] plan_id
Remarks
-
SHOW PLAN
displays the same information asEXPLAIN
. You can use theSHOW PLAN
command as an alternative to theEXPLAIN
command, if your database client does not supportEXPLAIN
. -
By default, the
SHOW PLAN
command displays theEXPLAIN
information of a query in text format. You can optionally choose to display the information in JSON format using theSHOW PLAN JSON
command. -
You can get the
plan_id
of a query from theINFORMATION_SCHEMA.PLANCACHE
view. See the Example section below for details. -
The
SHOW PLAN
command throws the following error if the global variableenable_disk_plan_explain
is not enabled:ERROR 2394 (HY000): The plan does not have associated explain information. enable_disk_plan_explain must be enabled at the time of plan generation.
In this scenario, you need to do the following:
- Run the following command to drop the plan from the plancache:
DROP 25 FROM PLANCACHE;
- Enable the global variable:
SET GLOBAL enable_disk_plan_explain=ON;
- Rerun the query to regenerate the plan, and query the plancache again to obtain the new
plan_id
.
Note: Every time a query is run, a new plan is generated along with the
plan_id
.
Example
The following example displays the plan statistics for the following SELECT
statement:
SELECT * FROM Employee;
+------+------+
| ID | Name |
+------+------+
| 10 | Jack |
| 30 | Ritz |
| 20 | Rob |
| 40 | Rick |
+------+------+
Run the following command to view the plan ID of the SELECT
query:
SELECT QUERY_TEXT,PLAN_ID FROM INFORMATION_SCHEMA.PLANCACHE WHERE QUERY_TEXT LIKE 'SELECT * FROM Employee';
****
+---------+------------------------+
| PLAN_ID | QUERY_TEXT |
+---------+------------------------+
| 25 | SELECT * FROM Employee |
+---------+------------------------+
Note: In the SELECT
statement, you can omit the WHERE
clause to view the plan ID of all the queries executed in the current session.
Now run the following command to view the statistics of the plan ID 25
:
SHOW PLAN 25;
****
+---------------------------------------------------+
| PLAN |
+---------------------------------------------------+
| Gather partitions:all alias:remote_0 |
| Project [Employee.ID, Employee.Name] |
| TableScan db.Employee table_type:sharded_rowstore |
+---------------------------------------------------+