数据库厂商如何实现事务?
使用数据库时,通常必须使用事务。比如说我想从A账户转一定数额的钱到B账户,这涉及到两个查询:
- 减少A账户的钱,
- 增加B账户的钱。
理论上可以分开查询,但是会出错。因此,可以肯定的是,我可以将这两个查询打包在一个事务中,并确保这两个操作要么定期结束,要么根本没有任何变化。没有金钱消失或创造。
问题是,在我看来,这只会将责任从我转移到数据库供应商身上。现在由数据库来执行这两项操作,并确保要么执行这两项操作,要么没有任何更改。数据库开发人员也面临着同样的错误发生的问题。
数据库供应商使用哪些技术来确保事务安全?
When working with database it is often essential to use transactions. Say for example that I want to transfer a certain amount of money from account A to account B. This involves two queries:
- decrease the money in account A
- increase it in account B.
In theory I can make the queries separately, but errors happen. So, to be sure, I can pack the two queries inside a transaction and be sure that either both operations end regularly or nothing has changed at all. No money disappears or is created.
The problem is that it seems to me that this only shifts the responsibility from me to the database vendor. Now it is up to the database to make both operations and be sure that either both are made or nothing has changed. And the database developers face the same problems that errors happen.
What techniques do database vendors use to ensure safety for transactions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
维基百科上的 ACID - 实现 页面将帮助您开始预写日志记录、影子分页以及多版本并发控制。请点击链接查找更多信息。
每个 DBMS 供应商都实现自己的算法,通常有几种不同的算法,具体取决于上下文、完整的 ACID 或宽松的要求、分布式事务一致性要求等......
The ACID - Implementations page on wikipedia will get you started on write-ahead logging, shadow paging and multi-version concurrency control. Follow the links to find more.
Each DBMS vendor implements their own algorithms, often several different ones depending on the context, full ACID or relaxed requirements, distributed transaction consistency requirements etc...