Indexes and query plans
An index trades write cost and storage for faster reads—when it matches the query.
What you will be able to do
- Read the plan from the innermost node outward.
- Compare estimated rows with actual rows; large gaps signal stale statistics.
- Use CREATE INDEX CONCURRENTLY in production.
In plain English
EXPLAIN ANALYZE shows what the planner actually did. A B-tree index helps equality and range predicates; a composite index follows the leftmost-prefix rule. Do not index every column; write cost and bloat add up.
create index lessons_course_idx
on lessons (course_slug, minutes desc);
explain analyze
select slug, title, minutes
from lessons
where course_slug = 'html'
and minutes >= 10
order by minutes desc
limit 5;Your turn
MediumIndex a lookup
Create an index on lessons(course_slug, minutes desc) and explain why it helps a filtered, ordered query.
SQL · starter
create index lessons_idx on lessons ();Check your understanding before moving on.
Knowledge checkQuestion 1
What does EXPLAIN ANALYZE do that EXPLAIN does not?
Select an answer to continue
Study tools
Make it yours.
Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.
Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign inFinished reading?
Lock in what you just learned.
0%
Mark this lesson complete to save your place and move one step closer to the certificate.