Live data from Hacker News

Avoid UUID Version 4 Primary Keys in Postgres

andyatkinson.com

1–10 of 463 posts

Re: Avoid UUID Version 4 Primary Keys in Postgres

#6
From the fine article:

  > Random values don’t have natural sorting like integers or lexicographic (dictionary) sorting like character strings. UUID v4s do have "byte ordering," but this has no useful meaning for how they’re accessed.
Might the author mean that random values are not sequential, so ordering them is inefficient? Of course random values can be ordered - and ordering by what he calls "byte ordering" is exactly how all integer ordering is done. And naive string ordering too, like we would do in the days before Unicode.

Re: Avoid UUID Version 4 Primary Keys in Postgres

#9
post #3

"if you use PostgreSQL" (in the scientific reporting world this would be the perennial "in mice")

The thing is, none of us are mice, but many of us use Postgres.

It would be the equivalent of "if you're a middle-aged man" or "you're an American".

P.S. I think some of the considerations may be true for any system that uses B-Tree indexes, but several will be Postgres specific.

Re: Avoid UUID Version 4 Primary Keys in Postgres

#10
post #3

"if you use PostgreSQL" (in the scientific reporting world this would be the perennial "in mice")

It's not just Postgres or even OLTP. For example, if you have an Iceberg table with SCD2 records, you need to regularly locate and update existing records. The more recent a record is, the more likely it is to be updated.

If you use UUIDv7, you can partition your table by the key prefix. Then the bulk of your data can be efficiently skipped when applying updates.

Post reply on HN