MySQL索引失效行鎖變表鎖

gdut17發表於2020-10-03

create table test_lock (
id int,
name varchar(255),
primary key (id),
unique (name)
)ENGINE=InnoDB default charset=utf8mb4;

insert test_lock values(1,'1001'),(2,'1002'),(3,'1003'),(4,'1004');

事務1
set autocommit=0;
update test_lock set id = 10 where name = 1002; --隱式型別轉換,索引失效,行鎖變表鎖
commit;

事務2
set autocommit=0;
update test_lock set name='1099' where id = 4;  -- 此時阻塞
commit;


相關文章