Often I deal with aggregate or parent entities which have attributes derived from their constituent or children members. For example:
The
byte_countandpacket_countof aTcpConnectionobject is computed from the same attributes of its two constituentTcpStreamobjects, which in turn are computed from their constituentTcpPacketobjects.An
Invoicesobject might have atotalwhich is basically the SUM() of its constituentInvoiceLineItems' prices, with a little freight, discount and tax logic thrown in.
When dealing with millions of packets or millions of invoiced line items (I wish!), on-demand computation of these derived attributes -- either in a VIEW or more commonly in presentation logic like reports or web interfaces -- is often unacceptably slow.
How do you decide, before performance concerns force your hand, whether to "promote" derived attributes to precomputed fields?
I personally wouldn't denormalize until performance trade-offs force my hand (because the downside of denormalizations are too drastic IMHO), but you might also consider:
Ref: The Database Programmer: The Argument for Denormalization. Be sure to read as well his article on Keeping Denormalized Values Correct - his recommendation is to use triggers. That brings home the kind of trade-off denormalization requires.