# 3.2.3 The Organizers (Aggregations) ![The Organizers](assets/arch_plan_organizers.png) With data retrieved by the Scouts and combined by the Matchmakers, the final step in the Query Algebra is usually shaping the output for the Admiral. This falls to **The Organizers**, a group of extremely stressed workers tasked with squashing, sorting, and throwing away data. ## Aggregates: The Compressors When the Admiral demands "Find me the SUM of all blue socks," he does not want a list of one million socks. He wants a single number. The **[[Operations/Aggregate|Aggregate]]** node is like a frantic duck trying to cram a towering mountain of suitcases into a single, tiny bucket. - A **HashAggregate** throws suitcases into categorized buckets on a large Desk (`work_mem`) to count them all at once. - A **GroupAggregate** requires the suitcases to be perfectly sorted beforehand, allowing the worker to count them as they pass by on a conveyor belt, resetting the counter every time the category changes. ## Sort: The Obsessive Alphabetizer The **[[Operations/Sort|Sort]]** node is simple but dangerous. The worker demands a massive Desk to lay out every single suitcase and alphabetize them. If the pile is too big for the Desk, the worker screams in frustration and starts dumping suitcases onto the slow, heavy metal floor (the Disk). A "Disk Spill" during a Sort is the elephant's worst nightmare! ## Limit: The Head Chopper The **[[Operations/Limit|Limit]]** node is the most powerful tool for a lazy elephant. Due to the "Pull" model of the army, the Limit node simply stands at the top of the hill, counting suitcases as they arrive. If the query says `LIMIT 10`, the moment the 10th suitcase is handed over, the Limit node yells "STOP!" and immediately shuts down the entire army below it. Answering "Give me the first 1" is infinitely cheaper than "Give me all of them." --- [[Chapter 3/3.2.2 - The Matchmakers (Joins)|← 3.2.2 - The Matchmakers (Joins)]] | [[Chapter 3/3.2 - Query Algebra|↑ 3.2 - Query Algebra]] | [[Chapter 3/3.3 - Sargability|3.3 - Sargability →]]