Currently doing a statistical function of CRM, it is necessary to establish related tables to store all kinds of data related to users.
For example: Statistics on the day of an employee new customers.
A statistical table was designed to store the number of customers per day for employees.
Then, when the employee adds the customer, the corresponding field in the statistics table is added 1. When deleting a customer, the corresponding field in the statistics table is reduced by 1.
This trigger adds 1 minus 1 and executes asynchronously with Swoole.
Recently, you'll need to add stats for this week, this month, this quarter, and this year.
I will "daily statistics" copy four copies, respectively, corresponding to the "Weekly statistics", "Monthly Statistics", "Quarterly Statistics", "annual statistics."
These five tables have a similar data structure.
My question now is:
1. Is this the best way to count the number of users per day with an asynchronous trigger? Is there any other better way?
2. Statistics week, month, quarter, year of the data, is from the "Daily statistics" in the calculation of good, or directly build such four tables or asynchronous trigger way to directly store relevant data good?
There is no expert can answer, thank you in this extremely
Reply content:
Currently doing a statistical function of CRM, it is necessary to establish related tables to store all kinds of data related to users.
For example: Statistics on the day of an employee new customers.
A statistical table was designed to store the number of customers per day for employees.
Then, when the employee adds the customer, the corresponding field in the statistics table is added 1. When deleting a customer, the corresponding field in the statistics table is reduced by 1.
This trigger adds 1 minus 1 and executes asynchronously with Swoole.
Recently, you'll need to add stats for this week, this month, this quarter, and this year.
I will "daily statistics" copy four copies, respectively, corresponding to the "Weekly statistics", "Monthly Statistics", "Quarterly Statistics", "annual statistics."
These five tables have a similar data structure.
My question now is:
1. Is this the best way to count the number of users per day with an asynchronous trigger? Is there any other better way?
2. Statistics week, month, quarter, year of the data, is from the "Daily statistics" in the calculation of good, or directly build such four tables or asynchronous trigger way to directly store relevant data good?
There is no expert can answer, thank you in this extremely
What is your customer volume? If millions or the following, if I do, it is possible to save a table. The table has two fields, one called, created_at
one called deleted_at
, all datetime types, and the two fields are indexed.
In the future when the statistics of real-time query can be, millions the following speed, and you want to check what range to check what range. With more data, adding a cache also makes it easy to solve performance problems. Get a lot of tables to make this thing too complicated.