Live data from Hacker News

UUIDs are popular, but bad for performance (2019)

percona.com

111–120 of 246 posts

Re: UUIDs are popular, but bad for performance (2019)

#111
post #108
post #10

Interestingly, for other systems you sometimes want the exact opposite: for your key space to be distributed across indexes to balance the load (vs wanting them all to hit the same “hot” index for MySQL). For example, Google’s Cloud Firestore is bottlenecked to 500 writes/second if your key is monotonically increasing (like a timestamp or these timestamp-based UUIDs) causing you to “hotspot” the index: https://cloud.…

Your other option is to hash your monotonically increasing numbers. You don't want to use something like SHA, as it does not give good distribution. You use something like murmur hash ( https://en.m.wikipedia.org/wiki/MurmurHash ). I've used it before for indexes at Google for values that may hotspot. See Google's impl here: https://github.com/google/zetasketch/blob/master/java/com/go...

> You don't want to use something like SHA, as it does not give good distribution

How come? Even distribution is one of requirements for crypto hash functions.

Re: UUIDs are popular, but bad for performance (2019)

#113

Earlier quoted context omitted.

Yeah. The main problem is people using them as primary keys in naïve systems like relational databases. You can't just expect a relational database to magically become a distributed system just by using UUIDs. There is a bit more work to do than that.

> You can't just expect a relational database to magically become a distributed system just by using UUIDs. Nobody thinks this, do they?

You’d be surprised. Unpleasantly, unfortunately.

Not sure if the term gets used much now a days, but ‘cargo cult’ programming is definitely a thing still. Never stopped.

Re: UUIDs are popular, but bad for performance (2019)

#114
post #108
post #10

Interestingly, for other systems you sometimes want the exact opposite: for your key space to be distributed across indexes to balance the load (vs wanting them all to hit the same “hot” index for MySQL). For example, Google’s Cloud Firestore is bottlenecked to 500 writes/second if your key is monotonically increasing (like a timestamp or these timestamp-based UUIDs) causing you to “hotspot” the index: https://cloud.…

Your other option is to hash your monotonically increasing numbers. You don't want to use something like SHA, as it does not give good distribution. You use something like murmur hash ( https://en.m.wikipedia.org/wiki/MurmurHash ). I've used it before for indexes at Google for values that may hotspot. See Google's impl here: https://github.com/google/zetasketch/blob/master/java/com/go...

Can you elaborate on the claim about SHA? If I'm not mistaken, all these cryptographic hashes have a 50% chance of flipping any one output bit upon changing a single input bit -- is there some hidden gotcha I'm unaware of?

Re: UUIDs are popular, but bad for performance (2019)

#115
post #70
post #65

Earlier quoted context omitted.

Because you don't want your record IDs to be perfectly sequential data. You only care about them being sequential enough that your database engine will write them down quickly and efficiently (for engines like InnoDB or MSSQL which have such behaviour). But as a developer you typically want them to be random so that you can generate them in a decentralised manner, prevent guessing or accidental joins, safely merge re…

But now the ID has a random concatenation of data in it, like the MAC address of the node that inserted it into the database and a timestamp. It'd be much more orderly for each node to have a sequential ID, the ID of the node that created it, a timestamp when it was created and a real UUID v4 for if someone wants to prevent collisions. Same data, but the primary key on an individual node is a lot smaller (half the si…

I 100% agree that metadata like timestamps and machine IDs, if you care about them, should have their own columns.

I only disagree with:

> It'd be much more orderly for each node to have a sequential ID

I've outlined some reasons above why a random ID has advantages over a sequential one.

I run Postgres in prod so I can use purely random UUIDv4, but for those running mysql or mssql, UUIDv6 and the like are a useful compromise between sequentiality and randomness. The fact that they happen to use timestamps as the source of sequentiality is only an implementation detail.

Re: UUIDs are popular, but bad for performance (2019)

#116
post #25

> and purely random (version 3) This is a typo, v3 isn't random. It is generated deterministically from inputs. > The only “repeated” value is the version, “4”, at the beginning of the 3rd field. All the other 124 bits are random. And this is close but not quite correct. UUID v4 has a couple of other fixed bits, there are only 121-122 random ones. There are patterns in the text representation other than constant numb…

This blog post is over two years old, that 3 vs 4 error is inexcusable.

Re: UUIDs are popular, but bad for performance (2019)

#117

Isn't this easily solved by supporting 128 bit keys and using UUIDs as intended, i.e. as integers and not in their string serialization? This is as nonsensical as storing IPv4 as strings instead of 32 bit integers.

That helps with storage, but still is larger than a bigint, and doesn't help with the random distribution of data. I believe newer versions of MySQL have a data type for this.

Well, you probably shouldn't cluster on a UUID, but it's not really a great idea to blindly cluster on a sequential id, either. You should cluster based on how you query the data to minimize I/O.

Re: UUIDs are popular, but bad for performance (2019)

#118

Isn't this easily solved by supporting 128 bit keys and using UUIDs as intended, i.e. as integers and not in their string serialization? This is as nonsensical as storing IPv4 as strings instead of 32 bit integers.

They do test a binary(16) field which is basically what you're talking about (and you could use a binary(32) for a 128-bit UUID).

Re: UUIDs are popular, but bad for performance (2019)

#119

Isn't this easily solved by supporting 128 bit keys and using UUIDs as intended, i.e. as integers and not in their string serialization? This is as nonsensical as storing IPv4 as strings instead of 32 bit integers.

I'm kind of shocked MySQL doesn't do this?

Experience has taught me to never be surprised when you learn that MySQL does something incorrectly. Having used it since v3.3 it's not unusual.
Post reply on HN