跳转到内容
欢迎抵达彼岸 彼岸花开 此处谁在 -彼岸论坛

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

Featured Replies

发表于

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?