The perils of UUID primary keys in SQLite

14 points by andersmurphy


lifepillar

Nice. It would be interesting to see the numbers for rowid tables where the integer key is random rather than monotonically increasing.

One thing the article doesn't mention, but I think it's important, is that the primary index on rowid tables is a B+-tree, while for “without rowid” tables it is a B-tree. So, generally speaking, the latter is not ideal when the average record's size exceeds a certain threshold because the internal nodes of the index store full records (iirc, SQLite's manual suggests 1/20th of the page size as a rule of thumb).

silentbicycle

Version 7 UUIDs have a 48-bit timestamp at the head, so they aren't randomly distributed like this. That will also help with the excessive paging and rebalancing.

Student

Are people really using uuids as their primary keys? What’s the benefit rather than having the uuid as an auxiliary key for when you want a uuid?