插入订单的总价值,或每次计算? [英] Insert Total value of order, or calculate every time?

查看:96
本文介绍了插入订单的总价值,或每次计算?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立了一个简单的电子商务网站,我对订单确认和创建有一些疑问...

I'm builing a simple e-commerce website, and i'm having some doubts on the order confirmation, and creation...

这是一个问题好实践然后一个真正的问题...

It's more a question of good practices then a real question...

应该:计算总订单值,

Should I: calculate the total order value, and insert on the database, or should i calculate it every time i read/dosomething with the order?

感谢

推荐答案

数据库土地中的最佳实践意味着规范化的数据,并且存储可以计算的值违反了这一点。

Best practices in database land means normalised data, and storing values that can be calculated violates that.

/ em>存储您可以计算的内容,除非您绝对确定这两个值之间不会有差异。

You should never store things that you can calculate unless you're absolutely certain that there won't be a discrepancy between the two values.

例如,如果您的订单包含两个100美元的订单,但订单设置为150美元,那么您认为应该会发生什么情况?

For example, what do you think should happen if your order consists of two $100 items but the order is set to $150?

有时,有理由(通常与效果相关)存储可以另外计算的值,但是性能增益必须是显着的必要,并且可能会删除或计划不一致。

Sometimes, there are justifications (usually performance related) to storing values that can be otherwise calculated but the performance gains have to be both significant and necessary, and the possibility of inconsistency either removed or planned for.

您可以删除触发器或物化视图等事件的可能性,也可以通过更改业务逻辑来检测和修复问题或通过其他方式来规划它们。

You can remove the possibility with things like triggers or materialised views, or you can plan for them by changing business logic to detect and fix problems, or by other means.

但是,通常,性能增益不值得减轻潜在问题的额外努力。毕竟,你看到了多少个订单? 个人项目?除美国mod,当然: - )

But usually, the performance gains aren't worth the extra effort of mitigating the potential problems. After all, how many orders do you see with millions of individual items on them? Other than the US DoD, of course :-)

这篇关于插入订单的总价值,或每次计算?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆