MySQL InnoDB自愿交易成为僵局受害者 [英] MySQL InnoDB volunteer transaction to be deadlock victim

查看:75
本文介绍了MySQL InnoDB自愿交易成为僵局受害者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MySQL(5.6或更高版本)中是否存在一种机制,可以使事务(或语句)在涉及死锁的情况下自愿成为受害者?

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?

在启用InnoDB死锁检测的情况下,当识别出死锁时,InnoDB决定杀死哪个事务(成为受害者),以允许其他事务继续进行.有一种算法可以确定哪个交易是受害者.

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.

我的问题是,我们是否可以在一条语句中使用任何会影响该算法的语法,这基本上告诉InnoDB:如果该语句/事务涉及死锁,请选择我作为受害者."

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."

推荐答案

这是我要做的更好的事情……" — TRX#8675309

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

在发生死锁的情况下,要为其终止事务的当前算法是,已更改了较少行的事务将被终止.如果是平局,则由InnoDB内部代码任意选择.我们不知道选择的原因.

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.

这篇关于MySQL InnoDB自愿交易成为僵局受害者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆