Closed satb closed 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.
@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?
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.
What would be the recommendation, in the case of MySQL for the database field type?
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?