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 16 min to read

Play it as a journeyTutor comes with a plan

When the table lives on fifty machines: distributed queries

The Query Planner
The Query Planner · Open board

The planner choosing a plan from row-count guesses. On many machines it makes the same kind of choice, and the price of a wrong guess is rows sent over a network.

Before you start. The Query Planner showed that the planner bets on how many rows a step returns, and picks a join method from that bet. Build three ways to join built the hash join, with its build side and probe side, and counted comparisons exactly. Partitioning split one big table by key range or by hash across machines. Batch Processing introduced the shuffle that brings one key to one machine. This lesson puts those four together inside a query.

Lesson 22 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

  • 1984: a database that stopped being one machine
  • Partition: one table, many pieces
  • Pruning: not opening the pieces that cannot match
  • Local work first: count where the rows live
  • The join problem: two tables, two places
  • Shuffle join: send every row to the machine that owns its key
  • Broadcast join: copy the small table everywhere
  • Choosing: it depends on which table is small
  • Co-location: the join that moves nothing
  • The three row counts, at fifty machines
  • When both sides are big
  • Skew: the slowest machine sets the time
  • Postgres: partitions on one machine, the same ideas
  • Real systems

Terms it explains: partition, partition key, pruning, shuffle join, broadcast join, Common mistakes, Teradata, Spark.

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