美文网首页
MySQL-Innodb数据组织-B+Tree

MySQL-Innodb数据组织-B+Tree

作者: 多血 | 来源:发表于2019-12-25 15:07 被阅读0次

概念

一个Index就是一个B+Tree。
方方面面看:https://www.slideshare.net/ovaistariq/pluk2011-btreeindexesandinnodb

Root Page

An index tree starts at a “root” page, whose location is fixed (and permanently stored in the InnoDB’s data dictionary) as a starting point for accessing the tree. The tree may be as small as the single root page, or as large as many millions of pages in a multi-level tree.

Since the root page is allocated when the index is first created, and that page number is stored in the data dictionary, the root page can never relocated or removed. Once the root page fills up, it will need to be split, forming a small tree of a root page plus two leaf pages.

However, the root page itself can’t actually be split, since it cannot be relocated. Instead, a new, empty page is allocated, the records in the root are moved there (the root is “raised” a level), and that new page is split into two. The root page then does not need to be split again until the level immediately below it has enough pages that the root becomes full of child page pointers (called “node pointers”), which in practice often means several hundred to more than a thousand.

Leaf Page Non-Leaf Page

Pages are referred to as being “leaf” pages or “non-leaf” pages (also called “internal” or “node” pages in some contexts). Leaf pages contain actual row data. Non-leaf pages contain only pointers to other non-leaf pages, or to leaf pages. The tree is balanced, so all branches of the tree have the same depth.

Level

InnoDB assigns each page in the tree a “level”: leaf pages are assigned level 0, and the level increments going up the tree. The root page level is based on the depth of the tree. All pages that are neither leaf pages nor the root page can also be called “internal” pages, if a distinction is important.

示例

image.png

数据词典

FSP_DICT_HDR_PAGE_NO ibdata的第8个page,用来存储数据词典表的信息 (只有拿到数据词典表,才能根据其中存储的表信息,进一步找到其对应的表空间,以及表的聚集索引所在的page no)。
Dict_Hdr Page的结构如下表所示:

image.png
数据词典以及加载
https://blog.51cto.com/yanzongshuai/2095128
https://blog.51cto.com/yanzongshuai/2095186

dict_table_t
----dict_index_t
--------unsigned space:32; /*!< space where the index tree is placed /
--------unsigned page:32;/
!< index tree root page number */

获取到Root Page,就能遍历整个Index了。
Root Page的格式和普通页格式一样,参见上面示例。

Non-Leaf节点的数据格式:
<Key, Pointer>
http://zhongmingmao.me/2017/05/12/innodb-btree-index/第一个例子为例

image.png
image.png
80 00 00 0a 表示10(最高位为符号位) 00 00 00 04表示Page 4
80 00 00 1e 表示30(最高位为符号位) 00 00 00 05表示Page 5

Page merge与Split

https://www.percona.com/blog/2017/04/10/innodb-page-merging-and-page-splitting/
http://zhongmingmao.me/2017/05/12/innodb-btree-index/
https://mp.weixin.qq.com/s/8vHSKjLUbBh1vxNqlrbwDQ

https://www.slideshare.net/ovaistariq/pluk2011-btreeindexesandinnodb
https://blog.jcole.us/2013/01/10/btree-index-structures-in-innodb/
http://mysql.taobao.org/monthly/2016/02/01/

相关文章

  • MySQL-Innodb数据组织-B+Tree

    概念 一个Index就是一个B+Tree。方方面面看:https://www.slideshare.net/ova...

  • b+tree数据结构、limit、order by、 group

    b+tree数据结构、limit、order by、 group by、where 分析思路: 从b+tree索引...

  • InnoDB 索引实现

    总述: 表数据文件本身就是按照B+Tree组织的一个索引结构文件 聚集索引-叶节点包含了完整的数据记录 InnoD...

  • InnoDB

    MySQL-InnoDB 架构 CheckPoint 已经被flush到页上的LSN。 刷盘策略 缩短数据库恢复时...

  • 索引失效

    引言 在一个列或多个列上建立索引,其本质是为这些列上的数据组织成平衡二叉树(B+Tree)之后,将基于全表扫描的时...

  • mysql索引

    mysql 不同引擎索引组织方式不同 MyISAM存储引擎,MyISAM引擎使用B+Tree作为索引结构,叶节点的...

  • 索引的原理

    目前大部分数据库系统及文件系统都采用B-Tree(B树)或其变种B+Tree(B+树)作为索引结构。B+Tree是...

  • MySQL听讲(五)——引擎

    MySQL常用的引擎有MyISAM,InnoDB,Memory。 MyISAM 底层数据结构:B+Tree。支持锁...

  • 索引常用说法的理解

    索引列的数据长度能少则少 数据长度越大-->一个数据块存放的节点越少-->b+tree的路数越少-->深度越高--...

  • 数据密集型应用系统设计

    数据密集型应用系统设计 1:索引是B+tree 非叶子节点不存储数据,叶子节点存储数据,并且节点内是顺序链表 2:...

网友评论

      本文标题:MySQL-Innodb数据组织-B+Tree

      本文链接:https://www.haomeiwen.com/subject/mgtcoctx.html