如何在mysql数据库中存储用户活动?
考虑一个具有大量用户活动的简单网站(例如 stackoverflow)。存储用户活动(例如投票、添加到收藏夹等)的最佳方式是什么。据我所知,有两种可能的方式:
去规范化:存储为文章投票的成员的用户 ID在文章表中的“谁投票了”列中。这将以逗号分隔的 ID 列表。
标准化:创建关系表以将文章 ID 与用户 ID 连接起来。这种方法具有不可估量的优势(并且我知道你们大多数人都会支持这个想法);但我担心的是(1)这个表很容易达到数百万行。由于它是索引的,读取应该足够快,但是(定期)更新长索引表可能会出现问题。 (2) 每次访问文章页面时,我们都需要多读一张表,这会减慢常规查询的速度。
Consider a simple websites with lots of user activities (like stackoverflow). What is the best way to store user activities such as votes, adding to favorites, etc. To my knowledge there are two possible ways:
De-normalized: Storing user IDs of members who has voted for an article in a column for "who has voted" in the articles table. This will be comma-separated list of IDs.
Normalized: Creating a relationship table to connect article ID to user ID. This method has invaluable advantage (and I know most of you will support this idea); but my concern is (1) This table can easily reach millions of row. Since it is indexed, reading should be fast enough, but updating (on a regular basis) of a long indexed table can be problematic. (2) Every time visiting the article page, we need to read one more table which will slow down the regular queries.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您还可以两全其美,拥有一个过渡数据库和一个“离线”刷新的汇总报告数据库
You could also do the best of both worlds and have a transitional database and a rolled up reporting database that is refreshed "offline"