Skip to content
Ameen Abozaid
Planned lessonMID-013-L07

Demo: from 4 seconds to 40 ms

  • Lesson 7 of 8
  • Mid-level
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

  1. Find the statement in pg_stat_statements; capture its EXPLAIN (ANALYZE, BUFFERS) (about 4 s, sequential scan with a sort).
  2. Read the plan: the filter removes most rows, and the sort spills to disk.
  3. Add (customer_id, created_at DESC); re-run and show the sort gone.
  4. Planned mistake: wrap the date column in date_trunc in the WHERE; the index is skipped. Fix: use a half-open range.
  5. Replace OFFSET with keyset pagination.
  6. 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.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Continue to next lesson

Type to search levels, phases, modules and lessons.