V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
MySQL 5.5 Community Server
MySQL 5.6 Community Server
Percona Configuration Wizard
XtraBackup 搭建主从复制
Great Sites on MySQL
Percona
MySQL Performance Blog
Severalnines
推荐管理工具
Sequel Pro
phpMyAdmin
推荐书目
MySQL Cookbook
MySQL 相关项目
MariaDB
Drizzle
参考文档
http://mysql-python.sourceforge.net/MySQLdb.html
q1450718943
V2EX  ›  MySQL

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

  •  
  •   q1450718943 · 64 天前 · 1230 次点击
    这是一个创建于 64 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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?

    2 条回复    2024-07-19 15:33:12 +08:00
    seers
        1
    seers  
       64 天前
    锁升级
    wenxueywx
        2
    wenxueywx  
       50 天前
    检查重复时就需要加 s lock 进行一致性读;
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2376 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 00:11 · PVG 08:11 · LAX 17:11 · JFK 20:11
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.