-
快照读:简单的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 来说,即使使用了覆盖索引,没访问到主键索引,也会对主键对应行进行加锁操作。