名称 | 自适应哈希索引 |
---|---|
适合使用场景 | 适合使用 = 和 IN 操作符的等值查询 |
不合适场景 | 不适合使用 like 和 % 的范围查询和高并发的joins |
优点 | 提高了Innodb的内存使用率和一些情况下二级索引的查询效率 |
缺点 | 占用Innodb的内存缓存,使用了 lacth 锁保护内存中的hash结构 |
mysql 术语列表中对自适应哈希索引的解释
-
AHI
自适应哈希索引 -
InnoDB 通过在内存中构造哈希索引,对使用
=
和IN
运算符 加速查找的表进行优化。MySQL监视表的索引搜索,如果查询可以从哈希索引中受益,它会自动为经常访问的索引页构建一个。从某种意义上说,MySQL在运行时配置自适应哈希索引以利用充足主内存,更接近主内存数据库的体系结构。InnoDB 此功能由innodb_adaptive_hash_index
配置选项。由于此功能有利于一些工作负载而非所有的工作负载,并且会占用缓冲池中的内存,因此通常您应该使用此功能进行基准测试,无论是启用还是禁用。 -
哈希索引始终基于现有的 InnoDB 二级索引构建 ,该索引被组织为B+树结构。MySQL可以在为B+树定义的任意长度的密钥的前缀上构建哈希索引,具体取决于针对索引的搜索模式。哈希索引可以是部分的; 整个B树索引不需要缓存在缓冲池中。
-
在MySQL 5.6及更高版本中,InnoDB 利用表的快速单值查找的另一种方法是使用InnoDB memcached插件。有关详细信息,请参见 第14.20节“InnoDB memcached插件”。
-
另请参见B+树,缓冲池,哈希索引,memcached,页面,二级索引。
adaptive hash index
An optimization for InnoDB tables that can speed up lookups using = and IN operators, by constructing a hash index in memory. MySQL monitors index searches for InnoDB tables, and if queries could benefit from a hash index, it builds one automatically for index pages that are frequently accessed. In a sense, the adaptive hash index configures MySQL at runtime to take advantage of ample main memory, coming closer to the architecture of main-memory databases. This feature is controlled by the in