How to Read MySQL EXPLAIN for a Slow SELECT
Start with one representative slow SELECT and a safe staging database. The plan can show expected access paths before you change an index or alter a production query.
Procedure
- Choose representative inputs. Reproduce the query against a sanctioned dataset with similar table distributions. Remove sensitive values from the notes. Check database version and schema first.
- Read the estimate. Use plain EXPLAIN for your installed server. Compare the selected key, estimated rows, join order and operations reported in Extra. Keep units and estimation uncertainty explicit.
- Test one change. Compare plans for the original query and a staged index or query rewrite. Measure results separately and confirm the rows returned still match. Execution-based analysis can run the statement, so apply it only where authorized.
- Review deployment impact. Check index size, write cost and migration lock behavior. Retest normal workloads before recommending the smallest production change.
If several queries look plausible, triage a MySQL slow query log safely to identify the small set whose plans are worth investigating.
Related guides
- How to Investigate MySQL and MariaDB Lock Waits
- How to Investigate a Slow First Server Response
- Developer Resources articles
Official references
Ferkesh Hosting. Last reviewed .
Ця стаття була корисною?
Спасибі за відгук!