Skip to content

Lab 07 — Sort and Aggregate

Scenario

A revenue leaderboard groups all orders by customer and sorts the aggregates while work_mem is limited to 2 MB. The plan may expose memory pressure and temporary I/O.

Run the exercise

make shell
\i sql/labs/07-sorting/bad_queries.sql

Investigate

  1. Identify aggregate and sort strategies.
  2. Record sort method, memory use, batches, and temporary reads or writes.
  3. Determine whether the constrained work_mem affects one or several nodes.
  4. Test session-local settings cautiously and compare repeated plans.
  5. Discuss concurrency risk before recommending a global memory increase.

Diagnostic question

Did execution spill to disk, and does the evidence justify changing the query, an index, or memory configuration?

Previous: Query rewrites · Next: Pagination