并发批量更新tableA的field3字段。
注:tableA有非主键索引 idx_field1(field1) , idx_field2(field2)
update tableA set field3 = '3' where field1='arg1' and field2='arg2'
报错:
Cause: com.mysql.cj.jdbc.exceptions.MySQLTransactionRollbackException: Deadlock found when trying to get lock; try restarting transaction
; Deadlock found when trying to get lock; try restarting transaction; nested exception is com.mysql.cj.jdbc.exceptions.MySQLTransactionRollbackException: Deadlock found when trying to get lock; try restarting transaction
解决方式一:
/* 主键更新 */
update tableA set field3 = '3' where id = 'id1'
传送门:https://zhuanlan.zhihu.com/p/648097430