zoukankan      html  css  js  c++  java
  • If one session has a shared or exclusive lock on record R in an index, another session cannot insert

    If one session has a shared or exclusive lock on record R in an index, another session cannot insert a new index 
    
    record in the gap immediately before R in the index order. 
    
    如果一个session 有一个共享或者排它锁在记录R上,另外的session 不能插入新的index record 在before R这个区间
    
    
    
    Session 1:
    
    mysql> start transaction;
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> select * from SmsTest where phoneNo=10 for update;
    +-------+---------+-------------+--------+
    | sn    | phoneNo | channelType | status |
    +-------+---------+-------------+--------+
    |    10 |      10 |           2 |      1 |
    | 45239 |      10 |           1 |      1 |
    | 45252 |      10 |           1 |      1 |
    +-------+---------+-------------+--------+
    3 rows in set (0.01 sec)
    
    
    
    
    Session 2:
    
    Database changed
    mysql>  insert into zjzc.SmsTest(PhoneNo,channelType,status)  values(1,1,1);
    Query OK, 1 row affected (0.01 sec)
    
    mysql>  insert into zjzc.SmsTest(PhoneNo,channelType,status)  values(2,1,1);
    Query OK, 1 row affected (0.00 sec)
    
    mysql>  insert into zjzc.SmsTest(PhoneNo,channelType,status)  values(3,1,1);
    Query OK, 1 row affected (0.01 sec)
    
    mysql>  insert into zjzc.SmsTest(PhoneNo,channelType,status)  values(4,1,1);
    Query OK, 1 row affected (0.00 sec)
    
    mysql>  insert into zjzc.SmsTest(PhoneNo,channelType,status)  values(5,1,1);
    Query OK, 1 row affected (0.00 sec)
    
    mysql>  insert into zjzc.SmsTest(PhoneNo,channelType,status)  values(6,1,1);
    Query OK, 1 row affected (0.00 sec)
    
    mysql>  insert into zjzc.SmsTest(PhoneNo,channelType,status)  values(7,1,1);
    Query OK, 1 row affected (0.00 sec)
    
    mysql>  insert into zjzc.SmsTest(PhoneNo,channelType,status)  values(8,1,1);
    Query OK, 1 row affected (0.01 sec)
    
    mysql>  insert into zjzc.SmsTest(PhoneNo,channelType,status)  values(9,1,1);
    ^[[A
    ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
    mysql>  insert into zjzc.SmsTest(PhoneNo,channelType,status)  values(9,1,1);
    ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
    mysql>  insert into zjzc.SmsTest(PhoneNo,channelType,status)  values(10,1,1); --hang
    
    mysql>  insert into zjzc.SmsTest(PhoneNo,channelType,status)  values(11,1,1);
    Query OK, 1 row affected (0.01 sec)
    

  • 相关阅读:
    R因子、聚类
    R语言存储
    JavaScript跨域实现
    大型项目工程代码快速上手指北
    Mac环境MySql初始密码设置
    Entity Framework基础—第六篇(Code First)
    Entity Framework基础—第五篇(Model First两种延迟加载)
    Entity Framework基础—第四篇(Model First)
    Entity Framework基础-第三篇
    Entity Framework基础—第二篇
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13350133.html
Copyright © 2011-2022 走看看