Skip to content

Lab 01 — Establish the Baseline

Source reference

This lab extends the execution-plan introduction in SQL/Query Optimization with PostgreSQL actual rows, loops, buffers, settings, and repeated measurement.

Business requirement

The Orders API must return the 50 newest completed orders for one customer. A high-activity customer reports latency far above the API SLO.

Rules

  1. Run sql/labs/01-baseline/bad_queries.sql with make first-lab.
  2. Do not create an index yet.
  3. Record planning time, execution time, estimated and actual rows, loops, and buffer hits and reads.
  4. State one falsifiable hypothesis.
  5. Run sql/labs/01-baseline/experiments.sql only after deciding what evidence would support or reject it.
  6. Open sql/labs/01-baseline/solutions.sql only after writing your diagnosis.

First diagnostic question

The query returns at most 50 rows. Which plan node processes the most rows, and what evidence proves that work—not the result size—is driving latency?

Suggested workflow

Use the evidence template in Lab operations, then compare repeated runs before changing the query or indexes.

Curriculum · Next: Index access paths