MySQL 8.0.31
Source Code Documentation
ibuf0ibuf.ic File Reference

Insert buffer. More...

#include "fsp0types.h"
#include "page0page.h"
#include "page0zip.h"
#include "buf0lru.h"

Classes

struct  ibuf_t
 Insert buffer struct. More...
 

Functions

static void ibuf_mtr_start (mtr_t *mtr)
 Starts an insert buffer mini-transaction. More...
 
static void ibuf_mtr_commit (mtr_t *mtr)
 Commits an insert buffer mini-transaction. More...
 
void ibuf_set_free_bits_func (buf_block_t *block, ulint val)
 Sets the free bit of the page in the ibuf bitmap. More...
 
static void ibuf_set_free_bits (buf_block_t *b, ulint v, ulint)
 
static bool ibuf_should_try (dict_index_t *index, ulint ignore_sec_unique)
 A basic partial test if an insert to the insert buffer could be possible and recommended. More...
 
static bool ibuf_inside (const mtr_t *mtr)
 Returns true if the current OS thread is performing an insert buffer routine. More...
 
static bool ibuf_bitmap_page (const page_id_t &page_id, const page_size_t &page_size)
 Checks if a page address is an ibuf bitmap page (level 3 page) address. More...
 
static ulint ibuf_index_page_calc_free_bits (ulint page_size, ulint max_ins_size)
 Translates the free space on a page to a value in the ibuf bitmap. More...
 
static ulint ibuf_index_page_calc_free_from_bits (const page_size_t &page_size, ulint bits)
 Translates the ibuf free bits to the free space on a page in bytes. More...
 
static ulint ibuf_index_page_calc_free_zip (const buf_block_t *block)
 Translates the free space on a compressed page to a value in the ibuf bitmap. More...
 
static ulint ibuf_index_page_calc_free (const buf_block_t *block)
 Translates the free space on a page to a value in the ibuf bitmap. More...
 
static void ibuf_update_free_bits_if_full (buf_block_t *block, ulint max_ins_size, ulint increase)
 Updates the free bits of an uncompressed page in the ibuf bitmap if there is not enough free on the page any more. More...
 

Variables

constexpr uint32_t IBUF_PAGE_SIZE_PER_FREE_SPACE = 32
 An index page must contain at least UNIV_PAGE_SIZE / IBUF_PAGE_SIZE_PER_FREE_SPACE bytes of free space for ibuf to try to buffer inserts to this page. More...
 

Detailed Description

Insert buffer.

Created 7/19/1997 Heikki Tuuri

Function Documentation

◆ ibuf_bitmap_page()

static bool ibuf_bitmap_page ( const page_id_t page_id,
const page_size_t page_size 
)
inlinestatic

Checks if a page address is an ibuf bitmap page (level 3 page) address.

Parameters
[in]page_idpage id
[in]page_sizepage size
Returns
true if a bitmap page

◆ ibuf_index_page_calc_free()

static ulint ibuf_index_page_calc_free ( const buf_block_t block)
inlinestatic

Translates the free space on a page to a value in the ibuf bitmap.

Returns
value for ibuf bitmap bits
Parameters
blockin: buffer block

◆ ibuf_index_page_calc_free_bits()

static ulint ibuf_index_page_calc_free_bits ( ulint  page_size,
ulint  max_ins_size 
)
inlinestatic

Translates the free space on a page to a value in the ibuf bitmap.

Parameters
[in]page_sizepage size in bytes
[in]max_ins_sizemaximum insert size after reorganize for the page
Returns
value for ibuf bitmap bits

◆ ibuf_index_page_calc_free_from_bits()

static ulint ibuf_index_page_calc_free_from_bits ( const page_size_t page_size,
ulint  bits 
)
inlinestatic

Translates the ibuf free bits to the free space on a page in bytes.

Parameters
[in]page_sizepage_size
[in]bitsvalue for ibuf bitmap bits
Returns
maximum insert size after reorganize for the page

◆ ibuf_index_page_calc_free_zip()

static ulint ibuf_index_page_calc_free_zip ( const buf_block_t block)
inlinestatic

Translates the free space on a compressed page to a value in the ibuf bitmap.

Returns
value for ibuf bitmap bits
Parameters
blockin: buffer block

◆ ibuf_inside()

static bool ibuf_inside ( const mtr_t mtr)
inlinestatic

Returns true if the current OS thread is performing an insert buffer routine.

For instance, a read-ahead of non-ibuf pages is forbidden by threads that are executing an insert buffer routine.

Returns
true if inside an insert buffer routine
Parameters
mtrin: mini-transaction

◆ ibuf_mtr_commit()

static void ibuf_mtr_commit ( mtr_t mtr)
inlinestatic

Commits an insert buffer mini-transaction.

Parameters
mtrin/out: mini-transaction

◆ ibuf_mtr_start()

static void ibuf_mtr_start ( mtr_t mtr)
inlinestatic

Starts an insert buffer mini-transaction.

Parameters
mtrout: mini-transaction

◆ ibuf_set_free_bits()

static void ibuf_set_free_bits ( buf_block_t b,
ulint  v,
ulint   
)
inlinestatic

◆ ibuf_set_free_bits_func()

void ibuf_set_free_bits_func ( buf_block_t block,
ulint  val 
)

Sets the free bit of the page in the ibuf bitmap.

This is done in a separate mini-transaction, hence this operation does not restrict further work to only ibuf bitmap operations, which would result if the latch to the bitmap page were kept. in: value to set: < 4

This is done in a separate mini-transaction, hence this operation does not restrict further work to only ibuf bitmap operations, which would result if the latch to the bitmap page were kept.

Parameters
blockin: index page of a non-clustered index; free bit is reset if page level is 0
valin: value to set: < 4

◆ ibuf_should_try()

static bool ibuf_should_try ( dict_index_t index,
ulint  ignore_sec_unique 
)
inlinestatic

A basic partial test if an insert to the insert buffer could be possible and recommended.

Parameters
indexin: index where to insert
ignore_sec_uniquein: if != 0, we should ignore UNIQUE constraint on a secondary index when we decide

◆ ibuf_update_free_bits_if_full()

static void ibuf_update_free_bits_if_full ( buf_block_t block,
ulint  max_ins_size,
ulint  increase 
)
inlinestatic

Updates the free bits of an uncompressed page in the ibuf bitmap if there is not enough free on the page any more.

This is done in a separate mini-transaction, hence this operation does not restrict further work to only ibuf bitmap operations, which would result if the latch to the bitmap page were kept. NOTE: The free bits in the insert buffer bitmap must never exceed the free space on a page. It is unsafe to increment the bits in a separately committed mini-transaction, because in crash recovery, the free bits could momentarily be set too high. It is only safe to use this function for decrementing the free bits. Should more free space become available, we must not update the free bits here, because that would break crash recovery.

Parameters
blockin: index page to which we have added new records; the free bits are updated if the index is non-clustered and non-unique and the page level is 0, and the page becomes fuller
max_ins_sizein: value of maximum insert size with reorganize before the latest operation performed to the page
increasein: upper limit for the additional space used in the latest operation, if known, or ULINT_UNDEFINED

Variable Documentation

◆ IBUF_PAGE_SIZE_PER_FREE_SPACE

constexpr uint32_t IBUF_PAGE_SIZE_PER_FREE_SPACE = 32
constexpr

An index page must contain at least UNIV_PAGE_SIZE / IBUF_PAGE_SIZE_PER_FREE_SPACE bytes of free space for ibuf to try to buffer inserts to this page.

If there is this much of free space, the corresponding bits are set in the ibuf bitmap.