postgres=# select * from sessions where video_id = 'YPq_hiOE-N8';

Hacking Postgres 101 — ULID function

· 59:00 · SQL & client

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

  1. Why random UUIDs hurt B-tree locality
  2. Security, performance, and ordering trade-offs
  3. Preparing the in-core identifier prototype
  4. Adding the catalog function and C implementation
  5. Encoding microsecond time in network byte order
  6. First generated values and generation benchmark
  7. Comparing indexed inserts with random UUIDs
  8. Buffer evidence and decision to target UUIDv7