开发者

A quick over view of facebook's db?

I find it hard to believe that Facebook uses simple sql, surely it would use some other method but lets assume for now it does use sql how would the code assimilating the 'wall' work?

Lets say that there is three tables (just for the example)

Friends: id (entry key) - uid(your id) - fid (your mates' id)

Wall:id (entry key) - username - comment 开发者_运维百科- time - commentcount

comments: id (entry key) - wid (wall id (original comment)) - reply - time

Lets forget about the like part and report etc, as well as mod things (ip, ban etc.) How would this work?

Select wall.id, wall.username, wall.comment, wall.time, wall.commentcount, comments.wid, comments.reply, comments.time FROM wall inner join comments ON wall.id=comments.wid ORDER BY wall.time;

That's your own wall but how do they get friend's? A heap of unions?


here you can find more information on how Facebook (and MANY other BIG sites) works.

http://highscalability.com/blog/category/facebook


Well, as the founder of a social networking site, let me explain something. You're close to correct... as for your question regarding how they get friends, in a mysql situation, they would while loop through all their friends where their id matches in the friends table. Then they would while loop the comments WHERE each of the friends id matches the user's id in my case, aka $_SESSION['user_id'] = uid. Remember though, not only are the comments on a while loop, but the query is also on a while loop so that it doesn't only query one instance of the logged in user = uid.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜