MySql 自适应哈希索引
一、介紹
哈希(hash)是一種非常快的查找方法,一般情況下查找的時間復雜度為O(1)。常用于連接(join)操作,如Oracle中的哈希連接(hash join)。
InnoDB存儲引擎會監控對表上索引的查找,如果觀察到建立哈希索引可以帶來速度的提升,則建立哈希索引,所以稱之為自適應(adaptive)的。
自適應哈希索引通過緩沖池的B+樹構造而來,因此建立的速度很快。而且不需要將整個表都建哈希索引,InnoDB存儲引擎會自動根據訪問的頻率
和模式來為某些頁建立哈希索引。
?
二、示例
三、限制
1.只能用于等值比較,例如=, <=>,in
2.無法用于排序
3.有沖突可能
4.Mysql自動管理,人為無法干預。
?
四、通過SHOW ENGINE INNODB STATUS 查看自適應哈希索引的使用情況
?
In MySQL 5.7, the adaptive hash index search system is partitioned. Each index is bound to a specific partition, and each partition is protected by a separate latch.
Partitioning is controlled by the?innodb_adaptive_hash_index_parts?configuration option. In earlier releases, the adaptive hash index search system was
protected by a single latch which could become a point of contention under heavy workloads. The?innodb_adaptive_hash_index_parts?option is set to 8 by default.
The maximum setting is 512.
The hash index is always built based on an existing?B-tree?index on the table.?InnoDB?can build a hash index on a prefix of any length of the key defined for the B-tree,
depending on the pattern of searches that?InnoDB?observes for the B-tree index. A hash index can be partial, covering only those pages of the index that are often accessed.
You can monitor the use of the adaptive hash index and the contention for its use in the?SEMAPHORES?section of the output of the?SHOW ENGINE INNODB STATUS?
command. If you see many threads waiting on an RW-latch created in?btr0sea.c, then it might be useful to disable adaptive hash indexing.
?
------------------------------------- INSERT BUFFER AND ADAPTIVE HASH INDEX ------------------------------------- Ibuf: size 1, free list len 0, seg size 2, 94 merges merged operations:insert 280, delete mark 0, delete 0 discarded operations:insert 0, delete mark 0, delete 0 Hash table size 4425293, node heap has 1337 buffer(s) 174.24 hash searches/s, 169.49 non-hash searches/s哈希索引只能用來搜索等值的查詢,對于其他查找類型,如范圍查找,是不能使用哈希索引的,因此這里出現no--hash searches的情況。
通過hash searches:non-hash searches可以大概了解使用哈希索引后的效率
?
?
參考
mysql reference : adaptive hash index?
?同類文章:
mysql 索引
來源:https://www.cnblogs.com/yuyutianxia/p/3841657.html
總結
以上是生活随笔為你收集整理的MySql 自适应哈希索引的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MySQL(七):InnoDB 自适应H
- 下一篇: MySQL中的自适应哈希索引