English 中文(简体)
使用量计数,或者有点tal?
原标题:Use count or have a field that tallies?

这一概念非常简单,形成了一个极为基本的信息板系统,我希望用户有一个员额。 现在,我正在辩论的是,在他们设立职位时,是否总是在他们身上添加一个字眼,或者在每次删除一个职位时,把一个字塔拉。 然而,我确信,由于意外情况,在要求员额计算时进行计数调查会更加准确(例如,一个校对被删除,而且其速度会适当降低),但是,这似乎不如说是,当其员额被装满时,就算出一个电梯,特别是如果它们在同一页上有10个员额,并且列出每个员额。

想法/建议

增 编

最佳回答

每次计算都是公正的。 除非你的工作量是天文的,否则国际宇宙航行联合会就是一个问题,减少了在保存和更新数据方面的努力。

仅确保您在用户栏上设置一个索引,以便你能够用WHERE条款有效地过滤数据。

如果你看上去,那么你就可以执行割裂战略,但鉴于它只是一个简单的信息板,你一定会碰到这个问题。

EDIT:

就在一页上重复了10次问答。 : 只是一劳永逸地将数据储存在一个变量中。 无需重复同样的询问。

问题回答

post_count should definitely be a column in the user table. the little extra effort to get this right is minimal compared to the additional database load you produce with running a few count query on every thread view.

如果您使用某种矿石或数据库的抽象,则在制作/删除过滤器时添加计数应当非常简单。

Just use COUNT. 这将更加准确,避免任何可能失职的案件。

你提到在一页数上显示这一职位是个问题,除非你有极高的交通地点。

在任何其他情况下,贵数据库服务器的问讯处将进行盘问,然后在问询所依赖的任何表格之前保持答复的切身。 在单页装载过程中,别无一可改变,因此,你只能一度执行询问。

如果你真的需要担心,你就只能把它放在一个变数中,然后立即执行询问。

总的来说,与你的逻辑相比,你的数据库查询总是极其高效。 因此,在用户表中保留员额(现值)的时间很可能远远少于在发表评论时提出更新用户表的问题。

此外,通常认为,像你所描述的那样,非行结构不善。

There are arguments for both, so ultimately it depends on the volume of traffic you expect. If your code is solid and properly layered, you can confidently keep a row count in your users record without worrying about losing accuracy, and over time, count() will potentially get heavy, but updating a row count also adds overhead.

对于一个小地点来说,它不会有任何区别,因此,如果(而且只有在)你重新成为提高效率的 stick,唯一获得有益答案的途径是操作一些基准,并为生态寻找出点。 一种或另一种方式是,它将成为2/8年quat的3/10秒,这样,无论感觉有何种权利:

It s totally reasonable to store the post counts in a column in your Users table. Then, to ensure that your post counts don t become increasingly inaccurate over time, run a scheduled task (e.g. nightly) to update them based on your Posts table.





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签