Skip to main content
Albero Academy

Query Optimization

Read the query plan and make slow queries fast.

Applied SQL9 min

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

read the plan
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) = 2026 can'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

  1. 01EXPLAIN shows the query plan — hunt for full-table scans.
  2. 02Missing indexes on filtered/joined columns are the top cause of slow queries.
  3. 03Functions on columns and leading %-wildcards disable indexes.
  4. 04Filter early, select only needed columns, and measure before optimising.

Finished this chapter?

Mark it complete to track your progress through SQL.