本篇内容介绍了“数据库事务隔离的级别”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
这是数据库事务原理和工程实践系列文章的第一篇,本文主要在Jim Gray的论文基础上分析关系数据库的事务隔离级别标准和不同隔离级别情况下的行为。第2节主要讨论ANSI标准的下的隔离级别,第3节主要讨论基于悲观锁实现的事务隔离级别,第4节主要讨论基于多版本技术的事务隔离,最后总结排序本文讨论到的各个隔离级别。
注,本文内容融入了作者个人的理解,并没有严格遵守原文的内容;其中cursor stability隔离级别将在后续文章中讨论,快照隔离级别与ANSI标准异象的比较也有所不同。
P3 幻读 ("Phantom"): SQL-transaction T1 reads the set of rows N that satisfy some
通过依次禁止这三种异象,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 |
Read Lock | Write Lock | |
Locking Read Uncommited | none required | Well-formed Writes, Long duration Write locks |
Locking Read Commited | Well-formed Reads, Short duration read lock | Well-formed Writes, Long duration Write locks |
Locking Repeatable Read | Well-formed Reads, Long duration data-item Read locks, Short duration Read Predicate locks | Well-formed Writes Long duration Write locks |
Locking Serializable | Well-formed Reads, Long duration Read locks | Well-formed Writes Long duration Write locks |
“数据库事务隔离的级别”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注创新互联-成都网站建设公司网站,小编将为大家输出更多高质量的实用文章!
Copyright © 2009-2022 www.wtcwzsj.com 青羊区广皓图文设计工作室(个体工商户) 版权所有 蜀ICP备19037934号