I’m trying to think ahead a little and avoid myself some extra pain if possible.
I’ve had this problem in past applications and have usually opted for the most verbose approach but would like the opinions of a few others.
If you have a basic table such as below, is it wise, and/or more efficient to include a field which includes a calculation from the information which could be found from two other columns. IE:
+-----+---------+------------+-------+--------+-------+
| id | room_id | bookdate | price | people | total |
+-----+---------+------------+-------+--------+-------+
| 414 | 132 | 2010-03-01 | 14.55 | 2 | 29.10 |
| 415 | 132 | 2010-03-02 | 14.55 | 2 | 29.10 |
| 416 | 132 | 2010-03-03 | 14.55 | 2 | 29.10 |
+-----+---------+------------+-------+--------+-------+
The information in the last field could be extracted from the product of the previous two, therefore it is redundant and unnecessary. Are there instances when it could still be worthwhile to have it?
As a rule of thumb, I don’t store values that can be calculated (especially ones that can be easily calculated) on the fly unless there is a performance issue and I need to save some processing time.
This is a classic tradeoff between performance and storage. I would recommend calculating the value until you need a performance boost.