Live data from Hacker News

Unexpected downsides of UUID keys in PostgreSQL

cybertec-postgresql.com

1–10 of 215 posts

Re: Unexpected downsides of UUID keys in PostgreSQL

#3
post #2

How can this be unexpected? Isn't this what Percona discussed for MySQL already several years ago? Or am I missing something?

They suggest to use UUID v7 at the end for more sequential keys. Maybe that's the new part since v7 is relatively recent.

Re: Unexpected downsides of UUID keys in PostgreSQL

#4
UUID is also used to avoid leaking information about the underlying system. This includes temporal information that could be used to infer the size of the dataset for all users.

If this isn’t a concern, then using a timestamp based approach as recommended in this article is a good approach. That is the default in MongoDB.

If it is a concern, one approach is to use random UUIDs to give to end users but then internally to have something like auto increment ids.

Re: Unexpected downsides of UUID keys in PostgreSQL

#10
Nothing unexpected about it at all. PostgreSQL's default index in this case is a B-tree, and they don't index disorderly data very well which is the nature of all UUID versions.

On the topic of how important it is for B-trees to be "orderly": https://news.ycombinator.com/item?id=34404641

PostgreSQL can do (among other types) 32-bit hash indices which work out better for certain use cases. Personally I would avoid B-trees for any UUID unless I really had to do partial or ranged scans on them.

Post reply on HN