1
我使用的MySQL 5.6與innodb。比方說,我們有以下兩個表:SELECT在併發UPDATE或INSERT期間是否保持一致?
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_head.order_detail_count
是3
。
我覺得我對事務沒有很好的理解,所以任何指向良好引用的指針(例如關於事務的書籍)都將不勝感激。