问题:
1.Next-Key在通过非唯一索引键查询时,通过等值查询。锁定上下区间的范围。即针对索引10、20、30,若是锁定20,那么Next-key算法会锁定(10,20),(20,30)还是[10,20),[20,30)或者(10,20],(20,30]。
实测是[10,20),[20,30),但是和书中提到的(10,20),(20,30)不符,和官网的概念也不一致
Suppose that an index contains the values 10, 11, 13, and 20. The possible next-key locks for this index cover the following intervals, where a round bracket denotes exclusion of the interval endpoint and a square bracket denotes inclusion of the endpoint:
(negative infinity, 10]
(10, 11]
(11, 13]
(13, 20]
(20, positive infinity)
2.Next-key是为了解决幻读问题。但是在通过等值非索引查询的时候,用Record Lock就行了,为啥还要用Gap Lock。
即如下:
只要锁住60这个索引,那么再次查询就不会出现幻读,为何需要范围锁定
select * from user where age =60 FOR UPDATE;