请教一下大佬们一个关于 MySQL 锁的问题

16次阅读

共计 379 个字符,预计需要花费 1 分钟才能阅读完成。

MySQL 文档中有这么一段

If a duplicate-key error occurs, a shared lock on the duplicate index record is set. This use of a shared lock can result in deadlock should there be multiple sessions trying to insert the same row if another session already has an exclusive lock. This can occur if another session deletes the row. Suppose that an InnoDB table t1 has the following structure:

相同的 insert 语句并发当唯一键冲突时会导致死锁,这里说的是发生唯一键冲突要先加 S lock 然后再获取 X lock,为什么需要加 S Lock?

正文完
 0