问题描述
我正在设计一个应用程序,该应用程序将涉及用户关注"彼此的活动,在 twitter 的意义上,但我对数据库/查询设计/效率不是很有经验.是否有管理此问题的最佳实践、要避免的陷阱等?我认为如果做得不好(或者甚至可能?),这可能会在数据库上造成非常大的负载.
I am designing an app that would involve users 'following' each other's activity, in the twitter sense, but I am not very experienced with database/query design/efficiency. Are there best practices for managing this, pitfalls to avoid, etc.? I gather this can create a very large load on the db if not done properly (or maybe even then?).
如果它有所作为,那么人们很可能只会关注"相对较少的人(但一个人可能有很多关注者).然而,这是不确定的,我不想指望它.
If it makes a difference it is likely that people will 'follow' only a relatively small number of people (but a person may have many followers). However this is not certain, and I wouldn't want to count on it.
感谢收到任何建议.谢谢.
Any advice gratefully received. Thanks.
推荐答案
使用完整的 非常简单易行标准化.如果你有一个用户表,每个用户都有一个唯一的 ID,你会有一个 TABLE_FOLLOWERS
表,其中包含 USERID
和 FOLLOWERID
列将每个用户的所有关注者描述为一对多的关系.
Pretty simple and easy to do with full normalisation. If you have a table of users, each with a unique ID, you would have a TABLE_FOLLOWERS
table with the columns, USERID
and FOLLOWERID
which would describe all the followers for each user as a one to one to many relationship.
即使在半体面的数据库服务器上有数百万个关联,只要您使用良好的数据库(IE,而不是 MS-Access),它也会运行良好且快速.
Even with millions of assosciations on a half decent database server this will perform well and fast as long as you are using a good database (IE, not MS-Access).
这篇关于“追随者"和效率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!