postgres=# select * from sessions where video_id = 'YPq_hiOE-N8';
Hacking Postgres 101 — ULID function
The ULID exercise evolved into PostgreSQL's UUIDv7 implementation.
session summary
They implemented a C prototype of a time-ordered 128-bit identifier, initially called ULID, combining microsecond time with random bytes in UUID storage. Generation speed matched gen_random_uuid(), while inserting millions of values into indexed tables remained constant instead of degrading as random UUIDs scattered writes across the B-tree. Buffer measurements showed a dramatic reduction in pages read, dirtied, and written. Rather than submit a bespoke format, they decided to align the implementation with the emerging UUIDv7 standard, which later reached core.
timecodes
- Why random UUIDs hurt B-tree locality
- Security, performance, and ordering trade-offs
- Preparing the in-core identifier prototype
- Adding the catalog function and C implementation
- Encoding microsecond time in network byte order
- First generated values and generation benchmark
- Comparing indexed inserts with random UUIDs
- Buffer evidence and decision to target UUIDv7