【InnoDB 存储引擎】15.5.2 Change Buffer(也叫插入缓冲或改变缓冲,用于提供插入修改删除速度,在内存中构建结构而不是每次修改都去修改二级索引)

1 什么是 Insert Buffer

官网说:

The change buffer is a special data structure that caches changes to secondary index pages when those 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

翻译:

1、它是一种特殊的数据结构

作用:缓存不在缓冲池中的二级索引页的『改变

2、它通常是由 insert、update、delete 导致

因为这些操作通常会改变二级索引的数据

3、当其他的 read 操作把 the pages 加载到 the buffer pool 中时,它和 the pages 进行合并

合并的结果是:在缓冲池中的脏的二级索引页随后被写入到索引文件中

白话文解释:

以插入操作为例,在进行插入操作的时候,待插入的二级索引数据不是排序好的但是在索引文件中我们又要求二级索引的数据是排序好的,怎么解决这个矛盾的问题?也就是随机读磁盘导致的效率低下问题!就是使用 Change Buffer 缓冲

在插入的时候如果二级索引页不在缓冲池中,那么我们在 the change buffer 中构建二级索引的数据结构而不是直接对磁盘随机读;等待随后其他读取操作把索引页加载到缓冲池中,此时进行 the change buffer 与 索引页的 merged 操作;merged 的结果最后被写入到索引文件中,通过 the change buffer 数据结构减少了随机读操作

那要这么说,如果插入数据到一张空表,就是直接在 the change buffer 中把二级索引的数据结构都构建好,最后直接写入索引文件中了,避免了大量的随机读写

2 为什么要用 Insert Buffer

官网说:

Unlike clustered indexes, secondary indexes are usually nonunique, 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 secondary index pages into the buffer pool from disk

解释:

跟聚簇索引不同的是,二级索引通常是非唯一的,插入到二级索引会发生随机顺序。类似的删除和更新操作也影响二级索引页。随后,当被影响的页被其它操作读取到缓冲池中,就会发生合并,避免了大量的(从二级缓冲页读取到缓冲池中)随机 I/O 访问

白话文解释:

避免了大量的(把二级缓冲页读取到缓冲池中的)随机 I/O 访问,改变了二级索引的插入效率!

3 什么是 Change Buffer

Change Buffer 是 Insert Buffer 的升级版,InnoDB 存储引擎可以对 DML 操作——INSERT、DELETE、UPDATE 都进行缓冲

4 对 Change Buffer 的配置

5 参考资料

change-buffer: https://dev.mysql.com/doc/refman/8.0/en/innodb-change-buffer.html

clustered indexes:聚簇索引(前提:必须知道)

secondary index:二级索引(前提:必须知道)


传送门: 保姆式Spring5源码解析

欢迎与作者一起交流技术和工作生活

联系作者

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Fire Fish

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值