Innodb关键特性之Adaptive Hash Index
发布时间:2022-03-30 10:59:16 所属栏目:搜索优化 来源:互联网
导读:众所周知,InnoDB使用的索引结构是B+树,但其实它还支持另一种索引:自适应哈希索引。 哈希表是数组+链表的形式。通过哈希函数计算每个节点数据中键所对应的哈希桶位置,如果出现哈希冲突,就使用拉链法来解决。更多内容可以参考 百度百科-哈希表 从以上可
众所周知,InnoDB使用的索引结构是B+树,但其实它还支持另一种索引:自适应哈希索引。 哈希表是数组+链表的形式。通过哈希函数计算每个节点数据中键所对应的哈希桶位置,如果出现哈希冲突,就使用拉链法来解决。更多内容可以参考 百度百科-哈希表 从以上可以知道,哈希表查找最优情况下是查找一次.而InnoDB使用的是B+树,最优情况下的查找次数根据层数决定。因此为了提高查询效率,InnoDB便允许使用自适应哈希来提高性能。 可以通过参数 innodb_adaptive_hash_index 来决定是否开启。阿里云默认是关闭的。 mysql>show variables like '%innodb_adaptive_hash_index%' +----------------------------------+-----------------+ | Variable_name | Value | +----------------------------------+-----------------+ | innodb_adaptive_hash_index | OFF | | innodb_adaptive_hash_index_parts | 8 | +----------------------------------+-----------------+ 存储引擎会自动对个索引页上的查询进行监控,如果能够通过使用自适应哈希索引来提高查询效率,其便会自动创建自适应哈希索引,不需要开发人员或运维人员进行任何设置操作。 自适应哈希索引是对innodb的缓冲池的B+树页进行创建,不是对整张表创建,因此速度很快。 可以通过查看innodb的status来查看自适应哈希索引的使用情况。 INSERT BUFFER AND ADAPTIVE HASH INDEX ------------------------------------- Ibuf: size 1, free list len 6236, seg size 6238, 50367801 merges merged operations: insert 78512159, delete mark 0, delete 0 discarded operations: insert 0, delete mark 0, delete 0 Hash table size 13148407, node heap has 0 buffer(s) Hash table size 13148407, node heap has 0 buffer(s) Hash table size 13148407, node heap has 0 buffer(s) Hash table size 13148407, node heap has 0 buffer(s) Hash table size 13148407, node heap has 0 buffer(s) Hash table size 13148407, node heap has 0 buffer(s) Hash table size 13148407, node heap has 0 buffer(s) Hash table size 13148407, node heap has 0 buffer(s) 0.00 hash searches/s, 67793.48 non-hash searches/s 可以看到自适应哈希索引的大小,以及使用情况。 注意: 从哈希表的特性来看,自适应哈希索引只能用于等值查询,范围或者大小是不允许的。 等值查询: select * from xx where name = "xxx"; (编辑:聊城站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
站长推荐