Menu

Why UUIDv4 Causes PostgreSQL/InnoDB B-Tree Bloat — and How RFC 9562 UUIDv7 Fixes It
📰

Why UUIDv4 Causes PostgreSQL/InnoDB B-Tree Bloat — and How RFC 9562 UUIDv7 Fixes It

DEV Community: postgres·Jason Y. (dev_in_the_fog)·12 days ago
#38YC8lXh
#devtopostgresql#devto#dev#uuidv7#bits
Long article (279 words) — no AI summary yet.
Reading 0:00
15s threshold

Using random UUIDv4 values as database primary keys looks clean at 100k rows and turns painful past 20M rows. The bottleneck is not UUID size (16 bytes)—it is write locality inside B-Tree indexes.

1. What Random UUIDv4 Does to B-Tree Pages

Sequential keys append to the rightmost leaf page of a B-Tree, so hot index writes stay inside RAM ( shared_buffers in PostgreSQL, innodb_buffer_pool in MySQL).

Completely random UUIDv4 keys scatter inserts across the entire index:

Half-full page splits inflate index size by 30–50% and drive random disk I/O.

In MySQL InnoDB, because the primary key is clustered and copied into every secondary index, random UUIDv4 keys degrade cache hit ratios across all indexes on the table.

2.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.