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.
Lesson 20 of 26 in Database Internals
The rest of this lesson is part of a plan.
A plan opens every lesson, board, video, lab and paper on chalk. Yearly is $39/year.