Skip to Content
数据库系统内幕
book

数据库系统内幕

by Alex Petrov
May 2020
Beginner to intermediate
319 pages
7h 3m
Chinese
China Machine Press
Content preview from 数据库系统内幕
事务处理与恢复
|
79
用更改,我们可以将这些操作缓冲在一起,从而减少磁盘写入的次数并分摊写入成本,
因为只要做一次磁盘写入即可,无须写入多次。
预取和立即换出缓存
页缓存也允许存储引擎对预取和换出进行细粒度的控制,存储引擎可以指示页缓存
在访问页之前提前加载页。例如,当在范围扫描中遍历叶节点时,可以预加载下一
个叶节点。同样,如果后台维护进程加载了某个页,则可以在进程完成后立即将其
换出缓存,因为它不太可能被进行中的查询用到。某些数据库(例如 PostgreSQL)
使用循环缓冲区(即先进先出的页置换策略)进行大规模顺序扫描。
5.1.4
页置换
当缓存容量用完时,为了加载新页,必须换出旧页。但是,除非我们换出近期不太可能
再次访问的页,否则这些页可能会反复加载多次
—
我们原本可以将它们始终放在内存
中。为了优化该行为,我们需要找到一种方法来估计后续页被访问的可能性。
为此,我们应当根据
换出策略
(有时也称为
页置换策略
)将页换出,该策略尝试找出近
期最不可能被再次访问的页。当这个页被换出后,新页可以加载到它的位置上。
为了实现高效的页缓存,我们需要一种有效的页置换算法。最理想的页置换策略可能需
要一个“水晶球”
—
它能预测未来的页访问次序,仅换出将在最长时间内不会用到的
页。由于请求并不一定遵循任何特定的模式或分布,所以很难精确地预测其行为。即使
如此,使用正确的页置换策略也能帮助减少换出的次数。
使用更大的缓存能够帮助我们减少换出的次数,这听起来似乎很合理。但事实并非如
此。可以说明这种困境的例子之一是
Bélády ...
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