Reputation: 3309
I would like to know how sites like Facebook (over 900 million users), Twitter (over 300 million users) etc... are able to select a user's login name and password from the database to check if the login credentials a user has entered is correct. For instance in SQL you use :
SELECT * FROM Persons
WHERE username=[username from user]
and password = [password from user]
but in bigger systems like Facebook, do they select all the 900 million users and check the login credentials of a single user when a user is login in? If not then what do they do?
PS :
Am asking because I am new in this area. I know SQL but want to know how systems with millions of users check the login credentials of their users and other related situations where users are searching for some specific information from the site.
Upvotes: 1
Views: 109
Reputation: 239260
Yes, this is how tables are queried. This is what SQL is for, efficiently querying large sets of data.
A properly indexed column can be ordered/filtered extremely efficiently. The database is not performing a linear search of 900 million records, it will use some kind of optimized binary search. Assuming a perfectly balanced binary tree, the worst case for searching through 900,000,000 would require only 30 comparisons, which is the log2 of 900,000,000.
Upvotes: 4