As data grows, query speed matters. Optimization is mostly about helping the database avoid scanning whole tables — with the right indexes and query shapes — and EXPLAIN is how you see what it's doing.
EXPLAIN
EXPLAIN SELECT * FROM students WHERE email = 'aanya@x.com';-- Look for a full-table scan where you expected an index to be used.
What makes queries slow
- Missing indexes on filtered/joined columns → full scans.
- Functions on columns —
WHERE YEAR(d) = 2026can't use an index; use a range instead. - Leading wildcards —
LIKE '%term'can't use an index;'term%'can. - SELECT * — moves more data than needed.
- Not filtering early — reduce rows before joining/aggregating.
Key takeaways
- 01EXPLAIN shows the query plan — hunt for full-table scans.
- 02Missing indexes on filtered/joined columns are the top cause of slow queries.
- 03Functions on columns and leading %-wildcards disable indexes.
- 04Filter early, select only needed columns, and measure before optimising.
