SELECT FOR UPDATE对不存在的行使用哪种锁?

时间:2019-06-27 10:56:21

标签: mysql transactions innodb

假设我们有2笔交易。

交易1:

mysql> begin;
Query OK, 0 rows affected (0.00 sec)

mysql> select * from user where id = 200 for update; // sql1
Empty set (0.00 sec)

然后开始交易2:

mysql> begin;
Query OK, 0 rows affected (0.00 sec)

mysql> select * from user where id = 200 for update; // sql2
Empty set (0.00 sec)

mysql> update user set name='' where id = 200; // sql3
Query OK, 0 rows affected (0.00 sec)
Rows matched: 0  Changed: 0  Warnings: 0

mysql> insert into user values(200,''); // sql4
ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction

两个事务的隔离级别均为REPEATABLE-READ

  1. 什么将被sql1或sql2锁定? X锁还是S锁?哪排是X锁还是S锁?

0 个答案:

没有答案