并发运行时事务(在 MySQL 中)的行为如何?
这是我的场景:
我有表 A,有 4 行(id、col1、col2、col3),最后 3 行有一个唯一索引(id 是主键)。假设有 2 个用户:用户 Foo 和用户 Bar。 如果 Foo 和 Bar 都启动一个事务,在表 A 上插入许多行,并且同时提交事务,那么该表是否可能会出现 UNIQUE 索引不一致的情况?
换句话说,如果一个事务是原子的(确实如此),是否意味着只要它运行,其他可能对第一事务一致性带来风险的事务就不会运行?
提前致谢!
Here is my scenario:
I have table A, that has 4 rows (id, col1, col2, col3) with a UNIQUE index put on the last 3 rows (id is primary key). Lets suppose there are 2 users: user Foo and user Bar.
If both, Foo and Bar, starts a transaction in that inserts many rows on table A, and at the same time, they commit their transactions, is it possible the table to present inconsistency for UNIQUE index?
In other words, if a transaction is atomic (and it is), does that mean that as long as it runs, no other transaction that can present a risk for first transaction consistency will run?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这些事务将同时运行(在大多数情况下,取决于您的事务隔离级别设置),但是提交时违反一致性的事务将导致错误并且必须回滚。
The transactions will run concurrently (for the most part, depending on your transaction isolation level setting), but the ones that violate consistency upon commit will result in an error and have to be rolled back.