MySQL(七):InnoDB 自适应Hash索引(Adaptive Hash Index)
文章目錄
-
- 1、簡述
- 2、AHI(Adaptive Hash index)創建條件及注意事項
- 3、AHI(Adaptive Hash index)監控
-
- 3.1、通過 *show engine innodb status* 命令查看AHI狀態
- 3.2、通過 information_schema.innodb_metrics 來監控AHI運行狀態
- 4、參考文獻
?
1、簡述
哈希(hash)查找非常快,一般情況下時間復雜度為 O(1),一般僅需要一次查找就能定位。而 B+ 樹的查找次數,取決于 B+ 樹的高度,B+ 樹的高度一般為 34層,因此便需要查詢34次。
InnoDB 存儲引擎通過觀察表上索引頁的查詢,如果發現建立哈希索引可以提升查詢效率,則會自動建立哈希索引,稱之為自適應哈希索引(Adaptive Hash Index)。
AHI 是基于緩沖池的B+樹構造的索引,因此速度非常快,而且不需要對整張表建立索引。InnoDB 存儲引擎會自動根據訪問的頻率和模式來自動為某些熱點頁建立哈希索引。
考慮到不同系統的差異,有些系統開啟自適應哈希索引可能會導致性能提升不明顯,而且為監控索引頁查詢次數增加了多余的性能損耗, MySQL5.7 更改了 AHI 實現機制,每個 AHI 都分配了特定分區,每個索引都綁定到特定分區,并且每個分區均受單獨的鎖存器保護。分區由 innodb_adaptive_hash_index_parts 變量控制。默認情況下,innodb_adaptive_hash_index_parts 變量值為8,最大值為 512。
自適應哈希索引功能由 innodb_adaptive_hash_index 變量啟用,或者在服務器啟動時由–skip-innodb-adaptive-hash-index關閉。
mysql> show variables like "innodb_adaptive_hash_index"; +----------------------------+-------+ | Variable_name | Value | +----------------------------+-------+ | innodb_adaptive_hash_index | ON | +----------------------------+-------+- 1
- 2
- 3
- 4
- 5
- 6
2、AHI(Adaptive Hash index)創建條件及注意事項
1、重復訪問某一特定查詢模式達到一定數量才會創建,如WHERE a = XXX,WHERE a = xxx and b = xxx。
2、AHI 只支持等值查詢=和IN,不支持LIKE, REGEXP等。
3、AHI 存在內存中,占用緩沖池資源(Buffer Pool)。
4、AHI 無法人為干預,只能配置開關:set global innodb_adaptive_hash_index=off/on。
3、AHI(Adaptive Hash index)監控
3.1、通過?show engine innodb status?命令查看AHI狀態
------------------------------------- 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 1 buffer(s) Hash table size 34679, node heap has 3 buffer(s) 0.00 hash searches/s, 0.00 non-hash searches/s- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
3.2、通過 information_schema.innodb_metrics 來監控AHI運行狀態
該表搜集了AHI 查詢次數,更新次數等信息,可以很好的監控其運行狀態,在某些負載下,AHI并不適合打開,關閉AHI可以避免額外的維護開銷。
mysql> set global innodb_monitor_enable = module_adaptive_hash; Query OK, 0 rows affected (0.00 sec)mysql> SELECT STATUS, NAME, subsystem FROM information_schema.INNODB_METRICS WHERE subsystem LIKE '%adaptive_hash%'; +---------+------------------------------------------+---------------------+ | STATUS | NAME | subsystem | +---------+------------------------------------------+---------------------+ | enabled | adaptive_hash_searches | adaptive_hash_index | | enabled | adaptive_hash_searches_btree | adaptive_hash_index | | enabled | adaptive_hash_pages_added | adaptive_hash_index | | enabled | adaptive_hash_pages_removed | adaptive_hash_index | | enabled | adaptive_hash_rows_added | adaptive_hash_index | | enabled | adaptive_hash_rows_removed | adaptive_hash_index | | enabled | adaptive_hash_rows_deleted_no_hash_entry | adaptive_hash_index | | enabled | adaptive_hash_rows_updated | adaptive_hash_index | +---------+------------------------------------------+---------------------+ 8 rows in set (0.00 sec)- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
4、參考文獻
來源:https://blog.csdn.net/u010647035/article/details/104729686
總結
以上是生活随笔為你收集整理的MySQL(七):InnoDB 自适应Hash索引(Adaptive Hash Index)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 不属于系统软件的是什么程序(不属于系统软
- 下一篇: MySql 自适应哈希索引