PlanetScale

The Problem with Using a UUID Primary Key in MySQL

Mar 19, 2024Brian Morrison II
The Problem with Using a UUID Primary Key in MySQL
SummaryAI, from the source post

This post details the performance implications of using UUIDs as primary keys in MySQL, contrasting them with auto-incrementing integers. It explains how random UUIDs can lead to B+ Tree page splitting and fragmentation, negatively impacting insert performance and storage utilization. The post recommends using the `BINARY(16)` data type for UUIDs, opting for ordered UUID variants (v6, v7), and utilizing MySQL's `UUID_TO_BIN` function with the 'swap flag'. It also suggests alternative ID types like Snowflake IDs, ULIDs, and NanoIDs, and references PlanetScale's use of NanoIDs for its API.

More from the MySQL Integer Data Types trail