当前位置:网站首页>Simple understanding of B tree and b+ tree
Simple understanding of B tree and b+ tree
2022-06-29 23:39:00 【Fairy wants carry】
Preface
First , We know , We use it B Trees B+ The tree is to increase the efficiency of our index ( Increase query efficiency )
We all know Binary search tree The time complexity of the search is O(log N), Its search efficiency is high enough , Then why do you still have B Trees and B+ The emergence of trees ? Is the time complexity of binary search tree smaller than that of binary search tree ?
problem :
This will throw disk read / write IO Efficiency is a problem , as everyone knows ,IO The query efficiency is very low , You need to read the disk and load the data into memory , When a large amount of data is stored , We can't load the received data into memory at once , Instead, it gradually loads into Disk page , Each disk page corresponds to the node of the tree , That is, the side shows the nodes of the tree ( data ) The more , More disk pages ,IO The more ( Back to );——> Tree depth and IO Operate the vibration wave
solve :
1. Each data node stores multiple elements , That is, every time you load , More data , More data on disk pages
2. Using multi tree
B Trees
First, let's talk about his structure directly : A pointer to the current data , A pointer pointing down , Another is data
One m Hierarchical B Tree features : When a node has k A child , For example, the head node has three children , So there must be k-1 Key words , That is, two keywords can divide the keywords of the subtree into 3 A subset of

Inquire about :
Pictured above is an example : If the query value is 5:
First disk IO: Locate in memory ( And 17、35 Compare ), Than 17 Small , The left subtree ;
Second disk IO: Locate in memory ( And 8、12 Compare ), Than 8 Small , The left subtree ;
The third disk IO: Locate in memory ( And 3、5 Compare ), find 5, End .
The whole process , We can see that : The number of comparisons is no less than that of binary search trees , Especially when there are many data in a node , But disk IO The number of times is greatly reduced . The comparison is done in memory ,( Because we compare in memory , And we can have more than one data at a time , data up 了 , So it greatly reduces IO), Compared to disk IO The speed of , The time-consuming comparison is almost negligible . So when the height of the tree is low enough , Can greatly improve efficiency . by comparison , It doesn't matter if there are many elements in the node , Just a few more memory interactions , As long as it does not exceed the size of disk pages .
B+ Trees
structure : Pointer pointing down + data ( Only leaf nodes have ), A linked table is used below , Specifically linked data
1. Yes k The middle node of the subtree contains k Elements (B In the tree is k-1 Elements ), Each element does not hold data , Index only , All the data
Are saved in the leaf node .
2. All leaf nodes contain the information of all elements , And pointers to records containing these elements , The size of the node depends on the leaf itself
Link from small to large .
3. All the intermediate node elements exist in the child nodes at the same time , Is the largest of the child node elements ( Or the smallest ) Elements .
advantage : A node stores content compared to B Trees , One pointer is missing , So every time IO Load data from hard disk into memory , Can load more data than B More trees , The side shows B+ The optimization of the tree

lookup :
And B The difference between trees is , We don't have a satellite search ( That is, the current data record pointed to by the index element ), This means that the same disk page can hold more node elements ——>IO Less operation

What needs to be added is , Clustered index in database (Clustered Index) in , The leaf node directly contains satellite data . In the nonclustered index (NonClustered Index) in , The leaf node has a pointer to the satellite data ;
B+ Tree range lookup
First, find the lower limit of the range by binary search , At this point, the function of our linked list is reflected , The upper limit can be found directly through the link sequence traversal of leaf nodes , Process is simple , Efficient ;

summary
B+ Trees are compared to B The advantages of trees :
1. A single node stores more elements , Make the query IO Fewer times ;
2. All queries need to find leaf nodes , Query performance is stable ;
3. All leaf nodes form an ordered list , Easy range query .
边栏推荐
- Matplotlib histogram of Matplotlib visualization plt bar()
- Node data collection and remote flooding transmission of label information
- Solr basic operation 1
- 我想知道今天还可以开户么?另外想问,现在在线开户安全么?
- 二叉树的序列化 力扣 297. 二叉树的序列化与反序列化 652. 寻找重复的子树
- 软件测试 接口测试 Postman测试工具 接口测试的流程 执行接口测试 接口关联 环境变量和全局变量 内置动态参数以及自动有的动态参数
- Solr基础操作4
- Xutils3 transfer set
- LC:有效的数独 + 旋转图像
- 股票开户安全吗?上海股票开户。
猜你喜欢

Status acquisition and control system of on-site express cabinet

How to solve the problem that the computer time is not automatically updated after proofreading

Create an API rapid development platform, awesome!

The concept and significance of mean, variance, standard deviation and covariance

Implementation of aut, a self-developed transport layer protocol for sound network -- dev for dev column

二叉树的序列化 力扣 297. 二叉树的序列化与反序列化 652. 寻找重复的子树

CE second operation

FPGA开发(2)——IIC通信

打造一个 API 快速开发平台,牛逼!

采购数智化爆发在即,支出宝“3+2“体系助力企业打造核心竞争优势
随机推荐
333333333333333333333333333333
Matplotlib histogram of Matplotlib visualization plt bar()
Head on Amway! Good looking and practical motor SolidWorks model material see here
大厂试水 HPE推出Arm CPU通用服务器产品
请指教什么是在线开户?另外,手机开户安全么?
Wechat applet: big red festive UI guessing lantern riddles is also called guessing character riddles
Wechat applet: (update) cloud development wechat group contacts
Matlab exercises -- program control process exercise
High performance and high availability computing architecture of "Weibo comments"
Under the epidemic, I left my job for a year, and my income increased 10 times
关于二叉树
这个简单的小功能,半年为我们产研团队省下213个小时
The concept and significance of mean, variance, standard deviation and covariance
Wechat applet: picture seconds plus watermark generation
What is online account opening? In addition, is it safe to open a mobile account?
constexpr 函数
Metaq cluster installation test
Speech signal processing (III): speech signal analysis [continuous "analog signal" -- Sampling, quantization, coding -- > discrete "digital signal"]
搭建企业级NTP时间服务器
Solr basic operation 1