CREATE TABLE `kk` ( `a` int(11) NOT NULL, `b` int(11) NOT NULL, `c` int(11) NOT NULL, PRIMARY KEY (`a`), UNIQUE KEY `bb` (`b`), KEY `cc` (`c`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8
mysql> select * from kk; +---+----+----+ | a | b | c | +---+----+----+ | 1 | 10 | 20 | | 3 | 13 | 23 | | 5 | 15 | 25 | | 7 | 17 | 27 | | 9 | 19 | 29 | +---+----+----+ 5 rows in set (0.16 sec)
铺助索引 主健
a=5 recordlock[5]
a<5 next_keylock[1,3,5]
a<=5 next_keylock[1,3,5,7]
a>5 next_keylock[7,9,sup]
a>=5 next_keylock[5,7,9,sup]
b=15 recordlock[5] recordlock[5]
b<15 next_keylock[10,13,15] recordlock[1,5]
b<=15 next_keylock[10,13,15,17] recordlock[1,3,5]
b>15 next_keylock[17,19,sup] recordlock[17,19]
c=25 next_keylock[25] ,caplock[27] recordlock[25]
c<25 next_keylock[20,23,25] recordlock[20,23]
c<=25 next_keylock[20,23,25,27] recordlock[20,23,25]
c>25 next_keylock[27,29,sup] recordlock[27,29]
rr级别: 解决不可重复读,幻读
set tx_isolation="REPEATABLE-READ"
select * from kk where a ... for update
select * from kk where b ... for update
select * from kk where c ... for update