Reputation: 373
How useful is it to store "simple" computation results in a (sql)-database?
Lets make an example:
From these informations i can compute the:
The question is: Should i only store the 3 raw values and compute the other 2 on every request or should i compute them once and store them too?
In other words: What is more more valuable? Computation power or storage space?
Upvotes: 1
Views: 246
Reputation: 141
To your question:
In other words: What is more more valuable? Computation power or storage space?
To answer this, you need to consider the use case of your data, and the trade-offs you are willing to make with speed and storage.
Consider the use case where there are 100 million records, and you need to run reports frequently which queries for Net Price, Overall costs. In this case, your reports will run slower if the values are computed. Now, If you need the reports to run faster, you can consider storing the computed values in the table.
As another use case, if you have the above data, and you have an audit table which stores every update to the data, and there are archive jobs that backup the data periodically, you will end up storing more data when the computed values are also part of the main table.
So the answer really depends on your use case and the trade-offs you are willing to make.
Upvotes: 1