Index

Free, with Google

Keep going, free.

A free account opens lessons 2 and 3 of every track, 33 more lessons, and keeps your progress and review cards on every device.

Start free with Google

A chalk plan

Open everything on chalk.

Every lesson, board, video, lab and paper, and the full review decks. Yearly is $39/year.

See plansStart free instead

Module 01 · Database Internals · One Database, to the Bolt · about 18 min to read

Play it as a journeyTutor comes with a plan

A row at a time, or a thousand: execution models

The Query Planner
The Query Planner · Open board

The planner picks one plan, a tree of steps. This lesson is about the next question: how do those steps hand data to each other once the plan starts to run.

Before you start. The plan, running showed a plan as a tree where each step asks the step below for the next row, and said analytic engines hand up a batch instead. Database 07: The Query Layer built that one-row-at-a-time tree by hand. Pages & Heap Files showed that a column store keeps each column in its own pages, so one question reads only the columns it names. This lesson explains why handing up a batch is faster, and why a column that is stored alone also gets small.

Lesson 12 of 26 in Database Internals

The rest of this lesson is part of a plan.

A plan opens every lesson, board, video, lab and paper on chalk. Yearly is $39/year.

See plansAlready a member? Sign in

Or start free: a free account opens lessons 2 and 3 of every track.

In this lesson

  • 2005: a database spent 26.6 seconds where a loop needs 0.22
  • One row per call: the Volcano iterator
  • A thousand values per call: the vector
  • One loop for the whole query: compilation
  • Fewer bytes per value: dictionary encoding
  • Same value repeated: run-length encoding
  • Why DuckDB and ClickHouse are fast
  • Volcano against vector against a fused loop
  • What each model gives up
  • Compression, with real sizes
  • Where these ideas live

Terms it explains: Volcano iterator, vector, Compiled, dictionary encoding, bit-packing, Run-length encoding, Common mistakes, Volcano, Vectorised, frame of reference, DuckDB, ClickHouse, Postgres, Parquet files.

Lab

Your query has an index and Postgres refuses to use it. At what fraction of the table does reading all of it in order start to win?

Drag What fraction of the table the query actually matches upward one notch at a time, and watch The plan it picks.

Open The selectivity crossover

Your sort spills to disk. Give it more memory and it stops. Why does nobody set work_mem to a gigabyte?

Click The default, then A big desk and The whole room, drag Sessions running it at once, and watch The whole box.

Open The work_mem dial

Related papers

Review Database Internals