mysql小特性:change buffer

2018-06-18 01:34:17来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

       

 

        change buffer是在其他数据库中没有的一个概念,说白了就是一块系统表空间分配的空间,针对的对象是辅助索引的叶子节点(为什么不是主键索引?因为主键索引是聚集索引,在磁盘上的排列是有序的,磁盘的顺序IO的性能很高,而随机IO的性能却很低)。当辅助索引的值有更新时,将这些更新先缓存起来,当有其他应用对相同的页做更新操作后,对该页进行整合,最后将整合后的值一起更新到磁盘文件中,减少了磁盘的I/O. change buffer是由InnoDB的系统表空间分配的,虽然叫buffer,但和double write buffer一样,都是表空间的空间,可以和其他数据页一样缓存在buffer pool中。
以下是change buffer相关文档的翻译,来自官方文档。
14.9.4 Configuring InnoDB Change Buffering
When INSERT, UPDATE, and DELETE operations are performed on a table, the values of indexed columns (particularly the values of secondary keys) are often in an unsorted order, requiring substantial I/O to bring secondary indexes up to date. InnoDB has a change buffer that caches changes to secondary index entries when the relevant page is not in the buffer pool, thus avoiding expensive I/O operations by not immediately reading in the page from disk. The buffered changes are merged when the page is loaded to the buffer pool, and the updated page is later flushed to disk. The InnoDB main thread merges buffered changes when the server is nearly idle, and during a slow shutdown.
当对表进行增删改操作的时候,由于索引列(尤其是复制索引列)的值总是无序的,更新辅助索引往往需要大量的随机I/O操作。InnoDB的change buffer会存放一些辅助索引条目,当有DML操作对辅助索引修改时,会先对这些索引页进行整合,之后一块刷新到磁盘上。InnoDB的主线程会在系统I/O空闲时或关机时整合这些索引页。
Because it can result in fewer disk reads and writes, the change buffer feature is most valuable for workloads that are I/O-bound, for example applications with a high volume of DML operations such as bulk inserts.
因为change buffer可以减少磁盘的读写,在有大量读写绑定的操作上会更体现它的价值,比如说对于批量插入操作的应用来说。
However, the change buffer occupies a part of the buffer pool, reducing the memory available to cache data pages. If the working set almost fits in the buffer pool, or if your tables have relatively few secondary indexes, it may be useful to disable change buffering. If the working set fits entirely within the buffer, change buffering does not impose extra overhead, because it only applies to pages that are not in the buffer pool.
然而,change buffer会占用buffer pool的内存空间,这样就会减少数据页在内存中的缓存。因此对于有辅助索引相关的表操作的时候,change buffer可能会有用,对于工作集都在缓冲池中的操作,change buffer就不会起作用,因为它只应用于索引页不完全在内存中的情况。
You can control the extent to which InnoDB performs change buffering using the innodb_change_buffering configuration parameter. You can enable or disable buffering for inserts, delete operations (when index records are initially marked for deletion) and purge operations (when index records are physically deleted). An update operation is a combination of an insert and a delete. In MySQL 5.5 and higher, the default innodb_change_buffering value is changed from inserts to all.
可以使用参数innodb_change_buffering来对是否使用change buffer来进行控制,5.5及以上的版本中默认值是all.
Permitted innodb_change_buffering values include:
该参数的参数值包含一下:
all

The default value: buffer inserts, delete-marking operations, and purges.

none

Do not buffer any operations.

inserts

Buffer insert operations.

deletes

Buffer delete-marking operations.

changes

Buffer both inserts and delete-marking operations.

purges

Buffer the physical deletion operations that happen in the background.

You can set the innodb_change_buffering parameter in the MySQL option file (my.cnf or my.ini) or change it dynamically with the SET GLOBAL command, which requires the SUPER privilege. Changing the setting affects the buffering of new operations; the merging of existing buffered entries is not affected.
innodb_change_buffering参数的值可以在配置文件(my.cnf or my.ini)中设置,或者具有SUPER权限的用户使用SET GLOBAL命令动态的修改,修改只对以后的操作生效。

可以通过以下命令来监控change buffer。
mysql> SHOW ENGINE INNODB STATUS\G;

-------------------------------------
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 276707, node heap has 1 buffer(s)
15.81 hash searches/s, 46.33 non-hash searches/s

seg size 指segment总的分配大小,以页为单位;
free list 指空闲数据页;
size 指已经合并数据页数量。

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:MySQL案例04:Cause: java.sql.SQLException: Could not retriev

下一篇:MySQL 时间函数