当前位置:网站首页>[MySQL from introduction to proficiency] [advanced chapter] (IX) precautions for InnoDB's b+ tree index
[MySQL from introduction to proficiency] [advanced chapter] (IX) precautions for InnoDB's b+ tree index
2022-07-28 11:14:00 【Man Nong Feige】
Hello! , I'm Manon Feige , Thank you for reading this article , Welcome to three links with one button .
1. Python Basic column , Basic knowledge in a net ,9.9 Yuan can't buy a loss , I can't buy it . Python From entry to mastery
️ 2. Python Crawler column , Systematically learn the knowledge points of reptiles .9.9 Yuan can't buy a loss , I can't buy it .python Reptile beginner level
️ 3. Ceph actual combat , Everything from principle to actual combat . Ceph actual combat
️ 4. Java Introduction to high concurrency programming , Punch in to learn Java High concurrency . Java Introduction to high concurrency programming
5. Take a stroll around the community , Weekly benefits , There are surprises every week . Manon Feige community , Leap plan
The whole network has the same name 【 Manon Feige 】 Welcome to your attention , personal VX: wei158556
List of articles
1. brief introduction
In the last article, we introduced clustering index , Non clustered index and federated index 【MySQL From entry to mastery 】【 Advanced 】( 8、 ... and ) Cluster index & Nonclustered index & Joint index . We are introducing B+ When indexing trees , First, draw the leaf nodes that store user records , Then draw the inner node that stores the directory records , actually B+ The formation process of trees is not like this .
2. Environmental Science
| Environmental Science | edition |
|---|---|
| Red Hat | 4.8.5-39 |
| MySQL | 5.7 |
3. The location of the root page remains unchanged for ten thousand years
B+ The actual formation process of trees is like this :
- Whenever a table is created B+ Tree index ( Clustered indexes are not artificially created , By default, there is ) When , Will create a... For this index The root node page . When there is no data in the table at first , Every B+ Corresponding to tree index The root node There are no user records in , There are no catalog entry records .
- When a user record is subsequently inserted into the table , First store the user record in this The root node in .
- When available in the root node When space runs out Continue inserting records , All records in the root node will be copied to a newly allocated page , such as page a in , Then the new page is Page splitting The operation of , Get another new page , Not as good as page b. At this time, the newly inserted record is based on the key value ( That is, the primary key value in the cluster index , The value of the corresponding index column in the secondary index ) The size of will be allocated to page a perhaps page b in , and The root node It is upgraded to a page that stores directory item records .
This process pays special attention to : One B+ The root node of the tree index is from the date of birth , It won't move . In this way, as long as we build an index on a table , Then the page number of its root node will be recorded somewhere , And then everything InnoDB When the index engine is used , Will take out the page number of the root node from that fixed place , To access this index .
4. Uniqueness of directory records in internal nodes
We know B+ The contents of the directory entry record in the inner node of the tree index are Index columns + Page number The collocation of , But this collocation is not rigorous for the secondary index , Also take index_demo Table as an example , Suppose the data in this table is like this .
| id | age | name |
|---|---|---|
| 1 | 30 | Zhou |
| 3 | 30 | Wang |
| 5 | 30 | Grandchildren |
| 7 | 30 | Li |
If the contents of the directory entry record in the secondary index are only Index columns + Page number If you match it , So for age Column after indexing B+ Trees should grow like this :
If we want to insert a new line of record , among id,age,name The values of :(9,30, Liu ), Then you are modifying this age The secondary index established by the column corresponds to B+ When I was a tree, I ran into a big problem : because page 3 The directory entry records stored in are created by age Column + Page number The value of , page 3 Corresponding to the two directory entry records in age The values of the columns are 30, And the new record we inserted age The value of the page is also 30, So should our newly inserted record be placed in page 4 in , Or should we put it in page 5 Middle ,
In order that the newly inserted record can find itself on that page , We need to Guaranteed at B+ The directory entry records of nodes in the same layer of the tree are unique except for the page number field . Therefore, the content of the directory entry record of the inner node of the secondary index is actually composed of three parts .
- Value of index column
- Primary key value
- Page number
That is, we add the primary key value to the directory entry records in the nodes in the secondary index , So you can make sure B+ Each directory entry record in each layer node of the tree is unique except for the page number field , So we are for age The diagram after the secondary index of the column should actually look like this :
Then we insert when , Because of the page 3 The directory entry records stored in are created by age Column + Primary key + Page number The value of , You can put the newly recorded age Column The value of and page 3 Of each catalog item record in age Column For comparison , If age Column If the value of is the same , You can then compare the primary key values , because B+ Records of different directory items in the same layer of the tree age Column + Primary key The value of must be different , Therefore, it is certain that the only directory entry record can be located in the end , In this case, it is finally determined that the new record should be inserted into the page 5 in .
5. A page stores at least 2 Bar record
One B+ The tree can easily store hundreds of millions of records with very few levels , The query speed is quite good , This is because B+ A tree is essentially a large multi-level directory , When passing through a directory, many invalid subdirectories will be filtered out , Until you finally access the directory where the real data is stored , What is the effect of storing only one subdirectory in a large directory ? That is, there are many directory levels , And only one record can be stored in the last directory where the real data is stored . It took a long time to store only one real user record , therefore InnoDB A data page can store at least two records .
summary
Necessary for interview InnoDB Of B+ Considerations for tree indexing , The location of the root page remains unchanged for ten thousand years , The directory entry record in the inner node is unique , A page stores at least 2 Bar record .
边栏推荐
- 零代码 | 轻松实现数据仓库建模,搭建BI看板
- 剑指 Offer 06. 从尾到头打印链表
- Remote shutdown of computer with mobile phone
- Make a virtual human with zego avatar | virtual anchor live broadcast solution
- BOM部分属性及理解
- 【MySQL从入门到精通】【高级篇】(十)MyISAM的索引方案&&索引的优缺点
- 盘点:令人心动的数据可视化图表
- Use the statement object to execute DDL statements to create tables
- 蓝桥杯嵌入式-HAL库-USART_TX
- Three ways for Cortex-M kernel to manage global interrupts
猜你喜欢

剑指 Offer 35. 复杂链表的复制

Blue Bridge Cup embedded Hal library USART_ RX

技术分享| 快对讲综合调度系统

低代码十问:一文讲透关于低代码的一切!

盘点:144个免费学习网站,全网最全资源合集

Generation and use of Lib library files in keil and IAR

Here is a super practical excel shortcut set (common + summary of eight categories)

Do data analysis, do you still not understand RFM analysis method (model)?

这里有一份超实用Excel快捷键合集(常用+八大类汇总)

【MySQL从入门到精通】【高级篇】(九)InnoDB的B+树索引的注意事项
随机推荐
Blue Bridge Cup embedded Hal library systick
RHEL 6.4 安装svn和apache
Learn how to do e-commerce data analysis (with operation analysis index framework)
Jianzhi offer 09. realize queue with two stacks
C language to convert float data into BCD data
Zero code | easily realize data warehouse modeling and build Bi Kanban
offsetof宏与container_of宏分析详解
A solution to the problem that ThinkPad fingerprint verification cannot be used in win7
ctf技能树----文件上传
leetcode:981. 基于时间的键值存储【迭代for的陷阱:on】
内存操作函数memcpy()和memmove()的用法
The 10th Landbridge cup embedded electronic provincial competition
【MySQL从入门到精通】【高级篇】(九)InnoDB的B+树索引的注意事项
学会使用MySQL的Explain执行计划,SQL性能调优从此不再困难
Judge whether the nixie tube is a common anode or a common cathode
JSON preliminary understanding
Arduino Basics
为什么传输前要进行编码与调制
1. Sum of two numbers
Why should coding and modulation be carried out before transmission