Hey Guys, I just had kind of a weird question regarding large user tables in databses. I know usually like a login script is coded to grab the username entered and then search through each row in the users table to find the corresponding row and then verify whether or not the password is valid. But how does that work with sites that have A LOT of users. Like for example, a site like Facebook. Wouldn't having 500MIL to 1BIL users be hard to find in a database table? Would think checking through every row would take forever But yeah I don't understand that. Unless, maybe that's the reason why companies like Facebook need really powerful servers?
Not a weird question at all - it's a very common type of problem. Facebook has a couple advantages. First, their data distributed across many servers. If they have the data split across 10,000 servers, conceivably they could split the work up. Second, typical queries like that also have database indexes involved. Think about how the index in the back of a book lets you find words quickly- if you're looking for a word starting with "H", you can skip the first half of the index. Or, think about searching a phone book - you can split it in half continuously. There are many textbooks written about different strategies for this type of operation, so it can be made a lot quicker than you'd think.