database design for 'followers' and 'followings'?

后端 未结 4 1626
醉话见心
醉话见心 2020-12-23 00:01

Dear database experts/programmers:

I have a mysql table with users information, such as

id      user_id         name etc.
1       userA            
2         


        
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-23 00:44

    General tip. Use integers for ids rather than strings. There is a significant performance difference. So drop users.user_id, and rename users.id to users.user_id. Secondly your followers table should have indexes on user_id and follower_id. Again there is a significant performance benefit. I also like the idea of having a unique index on (user_id, follower_id), calling that your primary key, and dropping your id column.

提交回复
热议问题