SELECT 在并发 UPDATE 或 INSERT 期间是否保持一致性?

Does SELECT keep consistency during concurrent UPDATE or INSERT?

我正在使用 MySQL 5.6 和 innodb。假设我们有以下两个表:

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)
);

考虑两个表的许多并发 INSERTUPDATE 一直在执行的情况。运行这些事务的应用程序经过精心设计,具有乐观锁定,因此并发执行不会产生任何不一致的数据。

在这种情况下,我担心发出以下查询:

SELECT 
    *
FROM
    order_head h
        JOIN
    order_detail d ON (h.id = d.order_head_id);

此查询是否总能确保 return 一致的结果?换句话说,这个查询从不混合多个不同事务的数据吗?例如,我不希望出现不一致的结果,例如记录数是 4order_head.order_detail_count3

我想我对交易的理解不是很好,所以任何指向好的参考资料(例如关于交易的书籍)的指针也将不胜感激。

这是任何 RDBMS 的基本原则。

任何 RDBMS 都必须完成的 ACID 规则 (https://en.wikipedia.org/wiki/ACID),在这种情况下是隔离,其中对数据库的每个查询不应受到同时发生的另一个查询的干扰。