Reputation: 2109
As described here, using a UUID / GUID is a bad idea in a relational database context. Is there an alternative that has library support?
Upvotes: 1
Views: 1486
Reputation: 1472
Not a great blog post. GUIDs are great in a situation where a client needs to generate its own primary key. If it's ok that the server generate the key, use an auto-incrementing integer primary key.
Let me elaborate on why this is not a great blog post. He says:
GUIDs/UUIDs are very random. Therefore, INSERTing into an index means jumping around a lot.
a Guid is really just a 16 Byte hex number; so I could come up with a naive index where a single insert could be done in constant time by just making a 32/16 array that you could traverse through digit by digit. So, inserting N items with my naive index could be done in Log(N) time. The argument in the blog post is terrible. I'm not sure have fast a GUID insert is but the "randomness" has nothing to do with the algorithmic complexity.
Here's a good blog post with some good links:
https://blog.codinghorror.com/primary-keys-ids-versus-guids/
I particularly like this link:
Good discussion of the tradeoffs of different keys.
Upvotes: 2