# How UUIDv4 Primary Keys Affect Database Insert Performance

DevFeed: [How UUIDv4 Primary Keys Affect Database Insert Performance](<https://devfeed.tech/articles/why-uuid-primary-keys-quietly-destroy-database-performance-39564.md>)

Original publisher: [Read original article](<https://ankit-rana.com/logs/12-uuids-primary-keys-performance/>)

Author: hello@ankit-rana.com

Published: 2026-03-16T00:00:00Z

Content type: article

Language: en

Sources: [Ankit Rana | Mechanical Sympathy](<https://devfeed.tech/sources/ankit-rana-mechanical-sympathy.md>)

Topics: [Database](<https://devfeed.tech/topics/database.md>), [MySQL](<https://devfeed.tech/topics/mysql.md>), [ordering](<https://devfeed.tech/topics/ordering.md>)

Tags: [b-tree](<https://devfeed.tech/tags/b-tree.md>), [database](<https://devfeed.tech/tags/database.md>), [database-performance](<https://devfeed.tech/tags/database-performance.md>), [fragmentation](<https://devfeed.tech/tags/fragmentation.md>), [innodb](<https://devfeed.tech/tags/innodb.md>), [latency](<https://devfeed.tech/tags/latency.md>), [mysql](<https://devfeed.tech/tags/mysql.md>), [performance](<https://devfeed.tech/tags/performance.md>), [system-design](<https://devfeed.tech/tags/system-design.md>), [uuid](<https://devfeed.tech/tags/uuid.md>)

## AI overview

This article explains how random UUIDv4 primary keys can reduce insert performance in clustered indexes. Random inserts land in the middle of B+ tree pages, causing page splits, fragmentation, additional writes, and buffer-pool churn. It recommends UUIDv7 or ULID, or an auto-increment clustered key with UUIDs in a unique secondary index.

## Source excerpt

The problem with UUIDv4 primary keys is not uniqueness, it is that random keys fight the storage engine's physical layout. In a clustered index the primary key is the table, so random inserts land mid-page, trigger page splits, leave pages half-full, and can inflate a 50 GB dataset to roughly 100 GB while wasting buffer pool on empty space. Use UUIDv7 or ULID, or keep an auto-increment clustered key with the UUID in a unique secondary index.