数据库事务隔离的级别
本篇内容介绍了“数据库事务隔离的级别”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
创新互联建站是一家专业提供潞州企业网站建设,专注与网站设计制作、成都网站制作、成都h5网站建设、小程序制作等业务。10年已为潞州众多企业、政府机构等服务。创新互联专业网站建设公司优惠进行中。
1 概述与背景
这是数据库事务原理和工程实践系列文章的第一篇,本文主要在Jim Gray的论文基础上分析关系数据库的事务隔离级别标准和不同隔离级别情况下的行为。第2节主要讨论ANSI标准的下的隔离级别,第3节主要讨论基于悲观锁实现的事务隔离级别,第4节主要讨论基于多版本技术的事务隔离,最后总结排序本文讨论到的各个隔离级别。
注,本文内容融入了作者个人的理解,并没有严格遵守原文的内容;其中cursor stability隔离级别将在后续文章中讨论,快照隔离级别与ANSI标准异象的比较也有所不同。
2 ANSI事务隔离级别
P3 幻读 ("Phantom"): SQL-transaction T1 reads the set of rows N that satisfy some
. SQL-transaction T2 then executes SQL-statements that generate one or more rows that satisfy the used by SQL-transaction T1. If SQL-transaction T1 then repeats the initial read with the same , it obtains a different collection of rows.
通过依次禁止这三种异象,ANSI确定了4种标准隔离级别,如下表所示:
级别 | P1(脏读) | P2(不可重复读) | P3(幻读) |
Read Uncommitted | 允许 | 允许 | 允许 |
Read Committed | 禁止 | 允许 | 允许 |
Repeatable Read | 禁止 | 禁止 | 允许 |
(Anomaly) Serializable | 禁止 | 禁止 | 禁止 |
Note: The exclusion of these penomena or SQL-transactions executing at isolation level SERIALIZABLE is a consequence of the requirement that such transactions be serializable. |
如标准文档所述,禁止了P1/P2/P3异象的事务即满足Serializable级别,但矛盾的是,标准文档中对Serializable又做了如下说明:
The execution of concurrent SQL-transactions at isolation level SERIALIZABLE is guaranteed to be serializable. A serializable execution is defined to be an execution of the operations of concurrently executing SQL-transactions that produces the same effect as some serial execution of those same SQL-transactions |
P1/P2/P3的形式化描述
Read Lock Write Lock Locking
Read Uncommitednone required
Well-formed Writes,
Long duration Write locks
Locking
Read CommitedWell-formed Reads,
Short duration read lockWell-formed Writes,
Long duration Write locks
Locking
Repeatable ReadWell-formed Reads,
Long duration data-item Read locks,
Short duration Read Predicate locksWell-formed Writes
Long duration Write locks
Locking
SerializableWell-formed Reads,
Long duration Read locksWell-formed Writes
Long duration Write locks
“数据库事务隔离的级别”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注创新互联网站,小编将为大家输出更多高质量的实用文章!
分享题目:数据库事务隔离的级别
网页链接:http://azwzsj.com/article/jpgiso.html