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.
On my Own Behalf
I offer training, tuning and consulting. Buying my book “SQL Performance Explained” (from €9.95) also supports my work on this website.