I have an application where there a number of calculations for each \'job revision\' – this involves the sum of multiple rows linked to that revision.
What I\'m wond
This is highly dependent on several factors, such as:
Each of these has different trade-offs, and there are multiple options for satisfying the balance of each.
If you are only dealing with a handful of rows, there is not much difference between any of these, and "just calculate it every time" is fine. If there is no actual need to make things faster, calculating every time is preferred as "more normal"
As always: don't just ask for what's good in the general case. Profile your own code, see where the bottlenecks are, and tend to follow the rule "Don't, yet".
It depends.
If there's convenient way to work it out as you go along, then you don't need a probably expensive query to calculate it out. The big problem with pre-calculating though is the extra levels of complexity that you can be lumbered with maintaining the totals and the data.
It's design compromise, so there's no right answer about where you'll end up. All I would say is you should treat pre-calculation of totals as an optmisation, so if you don't know you need to do it yet, it's a premature optmisation.
If things get out of step, you can end up with a significant amount of work squaring up your data. If they are getting out of step through unfixed bugs or unplugged gaps, it's a significant and ongoing amount of work.
Not something you should need to or in fact should have to rush into.