# 3.2 The Assembly Line (Query Algebra) ![Query Algebra](assets/arch_plan_algebra_summary.png) The Head Chef has drawn up the perfect service plan. But someone still has to go out and execute it. In Postgres, the actual physical labor is performed by a mismatched team of highly specialized **Operations** (Plan Nodes), executing what we affectionately call the **Query Algebra**. ## The Order-Driven Kitchen (The Pull Model) To understand the Staff, you must first understand how they communicate. The Postgres Execution Engine does not "push" data from the bottom up. Instead, it is an **Order-Driven Kitchen**. This "Pull" model ensures the elephant never does more work than he absolutely has to. To understand why this is special, contrast it with a **"Fire Hose" (Push) Model**. In a push kitchen, as soon as someone finds a potato, they throw it at the next person, who peels it and throws it at the next. If the customer suddenly says "I'm full!", the kitchen is still full of flying potatoes! In the Elephant Cafe, no work happens by accident. Every single physical movement is the result of someone higher up the chain explicitly demanding one more item. If you only asked for the first 10 plates (a **[[Operations/Limit|LIMIT]]**), the Maitre D' stops shouting after the 10th plate arrives. The signal to "STOP" travels back down the chain instantly. The lower stations immediately stop working and go to tea, even if there are millions of records left. It’s a very sensible way to be lazy! The kitchen is divided into three primary teams, each doing a different job. To understand the query plan, you must visit each station: 1. **[[Chapter 3/3.2.1 - The Food Runners (Scans)|The Food Runners (Scans)]]**: The ones who fetch raw ingredients from the pantry. 2. **[[Chapter 3/3.2.2 - The Matchmakers (Joins)|The Matchmakers (Joins)]]**: The ones who pair ingredients from different suitcases. 3. **[[Chapter 3/3.2.3 - The Prep Station (Aggregations)|The Prep Station (Aggregates)]]**: The ones who mash, stir, and count the final totals. ## The Logistics and the Fog of War Every staff member in the kitchen needs a place to work. In **[[Chapter 5/5.0 - The Hunger of Resources (Memory & Disk)|Chapter 5]]**, we will explore how every staff member is given a small **Counter** (`work_mem`). If a counter is too small, a "Spill to Disk" (the Frozen Pantry) occurs—turning a fast service into a slow ordeal! Furthermore, even the best-organized kitchen runs into traffic. In **[[Chapter 6/6.0 - The Waiting Game (Workloads & Locking)|Chapter 6]]**, we will observe these staff members bumping into each other (Locks) or waiting for the slow elevator to return from the basement (I/O Wait). By using the **[[Operations/_Postgres Operations|EXPLAIN ANALYZE]]** command, the Maitre D' hands you a **Service Receipt** detailing exactly how many plates were pulled and how much each staff member sweated. --- | ← Previous | ↑ Table of Contents | Next → | | :--- | :---: | ---: | | [[Chapter 3/3.1 - The Head Chef's Menu (Query Planning)\|3.1 The Head Chef's Menu (Query Planning)]] | [[Learn You a Postgres for Great Good\|Home]] | [[Chapter 3/3.2.1 - The Food Runners (Scans)\|3.2.1 The Food Runners (Scans)]] |