Index

Module 01 · Database InternalsOne Database, to the Bolt

The Query Planner

The Query Planner
The Query Planner · Open board

The Database Internals board behind most “why is this query slow” questions.

Before you start. The last lesson showed that Postgres, the open-source database this series opens up, never deletes a row on update - it writes a fresh copy and leaves the old one alone for anyone still reading it, until vacuum clears it away later. This lesson is about a different machine entirely: the one that decides, for any query you type, which of the table’s rows to even look at, and in what order.

Continue reading with a plan

The first three lessons of every track are free. This lesson is included with a plan, which unlocks every lesson, board, video, lab and paper for one price.

View plans →Already a member? Sign in

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 paper

Review Database Internals →

Saved in this browser, and to your account when you sign in.