Slow queries kill performance. Optimize them:
Use EXPLAIN: See how the database executes your query. Look for table scans (bad) vs index scans (good).
Common problems:
- Missing index on WHERE/JOIN columns
- SELECT * when you only need few columns
- N+1 queries (query in a loop)
- Functions on indexed columns:
WHERE YEAR(date) = 2024can't use index
Solutions:
- Add appropriate indexes
- Select only needed columns
- Use JOINs instead of loops
- Rewrite:
WHERE date >= '2024-01-01' AND date < '2025-01-01'
In interviews, mention EXPLAIN and index usage when discussing database performance.