Skip to content
About
Main content
Query Engines

Execution Engine Runtime

Once a query plan is chosen, why does the machine still sit idle, and what does each mechanism of a query runtime pay to buy that idle time back?

Who this mechanism is for: a developer who writes code and knows basic SQL, but has never looked inside a query engine. You do not need to know how a database executes a query. Every technical term is explained the first time it appears, and again in the glossary at the end. This mechanism assumes only that you have a rough idea of what a CPU core, a thread, a and a network are. A short primer follows the introduction.

The story we will follow

Mateo is a query-engine engineer at Gridlark, a company that analyzes electricity use for power utilities. He owns Lark, Gridlark's in-house SQL engine. Lark runs on a cluster of 40 machines (16 cores and 64 GB of memory each) and reads Parquet files (a column-oriented file format). The main table is readings: about 40 billion rows per month, one row per smart-meter reading, with the columns meter_id, ts (timestamp), kwh, tariff_zone and status. Two smaller tables help: meters (about 12 million rows) and tariffs (a few hundred rows). Lark runs three kinds of work: dashboards that must answer in seconds, a nightly billing job that runs for hours, and a new experiment on a "functions-as-a-service" platform.

Hana is the head of the data platform. She owns the cluster budget, and she asks the questions that engineers prefer to avoid: "Why is the cluster busy but slow? Why did the invoice go up?" A separate team writes the planner, the part of the engine that chooses which steps to run and in which order. The planner team is good. This mechanism is about the next stage: how the chosen plan is actually run on real cores and real machines.

During this mechanism, Mateo and Hana meet seven problems, one at the start of each article below. Each problem looks like a bug. Each one is actually a consequence of how a query runtime must behave. At the end of each article, we go back and solve the problem with the article's mechanisms.

This is the main idea of this whole mechanism:

How this mechanism is organized

After that: a summary, hands-on labs, interview questions and a glossary.

One request: keep the arithmetic. Almost every section ends in a small formula, and each formula gives a number you can compute for your own system before you build anything.

What do I do, and what does each option cost?

Can I see it myself?

Can I reason about it under questioning?

Trade-offs

The tensions this mechanism takes a position on. Each recurs across mechanisms.

Recurring principles

Ideas this mechanism meets that keep coming back, mechanism after mechanism.