Getting a MySQL Execution Plan


Put explain in front of an SQL statement to retrieve the execution plan.

EXPLAIN SELECT 1;

The plan is shown in tabular form (some less important columns removed):

~+-------+------+---------------+------+~+------+------------~
~| table | type | possible_keys | key  |~| rows | Extra
~+-------+------+---------------+------+~+------+------------~
~| NULL  | NULL | NULL          | NULL |~| NULL | No tables...
~+-------+------+---------------+------+~+------+------------~

The most important information is in the TYPE column. Although the MySQL documentation refers to it as “join type”, I prefer to describe it as “access type” because it actually specifies how the data is accessed. The meaning of the type value is described in the next section.

About our book “SQL Performance Explained”
Probably the best book on SQL performance I've read
Guillaume Lelarge on Amazon.co.uk (5 stars)

About the Author

Photo of Markus Winand
Markus Winand tunes developers for high SQL performance. He also published the book SQL Performance Explained and offers in-house training as well as remote coaching at http://winand.at/

?Recent questions at
Ask.Use-The-Index-Luke.com

0
votes
1
answer
87
views

PostgreSQL Bitmap Heap Scan on index is very slow but Index Only Scan is fast

12 hours ago Markus Winand ♦♦ 881
index postgresql postgres sql
3
votes
2
answers
360
views

pagination with nulls

2 days ago Rocky 46
pagination
0
votes
2
answers
74
views