> But the worst problem of using UUID version 4 in the particular case of DB primary keys is that it is random, and therefore, can't be sorted or indexed. This makes looking up one particular ID slower than alternatives.
Well, I do not agree with this. UUID4 can be sorted and indexed.
The problem is that the part of the index where it resides is less likely to be cached.
UUID7 improves on that since most operations are done on recently created objects, so the UUID7 indexes are more likely to be already in RAM, etc.
This is indeed, a much better way of seeing it. Also insertion order and sort order are not matching with UUID4 so updating the index is more expensive, and the gap between 2 consecutive UUID is bigger, this affects bisection when looking up in the index. This can be more or less significant depending of the DB and table engine (if any). But for an article targeting people not knowing what a UUID is, I'm simplifying a bit.
> But the worst problem of using UUID version 4 in the particular case of DB primary keys is that it is random, and therefore, can't be sorted or indexed. This makes looking up one particular ID slower than alternatives.
Well, I do not agree with this. UUID4 can be sorted and indexed.
The problem is that the part of the index where it resides is less likely to be cached.
UUID7 improves on that since most operations are done on recently created objects, so the UUID7 indexes are more likely to be already in RAM, etc.
This is indeed, a much better way of seeing it. Also insertion order and sort order are not matching with UUID4 so updating the index is more expensive, and the gap between 2 consecutive UUID is bigger, this affects bisection when looking up in the index. This can be more or less significant depending of the DB and table engine (if any). But for an article targeting people not knowing what a UUID is, I'm simplifying a bit.
And you can see all V4 ones (and even search) there: https://everyuuid.com/
Also a wonderful dive into how this magical feat was achieved:
https://eieio.games/blog/writing-down-every-uuid/
Of course, with cheating. But that’s what hacking is about.