MySQL技术内幕InnoDB存储引擎 - 关键特性 - 自适应哈希索引(AHI)
自适应哈希索引(AHI - Adaptive Hash Index)
AHI有什么用处
InnoDB的索引一般是B+树的。加载到buffer pool中索引页自然也是B+树结构的。
B+树结构找数据我们都知道和树高有直接关系,一般情况下树高3~4层,所以查询也需要3~4次。
如果某些数据访问频率高且访问模式符合一些要求的话,并且InnoDB判断如果使用哈希索引能提高效率的话,
InnoDB会根据这些数据在buffer中的B+树结构的索引页(并非整个表的索引)临时构造出哈希索引,
这样通过哈希索引只用一次查询就能找到需要的数据。
AHI的要求
AHI对访问频率和访问模式有一些要求:



AHI信息查看
通过 SHOW ENGINE INNODB STATUS 我们可以查看AHI的信息:
Hash table size 34679, node heap has 1 buffer(s) Hash table size 34679, node heap has 5 buffer(s) Hash table size 34679, node heap has 8 buffer(s) Hash table size 34679, node heap has 2 buffer(s) Hash table size 34679, node heap has 2 buffer(s) Hash table size 34679, node heap has 5 buffer(s) Hash table size 34679, node heap has 1 buffer(s) Hash table size 34679, node heap has 1 buffer(s) 4.25 hash searches/s, 6.48 non-hash searches/s

通过 innodb_adaptive_hash_index 可以设置是否启动 AHI:
show VARIABLES like 'innodb_adaptive_hash_index' innodb_adaptive_hash_index ON
浙公网安备 33010602011771号