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

Five stages, left to right, for the top-10 most-played songs query: 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 counts, sort, and return the top 10. A numbered description of each stage sits under the picture.

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.