MySQL Query Optimization Checklist: What Should You Check First?
DB

MySQL Query Optimization Checklist: What Should You Check First?


When MySQL query performance becomes a problem, it is easy to waste time restarting the analysis from scratch every time. A consistent review checklist makes the work much faster and less error-prone.

This post is intentionally structured as a practical checklist rather than a long theory guide.

The core idea is that slow queries are easier to fix when you narrow them down step by step through access path, read volume, sorting, and result size.

1. Have you identified the real slow query?

  • did you isolate the actual slow query?
  • is it slow on average or only in certain cases?
  • did behavior change after a deploy?

2. Did you check EXPLAIN?

  • is type equal to ALL?
  • is key equal to NULL?
  • is rows unusually large?
  • does Extra show Using filesort or Using temporary?

3. Do the indexes match the query pattern?

  • is there an index for the WHERE condition?
  • is there an index on join keys?
  • does the index also help with ORDER BY?
  • do functions or transformations block index usage?

4. Is the query reading too many rows?

  • is it reading only the rows it needs?
  • is a LIMIT missing where one should exist?
  • is it scanning a wider range than necessary?

5. Is the result set too large?

  • are you using SELECT * unnecessarily?
  • are only needed columns being fetched?
  • is the app reading data it does not really use?

6. Are sorting or temporary operations expensive?

  • is ORDER BY adding major cost?
  • are GROUP BY or DISTINCT heavy?
  • are temporary structures growing too large?

7. Is the join structure inefficient?

  • is join order inefficient?
  • are join input sets too large?
  • would narrowing one table earlier help?

8. If it is a write query, did you consider lock impact?

  • does it run inside a long transaction?
  • does it touch hotspot rows frequently?
  • is it connected to lock wait timeout or deadlock issues?

9. Did you validate in a realistic environment?

  • does the issue appear at real data volume?
  • is the test data distribution very different?
  • do you have a before/after comparison baseline?

Common mistakes

1. Adding one index and stopping there

The deeper problem may be sorting, joins, or oversized results.

2. Tuning from the SQL text alone

Without execution plans, you end up guessing.

3. Trusting only a small test environment

Real production scale can behave very differently.

Start Here

Continue with the core guides that pull steady search traffic.