paralleldrive / cuid

Collision-resistant ids optimized for horizontal scaling and performance.
Other
3.44k stars 123 forks source link

Database column type #95

Closed satb closed 6 years ago

satb commented 6 years ago

If the database column type is a string, could the monotonously increasing nature of the id be taken advantage of with a varchar column type in the db? Say in postgresql or mysql? Are there any downsides/tradeoffs of using varchar id instead of a long?

ericelliott commented 6 years ago

Yes, Postgres indexes are searched using binary search.

There are no practical downsides that you should worry about that I can think of, whereas, there are many downsides to using an auto-incrementing long. See the "Horizontal scalability" section in the docs.

satb commented 6 years ago

@ericelliott - Thank you. But how is the monotonically increasing nature being taken advantage of with an index (btree)? Wouldn't any column values (even non monotonically increasing) work the same way?

ericelliott commented 6 years ago

Good question. There is no single answer to it though because not all db and shard hash keys take advantage of monotonic order.

When they do, they can take advantage of append-only key sorts and and consistent hash qualities.

mkgo commented 6 years ago

What would be the recommendation, in the case of MySQL for the database field type?