Inside a Database
Tables whose keys point at each other, the B-tree that finds a row, three ways to join two tables and the planner that prices them, then transactions, the log that survives a crash, and the tree that writes in layers.
Databases & Data
Before you start
Some lessons here build on lessons from other arcs: Race Conditions, Bloom Filters.
- 1
Relational Databases: Tables & Keysin review
Data · Databases · ~20 minA database is tables of rows whose keys point at each other: a primary key names a row, a foreign key points at one, and the engine refuses every row that would break a pointer.
- 2
B-Trees: How Indexes Workin review
Data · Databases · ~25 minAn index is a wide, shallow tree with every leaf at one depth: a lookup reads one page per level, an insert splits upward, and the root grows only at the top, so any row is a few reads away.
- 3
SQL Joins, Visualizedin review
Data · Databases · ~25 minA join pairs the rows of two tables whose keys agree: a nested loop, a hash table, and two sorted runs find the same pairs at three prices, and the outer joins keep the rows nobody matched.
- 4
Query Plans: How SQL Executesin review
Data · Databases · ~25 minSQL says what, not how: a cost-based planner reads the table statistics, prices every way of scanning and joining in page reads, prunes the dearer plan over the same tables, and runs the cheapest.
- 5
Transactions & ACIDin review
Data · Databases · ~25 minA transaction is all or nothing and alone in the world. Interleave two transfers and an update is lost; lock what each touches until it ends and the books balance, at the price of the odd deadlock.
- 6
WAL: Crash Recoveryin review
Data · Databases · ~25 minWrite the intention to a log before touching a page, force the log at commit, and after a crash replay what was promised and undo what was not.
- 7
LSM Trees: Writing in Layersin review
Data · Databases · ~25 minWrites fill a sorted table in memory, full tables flush to disk as immutable runs, runs merge downward in the background, and a read checks the layers newest first.