Skip to Content
数据库系统内幕
book

数据库系统内幕

by Alex Petrov
May 2020
Beginner to intermediate
319 pages
7h 3m
Chinese
China Machine Press
Content preview from 数据库系统内幕
88
|
第
5
章
5.3.3
读异常和写异常
SQL 标准 [MELTON06] 提到并描述了在执行并发事务期间可能发生的
读异常
:脏读、不
可重复读和幻读。
脏读
(dirty read)是指一个事务能读到其他事务未提交的更改。例如,事务 T
1
更新了一
条用户记录的地址字段,事务 T
2
在 T
1
提交前就读到了已被更新的地址。事务 T
1
中止并
回滚其执行结果。然而 T
2
却已经能够读到该值,由此看出,它访问到了一个从未提交
过的值。
不可重复读
(nonrepeatable read,有时也称为模糊读(fuzzy read)),是指同一事务两次
查询
同一行
却得到不同的结果。例如,事务 T
1
读取一行,然后事务 T
2
修改该行并提交
了这一更改。如果 T
1
在完成执行之前再次查询同一行,则结果将会和前一次查询不同。
如果我们在事务执行过程中使用范围读取(即不是读取单个数据记录,而是读取一个范
围内的记录),则可能会看到
幻记录
。
幻读
是指事务两次查询同样的
行集合
却得到不同的
结果。它与不可重复读类似,但仅适用于范围查询。
同样地,也存在具有类似语义的
写异常
:丢失更新,脏写和写偏斜。
丢失更新
(lost update)发生在事务 T
1
和 T
2
同时尝试更新 V 的值时。T
1
和 T
2
读取 V 的
值。T
1
更新 V 并提交,之后 T
2
也更新 V 并提交。由于这两个事务不知道彼此的存在,
所以如果允许二者都提交,则 T
1
的结果将被 T
2
的结果覆盖,T
1
的更新将丢失。
脏写
(dirty write)指的是某个事务拿到了一个未提交的值(即脏读)
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

解密金融数据

解密金融数据

Justin Pauley

Publisher Resources

ISBN: 9787111655169