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


    
       
    
    
  • 相关阅读:
    网络杂项
    虚拟化
    虚拟化
    ssh
    开机启动命令/服务
    选择表达式
    查询一个表中的重复数据
    oracle逗号分隔函数
    只能为浮点数或整数的正则表达式
    后台模拟弹出上传匡
  • 原文地址:https://www.cnblogs.com/zhaoyangjian724/p/6199840.html
Copyright © 2020-2023  润新知