并发批量更新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'
文章讨论了在并发情况下批量更新tableA的field3时遇到的MySQLDeadlock问题,提供了通过主键更新而非依赖非主键索引来避免死锁的解决方法,并引用了知乎文章链接以供参考。

2008

被折叠的 条评论
为什么被折叠?



