News for hackers. Stuff that matters.
Re:Unexpected downsides of UUID keys in PostgreSQL by dewey on Thursday June 22, 2023 @08:26AM (#36431082)
> sacrifice the beauty and elegance of UUIDs

Out of curiosity, what makes UUIDs more elegant or beautiful than just plain old integers?

Re:Unexpected downsides of UUID keys in PostgreSQL by kogus on Thursday June 22, 2023 @08:31AM (#36431140)
“5” might be the key for a thousand different records in your database. A uuid is a key for exactly one. Integer keys permit wrong joins to have the appearance of working.
Re:Unexpected downsides of UUID keys in PostgreSQL by totalhack on Thursday June 22, 2023 @08:37AM (#36431207)
You can incorrectly join on any columns you want. That's not really the fault of the column types IMO, that's a problem in the layers above.
Re:Unexpected downsides of UUID keys in PostgreSQL by dpcx on Thursday June 22, 2023 @08:46AM (#36431297)
True, but you can't incorrectly join on UUID due to its anti-collision nature.
Re:Unexpected downsides of UUID keys in PostgreSQL by ibash on Thursday June 22, 2023 @11:18AM (#36433472)
Yes you can, you’ll not get the correct result set.
Re:Unexpected downsides of UUID keys in PostgreSQL by OJFord on Thursday June 22, 2023 @02:48PM (#36436907)
As sibling says, you can make exactly the same mistake and it not colliding just means no join - but if it's an outer join and one of many joins or in a nested query it might not be immediately obvious it's happened, or what the issue is even if it is.
Re:Unexpected downsides of UUID keys in PostgreSQL by FroshKiller on Thursday June 22, 2023 @08:54AM (#36431404)
Crucially, "5" might also be the key to a thousand different records in dozens of other development & QA databases for applications with integrations configured incorrectly. Integers can match coincidentally. UUIDs won't.
Re:Unexpected downsides of UUID keys in PostgreSQL by Phil_Latio on Thursday June 22, 2023 @09:24AM (#36431793)
> Integer keys permit wrong joins to have the appearance of working.

How do you justify such an argument in the real world without people looking at you in disgust? This is the dumbest argument I've ever heard.

Re:Unexpected downsides of UUID keys in PostgreSQL by allknowingfrog on Thursday June 22, 2023 @09:54AM (#36432202)
That's not a very constructive response. UUIDs do provide global uniqueness, which can occasionally make mistakes more obvious. Do you have a counter argument to support your strong objection?
Re:Unexpected downsides of UUID keys in PostgreSQL by magicalhippo on Thursday June 22, 2023 @09:55AM (#36432220)
While wrong joins is a weak argument IMHO, our customers somewhat frequently ask to merge data, either from test to prod or from one company to another (after acquisition f.ex.).

In a lot of cases that can be a pain due to overlapping integer primary keys and large parent-child table sets.

Re:Unexpected downsides of UUID keys in PostgreSQL by antifa on Thursday June 22, 2023 @02:09PM (#36436319)
You can tell all your tables to use the same sequence.
Re:Unexpected downsides of UUID keys in PostgreSQL by smolder on Thursday June 22, 2023 @02:14PM (#36436386)
We have some app generated internal IDs which have a 1 character prefix by type and then base64 sequential stuff after that. I'll admit it's nice knowing the type of an identifier by looking at it. I don't really like that they are strings, however. The original architect made some weird choices as far as deciding where and where not to optimize for performance.
Re:Unexpected downsides of UUID keys in PostgreSQL by ceeam on Thursday June 22, 2023 @08:29AM (#36431121)
Their uniqueness of course.

> To be able to generate keys independently of the database

> To move sets of related records between different databases without having to deal with renumbering everything

Re:Unexpected downsides of UUID keys in PostgreSQL by yes_man on Thursday June 22, 2023 @08:36AM (#36431202)
And adding greppability of logs in debugging situations. You can just search logs in any systems of yours with the UUID and find exact hits you are dealing with. Whereas with integers you will get all kinds of hits
Re:Unexpected downsides of UUID keys in PostgreSQL by phkahler on Thursday June 22, 2023 @09:37AM (#36431975)
Because UUIDs are universally Unique IDentifiers.
Re:Unexpected downsides of UUID keys in PostgreSQL by jandrewrogers on Thursday June 22, 2023 @06:07PM (#36439789)
Unfortunately, UUIDs aren't as universally unique in practice as people think. The standard flavors are banned in quite a few organizations that care a lot about data integrity for valid reasons. Standard UUIDs work for some applications but definitely not all.

For most applications you are better off using a sensible structured key, like incrementing an integer or similar, and encrypting it if you want to obscure it. Encrypting a 128-bit value is approximately free on modern CPUs.

Re:Unexpected downsides of UUID keys in PostgreSQL by maxgee on Thursday June 22, 2023 @08:29AM (#36431116)
Nothing. Integers are simpler and faster. They're also incorrect about COUNTs requiring a full record scan.
Re:Unexpected downsides of UUID keys in PostgreSQL by xkqd on Thursday June 22, 2023 @08:34AM (#36431172)
How are integers simpler? Even generation of unique integers is more complicated, let alone migrating them or moving them around.
Re:Unexpected downsides of UUID keys in PostgreSQL by phito on Thursday June 22, 2023 @08:50AM (#36431342)
Nothing? Really? Have you ever thought about that?
Re:Unexpected downsides of UUID keys in PostgreSQL by catlifeonmars on Thursday June 22, 2023 @12:41PM (#36434875)
* * *
Re:Unexpected downsides of UUID keys in PostgreSQL by Raz2 on Thursday June 22, 2023 @11:23AM (#36433560)
> To be able to generate keys independently of the database

This is a must if you don't want to couple your domain logic and DB. I want to generate a record with an ID inside my domain layer without depending on the DB and doing awkward DB save - DB read.