RR模式下,事物的更新问题

RR模式下 update问题

mysql> select @@TX_ISOLATION;
+-----------------+
| @@TX_ISOLATION  |
+-----------------+
| REPEATABLE-READ |
+-----------------+
1 row in set (0.00 sec)

session 1 2开启事物查询结果都为
mysql> select id,port from db_info;
+----+------+
| id | port |
+----+------+
|  1 | 3306 |


session2更新port,并提交,此时session2结果
mysql> update db_info set port=3308 where id=1;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select id,port from db_info;            
+----+------+
| id | port |
+----+------+
|  1 | 3308 |

查询session1:
mysql> select id,port from db_info;
+----+------+
| id | port |
+----+------+
|  1 | 3306 

session1更新并查看结果:
mysql> update db_info set port=port+1 where id=1;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select id,port from db_info;              
+----+------+
| id | port |
+----+------+
|  1 | 3309 |

此时可以看到port=port+1  并不是在session1查看的3306基础上,而是在session2 update之后的结果。
RR隔离模式下,数据更新,依然以最新的commit的数据为准,并不是以自己查看的为准。

你可能感兴趣的:(SQL优化,MySQL)