CREATE TABLE ` t2 ` (
` id ` int (11) the DEFAULT NULL,
` class ` int (11) the DEFAULT NULL,
The KEY ` id ` (` id `)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
The data is:
select * from t2.
+ -- -- -- -- -- - + -- -- -- -- -- -- -- +
| | id class |
+ -- -- -- -- -- - + -- -- -- -- -- -- -- +
| | 1 |
| 2 | 2 |
| | | 10 10
+ -- -- -- -- -- - + -- -- -- -- -- -- -- +
Transaction 1:
select * from t2 where id> 4 and id<5 for update;
Transaction 2
select * from t2 where id=2 for update; Normal
Select * from t2 where id=10 for update; Block
Is the locking range is (2, 10], this conforms to the next - the key lock,
But
insert into t2 values (2, 2); Blocking
Insert into t2 values (10, 10); Normal
Just the opposite and the select for update, this is what causes?
Insert the lock is intention index does not exist, check the gap before the end of the insert lock, but under the condition of existence, is how to check?
And why the mysql will expand the gap to the scope of the index values before and after? And added after a row index, the index value which is next to the key lock, this design is for the sake of what?
And some attempt on the personal home page, welcome criticism directions:
http://wangyoubin.com/? P=105