mysql innodb索引高度

来源:这里教程网 时间:2026-03-01 15:14:45 作者:

首先获取表上的索引情况

mysql> 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='ming/test02';

+-------------+---------------+----------+------+-------+---------+

| name        | name          | index_id | type | space | PAGE_NO |

+-------------+---------------+----------+------+-------+---------+

| ming/test02 | PRIMARY       |       71 |    3 |    44 |       3 |

| ming/test02 | idx_test02_c2 |      400 |    0 |    44 |      39 |

+-------------+---------------+----------+------+-------+---------+

2 rows in set (0.85 sec)

type:

0 是非唯一二级索引。

3是聚簇索引。

1是automatically generated clustered index ( GEN_CLUST_INDEX );

2是unique nonclustered index;唯一的非聚簇索引

32是全文索引。

查询innodb页的大小

mysql> show global variables like 'innodb_page_size';

+------------------+-------+

| Variable_name    | Value |

+------------------+-------+

| innodb_page_size | 16384 |

+------------------+-------+

1 row in set (0.67 sec)

接下来要用到操作系统命令hexdump,以十六进制查看文件

语法

hexdump [选项] [文件]...

选项

-n length 只格式化输入文件的前length个字节。

-C 输出规范的十六进制和ASCII码。

-b 单字节八进制显示。

-c 单字节字符显示。

-d 双字节十进制显示。

-o 双字节八进制显示。

-x 双字节十六进制显示。

-s 从偏移量开始输出。

-e 指定格式字符串,格式字符串包含在一对单引号中,格式字符串形如:'a/b "format1" "format2"'。

查看索引高度

[root@mdb01 ming]# hexdump -s 49216 -n 10  ./test02.ibd

000c040 0200 0000 0000 0000 4700               

000c04a

[root@mdb01 ming]# hexdump -s 639040 -n 10  ./test02.ibd     

009c040 0200 0000 0000 0000 9001               

009c04a

指定的偏移量的计算公式是page_no * innodb_page_size + 64。

49216 = 3 * 16384 +64.

PAGE_LEVEL 的值为 0200,表示这棵二级索引树的高度为 3(2+1)。

后面的4700和9001是索引的index_id。

操作系统上十六进制转十进制:

[root@mdb01 ming]# echo $((0x47))  

71

[root@mdb01 ming]# echo $((0x0190))

400

9001的读取顺序,应该是按照 两位为一组,倒着读 ,那么也就是01 90

相关推荐