logoalt Hacker News

The perils of UUID primary keys in SQLite

37 pointsby emschwartzyesterday at 11:13 PM19 commentsview on HN

Comments

blopkertoday at 12:43 AM

UUIDs are way over used. There is almost always a better key to use, usually a bigint for databases. If you're making some kind of leaderless distributed data store, then maybe, but even then there are other ID sharding strategies I'd go for first depending on the constraints.

For a single database, bigints are smaller and faster, with less footguns.

UUIDs can be nice for an opaque public ID, however I'd still prefer something like a Sqid for space and usability.

show 5 replies
pyuser583today at 2:48 AM

Oh gosh the ints v uuids debate for pks. This is worse than vim v eMacs or brackets v braces.

w10-1today at 1:44 AM

Isn't the solution just to use the rowid (after doing the read-id-after-insert dance)?

How much trouble does SQLite reysing rowid's actually cause?

yepyouknoyesterday at 11:29 PM

Perils of “UUIDv4”. Everyone knows that’s what UUIDv7 was really for, and you should always convert that to binary to optimize everything.

show 1 reply
dumbledorfyesterday at 11:38 PM

Wait how is sqlite doing a million inserts a second?

show 3 replies