匿名用户mysql> show create table t11;
+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| t11 | CREATE TABLE `t11` (
`id` int(11) NOT NULL,
`type_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |
+-------+-------------------------------------------
mysql> select * from t11;
+----+---------+
| id | type_id |
+----+---------+
| 1 | 3 |
| 2 | 3 |
| 3 | 4 |
| 4 | 3 |
| 5 | 4 |
| 6 | 4 |
| 7 | 5 |
| 8 | 5 |
| 9 | 4 |
| 12 | 4 |
| 15 | 4 |
+----+---------+
mysql> select * from t11 where type_id=4 for update; --sess1 ,rc
+----+---------+
| id | type_id |
+----+---------+
| 3 | 4 |
| 5 | 4 |
| 6 | 4 |
| 9 | 4 |
| 12 | 4 |
| 15 | 4 |
+----+---------+
mysql> select * from t11 where type_id=3 for update; --sess 2,rc
+----+---------+
| id | type_id |
+----+---------+
| 1 | 3 |
| 2 | 3 |
| 4 | 3 |
+----+---------+
rc下,sess1 ,sess2 为什么会等待了,会在id=3的记录上发生了等待?
data_locks中,单独看sess1 是6条行锁,sess2 是3个行锁,并且没有id=3上的锁 ,
为什么sess2 会请求id=3上的行锁呢?
墨值悬赏

评论
