有没有一种方法可以避免由于同一表中的共享锁升级而导致死锁?

时间:2019-01-29 07:02:42

标签: mysql database-deadlocks

我有一个InnoDB表“ test”,并且有两个事务查询该表。

会议1:

start transaction;
select * from test where testid = 200 lock in share mode;

会议2:

start transaction;
select * from test where testid = 200 lock in share mode;

会议1:

select * from test where testid = 200 for update;
-- Trying to get X lock and waits as session 2 already has a shared lock for this entry

会议2:

select * from test where testid = 200 for update;
--Deadlock occurs because of Shared lock of session 1 

有没有摆脱这种情况的方法?

0 个答案:

没有答案