MySQL InnoDB Engine--自適應雜湊索引總結
阿新 • • 發佈:2021-07-10
功能特性
在MySQL中,對雜湊索引的訪問僅需要一次HASH計算即可定位到目標位置,而對B樹索引的訪問需要依次訪問根節點>中間節點>葉子節點。 為優化B樹索引需要訪問多個"非葉子節點頁"才能定位到"葉子節點頁"的問題,InnoDB儲存引擎通過雜湊索引來幫助查詢快速找到"目標葉子節點頁"以提高查詢效能。 InnoDB儲存引擎通過監控表上索引頁的查詢模式,自動根據查詢模式對"熱點資料"來建立雜湊索引,因此被成為自適應雜湊索引。 自適應雜湊索引使用Buffer pool中的資料頁進行構造,僅儲存在記憶體中,不會持久化到磁碟上,且僅對熱點資料進行處理,因此構造自適應雜湊索引速度極快。 自適應雜湊索引不會對同一資料頁中所有記錄進行索引,而是根據訪問模式決定對相同鍵值的記錄進行如何索引,如對"大於等於"和"小於等於"兩種模式採用不同方式。 InnoDB儲存引擎僅支援B樹索引,不支援雜湊索引和全文索引。 可以通過SHOW ENGINE INNODB STATUS命令來檢視當前例項上自適應雜湊索引的使用情況,如------------------------------------- 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 796967, node heap has 0 buffer(s) Hash table size 796967, node heap has 0 buffer(s) Hash table size796967, node heap has 343 buffer(s) Hash table size 796967, node heap has 0 buffer(s) Hash table size 796967, node heap has 0 buffer(s) Hash table size 796967, node heap has 2 buffer(s) Hash table size 796967, node heap has 1 buffer(s) Hash table size 796967, node heap has 3 buffer(s) 0.00 hash searches/s, 0.00non-hash searches/s
PS1: SHOW ENGINE INNODB STATUS命令用來展示儲存引擎一段時間的狀態資料,而非當前資料。
PS2: hash searches和non-hash searches可能不準,在相同訪問頻率下,其值從幾十暴漲至幾十萬。