14.4.3 Adaptive Hash Index

  • The adaptive hash index (AHI) lets InnoDB perform more like an in-memory database on systems with appropriate combinations of workload and ample memory for the buffer pool, without sacrificing any transactional features or reliability. This feature is enabled by the innodb_adaptive_hash_index option, or turned off by --skip-innodb_adaptive_hash_index at server startup.
  • 自適應哈希索引(AHI)讓InnoDB在系統上執行更像內存數據庫,併爲緩衝池提供適當的工作負載和充足內存組合,而不會犧牲任何事務功能或可靠性,開啓AHI功需要在服務啓動的時候加上innodb_adaptive_hash_index選項,關閉的話加上--skip-innodb_adaptive_hash_index選項
  • Based on the observed pattern of searches, MySQL builds a hash index using a prefix of the index key. The prefix of the key can be any length, and it may be that only some of the values in the B-tree appear in the hash index. Hash indexes are built on demand for those pages of the index that are often accessed.
  • 根據觀察到的搜索模式,mysql使用索引的前綴來創建哈希索引,前綴可以是任意長度,並且可能只有B-tree中的某些值出現在哈希索引中,哈希索引是根據對經常訪問的索引頁的需求構建的。
  • If a table fits almost entirely in main memory, a hash index can speed up queries by enabling direct lookup of any element, turning the index value into a sort of pointer. InnoDB has a mechanism that monitors index searches. If InnoDB notices that queries could benefit from building a hash index, it does so automatically.
  • 如果一張表幾乎完全都在內存中,哈希索引可以通過直接查找元素的方式來加快查詢速度,把索引值轉換成一個排序的指針,innodb有監控索引搜索的機制,如果innodb注意到建立哈希索引可以加快查詢的效率,那麼它就會自動創建
  • With some workloads, the speedup from hash index lookups greatly outweighs the extra work to monitor index lookups and maintain the hash index structure. Sometimes, the read/write lock that guards access to the adaptive hash index can become a source of contention under heavy workloads, such as multiple concurrent joins. Queries with LIKE operators and % wildcards also tend not to benefit from the AHI. For workloads where the adaptive hash index is not needed, turning it off reduces unnecessary performance overhead. Because it is difficult to predict in advance whether this feature is appropriate for a particular system, consider running benchmarks with it both enabled and disabled, using a realistic workload. The architectural changes in MySQL 5.6 and higher make more workloads suitable for disabling the adaptive hash index than in earlier releases, although it is still enabled by default.
  • 在一些負載的情況下,哈希索引的加速查找效益明顯高於監控索引查詢和維護哈希索引結構的花費,有時,對自適應哈希索引進行訪問的讀/寫鎖可能成爲繁重工作負載下的爭用源,,例如併發連接,like操作帶有%匹配符的時候就不能在AHI中獲益,這種情況下自適應哈希索引是不需要的。那麼關閉它可以減少不必要的性能開銷,因爲很難預先預測這個特性是否適合某一特定系統,考慮使用實際的工作負載,在啓用和禁用的情況下運行基準測試。,MySQL 5.6和更高的體系結構更改使更多的工作負載適合於禁用自適應哈希索引,但默認情況下它仍處於啓用狀態。
  • 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.
  • 在MySQL 5.7中,自適應哈希索引搜索系統是分區的。每個索引都綁定到特定分區,每個分區由單獨的鎖存器保護,分區控制是由innodb_adaptive_hash_index_parts這個參數來配置的,在早些的發行版,自適應哈希索引搜索系統受到單個鎖存器的保護,這種鎖存器在繁重的工作負載下可能成爲爭用點,innodb_adaptive_hash_index_parts 選項的默認設置爲8。最大設置是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.
  • 哈希索引總是基於已經存在的B-tree索引的結構上來創建,InnoDB 可以在爲 B-tree定義的鍵的任意長度的前綴上建立一個哈希索引, 具體取決於 InnoDB 觀察到的 B-tree索引的搜索模式。哈希索引可以是部分的, 僅覆蓋經常訪問的索引頁。
  • 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.
  • 你可以監控自定義哈希索引的使用和爭用情況,查看 SHOW ENGINE INNODB STATUS 的輸出裏面的SEMAPHORES片段,如果你看到了和很多線程在等待btr0sea.c的RW-latch,那麼禁止自定義哈希索引可能對你是有好處的
  • For more information about the performance characteristics of hash indexes, see Section 8.3.8, “Comparison of B-Tree and Hash Indexes”.
  • 有關哈希索引的性能特性的更多信息,請看 Section 8.3.8, “Comparison of B-Tree and Hash Indexes”.

PREV:14.4.2 Change Buffer http://blog.51cto.com/itzhoujun/2352530
NEXT:14.4.4 Redo Log Buffer http://blog.51cto.com/itzhoujun/2352551

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章