Lesson 24 / 30

EXPLAIN at a Glance

Read EXPLAIN output to see whether MySQL uses an index or a full table scan, and fix slow queries.

Reading a query plan

EXPLAIN shows whether MySQL will use an index or scan the whole table.

EXPLAIN SELECT * FROM orders WHERE customer_id = 1;

Output:

id | table  | type | possible_keys        | key                  | rows
1  | orders | ref  | idx_orders_customer  | idx_orders_customer  | 2

type: ALL is a red flag

type: ALL in EXPLAIN means a full table scan — on a large table, that's usually a sign a useful index is missing.

Quick check: In EXPLAIN output, what does `type: ALL` usually indicate?

  • The query used an index perfectly
  • The table has no rows
  • The query will always be fast
  • A full table scan happened
Answer

A full table scan happened — ALL means MySQL had to read every row — often fixable with an index.