Efficiency and speed depend on how you use this data.
1#You have a model Userand a column "friends" with user_id friends in the same table.
It is fast to read and does not require a large amount of memory. But you have to decide in which row of the table the data should be stored, because you absolutely do not want to store / manage the same data in two different rows of the table. If you only need a method User.friends, this is a quick and efficient way to store identifiers. But if you want to have methods such as User.is_friends_with, you need to query each row in your user table. It will be neither fast nor effective.
2# User 'is_friends_with' user_id .
, #1, User.is_friends_with , User.friends .
3# User Friendship
, . Friendship (, , ). 100 , 100 .
, , #3. , .
source
share