› 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
cirton
V2EX  ›  MySQL

为什么这条语句表会被锁?

  •  
  •   cirton · Jan 15, 2021 · 2799 views
    This topic created in 2081 days ago, the information mentioned may be changed or developed.

    insert into a 表 select * from b 表 where not exists ( select 1 from c 表 where .... );

    执行这条语句,发现 c 表 被锁了?

    为什么一张查询的关联表会被锁呢?

    数据引擎是 innodb

    4 replies  •  2021-04-21 09:13:15 +08:00
    luoyou1014
        1
    luoyou1014  
       Jan 15, 2021
    C 表不锁,B 表会出现幻读。
    cirton
        2
    cirton  
    OP
       Jan 15, 2021
    @luoyou1014 可以在更新 a 表时不锁 c 表吗?
    现在更新 a 表时,c 表就会被锁导致业务暂停。对 mysql 不太熟,一般怎么处理这种情况呢?
    qiayue
        3
    qiayue  
       Jan 15, 2021
    不要用一条语句完成这个业务,用程序来完成
    512357301
        4
    512357301  
       Apr 21, 2021 via Android
    @cirton c 表不锁的话,如果 c 表在语句执行中更新了怎么办,以更新前为准还是更新后为准
    还有就是尽量不要在 where 中用子查询,我个人比较反感这种写法,有些场景下执行效率低,写起来也麻烦,唯一的好处就是语句逻辑比较直观
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   5387 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 02:08 · PVG 10:08 · LAX 19:08 · JFK 22:08
    ♥ Do have faith in what you're doing.