Hacker News new | ask | show | jobs
by NyxWulf 37 days ago
It's not just index pages. Generally databases write records into pages, which are then grouped into extents. If the primary key gives an ordering you can create new pages and start filling them up in an orderly fashion. If it's random, you are doing random inserts into pages everywhere all the time, then you start running out of room in pages and have to start splitting them. UUIDv7 solves the most painful parts of this problem in general and is a much better option for a Primary Key than UUIDv1-4.
2 comments

Assuming the database uses a UUID sort order that reflects UUIDv1 time-based sorting (the last version with timestamps and even then temporal ordering of UUIDs was only one possible sort order; v1 also included machine IDs and some databases optimized for locality by machine for reasons that made sense with v1 but also relate to why we gave up on v1 because machine IDs were problematic privacy issues in wider usage). Many of the databases implementing explicit v7 support are choosing time orders for v7 sorting, and only time orders.
> Generally

Except for Postgres

Postgresql uses pages too. The records aren't kept in any kind of order, but the indexes are. So uuidv7 is still useful for postgresql because it means inserts are less likely to be spread across many pages in the primary index.