3 ms·
> most UUIDs are going to be non-matches in their lower bits, assuming a random distribution But you can't assume a random distribution because anyone using UU
by gnaritas 11y ago
> most UUIDs are going to be non-matches in their lower bits, assuming a random distribution
But you can't assume a random distribution because anyone using UUID's for database keys isn't using random UUID's, they're using sequential ones.
- jsmthrowaway 11y agoWhich would still make the low-order quadword not match.
- gnaritas 11y agoIt's a database though, you don't get to control how comparisons are done. Guid's are larger than ints, so using them as keys or joining on them is going to be slightly slower (not that it makes them bad, I'm not against GUID's). Just as using a bigint will be slower than an int.
- jsmthrowaway 11y agoIf I were implementing the uuid type in Postgres and did anything other than `if(unlikely(LO(uuid1) == LO(uuid2)) && unlikely(HI(uuid1) == HI(uuid2)))` I'd consider myself doing the wrong thing, personally. Two 64-bit compares, two flag checks, and a branch, which is about as fast as it's going to get in the absence of a 128-bit architecture. You could actually vectorize the compares in SSE, I believe (but I stopped writing assembly before SSE existed and don't know much about it at a low level). This is why it's so critical to treat a UUID as an integer instead of a string, and I see a lot of code that does the latter.
- gnaritas 11y agoWhile all of that is true, it's really not relevant to a programmer deciding on which to use as a key; he has no control over any of those things.