I am working on Facebook application with nearly 1 mio users. For each user I need to insert into table a friends list. The friends list is used only in 1 page where items of user friends are shown.

When user register I have two options:


"INSERT INTO friends (userId, friendId) VALUES ".$friendList

$friendList is a string like: ($userId,2343),($userId,dfgdf),($userId,67567),…
and than use

SELECT userId FROM users LEFT JOIN friends ON users.userId=friends.userId


UPDATE users SET friends=$friends

$friendList is a string like: 34534,7634,3456346,834463
and than use

$friends=$db->get_var("SELECT friends FROM users WHERE userId=$userId");
SELECT userId FROM users WHERE userId IN ($friends);

If I use the option a), table friends will be really huge (considering almost every user has more than 200 friends). So which one do you think is better for perfromance?

are you absolutely sure about that? only one page? :slight_smile:

use option a

at the moment yes, only 1 page. Maybe in future there will be more pages where I will need to show friends data.

I was just worried that the table will be too large.

So option A. Thank you

several hundred million rows is large, still not even too large.