Change of InnoDB buffer passive merge

Source: Internet
Author: User

Passive merge Scenario one. Low secondary index page space: Ibuf_insert_low

1. When trying to cache the insert operation, assume that there is not enough space in the estimated two-level index page. May cause an index split, it is positioned to the location in the Ibuf tree where the page no is trying to cache, with a maximum of merge 8 page,merge in the form of asynchronous, which initiates an asynchronous read of the index page request.


Buffered: The current Level Two index page has cached records

Entry_size: Level Two index record size to be inserted

Page_dir_calc_reserved_space (1): Slot size for the record to be inserted

Ibuf_index_page_calc_free_from_bits (Zip_size,bits)): The remaining space size of the two-level index page to be inserted


/* Find out the volume of already bufferedinserts for the same index page */

min_n_recs= 0;

Buffered= ibuf_get_volume_buffered (&pcur, Space, Page_no,

OP = = Ibuf_op_delete

? &min_n_recs

: NULL, &mtr);


Do_merge = FALSE;


Open the previous record position in the Ibuf tree for the ibuf record to be inserted

Btr_pcur_open (Ibuf->index, Ibuf_entry,page_cur_le, mode, &pcur, &mtr);


if (op = = Ibuf_op_insert) {

Ulint bits = ibuf_bitmap_page_get_bits (

Bitmap_page,page_no, Zip_size, ibuf_bitmap_free,&bitmap_mtr);

if (buffered + entry_size + page_dir_calc_reserved_space (1)

>ibuf_index_page_calc_free_from_bits (Zip_size, bits)) {


Do_merge= TRUE;

Ibuf_get_merge_page_nos (FALSE,

Btr_pcur_get_rec (&pcur), &mtr,







if (Do_merge) {

buf_read_ibuf_merge_pages (False, Space_ids,space_versions,

Page_nos, n_stored);



1. What does buffered mean? What is Page_dir_calc_reserved_space (1)?

The number of records that have been cached when a Level two index page is inserted into a level two index. When a level two index is inserted. If the Level two index page splits, the page information for the Ibuf tree species record is partially aging.

It is therefore necessary to infer the bitmap each time it is inserted.

2, how to interpret the merge 8 pages?

The ibuf_max_n_pages_merged value is 8.

The number of merge pages is 8 and the current buffer pool size 1/4 min

Limit = Ut_min (ibuf_max_n_pages_merged, Buf_pool_get_curr_size ()/4);

while (*n_stored < limit) {


Page_nos[*n_stored] = prev_page_no;



3, which 8 pages of the merge?

Increment of 8 pages ... , do these 8 pages refer to an index page or a ibuftree page?

First, position the previous record of the record to be inserted, and push forward 8 records sequentially, based on the previous record. The Space ID and page No in these 8 records are the tags of the two-level index pages that need to be merge.


Enter the number of references:

Bool Sync:true If the caller wantsthis function to wait for the highest address page to get read in, before this Functionr Eturns

Const ulint* Space_ids:space ID Array

Const ib_int64_t* space_versions:the Spaces Musthave This version number (timestamp), otherwise we discard the read; We usethis to cancel reads if DISCARD + IMPORT could have changed the tablespace size

Const ulint* Page_nos: page-numbered group read-in

Ulint n_stored: Number of elements in the page Count group


Read the array page into memory, merge related page

Issues read requests for pages which THEIBUF module wants to read in, in order to contract the insert buffer tree. Technically, this function was like a read-ahead function

for (i = 0; i < n_stored; i++) {


Buf_read_page_low (&err, Sync && (i + 1 = = n_stored),

Buf_read_any_page, Space_ids[i],

Zip_size, TRUE, Space_versions[i],


if (sync) {

/* The I/O is already completed if wearrive from Fil_read */

if (!buf_page_io_complete (bpage)) {

return (0);




} Asynchronous Read


if (Io_type ==buf_io_read) {


if (uncompressed&&!recv_no_ibuf_operations) {

Ibuf_merge_or_delete_for_page (

(buf_block_t*) bpage, Bpage->space,

Bpage->offset,buf_page_get_zip_size (bpage),





2, Ibuf_merge_or_delete_for_page

Enter the number of references:

Block: Assuming that the page has been read from disk, point to pagex-latched

Space:index Page's Space ID

Page number of Page_no:index page

zip_size:compressed Page Size

Update_ibuf_bitmap: The usual condition is true. Assuming that tablespace has been or is being deleted, set false


This function is applied when a level two index page is read from disk to buffer pool. Merge all the corresponding actions for the page. Delete the entries in the insert buffer. Assuming that the page is not read but created in buffer pool, delete the operation record of his cache.

Passive merge scenario Two, insert buffer too large: Ibuf_insert_low

Assume that the insert buffer size is too large. Contract Insert buffer. and give up the cache this time.

1, Ibuf->size greater than ibuf->max_size+10 (Unit page) run a synchronization ibuf merge (Ibuf_contract), the merge page no is a randomly positioned record of page no, at most one time merge 8 pages. Discard this cache at the same time

2, the Ibuf_max_size=25%*bufferpool size, the percentage is controlled by Innodb_change_buffer_max_size. can be dynamically adjusted.


if (ibuf->size >= ibuf->max_size +ibuf_contract_do_not_insert) {

/*insert buffer is now too big, contract it but does not try to Insert */

/* Use synchronous contract (= = TRUE) */

ibuf_contract (TRUE);

Return (Ibuf_merge (0, &n_pages, sync));

Return (Ibuf_merge_pages (N_pages,sync));

return (Db_strong_fail);


Passive merge Scenario three. Insert operation may produce Ibuf Btree split: Ibuf_insert_low


1, when Ibuf->size<ibuf->max_size (ibuf_contract_on_insert_non_sync=0) do not do whatever operation

2, when ibuf->size>= ibuf->max_size+5, Ibuf_contract (true), synchronize once ibuf merge, position random

3, when ibuf->max_size< ibuf->size <= ibuf->max_size+5, Ibuf_contract (FALSE), asynchronous merge, Position random.

4, merge at least 8 pages, ut_min (ibuf_max_n_pages_merged, Buf_pool_get_curr_size ()/4);


if (err = = db_success && mode ==btr_modify_tree) {

Ibuf_contract_after_insert (entry_size);

if (Size < max_size +ibuf_contract_on_insert_non_sync) {



Sync = (size >= max_size +ibuf_contract_on_insert_sync);

size = Ibuf_contract (sync);

Return (Ibuf_merge (0,&n_pages, sync));

Return (Ibuf_merge_pages (N_pages,sync));



Change of InnoDB buffer passive merge

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.