快照读和当前读
-
快照讀:簡單的select操作,屬于快照讀,不加鎖。(當然,也有例外)
-
select * from table where ?;
-
-
當前讀:特殊的讀操作,插入/更新/刪除操作,屬于當前讀,需要加鎖。
-
select * from table where ? lock in share mode;
-
select * from table where ? for update;
-
insert into table values (…);
-
update table set ? where ?;
-
delete from table where ?;
-
lock in share mode 是加讀鎖,一行數據上可以加多個讀鎖
for update 是加寫鎖,一行數據上只能有一個寫鎖,讀寫互斥
只有訪問到的對象才會加鎖,for update 相對于lock in share mode 來說,即使使用了覆蓋索引,沒訪問到主鍵索引,也會對主鍵對應行進行加鎖操作。
總結
- 上一篇: RC隔离级别下的GAP间隙锁
- 下一篇: 什么原因可能导致主备延迟?