MYSQL INNODB 组合索引分支节点数据解析:
1、本文证明组合索引的所有键值在分支节点(非叶子结点也进行了存储)。
2、本文给出B+ 索引如何进行验证其B+树结构
脚本:
mysql> create table testzh(id int primary key auto_increment ,id2 int,id3 int,name varchar(20), key(id2,id3));
Query OK, 0 rows affected (0.07 sec)
delimiter //
create procedure ins()
begin
declare i int;
set i=0;
while i<100000 do
insert into testzh(id2,id3,name) values(FLOOR((RAND()*100000)),FLOOR((RAND()*100000)),'gaopeng');
set i=i+1;
end while;
end;
//
delimiter ;
写一个程序 主要读取下面几位每个块的:
64-66字节:B+层次,0是叶子结点,向上分别是1,2.... 如果是三层结构的则根结点为层次为2,分支为1,叶子结点为0
66-74字节:索引ID,对应INNODB_SYS_INDEXES 的INDEX_ID字段
24-26字节:块类型,我们主要查看0X45BF的类型是数据类型
这就是我161索引key(id2,id3)全部块,
这里我们看到我们的这个组合索引是 2层的 B+树结构
Block id is 4:Index page no is 161 : B+ Tree Level is 1
这个块就是根结点,那么我们需要读取它需要用到我写过的另外一个小程序
,用于读取其数据,但是这个程序写死了读取2个INT类型数据如下,按照顺序给出
这里B代表是ID1的值,A代表是ID2的值,那么这里我们
证明了在B+数的分支节点存储了组合索引的全部键值,
这里存储的是在叶子结点中物理位置的开始值
随便查询一下:
mysql> select * from testzh where id2=23;
+-------+------+-------+---------+
| id | id2 | id3 | name |
+-------+------+-------+---------+
| 99428 | 23 | 9079 | gaopeng |
| 378 | 23 | 59613 | gaopeng |
| 90301 | 23 | 93864 | gaopeng |
+-------+------+-------+---------+
3 rows in set (0.00 sec)
mysql> select * from testzh where id2=736;
+-------+------+-------+---------+
| id | id2 | id3 | name |
+-------+------+-------+---------+
| 2716 | 736 | 31951 | gaopeng |
| 95328 | 736 | 53286 | gaopeng |
| 75440 | 736 | 85983 | gaopeng |
+-------+------+-------+---------+
3 rows in set (0.00 sec)
mysql> select * from testzh where id2=1591;
+-------+------+-------+---------+
| id | id2 | id3 | name |
+-------+------+-------+---------+
| 10056 | 1591 | 58218 | gaopeng |
+-------+------+-------+---------+
可以看到这些值都是有的。
(编辑:好传媒网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|