Database Internals

Pages, indexes, logs and transactions underneath SQL.

What happens inside a database: storage hardware, pages and rows, row and column stores, the buffer pool, B-trees, LSM trees and other indexes, query planning, join algorithms and the optimiser, write-ahead logging and crash recovery, transactions, isolation levels, locking, MVCC, replication and distributed SQL. Vendor-neutral: PostgreSQL, MySQL/InnoDB, SQLite, SQL Server, Oracle, RocksDB and the managed cloud databases. By the end you can read a query plan, choose indexes, reason about concurrency bugs and diagnose a slow database.

6
chapters
21
modules
~9h
of learning
21
live now
21 modules

Take modules in any order. The route suggests one that builds up naturally.

Take a look inside

The big picture, before the details

One query's journey through a database engine, from SQL text to pages on disk, with the log and the copies that keep it safe. Watch the tour, or click any part.

SELECT … WHERE id = 42parse → planIndex Scanbuffer pool (memory)8 KB pages on diskwrite-ahead logT1 · T2 · locksisolation · MVCCreplicareplicaone query's journey

A query arrives: SQL text over a connection: what you want, not how to get it (module 1).

A taste of module 15: two transactions collide at each isolation level. Find the lowest level that stops each glitch.

T1: SELECT count(*) FROM doctors WHERE on_call; → 2
T2: SELECT count(*) FROM doctors WHERE on_call; → 2
T1: UPDATE doctors SET on_call = false WHERE name = 'Alice';
T2: UPDATE doctors SET on_call = false WHERE name = 'Bob';
T1: COMMIT;
T2: COMMIT; → nobody on call

Each read a snapshot showing two doctors, each changed a different row, so no write conflict was detected. Run one after the other, the second would have stayed; together, nobody is on call. That's write skew.

01

The big picture

What a database does with your query, and the hardware it works with.

2 modules · 40 min

02

Storing data

How rows sit inside pages and files, and how memory caches them.

3 modules · 70 min

03

Indexes

Finding rows without reading everything.

4 modules · 100 min

04

Running queries

Turning SQL into a plan, and a plan into rows.

3 modules · 75 min

05

Transactions and durability

Keeping data correct when things fail and users collide.

5 modules · 125 min

06

Beyond one machine

Copies, consensus and choosing an engine.

4 modules · 120 min