my mysql env: innodb_version | 5.5.30 version | 5.5.30-log version_compile_machine | x86_64 version_compile_os | Linux tx_isolation = REPEATABLE-READ innodb_locks_unsafe_for_binlog = OFF
I create a table A:
| A | CREATE TABLE `A` (
`id` int(11) NOT NULL,
`name` varchar(1024) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `i_name` (`name`(255))
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
mysql> select * from A;
+----+------+
| id | name |
+----+------+
| 2 | new |
| 7 | aa |
| 8 | adf |
| 9 | aa |
| 11 | a |
| 12 | bbb |
+----+------+
6 rows in set (0.00 sec)
当我使用sql时:
开始;
select * from A where id< = 2 for update;
我发现这个sql可以锁定下一行id = 7:
TABLE LOCK table `test`.`A` trx id 2F06 lock mode IX
RECORD LOCKS space id 0 page no 420 n bits 80 index `PRIMARY` of table `test`.`A` trx id 2F06 lock_mode X
Record lock, heap no 4 PHYSICAL RECORD: n_fields 4; compact format; info bits 0
0: len 4; hex 80000007; asc ;;
1: len 6; hex 00000000077f; asc ;;
2: len 7; hex ef000001750128; asc u (;;
3: len 2; hex 6161; asc aa;;
Record lock, heap no 12 PHYSICAL RECORD: n_fields 4; compact format; info bits 0
0: len 4; hex 80000002; asc ;;
1: len 6; hex 000000002ef1; asc . ;;
2: len 7; hex 1f0000020e0110; asc ;;
3: len 3; hex 6e6577; asc new;;
我不知道为什么?我认为主键索引可以找到uniq键2。