For the Facebook application, I need to save the user's friends list in my MySQL database. This list is being requested from my db, compared to other data, etc.
I currently store this list of friends in my user table, friends uids are collected in one text field, with '|' as a separator. For instance:
ID - UID - NAME - FRIENDS => 1 - 123456789 - John Doe - 987654321 | 123456 | 765432
My PHP file requests this line and retrieves the friends list, exploding this field ('|'). All this works great, every 1000 users have about 5 MB of disk space.
Now the problem is:
For an additional function, I also need to save the user names of the user. I can do it differently:
1) Save this data in an additional table. For instance:
ID - UID - NAME => 1 - 1234321 - Jane Doe
If I need a friendβs name with ID 1234321, I can request a name from this table. However, the problem is that this table will continue to grow until all users on Facebook are indexed (> 500 million rows). My web host won't like this! Such a table will take about 25 GB of disk space.
2) Another solution is to expand the data stored in the user table by adding the name in the UID to the friends field (with an additional separator, using ","). For instance:
ID - UID - NAME - FRIENDS => 1 - 123456789 - John Doe - 987654321, Mike Jones | 123456, Tom Bright | 765432, Rick Smith
script, (',') .. , ... " t !
3) , . , . :
ID - UID - FRIENDUID = > 1 - 123456789 - 54321
ID - UID - FRIENDUID = > 3 - 123456789 - 65432
ID - UID - FRIENDUID = > 2 - 987654321 - 54321
ID - UID - FRIENDUID = > 4 - 987654321 - 65432
, . , 500 , , , 300 , 150 . ... , ...
... ? , UID + Facebook? ? () , ?
, !