I'm new to databases and have been considering using a UUID as the primary key in my project, but I read some things which made me interested to learn more about the performance.
Currently, I am using the uuid data type and the default value is set to gen_random_uuid().
First of all, I was wondering: would UUIDs be less performant as a primary key?
If so...
(I'm not working with data of any considerable scale just yet; it's more of a theoretical question.)
UUIDs are slower than keys generated by a sequence. You'll just have to accept that, there is no way around it. For that reason you use UUIDs only if you have a compelling reason, like the keys are generated outside the database or need to be unique across several database.
There is some deeper discussion of this in my article.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With