News for hackers. Stuff that matters.
Re:UUIDs are popular, but bad for performance (2019) by web007 on Saturday January 08, 2022 @12:39PM (#29854010)
This article talks about random IDs leading to page thrashing, and MySQL b-tree indexes not handling them well. They are bad for _MySQL performance_.

It doesn't talk about NoSQL or sharding, where random IDs usually perform much better than sequential due to a lack of hot shards.

If you distribute your reads and writes at random across N machines you can get ~Nx performance vs one machine. If you make your writes sequential, you'll usually get ~1x performance because every insert goes to the same machine for this second/minute/day, then rolls to a new one for the next period. There are sharding schemes that can counter this, but they require insight into your data design before implementation.

Re:UUIDs are popular, but bad for performance (2019) by nightpool on Saturday January 08, 2022 @04:23PM (#29856430)
Sure, but each individual machine still has to do the same slow random lookups, right? Generally you want some deterministic component (for caching) and some random component (for sharding). Snowflakes work well for this, since you can use the upper bits for predictable caching and the lower bits for random entropy.
Re:UUIDs are popular, but bad for performance (2019) by hifriends on Saturday January 08, 2022 @01:46PM (#29854775)
its a MySQL blog, why would it talk about NoSQL?
Re:UUIDs are popular, but bad for performance (2019) by m0rphling on Sunday January 09, 2022 @05:55AM (#29862187)
I don't know if you've actually been to their blog recently, but Percona's community includes NoSQL as they maintain their own distro of MongoDB--similar in spirit to their MySQL and PostgreSQL offerings.

https://www.percona.com/blog/category/mongodb

https://www.percona.com/software/mongodb

Re:UUIDs are popular, but bad for performance (2019) by tehlike on Saturday January 08, 2022 @01:14PM (#29854401)
Even in MySQL - one can use Sequential UUIDs.
Re:UUIDs are popular, but bad for performance (2019) by inetknght on Saturday January 08, 2022 @02:19PM (#29855123)
I never understood why people would use sequential UUIDs. That rather defeats the purpose of a UUID. If you need something sequential then just use a much more simple number
Re:UUIDs are popular, but bad for performance (2019) by dspillett on Sunday January 09, 2022 @11:41AM (#29864843)
It depends on how the non-sequential part is derived.

IIRC this is often a mix of hardware network address and a portion that is either random or based on a high-precision time, so it is still unlikely that you'll see collisions between machines.

MS SQL Server's NEWSEQUENTIALID function returns something akin to a v4 UUID (fully random, aside from variant indicator bits, I'm not sure if the variant bits are respected in NEWSEQUENTIALIDs output or if it just returns a 128-bit number) but after the first is generated the rest follow in sequence until the sequence is reset (by a reboot). Assuming the variant indicators are present, there is are 122 random bits. Even if your system is up long enough to use 2^58 (2.8810^17 if you want that in decimal) IDs generated this way, you still effectively have 64-bits of randomness even if the variant bits are present. For most systems the chance of collision with sequential UUIDs is, while larger than with other types, still so small as to be inconsequential. These are "atoms in several galaxies" level numbers.

You don't want to use sequential UUIDs in place of v4 UUIDs where security matters, or course, as it is easy to work the next in sequence.

> If you need something sequential then just use a much more simple number*

Sequential isn't their only property. UUIDs, including those that increment from the start point, are intended not to collide with those generated elsewhere.

Sequential UUIDs are a compromise - giving away a small amount of collision protection in order to gain what could be a significant efficiency boost in some circumstances (DB indexes being the main one).

Re:UUIDs are popular, but bad for performance (2019) by tehlike on Sunday January 09, 2022 @02:09AM (#29860988)
https://docs.microsoft.com/en-us/sql/t-sql/functions/newsequ...

Each GUID generated by using NEWSEQUENTIALID is unique on that computer. GUIDs generated by using NEWSEQUENTIALID are unique across multiple computers only if the source computer has a network card.

Re:UUIDs are popular, but bad for performance (2019) by rco8786 on Saturday January 08, 2022 @02:30PM (#29855240)
Because simple integers are not universally unique, a major feature of UUIDs…
Re:UUIDs are popular, but bad for performance (2019) by atq2119 on Saturday January 08, 2022 @03:43PM (#29855990)
UUIDs are integers, they just happen to be 128 bits long instead of the more common 32 or 64, and they are usually printed in a specific way that differs from how integers are usually printed. But that's just smoke and mirrors.

UUIDs are generally not guaranteed to be universally unique. The name is misleading marketing.

If you generate them randomly, then the probability of collision is small enough not to matter, but the more you introduce deterministic elements, like generating them sequentially, the more your probability of collision increases.

Re:UUIDs are popular, but bad for performance (2019) by rco8786 on Saturday January 08, 2022 @07:16PM (#29858232)
Yes, of course. But making them sequential does not take away from the universal(ish) uniqueness
Re:UUIDs are popular, but bad for performance (2019) by rco8786 on Sunday January 09, 2022 @12:54PM (#29865649)
Meant ordered here, not sequential.
Re:UUIDs are popular, but bad for performance (2019) by inetknght on Saturday January 08, 2022 @03:27PM (#29855822)
Is this sarcasm? If you generate an incrementing-UUID then its predictability is going to make it not-universally unique too
Re:UUIDs are popular, but bad for performance (2019) by michaelmcmillan on Saturday January 08, 2022 @03:45PM (#29856013)
No. Incrementing an integer might be unique for the local database, but not unique for the universe.
Re:UUIDs are popular, but bad for performance (2019) by rco8786 on Saturday January 08, 2022 @03:27PM (#29855831)
That is…not what universally unique means.
Re:UUIDs are popular, but bad for performance (2019) by rwoerz on Saturday January 08, 2022 @03:46PM (#29856026)
From RFC4122: "A UUID is an identifier that is unique across both space and time, with respect to the space of all UUIDs."

Hard to achieve if everyone starts from 00000000-0000-0000-0000-000000000000.

Re:UUIDs are popular, but bad for performance (2019) by rco8786 on Saturday January 08, 2022 @07:18PM (#29858252)
Right that’s why nobody starts at 0. And you don’t have to only add 1 to be ordered, no DB I’m aware of just adds 1 to sequential UUIDs. There’s always randomness/entropy involved.
Re:UUIDs are popular, but bad for performance (2019) by ztorkelson on Saturday January 08, 2022 @05:41PM (#29857274)
Sequential UUIDs don’t start at 0. They are a 128-bit composite of two integers; a temporal component in the high order bits and a random component in the low order bits.
Re:UUIDs are popular, but bad for performance (2019) by anamexis on Saturday January 08, 2022 @03:47PM (#29856034)
UUIDs are just 128-bit simple integers.