我使用批量插入時,桌子上面臨僵局問題,查詢低於如何避免死鎖情況插入選擇更新重複?
INSERT INTO registrationupdates (refreshtime,firstseentime,userdevice,isexist,userpart,expires,ipaddress,contacturi,deviceid)
SELECT refreshtime,firstseentime,userdevice,isexist,userpart,expires,ipaddress,contacturi,(SELECT IFNULL(id,0) FROM devicedetails WHERE deviceip LIKE CONCAT('%',registrarip , '%'))
FROM register_temp_table WHERE isexist=1 ON DUPLICATE KEY UPDATE `refreshtime`=VALUES(refreshtime),`firstseentime`=VALUES(firstseentime),`userdevice`=VALUES(userdevice),`isexist`=VALUES(isexist);
我得到下面的錯誤消息
Deadlock found when trying to get lock; try restarting transaction
「contacturi」是唯一的鑰匙,而且索引上用戶部分列在註冊更新表上。
任何人都可以幫助我嗎?
參見[如何與應對死鎖(http://dev.mysql.com/doc/refman/5.7/en/innodb-deadlocks.html解決您的問題) – Drew