Inside the database
Strata keeps every table and index as a B-tree on pages of 4,096 bytes, writes each transaction to a log before it touches the database file, and plans each query by cost. This page opens the database the console keeps in this browser and shows its pages, its log, a crash and its recovery, and the planner at work.
The B-tree of a table or an index
A table’s tree is keyed by rowid and holds its rows in the leaves; an index’s tree is keyed by its columns and the rowid. A WITHOUT ROWID table is an index tree keyed by its PRIMARY KEY, whose entries are whole rows, and its indexes end in the key’s columns. Open an interior page to see the pages under it, and press a page to see its cells.
A page
Press a page.
The write-ahead log
A commit appends every page it changed as a frame, marks the last frame as the commit with the size of the database, and makes the log durable. Each frame carries a checksum that runs on from the frame before it. A checkpoint copies the newest frames into the database file and starts the log again.
A crash in the middle of a transaction
A database of its own, so the console’s is not touched: three transactions commit, a fourth inserts rows until its pages spill into the log, and then the power goes. A random part of what the disk had not yet made durable survives, so the last frame can be cut in the middle. Opening the files again replays the log up to its last whole commit.
The planner choosing a join order
For a join of four tables the planner works out the cheapest way to join every subset of them, from one table up, and keeps the best for each. Below are the ways it weighed for the whole join, cheapest first, with the cost it estimated, and then the plan it chose, run with the rows each step expected and gave.