Suppose you are creating an account on Twitch or any other website, you will immediately think of a cool username like noobmaster69🙃 and when you submit the form you immediately get User Name Already Taken😡 you will try out other cool names or even your own name but you get the same Err Message, Quite Frustrating right😂.
But have ever thought about how this works behind the scenes?🤔
Social media platforms like twitch/youtube have millions of users but still, these companies quickly check the availability of usernames by searching millions of usernames. hearing searching makes you think about linear & binary search Are they using these that we learned in high school? Nop Something far better
Suppose I have an SQL database with 10 million users, with a Unique key on the usernames column. To check if the username is taken or not I will Write the following Query
SELECT username FROM users WHERE username = $1;