EXPLAIN shows how MySQL plans to execute a query — which indexes it will use, how many rows it expects to touch, and in what order it joins tables. It turns performance tuning from guesswork into diagnosis.
Key Points
- Prefix any query: EXPLAIN SELECT …;
- type column ranks access quality: const > ref > range > index > ALL
- 'ALL' means a full table scan — usually the red flag to fix
- key shows the chosen index; rows estimates rows examined
- 'Using filesort' and 'Using temporary' in Extra flag expensive operations
- EXPLAIN ANALYZE (MySQL 8.0.18+) runs the query and reports real timings
.png)