数据库应用程序 - 实时存储或计算?
我有一个采购清单表,其中包含以下字段:商品名称、数量、单价、金额。请注意,金额等于数量 * 单价。
我的简单问题是,在检索数据时我应该存储金额还是计算它?我应该关注什么,存储还是处理?
I have a table of purchase list with fields: ItemName, Quantity, UnitPrice, Amount. Note that Amount is equal to Quantity * UnitPrice.
My simple problem is, should I STORE the amount or COMPUTE it when retrieving the data? To what should I concern about, storage or processing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
存储很便宜,为了方便我只是预先计算一下。不过,根据您的应用程序,这可能并不重要,除非您正在搜索或报告“金额”列。如果您要报道本专栏,那么我肯定会预先计算。我更担心连接和子查询。
Storage is cheap, I'd just pre-compute it for convenience. It probably won't matter much depending on your application though unless you are searching or reporting on the Amount column. If you are reporting on this column then I'd definitely pre-compute. I'd be more worried about joins and sub-queries.