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)
    结论 查询的时候看到的是老数据,更新的时候是以其他会话提交为准。
    


    
       
    
    
  • 相关阅读:
    struct2 学习总结
    c++ 容器(list学习总结)
    java 网络编程(五)----TCP进阶篇上传文本文件
    java 网络编程(四)----UDP进阶篇聊天小程序
    java 网络编程(三)---TCP的基础级示例
    java 网络编程(二)----UDP基础级的示例
    java 网络编程(一)---基础知识和概念了解
    GitHub和git和repo的使用
    android studio不能预览
    关于android studio2.3和android studio3.0
  • 原文地址:https://www.cnblogs.com/zhaoyangjian724/p/6199841.html
Copyright © 2011-2022 走看看