1. 程式人生 > >MySQL 5.7 Reference Manual】15.4.2 Change Buffer(變更緩衝)

MySQL 5.7 Reference Manual】15.4.2 Change Buffer(變更緩衝)

15.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.   變更緩衝是一個特殊的資料結構,當目標頁不在緩衝池中時,變更緩衝負責快取對二級索引頁的變更。被緩衝的變更內容可能是INSERT,UPDATE,或DELETE操作(DML)的結果。在下一次讀操作時這些頁會被載入緩衝池,之後變更緩衝中的內容將被合併。   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.   清理操作發生在系統基本空閒或緩慢關閉期間,它會週期性的把更新過的索引頁寫入磁碟。清理操作可以把索引值批量寫入磁碟,這樣比把單個值直接寫入磁碟更有效率。   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 15.21.2, “Forcing InnoDB Recovery” for more information).   當有許多二級索引要更新並且同時影響多行記錄時,變更緩衝合併可能需要耗費數個小時。在此期間,磁碟I/O不斷增加,這樣會造成磁碟讀取效能顯著下降。變更緩衝合併可能會在事務提交後繼續發生。事實上,變更緩衝合併也可能在服務關閉和重啟後繼續發生(更多資訊,請參考15.21.2, “強制InnoDB恢復”)。   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.   在記憶體中,變更緩衝佔用了InnoDB緩衝池的部分空間。在磁碟上,變更緩衝是系統表空間的一部分,這使得索引變更即使在系統重啟後仍然處於緩衝狀態。   The type of data cached in the change buffer is governed by the innodb_change_buffering configuration option. For more information, see Section 15.6.5, “Configuring InnoDB Change Buffering”. You can also configure the maximum change buffer size. For more information, see Section 15.6.5.1, “Configuring the Change Buffer Maximum Size”.   變更緩衝中快取的資料型別通過innodb_change_buffering配置項進行管理。更多資訊,請看15.6.5,“配置InnoDB變更緩衝”。你也可以配置變更緩衝大小的上限。更多資訊,請看15.6.5.1,“配置變更緩衝大小上限”。   Monitoring the Change Buffer(監控變更緩衝)   The following options are available for change buffer monitoring:   以下選項可用於變更緩衝監控:  
  • 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:   變更緩衝的狀態資訊位於“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 For more information, see Section 15.17.3, “InnoDB Standard Monitor and Lock Monitor Output”.   更多資訊,請參考15.17.3,“InnoDB標準監視器與鎖定監視器輸出”。  
  • 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標準監視器中輸出的大部分資料點,以及其他資料點。要看變更緩衝的指標及其描述,輸入以下查詢: mysql> SELECT NAME, COMMENT FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME LIKE '%ibuf%'\G For INNODB_METRICS table usage information, see Section 15.15.6, “InnoDB INFORMATION_SCHEMA Metrics Table”.   如何使用INNODB_METRICS表的資訊,請參考15.15.6,“InnoDB INFORMATION_SCHEMA指標表 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表提供緩衝池中每一頁的元資料,包括變更緩衝索引頁和變更緩衝點陣圖頁。變更緩衝頁是通過一些標記來識別的,PAGE_TYPE. IBUF_INDEX表示頁型別是變更緩衝索引頁,IBUF_BITMAP表示頁型別是變更緩衝點陣圖頁。 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. For example, you can query the INNODB_BUFFER_PAGE table to determine the approximate number of IBUF_INDEX and IBUF_BITMAP pages as a percentage of total buffer pool pages.   例如,你可以查詢INNODB_BUFFER_PAGE,通過計算佔總緩衝池頁的百分比來確認IBUF_INDEX頁和IBUF_BITMAP頁的大致數量。 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, seeSection 23.31.1, “The INFORMATION_SCHEMA INNODB_BUFFER_PAGE Table”. For related usage information, see Section 15.15.5, “InnoDB INFORMATION_SCHEMA Buffer Pool Tables”.   更多關於INNODB_BUFFER_PAGE表所提供的其他資料的資訊,請參考23.31.1,“INFORMATION_SCHEMA INNODB_BUFFER_PAGE表”。相關用法,請參考 15.15.5,“InnoDB INFORMATION_SCHEMA緩衝池表”。  
  • Performance Schema provides change buffer mutex wait instrumentation for advanced performance monitoring. To view change buffer instrumentation, issue the following query:
  Performance Schema提供對變更緩衝互斥等待的檢測資訊以增強對於效能的監控能力。要看效能緩衝檢測資訊,輸入以下查詢: 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 15.16.2, “Monitoring InnoDB Mutex Waits Using Performance Schema”.   更多關於監控InnoDB互斥等待的資訊,請參考15.16.2,“使用Performance Schema監控InnoDB互斥等待”。