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
- Run
sql/labs/01-baseline/bad_queries.sqlwithmake first-lab. - Do not create an index yet.
- Record planning time, execution time, estimated and actual rows, loops, and buffer hits and reads.
- State one falsifiable hypothesis.
- Run
sql/labs/01-baseline/experiments.sqlonly after deciding what evidence would support or reject it. - Open
sql/labs/01-baseline/solutions.sqlonly 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.