MySQL InnoDB volunteer transaction to be deadlock victim

≡放荡痞女 提交于 2019-12-24 07:47:32

问题


Is there a mechanism in MySQL (5.6 or later) to have a transaction (or statement) to volunteer to be a victim in the case it is involved in a deadlock?


With InnoDB deadlock detection on, when a deadlock is identified, InnoDB determines which transaction to kill (to be the victim) in order to allow the other transaction(s) to proceed. There's an algorithm used to determine which transaction is the victim.

My question is whether there is any syntax that we can use in a statement that will influence the algorithm, that basically tells InnoDB "if this statement/transaction is involved in a deadlock, then pick me as the victim."


回答1:


"It is a far, far better thing I do..." — TRX #8675309

The current algorithm for which transaction is killed in case of a deadlock is that the transaction that has changed fewer rows is killed. In case of a tie, the choice is made arbitrarily by InnoDB internal code; we do not know the reason for the choice.

So the only way one transaction can "volunteer" is to change fewer rows than the other transaction.



来源:https://stackoverflow.com/questions/47758614/mysql-innodb-volunteer-transaction-to-be-deadlock-victim

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!