Contents
What is UUID vs id?
A UUID is designed as a number that is globally unique in space and time. On the other hand a simply INT primary id key (e.g. AUTO_INCREMENT) will return a unique integer for the specific DB and DB table, but which is not universally unique (so if imported to another DB chances are there will be primary key conflicts).
Are UUIDs slow?
This is your primary key, you don’t want it to be slow. At its bit level, a UUID is 128 bits, which means it will fit into 16 bytes, note this is not very human readable, but it will keep storage low, and is only 4 times larger than a 32-bit int, or 2 times larger than a 64-bit int.
Are UUID and GUID the same?
The GUID designation is an industry standard defined by Microsoft to provide a reference number which is unique in any context. UUID is a term that stands for Universal Unique Identifier. Similarly, GUID stands for Globally Unique Identifier. So basically, two terms for the same thing.
Why is it good to use a UUID as a PK?
Reasons UUIDs are Good. There are several reasons using a UUID as a PK would be great compared to auto-incrementing integers: At scale, when you have multiple databases containing a segment (shard) of your data, for example a set of customers, using a UUID means that one ID is unique across all databases, not just the one you’re in now.
Why are UUIDs not used as primary keys?
For each of these columns in a set of table with billions of accounts, the extra size of foreign keys adds up fast. Another problem is fragmentation — because UUIDs are random, they have no natural ordering so cannot be used for clustering.
Can a UUID be treated as a string?
A naive use of a UUID, which might look like 70E2E8DE-500E-4630-B3CB-166131D35C21, would be to treat as a string, e.g. varchar (36) — don’t do that!! “Oh, pshaw”, you say, “no one would ever do such a thing.” Think twice — in two cases of very large databases I have inherited at relatively large companies, this was exactly the implementation.
Why are UUIDs not good for clustering?
Another problem is fragmentation — because UUIDs are random, they have no natural ordering so cannot be used for clustering. This is why SQL Server has implemented a newsequentialid () function that is suitable for use in clustered indexes, and is probably the right implementation for all UUID PKs.