My table's definition is
CREATE TABLE
auto_inc
(
id
int(11) NOT NULL AUTO_INCREMENT,PRIMARY KEY (
id
)) ENGINE=InnoDB DEFAULT CHARSET=latin1
At first there are four rows:
| id |
| 1 |
| 2 |
| 3 |
| 4 |
I opened session 1 and executed
#session 1
set transaction isolation level REPEATABLE READ
start transaction;
select * from auto_inc
return four rows 1,2,3,4.And then I opened another session 2 and executed
#session 2
insert into auto_inc(`id`) values(null)
and insert success.Back to session 1 I executed
#session 1
select * from auto_inc;#command 1
select * from auto_inc for update;#command 2
command 1 return four rows 1,2,3,4.But command 2 return 1,2,3,4,5.Could anyone gives me some clues why command 2 will see session 2's insertion? Thanks in advance!