標籤:mysql dba b+tree
1. 背景
* 在InnoDB儲存引擎中,表都是根據主鍵順序組織存放的,這種儲存方式的表稱為索引組織表(index organized table IOT)。
* 在InnoDB儲存引擎中,每張表都有個主鍵(Primary key),如果在建立表時沒有地定義主鍵,則InnoDB儲存引擎會選擇表中合格列或隱式建立主鍵。
650) this.width=650;" src="https://s3.51cto.com/wyfs02/M02/9C/62/wKioL1lv2t6QpmC3AADQufUXL7Q958.png" title="iot.png" alt="wKioL1lv2t6QpmC3AADQufUXL7Q958.png" />
2. 環境
mysql> select version();+------------+| version() |+------------+| 5.6.36-log |+------------+1 row in set (0.02 sec)mysql> select database();+------------+| database() |+------------+| mytest |+------------+1 row in set (0.00 sec)mysql> show tables;+------------------+| Tables_in_mytest |+------------------+| customer || district || history || item || new_orders || order_line || orders || stock || warehouse |+------------------+9 rows in set (0.00 sec)mysql> show variables like ‘innodb_page_size‘;+------------------+-------+| Variable_name | Value |+------------------+-------+| innodb_page_size | 8192 |+------------------+-------+1 row in set (0.04 sec)
3. 查詢
* 查詢每張表primary key對應的root page_no
mysql> select t.table_id table_id, t.name table_name, i.page_no root_page_no from information_schema.INNODB_SYS_INDEXES i, information_schema.INNODB_SYS_TABLES t where i.table_id = t.table_id and i.name = ‘PRIMARY‘ and t.name like ‘mytest/%‘;+----------+-------------------+--------------+| table_id | table_name | root_page_no |+----------+-------------------+--------------+| 22 | mytest/customer | 3 || 21 | mytest/district | 3 || 27 | mytest/item | 3 || 24 | mytest/new_orders | 3 || 26 | mytest/order_line | 3 || 25 | mytest/orders | 3 || 28 | mytest/stock | 3 || 20 | mytest/warehouse | 3 |+----------+-------------------+--------------+8 rows in set (0.04 sec)
* 查詢order_line表資料量
mysql> select count(1) from order_line;+----------+| count(1) |+----------+| 6001615 |+----------+1 row in set (9.03 sec)
* 通過表資料檔案order_line.ibd擷取高度 [跳過 root_page_no * innodb_page_size + 64, 擷取2位元組長度就是樹的高度]
由此可得樹的高度為3, 高度標記從0開始
[[email protected] src]# hexdump -s 24640 -n 2 -C /data/mysql_data_6/mytest/order_line.ibd;00006040 00 02 |..|00006042
4. B+Tree
高度 |
非分葉節點數 |
分葉節點數 |
資料行數 |
佔用空間 |
1 |
0 |
1 |
468 |
16.0KiB |
2 |
1 |
1203 |
> 563 thousand |
18.8MiB |
3 |
1204 |
1447209 |
> 677 million |
22.1GiB |
4 |
1448413 |
1740992427 |
> 814 billion |
25.9TiB |
5. xxx
本文出自 “sea” 部落格,請務必保留此出處http://lisea.blog.51cto.com/5491873/1949144
InnoDB--------查詢IOT B+ Tree的高度