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?