且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

带有两个相同查询(不同参数)的MySQL InnoDB死锁问题

更新时间:2023-02-14 16:41:52

查询使用index_status索引而不是fk_task_userid(node_id上​​的索引).这就是它使用其他node_id锁定记录的原因.

The query uses the index_status index instead of fk_task_userid (the index on node_id). This is the reason it locks records with other node_ids.

您可以在查询中运行解释,以查看实际锁定了多少记录(在检查的行中)以及需要锁定多少记录(返回的行)

You can run explain on your query to see how much records are actually locked (in rows examined) vs how much of them you need to lock (rows returned)

我怀疑,可以通过在字段(node_id,status)上创建复合索引来解决这种情况,但这并不是一个好的解决方案.我需要了解问题的本质.

I suspect, that I can solve the situation by creating a compound index on fields (node_id, status), but this isn't a good solution, I think. I need to understand the nature of the problem.

为什么?我觉得您的索引仍然不是***...在node_id,status上创建索引,它应该可以解决问题

Why? I feel your indexes are not optimal anyway... Create index on node_id,status, it should resolve the problem