优化器在表行数比较少的时候 会使用全表扫描,会形成全表全部的行加锁,因此须要使用force index 强制使用索引 来实现gap-lock(间隙锁)的应用sql
next-lock 加锁 会锁住 第一个不知足条件行优化
例以下表 number有惟一索引code
id | name | number |
---|---|---|
1 | Jack | 1 |
2 | Mike | 2 |
3 | Jon | 3 |
4 | Trevor | 4 |
执行索引
update set name = 'Franklin' where number < 2;
实际上 id=3 的行也会被锁住table