【问题标题】:Is it mysql bug or expected behavior?是mysql错误还是预期行为?
【发布时间】:2021-07-06 02:42:27
【问题描述】:

mysql 5.7.33
iso 级别:读取已提交
自动提交:关闭

第 1 节:
创建表 t1(tid int not null,tname varchar(32) null);
创建表 t2(tid int primary key not null, tname varchar(32) null);
插入 t1 值(1,'1'),(2,'2'),(3,'3'),(4,'4');
插入 t2 值(1,'1'),(2,'2'),(3,'3'),(4,'4');
提交;
设置自动提交=0;
从 t1 中删除 在哪里整理( 从 t2 中选择 tid 其中 tname 不为空 ) 并且 tname 为空 ;
没有提交

然后打开另一个会话(我们称之为会话 2),
执行:
更新 t2 设置 tname = null;
更新语句被会话 1 阻止。

并且会话 2 在 mysql 8.0.25 中也被阻止了。

【问题讨论】:

    标签: mysql subquery


    【解决方案1】:

    我在 8.0.20 运行它,但它也在 session2 中被阻止

    会话1

    select version();
    drop table if exists t1;
    drop table if exists t2;
    
    set session transaction isolation level read committed;
    SELECT @@transaction_isolation;
    
    create table t1(tid int not null,tname varchar(32) null);
    create table t2(tid int primary key not null, tname varchar(32) null);
    insert into t1 values(1,'1'),(2,'2'),(3,'3'),(4,'4');
    insert into t2 values(1,'1'),(2,'2'),(3,'3'),(4,'4');
    commit;
    set autocommit=0;
    delete from t1 where tid in( select tid from t2 where tname is not null ) and tname is null ;
    
    #commit;
    

    会话2

    set session transaction isolation level read committed;
    SELECT @@transaction_isolation;
    
    update t2 set tname = null;
    

    测试方法不同吗?

    【讨论】:

    • 再次测试,mysql 8.0.25,session 2也被阻塞了……
    猜你喜欢
    • 2011-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-25
    • 2019-08-11
    • 2011-07-03
    • 2013-07-04
    相关资源
    最近更新 更多