Skip to Content
数据库系统内幕
book

数据库系统内幕

by Alex Petrov
May 2020
Beginner to intermediate
319 pages
7h 3m
Chinese
China Machine Press
Content preview from 数据库系统内幕
59
第
4
章
B 树的实现
在上一章中,我们讨论了二进制格式的一般原理,并学习了如何创建单元格、构建层次
结构以及如何使用指针将它们与页进行连接。这些概念对原地更新和仅追加存储结构都
适用。在本章中,我们将讨论一些 B 树特有的概念。
本章各节在逻辑上分为三组。首先,我们将讨论数据组织:如何建立键和指针之间的关
系,以及如何实现页头和页之间的链接。
接下来,我们将讨论从根节点到叶子节点的整个下降过程:如何执行二分搜索,以及如
何收集相关内容并跟踪父节点,以备后续发生节点的分裂或合并时使用。
最后,我们将讨论优化技术(再平衡、仅在右边追加和批量加载)、维护过程和垃圾收集。
4.1
页头
页头保存有关可用于页定位、维护和优化的信息。它通常包含描述页内容和布局的标志
位、页中单元格的数量、标记空闲空间的上界与下界偏移量(用于追加单元格偏移量和
数据)以及其他有用的元数据。
例如,PostgreSQL 会在头部储存页大小和布局版本。在 MySQL InnoDB 中,页头保存
该页中的记录总数、层数和其他一些与实现相关的值。在 SQLite 中,页头存储单元格的
数量和最右指针。
4.1.1
魔数
文件或页头中经常放置的一个值是魔数。通常,它是一个多字节块,包含一个常数值,
表示该块代表一个页,并指定页的类型或标识其版本。
魔数通常用于校验和完整性检查 [GIAMPAOLO98]。随机偏移量下的字节序列与魔数完
全匹配的概率很小。如果匹配,则偏移量很可能是正确的。例如,为了验证页加载和对
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