Skip to Content
数据库系统内幕
book

数据库系统内幕

by Alex Petrov
May 2020
Beginner to intermediate
319 pages
7h 3m
Chinese
China Machine Press
Content preview from 数据库系统内幕
136
|
第
7
章
7.3.5
压缩
我们已经在 B 树的上下文中讨论过压缩(参见 4.6 节)。类似的思想也适用于 LSM 树。
这里的主要区别在于 LSM 树表是不可变的,并且通常是在一次请求中写入的。当按页
压缩数据时,压缩后的页不是页对齐的,因为它们的大小比未压缩的小。
为了能够处理被压缩的页,我们需要在写入它们的内容时跟踪它们的地址边界。我们可
以用零来填充压缩的页,使它们与页大小对齐,但这样我们就失去了压缩的好处。
为了使被压缩的页可寻址,我们需要一个间接层来存储偏移量和压缩页的大小。图 7-10
展示了压缩块和未压缩块之间的映射。压缩后的页
一定
比原始的小,否则压缩它们就没
有意义了。
偏移表
压缩的页
(
磁盘
)
未压缩的页
(
虚拟
)
图
7-10
:读取压缩块(虚线表示从映射表到磁盘上压缩页偏移量的指针。未压缩的页一般位于
页缓存中)
在压缩和刷盘期间,压缩的页被顺序地追加,并且压缩信息(原始未压缩的页偏移量和
实际压缩的页偏移量)存储在单独的文件段中。在读取过程中,将压缩后的页偏移量及
其大小查询出来,之后在内存中解压缩并物化。
7.4
无序
LSM
存储
到目前为止讨论过的大多数存储结构都是
有序
地存储数据的。可变和不可变的 B 树页、
FD 树中的有序段、LSM 树中的 SSTable 都是按键顺序存储数据记录的。这些结构保留
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