線上問題:在業務並發量高時,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操作即可規避此問題