存储行数或只是计数行? [英] storing the count of rows or just count the rows?
问题描述
为了举例说明我的情况,想一个问题&答案平台像stackoverflow。基本上有问题
和答案
表。显示特定问题的答案数量的最佳做法是什么?
To exemplify my situation, think of a Question & Answer platform like stackoverflow. Basically there are questions
and answers
tables. What is the best practice for displaying the number of answers of a specific question?
-
表
questions
?每次添加或删除新答案时,都应更新计数列。
Should there be a "count column" in the
questions
table? Every time new answer is added or deleted "count column" should be updated.
$ c>答案表?我非常担心这个选项是加载到数据库,但我不确定。
Or just do count the rows of the answers using MySQL in the answers
table? My concern in this option is the load to database but I am not sure.
推荐答案
我不担心加载数据库,除非你真的发现它是一个问题。实际上,保持计数的选项需要对每个CRUD操作进行额外更新,因此我认为这将比偶尔计数更多的开销。首先使用 KISS ,如果您发现问题,请修复它:)
I would not worry about load on the database unless you actually find it to be a problem. In fact, the option of keeping a count requires an additional update on every CRUD operation, so I would think that would be more overhead than an occasional count. Go with KISS first, and if you find a problem, then fix it :)
这篇关于存储行数或只是计数行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!