MySQL thread id 3, query id 51 localhost 127.0.0.1 root Sending data
select * from tbl_no_index where i=4 for update
------- TRX HAS BEEN WAITING 28 SEC FOR THIS LOCK TO BE GRANTED:
[color=Red]RECORD LOCKS space id 0 page no 197 n bits 72 index `GEN_CLUST_INDEX` of table `test`.`tbl_no_index` trx id 0 3853 lock_mode X waiting[/color]
Record lock, heap no 2 PHYSICAL RECORD: n_fields 4; compact format; info bits 0
0: len 6; hex 000000000400; asc ;; 1: len 6; hex 000000000f01; asc ;; 2: len 7; hex 800000002d0110; asc - ;; 3: len 4; hex 80000001; asc ;;
------------------
---TRANSACTION 0 3849, ACTIVE 914 sec, OS thread id 2868
2 lock struct(s), heap size 320, 5 row lock(s)
MySQL thread id 2, query id 45 localhost 127.0.0.1 root
Trx read view will not see trx with id >= 0 3850, sees < 0 3850
复制代码
如下测试: 测试2:插入的字段记录有gap的并发情况
session一:
root@localhost[test] 10:32:21>set autocommit=off;
Query OK, 0 rows affected (0.00 sec)
root@localhost[test] 11:29:19>select * from tbl_no_index;
+------+
| i |
+------+
| 1 |
| 2 |
| 7 |
| 11 |
| 12 |
+------+
5 rows in set (0.00 sec)
root@localhost[test] 11:29:33>select * from tbl_no_index where i=2 [color=Red]for update[/color];
+------+
| i |
+------+
| 2 |
+------+
1 row in set (0.00 sec)
复制代码
session二:
root@localhost[test] 11:29:51>set autocommit=0;
Query OK, 0 rows affected (0.02 sec)
root@localhost[test] 11:29:55>[color=Red]insert into tbl_no_index values(5);[/color]
Query OK, 1 row affected (0.00 sec)
root@localhost[test] 11:30:03>select * from tbl_no_index;