vendredi 29 mars 2019

Is there a good practice to replace SELECT COUNT(*) by table with a row [Counter] for making a real time dashboard

I have a project where we track the performances of all users and display them in a dashboard. The dashboard refresh every 30 seconds.

I track the users actions in a table named Logs with the rows:

[IdUser] [IDActionType] [DateTimeAction]

Now for some clients the table now have 10 millions rows. It's good for keeping a log but not for a dashboard where you do a SELECT COUNT BETWEEN XDate AND YDate every 30 seconds. (There's multiple queries and multiples graphs, it's just simplified for the example.)

Is there lectures, texts, websites talking about optimizing a database / good practices around doing tables for a dashboard.

I'm thinking about doing one table by graph and every table would look like this:

CREATE TABLE GRAPH_USERS_ACTIONS ( [Day], [Action], [Counter] )

Where I would just increment the counter. They can do 500 actions per day so by doing that I can divide the rows after one year by 500 and I can delete rows older than one year without deleting the logs.

Is this good practice? I hate that because it is repeating the data we could get by simply doing

SELECT COUNT(*) FROM Logs where DateTime Between 00:00:00 AND 23:59:59

But that select is so long to execute on the old clients servers.

And do you know any detailed articles about this topic?

Aucun commentaire:

Enregistrer un commentaire