![[chap_4_operations.png]]
# Chapter 4: The Grand Operations (The Soldiers)
The General has drawn up the perfect battle plan. But someone still has to go out into the mud and execute it. In Postgres, the actual physical labor is performed by a mismatched army of highly specialized Operations. They are the grunts.
At the very bottom of the hierarchy are the **Scouts**. If the general commands brute force, the [[SeqScan|Sequential Scan]] begrudgingly walks through every file in the cabinet. If there is a cheat sheet available, the [[IndexScan|Index Scan]] or [[IndexOnlyScan|Index Only Scan]] cleanly snipes the required rows. Sometimes, a complex maneuver like the [[BitmapHeapScan|Bitmap Heap Scan]] and [[BitmapIndexScan|Bitmap Index Scan]] work together, reading an index to build a massive coordinate map before fetching all the pages at once to minimize disk arm movement.
Once the data is retrieved, the **Matchmakers** take over. When asked to join two lists together, the exhausted soldiers use different strategies depending on how terrible the lists are. A [[NestedLoop|Nested Loop Join]] is the brute-force approach, comparing every item in list A to every item in list B. If the lists are massive but unsorted, the engine will painfully build a temporary table via a [[HashJoin|Hash Join]]. But if both lists are perfectly ordered, the [[MergeJoin|Merge Join]] elegantly zippers them together in a single, beautiful pass.
Finally, the data must be presented. The **Organizers** take the raw, matched rows and beat them into shape. An [[Aggregate]] or [[WindowAgg]] performs mass summation, while a [[Sort]] fiercely shoves rows into alphabetical or numerical order. Sometimes, if the job is too massive for one lonely elephant, the General will order a "Gather" maneuver, summoning a team of parallel workers to split the labor and scream their results back to the leader as fast as possible. Sometimes, the elephant will even use a [[Materialize]] operation, essentially putting a bucket underneath a leaky pipe to catch a temporary state so it doesn't have to recalculate it later. Operations like [[Limit]], [[Result]], and [[ModifyTable]] handle the final trimming and writing, ensuring that when the result is finally handed back up to the user, the exact minimum amount of effort was expended.
But there is a problem. The soldiers are fast, but they are fragile. What happens if the general issues an order and someone trips over the power cord before the physical work is finished? To survive the hazards of the world, our elephant needs more than just a battle plan—he needs a **Promise**.