How a Query Runs
Concept. A database engine turns SQL text into a physical plan of operators, such as scans, joins, aggregates, and sorts, and runs it, often split across many workers.
Intuition. SELECT user_id, COUNT(*) FROM Listens GROUP BY user_id describes the result you want. The engine decides how to produce it.
The Journey: From Text to Results
Figure: How one query runs: five stagesThe top-10 most-played songs query moves through five stages, left to right. 1, parse and analyze the SQL. 2, choose a plan of operators: scan, join, group, sort. 3, the coordinator splits the scan into tasks. 4, workers run the tasks in parallel and compute partial counts. 5, merge the partial counts, sort, and return the top 10.
Figure 1. The top-10 songs query, stage by stage. The exact plan depends on the engine, its statistics, the data layout, and the available resources.
You write the result you want. The engine chooses the physical work needed to produce it. Module 2 opens that engine, from storage on one machine to computation across many workers.