Demo: from 4 seconds to 40 ms
On This Lesson 3 topics
This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.
In this lesson
fix one slow Shop endpoint query step by step with evidence.
Draft outline details
Step by step
- Find the statement in
pg_stat_statements; capture itsEXPLAIN (ANALYZE, BUFFERS)(about 4 s, sequential scan with a sort). - Read the plan: the filter removes most rows, and the sort spills to disk.
- Add
(customer_id, created_at DESC); re-run and show the sort gone. - Planned mistake: wrap the date column in
date_truncin theWHERE; the index is skipped. Fix: use a half-open range. - Replace
OFFSETwith keyset pagination. - Record before/after plans and timings (about 40 ms).
Prepares MID-013-LAB1.
Check your understanding
Which single change removed the sort?
Show answer
The composite index matching the ORDER BY.
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.