php - mysql 大数据 按时间 统计总数 必须用count吗?
世界只因有你
世界只因有你 2017-05-16 13:11:10
0
2
517

1、想统计今日新增客户数,昨日新增客户数,以及今日跟进记录数等等,数据量很大,前面用的是加1减1的方式,但经常会出现误差,怎么解决这个统计的问题?难道必须用count吗?

世界只因有你
世界只因有你

reply all(2)
洪涛

It is best not to perform statistics on large amounts of data directly on the main database - the method of adding 1 and subtracting 1 without locking the table is inaccurate. Locking the table affects performance, and the count performance will also be poor.

It is recommended to separate the statistical function into a subsystem, and the business server notifies the operation of adding/deleting customers to this statistical subsystem through the message queue.

In this subsystem, you can consider using a time series database (such as open source Elasticsearch) for storage, which is very convenient for statistics. Even if you don't need a special time series database and use mysql directly, you can create a separate mysql database, so that the lock table can be increased by 1, subtracted by 1, or counted. It is not the main database anyway.

左手右手慢动作
  • If it is an auto-incrementing ID, it can be calculated by subtracting yesterday’s last one from today’s last one.

  • The statistics table used is plus 1 and minus 1

  • Use count

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!