Skip to Content
数据库系统内幕
book

数据库系统内幕

by Alex Petrov
May 2020
Beginner to intermediate
319 pages
7h 3m
Chinese
China Machine Press
Content preview from 数据库系统内幕
B
树的实现
|
69
4.6
压缩
存储原始的、未压缩的数据会导致显著的开销,因此许多数据库提供了压缩数据的方法
以节省存储空间。这里显然是要在访问速度和压缩率之间进行权衡:较大的压缩率可以
提升数据存储空间利用率,允许你在一次访问中获取更多的数据,但这可能需要更多的
内存和 CPU 周期来进行压缩和解压缩。
我们可以在不同的粒度级别上进行压缩。尽管压缩整个文件可以产生更好的压缩率,但
由于整个文件必须在更新时被重新压缩,所以它的应用有限。更细粒度的压缩通常更适
合较大的数据集。压缩整个索引文件既不切实际也难以高效实现:为了寻址一个特定页,
必须访问整个文件或其包含压缩元数据的段(以便定位一个已压缩的段),然后将其解压
缩并使其可用。
另一种选择是按页压缩数据。它很适合我们所讨论的情形,因为到目前为止我们讨论的
算法都使用固定大小的页。页可以独立地进行压缩和解压缩,从而允许你将压缩与页的
加载和刷盘耦合起来。然而,这样一来,被压缩的页只能占用磁盘块的一部分。并且,由
于传输通常以磁盘块为单位进行,所以可能需要换入额外的字节 [RAY95]。在图 4-10 中,
你可以看到压缩页(a)占用的空间小于磁盘块,当我们加载该页时,我们还会换入属于另
一页的额外字节。对于跨越多个磁盘块的页,如图 4-10b,我们必须读取一个附加的块。
磁盘块
a) b)
图
4-10
:压缩和块填充
另一种方法是仅压缩数据,要么按行(压缩整条数据记录),要么按列(对每一列进行压
缩)。在这种情况下,页的管理和压缩是解耦的。
在撰写本书时参考的大多数开源数据库都使用了可插拔的压缩方法 ...
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