cuid
cuid copied to clipboard
Performance implications of using CUID as primary key in MySQL
I have a question regarding of using CUID’s in MySQL and their performance characteristics.
I can see in the Prisma source code that they store cuid's as VARCHAR(25) for id columns, which implies (at least) 25 bytes per id as opposed to 4 or 8 bytes for (big)int. And these will of course also be used for join-tables and foreign keys.
Although I think nowadays we shouldn’t be concerned that much about disk-space, maybe even index-size; what concerns me is the efficiency of index-lookups for VARCHAR. I understand CUID’s are monotonically increasing which is beneficial for b-tree indexes but I expect that an integer index is (much) more efficient than varchar.
I couldn't find any benchmarks regarding cuid (or similar monotonically increasing string id's). Does this scale to millions (or billions) of rows, or does it fall apart at some point? Thanks!
Maybe because js Number
types is not reliable when dealing with integer greater than 53 bits, see https://www.ecma-international.org/ecma-262/6.0/#sec-number.max_safe_integer.
Just my two cents.
It scales well to billions of rows. We used it in Adobe Creative Cloud.