衆所周知,InnoDB使用的索引結構是B+樹,但其實它還支持另外一種索引:自適應哈希索引。node
哈希表是數組+鏈表的形式。經過哈希函數計算每一個節點數據中鍵所對應的哈希桶位置,若是出現哈希衝突,就使用拉鍊法來解決。更多內容能夠參考 百度百科-哈希表mysql
從以上能夠知道,哈希表查找最優狀況下是查找一次.而InnoDB使用的是B+樹,最優狀況下的查找次數根據層數決定。所以爲了提升查詢效率,InnoDB便容許使用自適應哈希來提升性能。sql
能夠經過參數 innodb_adaptive_hash_index 來決定是否開啓。默認是打開的。數組
mysql> show variables like "innodb_adaptive_hash_index"; +----------------------------+-------+ | Variable_name | Value | +----------------------------+-------+ | innodb_adaptive_hash_index | ON | +----------------------------+-------+
存儲引擎會自動對個索引頁上的查詢進行監控,若是可以經過使用自適應哈希索引來提升查詢效率,其便會自動建立自適應哈希索引,不須要開發人員或運維人員進行任何設置操做。運維
自適應哈希索引是對innodb的緩衝池的B+樹頁進行建立,不是對整張表建立,所以速度很快。函數
能夠經過查看innodb的status來查看自適應哈希索引的使用狀況。性能
mysql> show engine innodb status \G *************************** 1. row *************************** Type: InnoDB Name: Status: ===================================== 2019-03-07 23:37:23 0x7f1f2d34c700 INNODB MONITOR OUTPUT ===================================== Per second averages calculated from the last 6 seconds ------------------------------------------------------ INSERT BUFFER AND ADAPTIVE HASH INDEX ------------------------------------- Ibuf: size 1, free list len 0, seg size 2, 0 merges merged operations: insert 0, delete mark 0, delete 0 discarded operations: insert 0, delete mark 0, delete 0 Hash table size 34679, node heap has 0 buffer(s) Hash table size 34679, node heap has 0 buffer(s) Hash table size 34679, node heap has 0 buffer(s) Hash table size 34679, node heap has 0 buffer(s) Hash table size 34679, node heap has 0 buffer(s) Hash table size 34679, node heap has 0 buffer(s) Hash table size 34679, node heap has 0 buffer(s) Hash table size 34679, node heap has 0 buffer(s) 0.00 hash searches/s, 0.00 non-hash searches/s ------------------------------- END OF INNODB MONITOR OUTPUT ============================
能夠看到自適應哈希索引大小,每秒的使用狀況。spa
注意從哈希表的特性來看,自適應哈希索引只能用於等值查詢,範圍或者大小是不容許的。code
等着查詢: select * from xx where name = "xxx";blog