Mysql 选择是否在并发更新或插入期间保持一致性?
我在innodb中使用MySQL 5.6。假设我们有以下两个表:Mysql 选择是否在并发更新或插入期间保持一致性?,mysql,sql,transactions,rdbms,Mysql,Sql,Transactions,Rdbms,我在innodb中使用MySQL 5.6。假设我们有以下两个表: create table order_head ( id int not null, version int not null, order_detail_count int not null, primary key (id) ); create table order_detail ( id int not null, product_id int not null,
create table order_head (
id int not null,
version int not null,
order_detail_count int not null,
primary key (id)
);
create table order_detail (
id int not null,
product_id int not null,
qty int not null,
order_head_id int not null,
primary key (id),
foreign key (order_head_id)
references order_head (id)
);
考虑这样一种情况:两个表的许多并发的INSERT和UPDATE都在执行。运行这些事务的应用程序设计良好,具有乐观锁定,因此并发执行不会产生任何不一致的数据
在这种情况下,我担心会提出以下问题:
SELECT
*
FROM
order_head h
JOIN
order_detail d ON (h.id = d.order_head_id);
此查询是否始终确保返回一致的结果?换句话说,这个查询从不混合多个不同事务的数据吗?例如,我不希望出现不一致的结果,例如记录计数为4
,而order\u head.order\u detail\u count
为3
我认为我对事务没有很好的理解,因此任何指向好的参考资料(例如关于事务的书籍)的指针都会非常感激。这是任何RDBMS的基本原则 ACID规则()规定任何RDBMS都必须完成,在这种情况下,对数据库的每个查询都不应受到同时发生的另一个查询的干扰