Why is a MySQL table also its primary key, and what are the two logs for?
MySQL is the database I meet most often in large web companies, and it earned that place by being fast, simple to run, and very good at one thing: lots of small reads and writes by primary key.
InnoDB stores every row inside the primary key's B-tree. A lookup by primary key goes straight to the row. Choose the key well and most queries are cheap.
The binlog has fed replicas, backups and change-data pipelines for decades. Huge fleets are built on it.
Clear memory settings, a small set of logs, and tooling at every layer, from MySQL Shell to orchestrator and Vitess.
Complex analytics with many joins, rich data types, or extensions like PostGIS: PostgreSQL usually fits better.
This track tells MySQL as one story: what InnoDB is, how it stores your data, what happens on every write, how it stays up, how I run it, and what to do when it breaks.
This page is about one file per table. I show you how InnoDB stores a table as its own primary-key index, and how two logs split the jobs: redo for crashes, binlog for replicas. After it you will be able to find any table's .ibd file, read checkpoint age, check binlog retention, and tell whether undo is piling up.
A relational database. Each table file is its primary-key index.
Good at: High-volume websites. Lookups by ID. Simple queries at huge scale. Operationally simple read replicas. Two logs: redo for crashes, binlog for replicas.
Runs as: one mysqld process, a thread per connectionStep through a primary key lookup in InnoDB, then compare it with PostgreSQL using the switch.
Three: root, branch and leaf. In InnoDB the leaf holds the row itself, so there is no separate table page to read. PostgreSQL needs one more.
You add an index on email to a large InnoDB table whose primary key is a UUID stored as CHAR(36). The new index is much bigger than the emails alone. Why, and what would you have done differently?
Write your answer down first. Then open mine.
Why: in InnoDB, every secondary index entry stores the primary key as its pointer to the row. Each email entry carries the 36-character UUID with it. A lookup by email finds the primary key in the secondary index, then walks the clustered index to get the row.
The other cost: random UUIDs land all over the clustered index, so inserts split pages and the buffer pool holds more pages than it needs to.
What I would do: store the UUID as BINARY(16) with UUID_TO_BIN(uuid, 1), which also reorders a version 1 UUID by time. Or use a BIGINT auto-increment primary key and keep the UUID as a unique secondary column for the outside world. Every secondary index gets smaller either way. Watch the difference in Watch an index grow.
The same mechanism, replication and failover, migrations and upgrades, sharding and partitioning, elsewhere on the site: in real incidents, in measurements, and in designs.
Pick an answer. You will see whether it is right, and why.
1. How are rows ordered inside an InnoDB table file?
The table is a clustered index on the primary key: the rows live in the leaves of that B+ tree.
2. Which log does crash recovery replay?
Redo rebuilds the data pages. The binlog is for replicas and point-in-time recovery.
3. One snapshot stays open while other sessions update rows. Which number grows?
Purge cannot remove undo records the old snapshot might need. In Notebook 1 it went from 11 to 20,006.
4. Why do random UUID primary keys slow inserts down?
Each insert dirties a different page, and every secondary index stores the 16-byte key too. Time-ordered keys go to the end.
How do databases actually work? From one row on disk to transactions: the words you need, PostgreSQL, MySQL and MongoDB from the files up, then Redis, Cassandra and vector search, side by side, and the query and concurrency traps.