本文旨在了解MySQL InnoDB引擎如何支持事务的隔离级别。
文章主要内容分两个部分。
第一部分阐述数据库的并发问题以及为之产生的ANSI SQL 标准隔离级别。
第二部分根据 MySQL 官方文档解释 InnoDB 是如何支持这些隔离级别的。
ANSI SQL 隔离级别的定义是来源于三个异象问题,ANSI SQL在权衡系统的可靠性和性能之间定义了不同的级别。所以这里先介绍主流的三个并发问题是什么。
Def: The so-called phantom problem occurs within a transaction when the same query produces different sets of rows at different times. For example, if a SELECT is executed twice, but returns a row the second time that was not returned the first time, the row is a “phantom” row.
ANSI SQL下规定的隔离级别(1992 - 很老的标准了)
- 未提交读 - Read Uncommited
- 风险挺高,但是如果只是存粹的读操作可以推荐使用(MyISAM也挺香呀)
- 已提交读 - Read Commited(互联网主流默认使用的隔离级别)
- 事务无法看见其他未提交事务的修改
- 可重复读 - Repeatable Read (MySQL 默认)
- 只读事务开始时的快照数据
- 可序列化 - Serializable
Each consistent read, even within the same transaction, sets and reads its own fresh snapshot.
Consistent reads within the same transaction read the snapshot established by the first read.
原文:https://www.cnblogs.com/yousheng/p/12944218.html