paralleldrive / cuid2

Next generation guids. Secure, collision-resistant ids optimized for horizontal scaling and performance.
MIT License
2.6k stars 53 forks source link

Can you Guide me which MySQL Data Type we should use for CUID #34

Closed IamManchanda closed 1 year ago

IamManchanda commented 1 year ago

Not sure whether this is right place to query this "so apologies" but can you Guide me which MySQL Data Type we should use for CUID? I mean what do you recommend?

https://www.w3schools.com/mysql/mysql_datatypes.asp

ericelliott commented 1 year ago

CHAR(24) is a good default if you're using default settings (recommended).

You can use the binary options as well, but you'll need to do the translations from and to binary when you use the ids in your text data. Math for how to calculate bits is log2(36^(24)) where n is the number of characters you're using (defaults to 24). With default settings, that will be 125 bits. (You can squeeze it into 124 if you isolate bit conversion for the first char). Binary is generally not worth the extra development effort using modern hardware systems.

IamManchanda commented 1 year ago

Thanks sir for clarifications @ericelliott ... thanks a lot, helps me :)