zoukankan      html  css  js  c++  java
  • RR模式下的事务隔离

    <pre name="code" class="html">mysql> select * from t100;                                                          Session 2:
    +----+------+-------+------+
    | sn | id   | quota | free |                                             mysql> select * from t100; 读到的记录为 10 |  300 | 1     | 290  
    +----+------+-------+------+
    |  1 |    7 | NULL  | NULL |
    |  2 |    9 | NULL  | NULL |
    |  3 |  990 | NULL  | NULL |
    |  4 |   12 | NULL  | NULL |
    |  5 |   13 | NULL  | NULL |
    |  6 |   14 | NULL  | NULL |
    |  7 |   15 | NULL  | NULL |
    |  8 |   22 | NULL  | NULL |
    |  9 |   23 | NULL  | NULL |
    | 10 |  300 | 1     | 290  |
    +----+------+-------+------+
    10 rows in set (0.00 sec)
                                                                                           Session 2:
    mysql> update t100 set free = free -quota where sn=10;           mysql> select * from t100; 读到的还是290 因为RR模式下 以第一读为准
    Query OK, 1 row affected (0.00 sec)
    Rows matched: 1  Changed: 1  Warnings: 0
    
    mysql> commit;
    Query OK, 0 rows affected (0.01 sec)
    
    mysql> select * from t100;
    +----+------+-------+------+
    | sn | id   | quota | free |
    +----+------+-------+------+
    |  1 |    7 | NULL  | NULL |
    |  2 |    9 | NULL  | NULL |
    |  3 |  990 | NULL  | NULL |
    |  4 |   12 | NULL  | NULL |
    |  5 |   13 | NULL  | NULL |
    |  6 |   14 | NULL  | NULL |
    |  7 |   15 | NULL  | NULL |
    |  8 |   22 | NULL  | NULL |
    |  9 |   23 | NULL  | NULL |
    | 10 |  300 | 1     | 289  |
    +----+------+-------+------+                                                        Session 2:
    10 rows in set (0.00 sec)
    
    
                                                                                      执行
                                                                                      mysql> select * from t100;
                                                                                     +----+------+-------+------+
                                                                                     | sn | id   | quota | free |
                                                                                     +----+------+-------+------+
                                                                                     |  1 |    7 | NULL  | NULL |
                                                                                     |  2 |    9 | NULL  | NULL |
                                                                                     |  3 |  990 | NULL  | NULL |
                                                                                     |  4 |   12 | NULL  | NULL |
                                                                                     |  5 |   13 | NULL  | NULL |
                                                                                     |  6 |   14 | NULL  | NULL |
                                                                                     |  7 |   15 | NULL  | NULL |
                                                                                     |  8 |   22 | NULL  | NULL |
                                                                                     |  9 |   23 | NULL  | NULL |
                                                                                     | 10 |  300 | 1     | 290  |
                                                                                     +----+------+-------+------+
                                                                                    10 rows in set (0.00 sec)
    
                                                                  mysql> update t100 set free = free -quota where sn=10;
                                                                      Query OK, 1 row affected (0.00 sec)
                                                                  Rows matched: 1  Changed: 1  Warnings: 0
    
                                                                mysql> commit;
                                                                Query OK, 0 rows affected (0.01 sec)
    
                                                               mysql> select * from t100;
                                                              +----+------+-------+------+
                                                              | sn | id   | quota | free |
                                                               +----+------+-------+------+
                                                               |  1 |    7 | NULL  | NULL |
                                                                |  2 |    9 | NULL  | NULL |
                                                               |  3 |  990 | NULL  | NULL |
                                                                |  4 |   12 | NULL  | NULL |
                                                                 |  5 |   13 | NULL  | NULL |
                                                               |  6 |   14 | NULL  | NULL |
                                                              |  7 |   15 | NULL  | NULL |
                                                             |  8 |   22 | NULL  | NULL |
                                                              |  9 |   23 | NULL  | NULL |
                                                               | 10 |  300 | 1     | 288  |
                                                              +----+------+-------+------+
                                                              10 rows in set (0.00 sec)
    结论 查询的时候看到的是老数据,更新的时候是以其他会话提交为准。
    


    
                                        
    
  • 相关阅读:
    Codeforces 401C Team 贪心法
    C++ 编译,执行过程 具体解释。
    [从头学数学] 第156节 概率初步
    关于flex,好像有12个属性非常重要
    数据清洗小记(12):姓与名的提取
    理解Angular中的$apply()以及$digest()
    Oracle开发者守则
    黑马程序猿——25,打印流,合并流,对象序列化,管道流,RandomAccessFile
    GPU 编程入门到精通(四)之 GPU 程序优化
    Python 面向对象编程 继承 和多态
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13350678.html
Copyright © 2011-2022 走看看