当前位置:网站首页>What is the b+tree index of MySQL? How does the cluster index grow?
What is the b+tree index of MySQL? How does the cluster index grow?
2022-07-27 22:53:00 【nuzzzzz】

You must know MySQL Conduct CRUD It's in memory , That is to say Buffer Pool in . And then you know when there's no memory MySQL When data is needed ,MySQL From Disk Pass through IO Operation to read data into memory . The reading unit is : Data pages
The general data page length is as follows

you 're right , Real data is stored in the data page , And the data pages are organized in the form of two-way linked tables in memory ! Here's the picture

And in the B+Tree Setting of , It requires that the primary key index be incremented , That is to say, if the primary key index is incremented , All data in the data page on the right is required to be larger than that in the data page on the left . But it's clear that the picture doesn't fit , So you need to split the page to make it look like this .

good , Now think about it , You must have heard of it before :MySQL Of B+Tree Cluster index , Only leaf nodes store real data , Instead of storing index data in leaf nodes , And leaf nodes are connected by two-way linked list
you 're right , All that B+Tree The leaf node of is the data page in the figure above , And they are really linked through a two-way linked list !
Let's move on , If you only look at the two-way list connected by data pages in the figure above , Now if we search id=7 The data line , What will happen then ?
Obviously we're going to scan from the beginning !
Then you may ask : I didn't mean B+Tree The primary key is required to be incremental ? And there is a page splitting mechanism to ensure that all data in the right data page is larger than the index value of the left data page . It's not good to do a binary search ?
answer : Yes , It's really possible to do a binary search in a single data page , But the organization relationship between data pages is linked list , So traversal from the beginning is inevitable .
that MySQL What to do ?
Here's the picture :MySQL An index directory is abstracted for many data pages

With this index, we can easily search through many data pages ! Have the ability of binary search directly !
And this directory actually exists in the data page , Unlike leaf nodes , It only stores index information , The leaf node stores real data ?
And the birth of index pages means B+Tree The rudiment of the world has been born !
As users continue to select,buffer pool There are more and more data pages in , Then the data in the index page will also rise . When the existing index volume exceeds 16KB( The capacity of a data page ) We have to create a new index page to store new index information . And then this one B+Tree It's going to get fatter and fatter .
Then you know B+Tree yes B Varieties of trees , and B Trees can actually be 2-3 Trees 、2-3-4 Count .... wait M A general term for rank trees , When the number of elements that can be stored in each node reaches the upper limit , The tree will grow high .
Like the picture below :

边栏推荐
猜你喜欢

Kubernetes binary deployment - theoretical part

In depth analysis - file operation
DP traceability problem

云计算服务主要安全风险及应对措施

Project management tool Zen

Markdown extended syntax

The follow-up is coming. Whether it's OK without reference, let's make it clear to everyone at once!

对象创建过程及对象布局

视频人体行为检测

智能家居浪潮来袭,如何让机器看懂世界 【结尾有资料】
随机推荐
Jeninkins offline deployment
中职磐云网络安全大赛-------隐藏信息探索
Uniswap集成sudoswap,能否拉开NFT流动性新序幕?
jstack那些事
2022/6/5 exam summary
Cy3荧光标记抗体/蛋白试剂盒 (10~100mg标记量)
Exam summary on May 31, 2022
Oppo find x2 series release: 3k+120hz curved screen, DxO score first, top version 6999 yuan!
格力口罩来了!KN95口罩只要5.5元一个!
浅谈数仓的数据治理
2022/4/8 exam summary
Jumpserver learning
Feed stream application reconfiguration - Architecture
深度剖析 —— 文件操作
51单片机内部外设:实时时钟(SPI)
8000字讲透OBSA原理与应用实践
物联网架构完全指南
已有6名员工确诊!三星第三度关闭龟尾手机工厂!
The purpose of DDD to divide domains, sub domains, core domains, and support domains
Possible causes of index failure