14.4.2 Change Buffer

The change buffer is a special data structure that caches changes to secondary index pages when affected pages are not in the buffer pool. The buffered changes, which may result from INSERT, UPDATE, or DELETE operations (DML), are merged later when the pages are loaded into the buffer pool by other read operations.
change buffer是一種特殊的數據結構,當受影響的頁不在緩衝池中時,會對輔助索引頁的更改進行緩存。這 buffered changes 是由insert,update,delete等操作導致的,當頁面被其他讀操作加載到緩衝池中時會進行合併。
Unlike clustered indexes, secondary indexes are usually non-unique, and inserts into secondary indexes happen in a relatively random order. Similarly, deletes and updates may affect secondary index pages that are not adjacently located in an index tree. Merging cached changes at a later time, when affected pages are read into the buffer pool by other operations, avoids substantial random access I/O that would be required to read-in secondary index pages from disk.
與聚集索引不同, 輔助索引通常是非唯一的, 並且插入輔助索引的順序相對隨機。同樣,刪除和更新可能會影響不在索引樹中相鄰的輔助索引頁,當受影響的頁被其他操作讀取到緩衝池中時,在稍後的時間內合併緩存的更改,可以避免從磁盤讀取輔助索引頁所需的大量隨機訪問 I/O。
Periodically, the purge operation that runs when the system is mostly idle, or during a slow shutdown, writes the updated index pages to disk. The purge operation can write disk blocks for a series of index values more efficiently than if each value were written to disk immediately.
定期地,當系統基本處於空閒狀態或緩慢關閉期間運行的purge操作會將更新後的索引頁寫入磁盤。,與每個值立即寫入磁盤相比,purge操作可以更有效地爲一系列索引值寫入磁盤塊。
Change buffer merging may take several hours when there are numerous secondary indexes to update and many affected rows. During this time, disk I/O is increased, which can cause a significant slowdown for disk-bound queries. Change buffer merging may also continue to occur after a transaction is committed. In fact, change buffer merging may continue to occur after a server shutdown and restart (see Section 14.21.2, “Forcing InnoDB Recovery” for more information).
當需要更新許多二級索引和許多受影響的行時,change buffer合併可能需要幾個小時。在此期間,磁盤I/O會遞增這可能會導致磁盤綁定的查詢顯着減慢。在提交事務後, change buffer合併也可能繼續發生。事實上, 在服務器關閉並重新啓動後(更多信息請看Section 14.21.2, “Forcing InnoDB Recovery” ), change buffer合併可能會繼續發生
In memory, the change buffer occupies part of the InnoDB buffer pool. On disk, the change buffer is part of the system tablespace, so that index changes remain buffered across database restarts.
在內存中,change buffer佔用InnoDB緩衝池的一部分。在磁盤上,change buffer是系統表空間的一部分。因此,索引更改在數據庫重新啓動期間仍然保持緩衝狀態
The type of data cached in the change buffer is governed by the innodb_change_buffering configuration option. For more information, see Section 14.6.5, “Configuring InnoDB Change Buffering”. You can also configure the maximum change buffer size. For more information, see Section 14.6.5.1, “Configuring the Change Buffer Maximum Size”.
更改緩衝區中緩存的數據類型受 innodb_change_buffering配置參數的影響,更多信息,請看 Section 14.6.5, “Configuring InnoDB Change Buffering”.您還可以配置最大change buffer大小,更多信息請看 Section 14.6.5.1, “Configuring the Change Buffer Maximum Size”.

Monitoring the Change Buffer

The following options are available for change buffer monitoring:
以下選項可用於監控 change buffer:

  • InnoDB Standard Monitor output includes status information for the change buffer. To view monitor data, issue the SHOW ENGINE INNODB STATUS command.
  • InnoDB標準監視器輸出包括改變緩衝區狀態信息。查看監視器數據,請發出SHOW ENGINE INNODB STATUS命令
    mysql> SHOW ENGINE INNODB STATUS\G
    Change buffer status information is located under the INSERT BUFFER AND ADAPTIVE HASH INDEX heading and appears similar to the following:
    Change buffer狀態信息位於INSERT BUFFER AND ADAPTIVE HASH INDEX下面,並顯示如下所示:

            -------------------------------------
            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 4425293, used cells 32, node heap has 1 buffer(s)
            13577.57 hash searches/s, 202.47 non-hash searches/s
            13578.

    For more information, see Section 14.17.3, “InnoDB Standard Monitor and Lock Monitor Output”.
    更多信息請看Section 14.17.3, “InnoDB Standard Monitor and Lock Monitor Output”.

  • The INFORMATION_SCHEMA.INNODB_METRICS table provides most of the data points found in InnoDB Standard Monitor output, plus other data points. To view change buffer metrics and a description of each, issue the following query:
  • INFORMATION_SCHEMA.INNODB_METRICS 表提供了在InnoDB標準監視器輸出的大部分數據點和加上其他數據點。要查看change buffer的度量值和每個說明, 請發出以下查詢:
    mysql> SELECT NAME, COMMENT FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME LIKE '%ibuf%'\G
    • For INNODB_METRICS table usage information, see Section 14.15.6, “InnoDB INFORMATION_SCHEMA Metrics Table”.
      關於INNODB_METRICS表的使用信息,請看 Section 14.15.6, “InnoDB INFORMATION_SCHEMA Metrics Table”.
  • The INFORMATION_SCHEMA.INNODB_BUFFER_PAGE table provides metadata about each page in the buffer pool, including change buffer index and change buffer bitmap pages. Change buffer pages are identified by PAGE_TYPE. IBUF_INDEX is the page type for change buffer index pages, and IBUF_BITMAP is the page type for change buffer bitmap pages.
  • INFORMATION_SCHEMA.INNODB_BUFFER_PAGE表提供的緩衝池中的每一頁的元數據,包括change buffer索引和change buffer位圖頁,Change buffer 頁是PAGE_TYPE來標識的. IBUF_INDEX是change buffe索引頁的頁面類型,ibuf_bitmap是change buffe位圖頁的頁面類型
    Warning:
    Querying the INNODB_BUFFER_PAGE table can introduce significant performance overhead. To avoid impacting performance, reproduce the issue you want to investigate on a test instance and run your queries on the test instance.
    查詢INNODB_BUFFER_PAGE表可以帶來顯着的性能開銷,避免影響性能,複製要在測試實例上進行調查的問題,並在測試實例上運行查詢

For example, you can query the INNODB_BUFFER_PAGE table to determine the approximate number of IBUF_INDEX andIBUF_BITMAP pages as a percentage of total buffer pool pages.
例如,你可以查詢INNODB_BUFFER_PAGE表來確定ibuf_index和ibuf_bitmap頁數目大約爲總緩衝池頁面的百分比。
mysql> SELECT (SELECT COUNT() FROM INFORMATION_SCHEMA.INNODB_BUFFER_PAGE
WHERE PAGE_TYPE LIKE 'IBUF%') AS change_buffer_pages,
(SELECT COUNT(
) FROM INFORMATION_SCHEMA.INNODB_BUFFER_PAGE) AS total_pages,
(SELECT ((change_buffer_pages/total_pages)*100))
AS change_buffer_page_percentage;
+---------------------+-------------+-------------------------------+
| change_buffer_pages | total_pages | change_buffer_page_percentage |
+---------------------+-------------+-------------------------------+
| 25 | 8192 | 0.3052 |
+---------------------+-------------+-------------------------------+

For information about other data provided by the INNODB_BUFFER_PAGE table, see Section 24.31.1, “The INFORMATION_SCHEMA INNODB_BUFFER_PAGE Table”. For related usage information, see Section 14.15.5, “InnoDB INFORMATION_SCHEMA Buffer Pool Tables”.
有關 INNODB_BUFFER_PAGE 表提供的其他數據的信息,請看Section 24.31.1, “The INFORMATION_SCHEMA INNODB_BUFFER_PAGE Table”.相關使用信息,請看Section 14.15.5, “InnoDB INFORMATION_SCHEMA Buffer Pool Tables”.
Performance Schema provides change buffer mutex wait instrumentation for advanced performance monitoring. To view change buffer instrumentation, issue the following query:
Performance Schema數據庫提供了用於高級性能監視的change buffer互斥等待有關信息,若要查看change buffer有關信息,請發出以下查詢

mysql> SELECT * FROM performance_schema.setup_instruments
WHERE NAME LIKE '%wait/synch/mutex/innodb/ibuf%';
+-------------------------------------------------------+---------+-------+
| NAME | ENABLED | TIMED |
+-------------------------------------------------------+---------+-------+
| wait/synch/mutex/innodb/ibuf_bitmap_mutex | YES | YES |
| wait/synch/mutex/innodb/ibuf_mutex | YES | YES |
| wait/synch/mutex/innodb/ibuf_pessimistic_insert_mutex | YES | YES |
+-------------------------------------------------------+---------+-------+

For information about monitoring InnoDB mutex waits, see Section 14.16.2, “Monitoring InnoDB Mutex Waits Using Performance Schema”.
有關監視InnoDB互斥鎖的信息。請看 Section 14.16.2, “Monitoring InnoDB Mutex Waits Using Performance Schema”.

PREV:14.4.1 Buffer Pool http://blog.51cto.com/itzhoujun/2352513
NEXT:14.4.3 Adaptive Hash Index http://blog.51cto.com/itzhoujun/2352547

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