specita
2020-09-09 11:40:24 +08:00
我觉得会死锁啊,会竞争 X 锁啊。你开两个事务,start transaction 手动测试就知道了啊。
看之前的回答我还怀疑自己,测试了下:
Trx id counter 101931
Purge done for trx's n:o < 101930 undo n:o < 0 state: running but idle
History list length 11
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION 101930, ACTIVE 16 sec
2 lock struct(s), heap size 1136, 1 row lock(s), undo log entries 1
MySQL thread id 13, OS thread handle 19224, query id 835 localhost ::1 root starting
show engine innodb status
---TRANSACTION 101928, ACTIVE 107 sec starting index read
mysql tables in use 1, locked 1
LOCK WAIT 3 lock struct(s), heap size 1136, 3 row lock(s)
MySQL thread id 14, OS thread handle 1736, query id 834 localhost ::1 root Searching rows for update
update user set id = 1 where name = 'aa'
------- TRX HAS BEEN WAITING 10 SEC FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 489 page no 3 n bits 72 index PRIMARY of table `orange`.`user` trx id 101928 lock_mode X locks rec but not gap waiting
Record lock, heap no 2 PHYSICAL RECORD: n_fields 5; compact format; info bits 0