在Mysql中,事务隔离级别RC(read commit)和 RR(repeatable read)两种事务隔离级别基于多版本并发控制MVCC(multi-version concurrency control)来实现。
由于RC隔离级别需要保持语句级别的一致性,事务中每一次读取都是访问当前时间点的已提交数据,因此事务中多查询语句时会创建多个不同的ReadView,开销较大,复杂度更高,而对于RR隔离级别,仅需要一个版本的ReadView,消耗更少。因此Mysql默认使用RR隔离级别。
-
- RC隔离级别获得的语句级读一致性
- RR隔离级别获得的事务级读一致性
if the transcation isolation level is REPEATABLE READ (the defalut level),all consistent reads within the same transcation read the snapshot established by the first such read in the transaction.
With READ COMMITTED isolation level,each consistent read within a transaction sets and reads its own fresh snapshot.
对于RC隔离级别,访问数据库是每次语句执行时间点的数据,而对于RR隔离级别,访问的数据是事务第一条语句执行时间点的数据。
在RR隔离级别下,执行start transaction命令后,并未开启事务,而是等到第一条语句执行时开启事务,并建立一致性读的snapshot,如果希望在start transaction时