If you need sorting and filtering by date, just add a timestamp to your table instead of misusing an Id column for that.
Re:Avoid UUIDv4 Primary Keys
by majorchord on Monday December 15, 2025 @11:38AM
(#46276764)
> just
It is easy to have strong opinions about things you are sheltered from the consequences of.
Re:Avoid UUIDv4 Primary Keys
by mixmastamyk on Monday December 15, 2025 @11:36AM
(#46276739)
That happens, in general. The benefit comes when it’s time to look up by uuid only; the prefix is an index to its disk block location.
> the prefix is an index to its disk block location
What? This is definitely not the case and can’t be because B-tree nodes change while UUIDs do not.
Re:Avoid UUIDv4 Primary Keys
by mixmastamyk on Monday December 15, 2025 @01:45PM
(#46278577)
I didn’t mean that literally, but no longer editable. Was supposed to have “like” etc in there.
But UUIDv7 doesn’t change that at all. It doesn’t matter what flavor of UUID you choose. The ID is always “like” an index to a block in that you traverse the tree to find the node. What UUIDv7 does is improve some performance characteristics when creating new entries and potentially for caching.
Exactly, be explicit, don't shoehorn multiple purposes into a single column that's supposed to be a largely meaningless unique identifier.
That is absolutely not the purpose. The specific purpose of uuidv7 is to optimize for B-Tree characteristics, not so you can craft queries based on the IDs being sequential.
This assumption that you can query across IDs is exactly what is being cautioned against. As soon as you do that, you are talking a dependency on an implementation detail. The contract is that you get a UUID, not that you get 48 bits of timestamp. There are 8 different UUID types and even v7 has more than one variant.
Pretty sure sorting and filtering them by date/time range in a database is the purpose.