线上问题:在业务并发量高时,insert某条数据时出现MySQLTransactionRollbackException
日志显示:Caused by: org.hibernate.exception.LockAcquisitionException: could not execute statement
代码排查:
代码执行:0.34ms FullSQL= delete from ms_order_attachment where related_no='8315941921254623749123'
在insert时会先执行一个delete语句,如果此语句没有对应的的数据时,mysql会进行短暂的锁表操作,导致insert出现deadlock
修复:
针对于delete操作,先进行查询,查询出结果大于0条,进行delete操作即可规避此问题