Several times I came across the following situation and wondered what the best practices say about this situation:
Rows are inserted into the table as users perform some actions. For example, each time a user visits a certain part of a website, a line is inserted with their IP address, username and link URL. Elsewhere, I want to show a summary of these actions. In our example, I want to allow administrators to enter the website and see how many visits are for a particular user.
The most natural way to do this (IMO) is to insert a row for each visit, and each time the administrator asks for the totals, count the number of rows in the corresponding table for this user. However, in such situations, there may be thousands and thousands of lines per user. If administrators often request totals, a constant request for counters can put a strain on the database. Therefore, it seems to be the right decision to insert separate lines, but at the same time store some summary data with current totals as you enter data (to avoid recounting these totals again and again).
What is the best practice or most common database schema schema for this situation? You can ignore the specific example that I have compiled, my real question is how to handle such cases, as it relates to large volumes of data and frequently requested totals or calculations of this data.
source share