best way to store 1:1 user relationships in relational database

后端 未结 4 1031
独厮守ぢ
独厮守ぢ 2021-02-01 09:24

What is the best way to store user relationships, e.g. friendships, that must be bidirectional (you\'re my friend, thus I\'m your friend) in a rel. database, e.g. MYSql?

<
4条回答
  •  礼貌的吻别
    2021-02-01 10:12

    Using double rows, while it creates extra data, will greatly simplify your queries and allow you to index smartly. I also remember seeing info on Twitter's custom MySQL solution wherein they used an additional field (friend #, basically) to do automatic limiting and paging. It seems pretty smooth: https://blog.twitter.com/2010/introducing-flockdb

提交回复
热议问题