› 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 · Jul 6, 2024 · 2692 views
    This topic created in 817 days ago, the information mentioned may be changed or developed.

    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 replies  •  2024-07-19 15:33:12 +08:00
    seers
        1
    seers  
       Jul 6, 2024
    锁升级
    wenxueywx
        2
    wenxueywx  
       Jul 19, 2024
    检查重复时就需要加 s lock 进行一致性读;
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   813 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 21:55 · PVG 05:55 · LAX 14:55 · JFK 17:55
    ♥ Do have faith in what you're doing.