隔离级别是可重复读:总是读取 CREATE_VERSION 小于或等于当前事务 ID 的记录,在这个前提下,如果数据仍有多个版本,则取最新(事务 ID 最大)的。隔离级别是读已提交:总是取最新的版本即可,即最近被 Commit 的那个版本的数据记录。在mysql官网中是这么描述的
If the transaction isolation level is REPEATABLE READ (the default level), all consistent reads within the same transaction read the snapshot established by the first such read in that transaction. You can get a fresher snapshot for your queries by committing the current transaction and after that issuing new queries.With READ COMMITTED isolation level, each consistent read within a transaction sets and reads its own fresh snapshot.翻译:隔离级别是可重复读:在同一个事务中,一致性读总是去读在该事务第一次读取时生成的快照。隔离级别是读已提交:事务中的每次读取都取自己新生成的快照。相比之下,周老师形容的更贴近隔离级别的概念上,官方的描述则是底层的具体实现逻辑。两者结合一下就是可重复读:通过在每个事物只读取第一次select时生成的快照和undolog比较,根据一个可见性规则判断,是否可以读当前版本的记录,可以就返回,不行就继续比较再上一个版本,直到最老的版本;读已提交:除了每次读取都会使用最新的快照,后面的都和可重复读的逻辑一样。为什么我这里说的是可见性规则呢?是因为周老师描述里“总是读取 CREATE_VERSION 小于或等于当前事务 ID 的记录”很容易错误的理解为当前版本记录里的trx_idrw_trx_ids抄过来的 ids_t m_ids;/** The read should not see any transaction with trx id >= this value. In other words, this is the "high water mark". */ //赋值是即将分配的下一个事务id,所以大于等于这个id的记录对当前事务来说都是不可见的 trx_id_t m_low_limit_id;/** The read should see all trx ids which are strictly smaller (
欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) | Powered by Discuz! X3.4 |