表结构:
CREATE TABLE `student` ( `id` int NOT NULL, `name` varchar(255) DEFAULT NULL, `age` int DEFAULT NULL, `score` int DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; 已经有如下数据 (1, 'Alice', 20, 85),
(8, 'Bob', 22, 92),
(15, 'Charlie', 21, 78),
(25, 'David', 23, 95), (33, 'Eva', 20, 88),
(44, 'Frank', 22, 79),
(50, 'Grace', 21, 94),
(55, 'Henry', 23, 87);
事务 A 执行: time1: update student set score=88 where id=22;
time3: insert into student(id, name, age, score) value(22, 'John', 28, 88);
事务 B 执行: time2:update student set score=99 where id=21;
time4: insert into student(id, name, age, score) value(21, 'John', 28, 99);
在 time1 时刻事务 A 会加上 next-key lock (15, 25)
time2:update student set score=99 where id=21; 时刻下为什么不会被阻塞 死锁又是怎么产生的
