There is a users table with an id index. It is necessary to implement the ability for users to add each other to bookmarks. Is it possible to use the following table if its expected size is up to 100 million? lines? Is there a more productive way to solve this problem?

CREATE TABLE `friends` ( `user1` int(11) unsigned NOT NULL, `user2` int(11) unsigned NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8; 
  • And what queries will you use to get data from it? - Visman
  • Most often, you will need to receive a list of friends of a given user. - Igor
  • So for this column (for which the condition will be) you need to create an index. - Visman
  • There is a way to optimize your database schema. In general, remove this table and store friends in the field with the user (this is generally called de-normalization). BUT! This will naturally limit the query options that you can perform with friends. - Vartlok
  • Is this the only option? How do social networks cope with this load? Is there a better way to find out if $ user1 is a subscriber of $ user2 than the following: SELECT COUNT (*) FROM friends WHERE user1 = $ user1 AND user2 = $ user2? - Igor

0