Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Life Altering PostgreSQL Patterns (mccue.dev)
7 points by rbanffy 10 months ago | hide | past | favorite | 2 comments


You should never use a truly random UUID for an indexed column like the primary key.

The clustering of the random values makes for terrible indexes, you should use something like uuid_generate_v7();

This has the added benefit of being able to get the timestamp out of the primary key e.g.

SELECT uuid_v7_to_timestamptz('018570bb-4a7d-7c7e-8df4-6d47afd8c8fc');

uuid_v7_to_timestamptz

----------------------------

2023-01-02 04:26:40.637+00


The concept of system_id for marking special rows was interesting, I haven't seen it described in quite that way.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: