Skip to Content
数据库系统内幕
book

数据库系统内幕

by Alex Petrov
May 2020
Beginner to intermediate
319 pages
7h 3m
Chinese
China Machine Press
Content preview from 数据库系统内幕
42
|
第
2
章
是叶节点还是非叶节点(即,该节点是拥有键和值还是仅拥有键)被分裂并不重要。在
叶节点分裂的情况下,键连同其相关值一起被移动。
分裂完成后有两个节点,我们必须选择正确的节点才能完成插入。为此,我们可以使用
分隔键不变量。如果插入的键小于要提升的键,则最后插入到原分裂节点。否则,我们
将要插入的键放入新创建的节点。
总之,节点分裂分为四个步骤:
1. 分配一个新节点。
2. 将一半元素从分裂节点复制到新节点。
3. 将新元素放入相应节点。
4. 在分裂节点的父节点处,添加一个分隔键和指向新节点的指针。
2.3.7 B
树的节点合并
为了进行删除,首先要定位目标叶节点。当叶节点被定位后,键和与其相关的值就被删除。
如果相邻节点所拥有的值太少(即,其占用率低于阈值),则需要合并同一层的节点。这
种情况称为
下溢
(underflow)。 [BAYER72] 描述了两种下溢场景:如果两个相邻节点
具有公共父节点,并且它们的内容能够放入单个节点,则它们的内容应该合并(连接起
来);如果它们的内容无法放入单个节点,则应在它们之间重新分配键以恢复平衡(参见
4.4 节)。更准确地说,如果满足以下条件,则合并两个节点:
•
对于叶节点:如果一个节点可以容纳最多 N 个键值对,并且两个相邻节点中的键值
对的数目加起来小于或等于 N。
•
对于非叶节点:如果一个节点可以容纳最多 N +1 个指针,并且两个相邻节点中指针
的数量加起来小于或等于 N+1。
图 2-13 展示了删除元素 16 时的合并过程。在这个过程中,我们将元素从一个兄弟节 ...
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