MySQL 5.7 Reference Manual】15.4.2 Change Buffer(变更缓冲)

摘要:
在系统几乎空闲时,或在气体流量关闭时,定期将更新的数据写入磁盘。与立即将每个值写入磁盘相比,清除操作可以有效地写入一系列索引值的磁盘块。当系统基本空闲或缓慢关闭时,会进行清理操作。它定期将更新的索引页写入磁盘。更改缓冲区余量可能需要几个小时,直到有大量的二级索引被更新,并且可能会受到影响。在此期间,磁盘I/O增加,这可能会导致磁盘边界查询的速度明显减慢。更改缓冲区的余量将在提交事务后继续发生。事实上,更改缓冲区边距将在服务器关闭并启动后继续保持。当有许多次要索引要更新并且多行记录同时受到影响时,更改缓冲区合并可能需要几个小时。事务提交后,更改缓冲合并可能会继续发生。在内存中,changebuffer占用NoDB缓冲池的一部分。在磁盘上,交换机缓冲区是系统表空间的一部分,因此交换机的主缓冲区是存储数据库的一部分。在内存中,更改缓冲区占用InnoDB缓冲池的一部分。更改缓冲区中的数据缓存类型由innodb_change_buffering配置选项控制。有关更多信息,请参阅第15.6.5节“配置InnoBhangeBuffering”。您可以配置最大更改缓冲区大小。有关详细信息,请参见第15.6.1节“配置更改缓冲区最大大小”。通过innodb_Change_Buffering配置项更改缓冲区中缓存的数据类型。监视更改缓冲区以下选项可用于更改缓冲区监视:以下选项可用来监视更改缓冲:InnoDB标准监视器输出包括更改缓冲区的状态信息。要查看监视器数据,请发出SHOWINGINEINNODSTATUSCOMMAND(显示节点状态)命令。InnoDB标准监视器将输出更改缓冲区的状态信息。

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 STATUSG
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互斥等待”。

免责声明:文章转载自《MySQL 5.7 Reference Manual】15.4.2 Change Buffer(变更缓冲)》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇nginx 设置 404 500 页面跳转到指定页面python_18(Django基础)下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

MyBatis(三)全局配置文件 之 databaseProvider 数据库厂商标识

databaseIdProvider环境一、databaseIdProvider 属性 MyBatis可以根据不同的数据库厂商执行不同的语句 <databaseIdProvider type="DB_VENDOR"> <!-- 为不同的数据库厂商起别名 --> <property name="M...

mysql性能监控相关

如果是root帐号,你能看到所有用户的当前连接。如果是其它普通帐号,只能看到自己占用的连接 怎么进入mysql命令行呢? mysql的安装目录下面有个bin目录,先用命令行进入该目录,然后用 mysql -uroot -p123456 来登录(注意:用户名和密码不用包含“”) 命令: show processlist; 如果是root帐号,你能看到所有用户...

mysql源码安装

阿里云 windows 版本为 mysql 5.7 之后下载 boost库 () wget https://jaist.dl.sourceforge.net/project/boost/boost/1.61.0/boost_1_61_0.tar.gz 先后尝试编译安装boost_1_64_0.tar.gz 及boost_1_61_0.tar.gz 都在编译...

《MySQL数据库》MySQL ERRORLOG,BINLOG,SLOWLOG日志详解

前言 MySQL 经常出现启动错误或者执行错误等等,这个时候我们需要查询error日志 在数据库使用中,经常会出现需要恢复数据的情况,MySQL如果需要恢复数据的话需要开启binlog(二进制日志)。 Error Log 错误日志默认设置如下: 1. error log 默认路径在数据文件下。 2. error log 默认文件名为主机名.err,例如:i...

mysql事务详解

事务的四大特性ACID如下:       原子性:事务中的所有操作,要么全部完成,要么不做任何操作,不能只做部分操作。如果在执行的过程中发了错误,要回滚(Rollback)到事务开始前的状态,就像这个事务从来没有执行过。         事务的四大隔离级别如下: 一、读未提交。(A事务能够读取到B事务对数据的增删改操作)   该事务级别会出现脏读问题。...

MySQL 连接查询

一.什么是连接查询 1.连接查询是一种非常常见的数据库操作,在两张(或者多张)表中进行匹配. 2.以mysql为例,支持Cross join(交叉连接), inner join(内连接), outer join(外连接),等其他连接.  二、数据准备(创建emp员工表和dept部门表并插入数据) SET NAMES utf8mb4; SET FOREIGN...