Build sort and aggregate with a memory limit

The plan as a tree of steps, with the steps that must see every row before they can answer. Sort and aggregate are two of those steps; this lesson builds them with a limit on how much memory each may use.
Before you start. The plan, running watched Postgres sort and group with work_mem as the limit, and counted temp-file blocks as the sign of a spill. Sorting & Searching has merge sort in memory. This lesson builds the version that goes to disk, so you can see why the numbers in 0579 come out as they do. The code is in teaching/code/database-internals/02-sortagg; it reads Go.