查看表中指定索引的高度:
索引层数的表示法:
索引中每个页的结构图:
page Header中有个page level的值,这个值保存这个B+树的高度值,由于B+树从0开始算,所以B+树的高度=page level的值再加1
由于B+树中是从root页开始查找数据,而root页中的page header中的page level中存储这颗B+树的高度值,所以下面需要查找到指定索引的root页的page_no
查找索引树中的root页的位置:
查看指定表索引对应的 space 和root页的page_no
select b.name,a.name,index_id,type,a.space,a.page_no from information_schema.innodb_sys_indexes a, information_schema.innodb_sys_tables b where a.table_id=b.table_id and a.space<>0 and b.name like 'employees/%';
+--------------------------------+------------+----------+------+-------+---------+
| name | name | index_id | type | space | page_no |
+--------------------------------+------------+----------+------+-------+---------+
| employees/departments | PRIMARY | 59 | 3 | 35 | 3 |
| employees/departments | dept_name | 60 | 2 | 35 | 4 |
| employees/dept_emp | PRIMARY | 64 | 3 | 37 | 3 |
| employees/dept_emp | emp_no | 65 | 0 | 37 | 4 |
| employees/dept_emp | dept_no | 66 | 0 | 37 | 5 |
| employees/dept_manager | PRIMARY | 61 | 3 | 36 | 3 |
| employees/dept_manager | emp_no | 62 | 0 | 36 | 4 |
| employees/dept_manager | dept_no | 63 | 0 | 36 | 5 |
| employees/employees | PRIMARY | 125 | 3 | 83 | 3 |
| employees/employees_cmp | PRIMARY | 136 | 3 | 110 | 3 |
| employees/employees_compress | PRIMARY | 134 | 3 | 108 | 3 |
| employees/employees_compress_1 | PRIMARY | 141 | 3 | 125 | 3 |
| employees/salaries | PRIMARY | 69 | 3 | 39 | 3 |
| employees/salaries | emp_no | 70 | 0 | 39 | 4 |
| employees/salaries | idx_salary | 142 | 0 | 39 | 143 |
| employees/titles | PRIMARY | 67 | 3 | 38 | 3 |
| employees/titles | emp_no | 68 | 0 | 38 | 4 |
+--------------------------------+------------+----------+------+-------+---------+
以上显示employees库中的表departments中的PRIMARY索引的space=35 page_no=3,page_no表示这个索引对应的root页号
通过hexdump工具来查看索引高度
[root@node232 ~]# hexdump --help
hexdump:无效选项 -- -
hexdump: [-bcCdovx] [-e fmt] [-f fmt_file] [-n length] [-s skip] [file ...]
参数:
-s:从偏移量多少开始
-n:读取多少个字节
hexdump -s 16384*3+64 -n 2
16384*3表示从第3个页开始位置开始读
64表示:每个页中64bytes的位置存储的就是page level的值
[root@node232 employees]# hexdump -s 49216 -n 2 -C /usr/local/mysql/data/employees/departments.ibd
0000c040 00 00 |..|
0000c042
其中:00 00 表示索引高度只有一层,因为没有数据
查看表departments数据量:
(root@DB)[employees]> select count(*) from departments;
+----------+
| count(*) |
+----------+
| 9 |
+----------+
1 row in set (0.04 sec)
[root@node232 employees]# hexdump -s 49216 -n 2 -C /usr/local/mysql/data/employees/employees.ibd
0000c040 00 01 |..|
0000c042
其中:00 01 表示索引高度只有两层
查看表employees的数据量:
(root@DB)[employees]> select count(*) from employees;
+----------+
| count(*) |
+----------+
| 300024 |
+----------+
1 row in set (0.77 sec)
2020-07-28
MySQL查看表中指定索引的高度
评论
发表评论
姓 名: