Architecture
Explore disk-paged B+trees, bounded memory and crash recovery.
One engine, two entry points
Embedded applications call the Go engine directly. The standalone server adds network protocols, authentication and operational services around the same database foundation.
SELECT * FROM ideas;The embedded path avoids a network round trip. The server path gives other processes a connection over the MySQL 8.4 SQL and wire protocol.
From SQL to rows
| Layer | Responsibility |
|---|---|
| Engine | Database lifecycle, query API and transaction entry points |
| Query | SQL lexing, parsing and statement representation |
| Catalog | Tables, expression evaluation and statement execution |
| B+ tree | Indexed key storage and lookup |
| Storage | Buffer pool, persistent pages and write-ahead logging |
The repository organizes these layers under pkg/. Use that code and its regression tests as the authority for specific behavior.
Disk pages, bounded memory
Each table and index is a B+tree of 4 KiB pages with CRC-32C checksums. The buffer pool defaults to 128 MiB. Opening a database loads catalog metadata, not every row into memory.
Results stream to clients. Large transaction write sets, sorts, eligible GROUP BY groups and derived UNIONs spill to scratch files beside the database. Memory use still depends on the statement: the page cache is not a hard cap on total server memory.
Set -cache in pages and -memory-limit for a soft memory budget. The server also detects container cgroup limits.
Durability & recovery
Group commit batches WAL syncs. A rollback journal protects against torn page writes, while fuzzy checkpoints and a persistent free list support recovery and page reuse. Checkpoints run every five minutes or after 256 MiB of WAL by default.
Keep the database and associated files together. Use the supported backup facilities for consistent backups instead of copying a live database file by itself.
Explore the internals
See the architecture overview and the detailed architecture guide. For practical deployment boundaries, continue to the production guide.