DBMS book cover

Your technical library

DBMS

16 modules · 102 topics

About this book
Concepts · DBMS

DBMS

This course builds a relational database engine from nothing. It starts with the problem a database solves — what goes wrong when a program keeps its data in plain files — and follows a query and a transaction down through every layer that answers it: the relational model and SQL, schema design, how tables sit on pages on disk, the indexes that find rows, the operators that run a query and the optimiser that chooses them, the transactions and concurrency control that keep many users correct, and the log that makes a crash survivable. It is written for any engineer who uses databases and wants to know what is inside one, and it assumes no database knowledge at all.

It builds on Data Structures and Algorithms for the in-memory structures and sorting it reuses, on Operating Systems for disks, the page cache, `fsync` and locks, and on Mathematics for the probability behind query estimates. Everything about databases themselves is taught here, from the first definition.

What a database is, the relational model and SQL give the vocabulary and the language: tables, keys and constraints, the algebra every query compiles into, and SQL read as that algebra — including the places, such as NULL, where SQL quietly departs from it. Schema design turns a domain into tables that cannot contradict themselves. Storage and the cost model puts tables on pages and prices every operation in page reads and writes, and indexes and B+ trees and hashing and specialised indexes build the structures that avoid reading everything. Query execution builds the operators that scan, join, sort and aggregate, and query optimisation the planner that chooses among them.

Transactions says what a database promises when many programs change data at once, and locking and timestamps, optimism and versions are the two families of mechanism that keep that promise. Recovery makes committed work survive a crash. Log-structured storage then builds the other great storage design — the LSM-tree — and compares it with the B-tree on the same scale. The last two modules go past the textbook: modern engines asks what changes when data no longer sits on spinning disks, and analytical engines shows how a column store scans a fraction of the data a query covers.

Design decisions are shown against engines that chose differently — PostgreSQL, MySQL's InnoDB, SQLite, RocksDB, LMDB and DuckDB — so each is visibly a choice. The PostgreSQL course then shows what one real engine chose, and System Design what these mechanisms become across many machines.

A few topics are marked optional: the theory behind the practice — relational calculus, the expressive-power proof, the normalisation algorithms and fourth normal form. Nothing later depends on them, so you can pass over them and come back.

102 topics across 16 modules, in dependency order.

This course builds a relational engine from first principles. Not how to use one, and not how one behaves across machines — how one is constructed: the dependency theory a schema rests on, the file and index structures that make a query fast, the algorithms that execute it, the protocols that keep it correct under concurrency, and the recovery method that makes a crash survivable.

A topic ends at the algorithm, not at the name. Each one states its invariant, gives the algorithm in steps, derives its cost in page I/Os, and names the case where it degrades — so you could implement it, or hand-execute it on a five-element example and get the right answer.

Design decisions are shown against engines that chose differently. PostgreSQL, InnoDB, SQLite, RocksDB, LMDB and DuckDB disagree with each other constantly, and those disagreements are the evidence that a decision was real rather than inevitable.

Topics still being written are labelled and excluded from progress, so the count reflects what is actually finished.

The same subject can appear in more than one course here, and what separates the appearances is altitude. B-trees are the clearest case: the node layout, the split and merge algorithms and the latch protocol are in this course; why a page-oriented structure beats a file at all, and when an LSM beats a B-tree, is System Design; what nbtree actually does and what it costs in production is PostgreSQL. Where this course needs a result one of the others already derived, it links back to it and does not repeat it.

Course map

Read at your own pace. Each topic is one continuous page; mark it done as you finish.

Start with 01.1 · Why a database: what goes wrong when a program keeps its data in filesReview what you have finished