Storing UUIDs as strings can make MySQL indexes roughly nine times larger than needed
A UUID is 16 bytes, but schemas that map it to VARCHAR(36) or CHAR(36) under MySQL utf8mb4 reserve 144 bytes per value, and the index repeats that cost. The article estimates a million-row index at about 16 MB in compact binary form versus about 144 MB as strings, adding extra I/O, buffer pool use, and slower comparisons. It recommends storing UUIDs as BINARY(16) with conversion functions, noting that Postgres's native uuid type avoids the problem. It also cautions that truncating UUIDs to short IDs causes collisions much sooner than expected, and that random v4 keys cause insert slowdowns at scale, which time-ordered v7 or ULID values can mitigate at the cost of revealing creation time.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in