MySQL 8.0.39
Source Code Documentation
|
Insert buffer. More...
#include <sys/types.h>
#include "btr0sea.h"
#include "ha_prototypes.h"
#include "ibuf0ibuf.h"
#include "sync0sync.h"
#include <debug_sync.h>
#include "my_dbug.h"
#include "btr0btr.h"
#include "btr0cur.h"
#include "btr0pcur.h"
#include "buf0buf.h"
#include "buf0rea.h"
#include "dict0boot.h"
#include "fil0fil.h"
#include "fsp0fsp.h"
#include "fsp0sysspace.h"
#include "fut0lst.h"
#include "lock0lock.h"
#include "log0buf.h"
#include "log0chkp.h"
#include "log0recv.h"
#include "que0que.h"
#include "rem0cmp.h"
#include "rem0rec.h"
#include "row0upd.h"
#include "srv0start.h"
#include "trx0sys.h"
Variables | |
bool | srv_ibuf_disable_background_merge |
constexpr size_t | IBUF_BITS_PER_PAGE = 4 |
Number of bits describing a single page. More... | |
constexpr uint32_t | IBUF_BITMAP = PAGE_DATA |
The start address for an insert buffer bitmap page bitmap. More... | |
ulong | innodb_change_buffering = IBUF_USE_ALL |
Operations that can currently be buffered. More... | |
uint | ibuf_debug |
Flag to control insert buffer debugging. More... | |
ibuf_t * | ibuf = nullptr |
The insert buffer control structure. More... | |
constexpr uint32_t | IBUF_REC_FIELD_SPACE = 0 |
in the pre-4.1 format, the page number. More... | |
constexpr uint32_t | IBUF_REC_FIELD_MARKER = 1 |
starting with 4.1, a marker consisting of 1 byte that is 0 More... | |
constexpr uint32_t | IBUF_REC_FIELD_PAGE = 2 |
starting with 4.1, the page number More... | |
constexpr uint32_t | IBUF_REC_FIELD_METADATA = 3 |
the metadata field More... | |
constexpr uint32_t | IBUF_REC_FIELD_USER = 4 |
first user field More... | |
Offsets to the per-page bits in the insert buffer bitmap | |
constexpr uint32_t | IBUF_BITMAP_FREE = 0 |
Bits indicating the amount of free space. More... | |
constexpr uint32_t | IBUF_BITMAP_BUFFERED = 2 |
true if there are buffered changes for the page More... | |
constexpr uint32_t | IBUF_BITMAP_IBUF = 3 |
true if page is a part of the ibuf tree, excluding the root page, or is in the free list of the ibuf More... | |
Format of the IBUF_REC_FIELD_METADATA of an insert buffer record | |
The fourth column in the MySQL 5.5 format contains an operation type, counter, and some flags. | |
constexpr uint32_t | IBUF_REC_INFO_SIZE = 4 |
Combined size of info fields at the beginning of the fourth field. More... | |
constexpr uint32_t | IBUF_REC_OFFSET_COUNTER = 0 |
Operation counter. More... | |
constexpr uint32_t | IBUF_REC_OFFSET_TYPE = 2 |
Type of operation. More... | |
constexpr uint32_t | IBUF_REC_OFFSET_FLAGS = 3 |
Additional flags. More... | |
constexpr uint32_t | IBUF_REC_COMPACT = 0x1 |
Set in IBUF_REC_OFFSET_FLAGS if the user index is in COMPACT format or later. More... | |
static ib_mutex_t | ibuf_pessimistic_insert_mutex |
The mutex used to block pessimistic inserts to ibuf trees. More... | |
static ib_mutex_t | ibuf_mutex |
The mutex protecting the insert buffer structs. More... | |
static ib_mutex_t | ibuf_bitmap_mutex |
The mutex protecting the insert buffer bitmaps. More... | |
const ulint | IBUF_MERGE_AREA = 8 |
The area in pages from which contract looks for page numbers for merge. More... | |
const ulint | IBUF_MERGE_THRESHOLD = 4 |
Inside the merge area, pages which have at most 1 per this number less buffered entries compared to maximum volume that can buffered for a single page are merged along with the page whose buffer became full. More... | |
const ulint | IBUF_MAX_N_PAGES_MERGED = IBUF_MERGE_AREA |
In ibuf_contract at most this number of pages is read to memory in one batch, in order to merge the entries for them in the insert buffer. More... | |
const ulint | IBUF_CONTRACT_ON_INSERT_NON_SYNC = 0 |
If the combined size of the ibuf trees exceeds ibuf->max_size by this many pages, we start to contract it in connection to inserts there, using non-synchronous contract. More... | |
const ulint | IBUF_CONTRACT_ON_INSERT_SYNC = 5 |
If the combined size of the ibuf trees exceeds ibuf->max_size by this many pages, we start to contract it in connection to inserts there, using synchronous contract. More... | |
const ulint | IBUF_CONTRACT_DO_NOT_INSERT = 10 |
If the combined size of the ibuf trees exceeds ibuf->max_size by this many pages, we start to contract it synchronous contract, but do not insert. More... | |
static void | ibuf_enter (mtr_t *mtr) |
Sets the flag in the current mini-transaction record indicating we're inside an insert buffer routine. More... | |
static void | ibuf_exit (mtr_t *mtr) |
Sets the flag in the current mini-transaction record indicating we're exiting an insert buffer routine. More... | |
static void | ibuf_btr_pcur_commit_specify_mtr (btr_pcur_t *pcur, mtr_t *mtr) |
Commits an insert buffer mini-transaction and sets the persistent cursor latch mode to BTR_NO_LATCHES, that is, detaches the cursor. More... | |
static page_t * | ibuf_header_page_get (mtr_t *mtr) |
Gets the ibuf header page and x-latches it. More... | |
static page_t * | ibuf_tree_root_get (mtr_t *mtr) |
Gets the root page and sx-latches it. More... | |
void | ibuf_close (void) |
Closes insert buffer and frees the data structures. More... | |
static void | ibuf_size_update (const page_t *root) |
Updates the size information of the ibuf, assuming the segment size has not changed. More... | |
void | ibuf_init_at_db_start (void) |
Creates the insert buffer data structure at a database startup and initializes the data structures for the insert buffer. More... | |
void | ibuf_max_size_update (ulint new_val) |
Updates the max_size value for ibuf. More... | |
void | ibuf_bitmap_page_init (buf_block_t *block, mtr_t *mtr) |
Initializes an ibuf bitmap page. More... | |
byte * | ibuf_parse_bitmap_init (byte *ptr, byte *end_ptr, buf_block_t *block, mtr_t *mtr) |
Parses a redo log record of an ibuf bitmap page init. More... | |
static ulint | ibuf_bitmap_page_get_bits_low (const page_t *page, const page_id_t &page_id, const page_size_t &page_size, ulint latch_type, mtr_t *mtr, ulint bit) |
Gets the desired bits for a given page from a bitmap page. More... | |
ulint | ibuf_bitmap_page_get_bits (const page_t *page, const page_id_t &page_id, const page_size_t &page_size, ulint bit, mtr_t *mtr) |
Gets the desired bits for a given page from a bitmap page. More... | |
static void | ibuf_bitmap_page_set_bits (page_t *page, const page_id_t &page_id, const page_size_t &page_size, ulint bit, ulint val, mtr_t *mtr) |
Sets the desired bit for a given page in a bitmap page. More... | |
static const page_id_t | ibuf_bitmap_page_no_calc (const page_id_t &page_id, const page_size_t &page_size) |
Calculates the bitmap page number for a given page number. More... | |
static page_t * | ibuf_bitmap_get_map_page (const page_id_t &page_id, const page_size_t &page_size, ut::Location location, mtr_t *mtr) |
Gets the ibuf bitmap page where the bits describing a given file page are stored. More... | |
static void | ibuf_set_free_bits_low (const buf_block_t *block, ulint val, mtr_t *mtr) |
Sets the free bits of the page in the ibuf bitmap. 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... | |
void | ibuf_reset_free_bits (buf_block_t *block) |
Resets the free bits of the page in the ibuf bitmap. More... | |
void | ibuf_update_free_bits_low (const buf_block_t *block, ulint max_ins_size, mtr_t *mtr) |
Updates the free bits for an uncompressed page to reflect the present state. More... | |
void | ibuf_update_free_bits_zip (buf_block_t *block, mtr_t *mtr) |
Updates the free bits for a compressed page to reflect the present state. More... | |
void | ibuf_update_free_bits_for_two_pages_low (buf_block_t *block1, buf_block_t *block2, mtr_t *mtr) |
Updates the free bits for the two pages to reflect the present state. More... | |
static bool | ibuf_fixed_addr_page (const page_id_t &page_id, const page_size_t &page_size) |
Returns true if the page is one of the fixed address ibuf pages. More... | |
bool | ibuf_page_low (const page_id_t &page_id, const page_size_t &page_size, bool x_latch, ut::Location location, mtr_t *mtr) |
Checks if a page is a level 2 or 3 page in the ibuf hierarchy of pages. More... | |
static page_no_t | ibuf_rec_get_page_no_func (mtr_t *mtr, const rec_t *rec) |
Returns the page number field of an ibuf record. More... | |
static page_no_t | ibuf_rec_get_page_no (mtr_t *mtr, const rec_t *rec) |
static space_id_t | ibuf_rec_get_space_func (mtr_t *mtr, const rec_t *rec) |
Returns the space id field of an ibuf record. More... | |
static space_id_t | ibuf_rec_get_space (mtr_t *mtr, const rec_t *rec) |
static void | ibuf_rec_get_info_func (mtr_t *mtr, const rec_t *rec, ibuf_op_t *op, bool *comp, ulint *info_len, ulint *counter) |
Get various information about an ibuf record in >= 4.1.x format. More... | |
void | ibuf_rec_get_info (mtr_t *mtr, const rec_t *rec, ibuf_op_t *op, bool *comp, ulint *info_len, ulint *counter) |
static ibuf_op_t | ibuf_rec_get_op_type_func (mtr_t *mtr, const rec_t *rec) |
Returns the operation type field of an ibuf record. More... | |
ibuf_op_t | ibuf_rec_get_op_type (mtr_t *mtr, const rec_t *rec) |
ulint | ibuf_rec_get_counter (const rec_t *rec) |
Read the first two bytes from a record's fourth field (counter field in new records; something else in older records). More... | |
bool | ibuf_rec_has_multi_value (const rec_t *rec) |
Determine if there is any multi-value field data on the change buffer record. More... | |
static void | ibuf_add_ops (std::atomic< ulint > *arr, const ulint *ops) |
Add accumulated operation counts to a permanent array. More... | |
static void | ibuf_print_ops (const std::atomic< ulint > *ops, FILE *file) |
Print operation counts. More... | |
static dict_index_t * | ibuf_dummy_index_create (ulint n, bool comp) |
Creates a dummy index for inserting a record to a non-clustered index. More... | |
static void | ibuf_dummy_index_add_col (dict_index_t *index, const dtype_t *type, ulint len) |
Add a column to the dummy index. More... | |
static void | ibuf_dummy_index_free (dict_index_t *index) |
Deallocates a dummy index for inserting a record to a non-clustered index. More... | |
static dtuple_t * | ibuf_build_entry_from_ibuf_rec_func (mtr_t *mtr, const rec_t *ibuf_rec, mem_heap_t *heap, dict_index_t **pindex) |
Builds the entry used to. More... | |
dtuple_t * | ibuf_build_entry_from_ibuf_rec (mtr_t *mtr, const rec_t *ibuf_rec, mem_heap_t *heap, dict_index_t **pindex) |
static ulint | ibuf_rec_get_size (const rec_t *rec, const byte *types, ulint n_fields, bool comp) |
Get the data size. More... | |
static ulint | ibuf_rec_get_volume_func (mtr_t *mtr, const rec_t *ibuf_rec) |
Returns the space taken by a stored non-clustered index entry if converted to an index record. More... | |
ulint | ibuf_rec_get_volume (mtr_t *mtr, const rec_t *rec) |
static dtuple_t * | ibuf_entry_build (ibuf_op_t op, dict_index_t *index, const dtuple_t *entry, space_id_t space, page_no_t page_no, ulint counter, mem_heap_t *heap) |
Builds the tuple to insert to an ibuf tree when we have an entry for a non-clustered index. More... | |
static dtuple_t * | ibuf_search_tuple_build (space_id_t space, page_no_t page_no, mem_heap_t *heap) |
Builds a search tuple used to search buffered inserts for an index page. More... | |
static bool | ibuf_data_enough_free_for_insert (void) |
Checks if there are enough pages in the free list of the ibuf tree that we dare to start a pessimistic insert to the insert buffer. More... | |
static bool | ibuf_data_too_much_free (void) |
Checks if there are enough pages in the free list of the ibuf tree that we should remove them and free to the file space management. More... | |
static bool | ibuf_add_free_page (void) |
Allocates a new page from the ibuf file segment and adds it to the free list. More... | |
static void | ibuf_remove_free_page (void) |
Removes a page from the free list and frees it to the fsp system. More... | |
void | ibuf_free_excess_pages (void) |
Frees excess pages from the ibuf free list. More... | |
static ulint | ibuf_get_merge_page_nos_func (bool contract, const rec_t *rec, mtr_t *mtr, space_id_t *space_ids, page_no_t *page_nos, ulint *n_stored) |
Reads page numbers from a leaf in an ibuf tree. More... | |
static const rec_t * | ibuf_get_user_rec (btr_pcur_t *pcur, mtr_t *mtr) |
Get the matching records for space id. More... | |
ulint | ibuf_get_merge_page_nos (bool contract, const rec_t *rec, mtr_t *mtr, space_id_t *ids, page_no_t *pages, ulint *n_stored) |
static ulint | ibuf_get_merge_pages (btr_pcur_t *pcur, space_id_t space, ulint limit, page_no_t *pages, space_id_t *spaces, ulint *n_pages, mtr_t *mtr) |
Reads page numbers for a space id from an ibuf tree. More... | |
static ulint | ibuf_merge_pages (ulint *n_pages, bool sync) |
Contracts insert buffer trees by reading pages to the buffer pool. More... | |
ulint | ibuf_merge_space (space_id_t space) |
Contracts insert buffer trees by reading pages referring to space_id to the buffer pool. More... | |
static ulint | ibuf_merge (ulint *n_pages, bool sync) |
Contract the change buffer by reading pages to the buffer pool. More... | |
static ulint | ibuf_contract (bool sync) |
Contract the change buffer by reading pages to the buffer pool. More... | |
ulint | ibuf_merge_in_background (bool full) |
Contract the change buffer by reading pages to the buffer pool. More... | |
static void | ibuf_contract_after_insert (ulint entry_size) |
Contract insert buffer trees after insert if they are too big. More... | |
static bool | ibuf_get_volume_buffered_hash (const rec_t *rec, const byte *types, const byte *data, ulint comp, ulint *hash, ulint size) |
Determine if an insert buffer record has been encountered already. More... | |
static ulint | ibuf_get_volume_buffered_count_func (mtr_t *mtr, const rec_t *rec, ulint *hash, ulint size, lint *n_recs) |
Update the estimate of the number of records on a page, and get the space taken by merging the buffered record to the index page. More... | |
static ulint | ibuf_get_volume_buffered_count (mtr_t *mtr, const rec_t *rec, ulint *hash, ulint size, lint *n_recs) |
static ulint | ibuf_get_volume_buffered (const btr_pcur_t *pcur, space_id_t space, page_no_t page_no, lint *n_recs, mtr_t *mtr) |
Gets an upper limit for the combined size of entries buffered in the insert buffer for a given page. More... | |
void | ibuf_update_max_tablespace_id (void) |
Reads the biggest tablespace id from the high end of the insert buffer tree and updates the counter in fil_system. More... | |
static ulint | ibuf_get_entry_counter_low_func (mtr_t *mtr, const rec_t *rec, space_id_t space, page_no_t page_no) |
Helper function for ibuf_get_entry_counter_func. More... | |
static ulint | ibuf_get_entry_counter_func (space_id_t space, page_no_t page_no, const rec_t *rec, mtr_t *mtr, bool only_leaf) |
Calculate the counter field for an entry based on the current last record in ibuf for (space, page_no). More... | |
ulint | ibuf_get_entry_counter (space_id_t space, page_no_t page_no, const rec_t *rec, mtr_t *mtr, bool exact_leaf) |
static dberr_t | ibuf_insert_low (ulint mode, ibuf_op_t op, bool no_counter, const dtuple_t *entry, ulint entry_size, dict_index_t *index, const page_id_t &page_id, const page_size_t &page_size, que_thr_t *thr) |
Buffer an operation in the insert/delete buffer, instead of doing it directly to the disk page, if this is possible. More... | |
bool | ibuf_insert (ibuf_op_t op, const dtuple_t *entry, dict_index_t *index, const page_id_t &page_id, const page_size_t &page_size, que_thr_t *thr) |
Buffer an operation in the insert/delete buffer, instead of doing it directly to the disk page, if this is possible. More... | |
static rec_t * | ibuf_insert_to_index_page_low (const dtuple_t *entry, buf_block_t *block, dict_index_t *index, ulint **offsets, mem_heap_t *heap, mtr_t *mtr, page_cur_t *page_cur) |
During merge, inserts to an index page a secondary index entry extracted from the insert buffer. More... | |
static void | ibuf_insert_to_index_page (const dtuple_t *entry, buf_block_t *block, dict_index_t *index, mtr_t *mtr) |
static void | ibuf_set_del_mark (const dtuple_t *entry, buf_block_t *block, const dict_index_t *index, mtr_t *mtr) |
During merge, sets the delete mark on a record for a secondary index entry. More... | |
static void | ibuf_delete (const dtuple_t *entry, buf_block_t *block, dict_index_t *index, mtr_t *mtr) |
During merge, delete a record for a secondary index entry. More... | |
static bool | ibuf_restore_pos (space_id_t space_id, page_no_t page_no, const dtuple_t *search_tuple, ulint mode, btr_pcur_t *pcur, mtr_t *mtr) |
Restores insert buffer tree cursor position. More... | |
static bool | ibuf_delete_rec (space_id_t space, page_no_t page_no, btr_pcur_t *pcur, const dtuple_t *search_tuple, mtr_t *mtr) |
Deletes from ibuf the record on which pcur is positioned. More... | |
void | ibuf_merge_or_delete_for_page (buf_block_t *block, const page_id_t &page_id, const page_size_t *page_size, bool update_ibuf_bitmap) |
When an index page is read from a disk to the buffer pool, this function applies any buffered operations to the page and deletes the entries from the insert buffer. More... | |
void | ibuf_delete_for_discarded_space (space_id_t space) |
Deletes all entries in the insert buffer for a given space id. More... | |
bool | ibuf_is_empty (void) |
Looks if the insert buffer is empty. More... | |
void | ibuf_print (FILE *file) |
Prints info of ibuf. More... | |
dberr_t | ibuf_check_bitmap_on_import (const trx_t *trx, space_id_t space_id) |
Checks the insert buffer bitmaps on IMPORT TABLESPACE. More... | |
void | ibuf_set_bitmap_for_bulk_load (buf_block_t *block, bool reset) |
Updates free bits and buffered bits for bulk loaded page. More... | |
Insert buffer.
Created 7/19/1997 Heikki Tuuri
|
static |
Allocates a new page from the ibuf file segment and adds it to the free list.
Add accumulated operation counts to a permanent array.
Both arrays must be of size IBUF_OP_COUNT.
arr | in/out: array to modify |
ops | in: operation counts |
|
static |
Gets the ibuf bitmap page where the bits describing a given file page are stored.
[in] | page_id | Page id of the file page |
[in] | page_size | Page size of the file page |
[in] | location | Location where called |
[in,out] | mtr | Mini-transaction |
|
inline |
Gets the desired bits for a given page from a bitmap page.
[in] | page | Bitmap page |
[in] | page_id | Page id whose bits to get |
[in] | page_size | Page id whose bits to get |
[in] | bit | IBUF_BITMAP_FREE, IBUF_BITMAP_BUFFERED, ... |
[in,out] | mtr | Mini-transaction holding an x-latch on the bitmap page |
|
inlinestatic |
Gets the desired bits for a given page from a bitmap page.
[in] | page | Bitmap page |
[in] | page_id | Page id whose bits to get |
[in] | page_size | Page size |
[in] | latch_type | MTR_MEMO_PAGE_X_FIX, MTR_MEMO_BUF_FIX, ... |
[in,out] | mtr | Mini-transaction holding latch_type on the bitmap page |
[in] | bit | IBUF_BITMAP_FREE, IBUF_BITMAP_BUFFERED, ... |
void ibuf_bitmap_page_init | ( | buf_block_t * | block, |
mtr_t * | mtr | ||
) |
Initializes an ibuf bitmap page.
block | in: bitmap page |
mtr | in: mtr |
|
inlinestatic |
Calculates the bitmap page number for a given page number.
[in] | page_id | page id |
[in] | page_size | page size |
|
static |
Sets the desired bit for a given page in a bitmap page.
[in,out] | page | bitmap page |
[in] | page_id | page id whose bits to set |
[in] | page_size | page size |
[in] | bit | IBUF_BITMAP_FREE, IBUF_BITMAP_BUFFERED, ... |
[in] | val | value to set |
[in,out] | mtr | mtr containing an x-latch to the bitmap page |
|
inlinestatic |
Commits an insert buffer mini-transaction and sets the persistent cursor latch mode to BTR_NO_LATCHES, that is, detaches the cursor.
pcur | in/out: persistent cursor |
mtr | in/out: mini-transaction |
|
inline |
|
static |
Builds the entry used to.
1) IBUF_OP_INSERT: insert into a non-clustered index
2) IBUF_OP_DELETE_MARK: find the record whose delete-mark flag we need to activate
3) IBUF_OP_DELETE: find the record we need to delete
when we have the corresponding record in an ibuf index.
NOTE that as we copy pointers to fields in ibuf_rec, the caller must hold a latch to the ibuf_rec page as long as the entry is used!
[in] | mtr | mini-transaction owning rec |
[in] | ibuf_rec | record in an insert buffer |
[in] | heap | heap where built |
[out] | pindex | own: dummy index that describes the entry |
dberr_t ibuf_check_bitmap_on_import | ( | const trx_t * | trx, |
space_id_t | space_id | ||
) |
Checks the insert buffer bitmaps on IMPORT TABLESPACE.
trx | in: transaction |
space_id | in: tablespace identifier |
void ibuf_close | ( | void | ) |
Closes insert buffer and frees the data structures.
|
static |
Contract the change buffer by reading pages to the buffer pool.
[in] | sync | whether the caller waits for the issued reads to complete |
|
inlinestatic |
Contract insert buffer trees after insert if they are too big.
entry_size | in: size of a record which was inserted into an ibuf tree |
|
inlinestatic |
Checks if there are enough pages in the free list of the ibuf tree that we dare to start a pessimistic insert to the insert buffer.
|
inlinestatic |
Checks if there are enough pages in the free list of the ibuf tree that we should remove them and free to the file space management.
|
static |
During merge, delete a record for a secondary index entry.
entry | in: entry |
block | in/out: block |
index | in: record descriptor |
mtr | in/out: mtr; must be committed before latching any further pages |
void ibuf_delete_for_discarded_space | ( | space_id_t | space | ) |
Deletes all entries in the insert buffer for a given space id.
This is used in DISCARD TABLESPACE and IMPORT TABLESPACE. NOTE: this does not update the page free bitmaps in the space. The space will become CORRUPT when you call this function!
space | in: space id |
|
static |
Deletes from ibuf the record on which pcur is positioned.
If we have to resort to a pessimistic delete, this function commits mtr and closes the cursor.
space | in: space id |
page_no | in: index page number that the record should belong to |
pcur | in: pcur positioned on the record to delete, having latch mode BTR_MODIFY_LEAF |
search_tuple | in: search tuple for entries of page_no |
mtr | in: mtr |
|
static |
Add a column to the dummy index.
index | in: dummy index |
type | in: the data type of the column |
len | in: length of the column |
|
static |
Creates a dummy index for inserting a record to a non-clustered index.
n | in: number of fields |
comp | in: true=use compact record format |
|
static |
Deallocates a dummy index for inserting a record to a non-clustered index.
index | in, own: dummy index |
|
inlinestatic |
Sets the flag in the current mini-transaction record indicating we're inside an insert buffer routine.
mtr | in/out: mini-transaction |
|
static |
Builds the tuple to insert to an ibuf tree when we have an entry for a non-clustered index.
NOTE that the original entry must be kept because we copy pointers to its fields.
op | in: operation type |
index | in: non-clustered index |
entry | in: entry for a non-clustered index |
space | in: space id |
page_no | in: index page number where entry should be inserted |
counter | in: counter value; ULINT_UNDEFINED=not used |
heap | in: heap into which to build |
|
inlinestatic |
Sets the flag in the current mini-transaction record indicating we're exiting an insert buffer routine.
mtr | in/out: mini-transaction |
|
inlinestatic |
Returns true if the page is one of the fixed address ibuf pages.
[in] | page_id | page id |
[in] | page_size | page size |
void ibuf_free_excess_pages | ( | void | ) |
Frees excess pages from the ibuf free list.
This function is called when an OS thread calls fsp services to allocate a new file segment, or a new page to a file segment, and the thread did not own the fsp latch before this call.
|
inline |
|
static |
Calculate the counter field for an entry based on the current last record in ibuf for (space, page_no).
[in] | space | space id of entry |
[in] | page_no | page number of entry |
[in] | rec | the record preceding the insertion point |
mtr | mini-transaction | |
[in] | only_leaf | true if this is the only leaf page that can contain entries for (space,page_no), that is, there was no exact match for (space,page_no) in the node pointer |
|
static |
Helper function for ibuf_get_entry_counter_func.
Checks if rec is for (space, page_no), and if so, reads counter value from it and returns that + 1.
[in] | mtr | mini-transaction of rec |
[in] | rec | insert buffer record |
[in] | space | space id |
[in] | page_no | page number |
ULINT_UNDEFINED | if the record does not contain any counter |
0 | if the record is not for (space, page_no) |
1 | + previous counter value, otherwise |
|
inline |
|
static |
Reads page numbers from a leaf in an ibuf tree.
[in] | contract | true if this function is called to contract the tree, false if this is called when a single page becomes full and we look if it pays to read also nearby pages |
[in] | rec | insert buffer record |
[in] | mtr | mini-transaction holding rec |
[in,out] | space_ids | space id's of the pages |
[in,out] | page_nos | buffer for at least IBUF_MAX_N_PAGES_MERGED many page numbers; the page numbers are in an ascending order |
[out] | n_stored | number of page numbers stored to page_nos in this function |
|
static |
Reads page numbers for a space id from an ibuf tree.
pcur | in/out: cursor |
space | in: space for which to merge |
limit | in: max page numbers to read |
pages | out: pages read |
spaces | out: spaces read |
n_pages | out: number of pages read |
mtr | in: mini-transaction |
|
static |
Get the matching records for space id.
pcur | in: the current cursor |
mtr | in: mini-transaction |
|
static |
Gets an upper limit for the combined size of entries buffered in the insert buffer for a given page.
pcur | in: pcur positioned at a place in an insert buffer tree where we would insert an entry for the index page whose number is page_no, latch mode has to be BTR_MODIFY_PREV or BTR_MODIFY_TREE |
space | in: space id |
page_no | in: page number of an index page |
n_recs | in/out: minimum number of records on the page after the buffered changes have been applied, or NULL to disable the counting |
mtr | in: mini-transaction of pcur |
|
inlinestatic |
|
static |
Update the estimate of the number of records on a page, and get the space taken by merging the buffered record to the index page.
[in] | mtr | mini-transaction owning rec |
[in] | rec | insert buffer record |
[in,out] | hash | hash array |
[in] | size | number of elements in hash array |
[in,out] | n_recs | estimated number of records on the page that rec points to |
|
static |
Determine if an insert buffer record has been encountered already.
rec | in: ibuf record in post-4.1 format |
types | in: fields |
data | in: start of user record data |
comp | in: 0=ROW_FORMAT=REDUNDANT, nonzero=ROW_FORMAT=COMPACT |
hash | in/out: hash array |
size | in: number of elements in hash array |
Gets the ibuf header page and x-latches it.
mtr | in/out: mini-transaction |
void ibuf_init_at_db_start | ( | void | ) |
Creates the insert buffer data structure at a database startup and initializes the data structures for the insert buffer.
Creates the insert buffer data structure at a database startup.
bool ibuf_insert | ( | ibuf_op_t | op, |
const dtuple_t * | entry, | ||
dict_index_t * | index, | ||
const page_id_t & | page_id, | ||
const page_size_t & | page_size, | ||
que_thr_t * | thr | ||
) |
Buffer an operation in the insert/delete buffer, instead of doing it directly to the disk page, if this is possible.
Does not do it if the index is clustered or unique.
[in] | op | operation type |
[in] | entry | index entry to insert |
[in,out] | index | index where to insert |
[in] | page_id | page id where to insert |
[in] | page_size | page size |
[in,out] | thr | query thread |
|
static |
Buffer an operation in the insert/delete buffer, instead of doing it directly to the disk page, if this is possible.
[in] | mode | BTR_MODIFY_PREV or BTR_MODIFY_TREE |
[in] | op | operation type |
[in] | no_counter | true=use 5.0.3 format; false=allow delete buffering |
[in] | entry | index entry to insert |
[in] | entry_size | rec_get_converted_size(index, entry) |
[in,out] | index | index where to insert; must not be unique or clustered |
[in] | page_id | page id where to insert |
[in] | page_size | page size |
[in,out] | thr | query thread |
|
static |
entry | in: buffered entry to insert |
block | in/out: index page where the buffered entry should be placed |
index | in: record descriptor |
mtr | in: mtr |
|
static |
During merge, inserts to an index page a secondary index entry extracted from the insert buffer.
entry | in: buffered entry to insert |
block | in/out: index page where the buffered entry should be placed |
index | in: record descriptor |
offsets | out: offsets on *rec |
heap | in/out: memory heap |
mtr | in/out: mtr |
page_cur | in/out: cursor positioned on the record after which to insert the buffered entry |
bool ibuf_is_empty | ( | void | ) |
Looks if the insert buffer is empty.
void ibuf_max_size_update | ( | ulint | new_val | ) |
Updates the max_size value for ibuf.
in: new value in terms of percentage of the buffer pool size
new_val | in: new value in terms of percentage of the buffer pool size |
Contract the change buffer by reading pages to the buffer pool.
[out] | n_pages | number of pages merged |
[in] | sync | whether the caller waits for the issued reads to complete |
ulint ibuf_merge_in_background | ( | bool | full | ) |
Contract the change buffer by reading pages to the buffer pool.
[in] | full | If true, do a full contraction based on PCT_IO(100). If false, the size of contract batch is determined based on the current size of the change buffer. |
void ibuf_merge_or_delete_for_page | ( | buf_block_t * | block, |
const page_id_t & | page_id, | ||
const page_size_t * | page_size, | ||
bool | update_ibuf_bitmap | ||
) |
When an index page is read from a disk to the buffer pool, this function applies any buffered operations to the page and deletes the entries from the insert buffer.
If the page is not read, but created in the buffer pool, this function deletes its buffered entries from the insert buffer; there can exist entries for such a page if the page belonged to an index which subsequently was dropped.
[in,out] | block | if page has been read from disk, pointer to the page x-latched, else NULL |
[in] | page_id | page id of the index page |
[in] | update_ibuf_bitmap | normally this is set to true, but if we have deleted or are deleting the tablespace, then we naturally do not want to update a non-existent bitmap page |
[in] | page_size | page size |
Contracts insert buffer trees by reading pages to the buffer pool.
n_pages | out: number of pages to which merged |
sync | in: true if the caller wants to wait for the issued read with the highest tablespace address to complete |
ulint ibuf_merge_space | ( | space_id_t | space | ) |
Contracts insert buffer trees by reading pages referring to space_id to the buffer pool.
space | in: tablespace id to merge |
bool ibuf_page_low | ( | const page_id_t & | page_id, |
const page_size_t & | page_size, | ||
bool | x_latch, | ||
ut::Location | location, | ||
mtr_t * | mtr | ||
) |
Checks if a page is a level 2 or 3 page in the ibuf hierarchy of pages.
Must not be called when recv_no_ibuf_operations==true.
[in] | page_id | page id |
[in] | page_size | page size |
[in] | x_latch | false if relaxed check (avoid latching the bitmap page) |
[in] | location | Location where called |
[in,out] | mtr | mtr which will contain an x-latch to the bitmap page if the page is not one of the fixed address ibuf pages, or NULL, in which case a new transaction is created. |
byte * ibuf_parse_bitmap_init | ( | byte * | ptr, |
byte * | end_ptr, | ||
buf_block_t * | block, | ||
mtr_t * | mtr | ||
) |
Parses a redo log record of an ibuf bitmap page init.
[in] | ptr | Buffer. |
[in] | end_ptr | Buffer end. |
[in] | block | Block or nullptr. |
[in] | mtr | MTR or nullptr. |
void ibuf_print | ( | FILE * | file | ) |
Prints info of ibuf.
in: file where to print
file | in: file where to print |
|
static |
Print operation counts.
The array must be of size IBUF_OP_COUNT.
ops | in: operation counts |
file | in: file where to print |
Read the first two bytes from a record's fourth field (counter field in new records; something else in older records).
in: ibuf record
rec | in: ibuf record |
|
inline |
|
static |
Get various information about an ibuf record in >= 4.1.x format.
[in] | mtr | Mini-transaction owning rec, or nullptr if this is called from ibuf_rec_has_multi_value(). Because it's from page_validate() which doesn't have mtr at hand |
[in] | rec | Ibuf record |
[in,out] | op | Operation type, or NULL |
[in,out] | comp | Compact flag, or NULL |
[in,out] | info_len | Length of info fields at the start of the fourth field, or NULL |
[in] | counter | Counter value, or NULL |
Returns the operation type field of an ibuf record.
[in] | mtr | mini-transaction owning rec |
[in] | rec | ibuf record |
Returns the page number field of an ibuf record.
[in] | mtr | mini-transaction owning rec |
[in] | rec | ibuf record |
|
inlinestatic |
Get the data size.
rec | in: ibuf record |
types | in: fields |
n_fields | in: number of fields |
comp | in: 0=ROW_FORMAT=REDUNDANT, nonzero=ROW_FORMAT=COMPACT |
|
inlinestatic |
|
static |
Returns the space id field of an ibuf record.
For < 4.1.x format records returns 0.
[in] | mtr | mini-transaction owning rec |
[in] | rec | ibuf record |
Returns the space taken by a stored non-clustered index entry if converted to an index record.
[in] | mtr | mini-transaction owning rec |
[in] | ibuf_rec | ibuf record |
bool ibuf_rec_has_multi_value | ( | const rec_t * | rec | ) |
Determine if there is any multi-value field data on the change buffer record.
[in] | rec | ibuf record |
|
static |
Removes a page from the free list and frees it to the fsp system.
void ibuf_reset_free_bits | ( | buf_block_t * | block | ) |
Resets the free bits 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. NOTE: The free bits in the insert buffer bitmap must never exceed the free space on a page. It is safe to decrement or reset the bits in the bitmap in a mini-transaction that is committed before the mini-transaction that affects the free space.
block | in: index page; free bits are set to 0 if the index is a non-clustered non-unique, and page level is 0 |
|
static |
Restores insert buffer tree cursor position.
[in] | space_id | Tablespace id |
[in] | page_no | index page number where the record should belong |
[in] | search_tuple | search tuple for entries of page_no |
[in] | mode | BTR_MODIFY_LEAF or BTR_MODIFY_TREE |
[in,out] | pcur | persistent cursor whose position is to be restored |
[in,out] | mtr | mini-transaction |
|
static |
Builds a search tuple used to search buffered inserts for an index page.
This is for >= 4.1.x format records.
space | in: space id |
page_no | in: index page number |
heap | in: heap into which to build |
void ibuf_set_bitmap_for_bulk_load | ( | buf_block_t * | block, |
bool | reset | ||
) |
Updates free bits and buffered bits for bulk loaded page.
[in] | block | index page |
[in] | reset | flag if reset free val |
|
static |
During merge, sets the delete mark on a record for a secondary index entry.
entry | in: entry |
block | in/out: block |
index | in: record descriptor |
mtr | in: mtr |
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.
block | in: index page of a non-clustered index; free bit is reset if page level is 0 |
val | in: value to set: < 4 |
|
inlinestatic |
Sets the free bits 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.
block | in: index page; free bits are set if the index is non-clustered and page level is 0 |
val | in: value to set: < 4 |
mtr | in/out: mtr |
|
static |
Updates the size information of the ibuf, assuming the segment size has not changed.
root | in: ibuf tree root |
Gets the root page and sx-latches it.
mtr | in: mtr |
void ibuf_update_free_bits_for_two_pages_low | ( | buf_block_t * | block1, |
buf_block_t * | block2, | ||
mtr_t * | mtr | ||
) |
Updates the free bits for the two pages to reflect the present state.
Does this in the mtr given, which means that the latching order rules virtually prevent any further operations until mtr is committed. NOTE: The free bits in the insert buffer bitmap must never exceed the free space on a page. It is safe to set the free bits in the same mini-transaction that updated the pages.
block1 | in: index page |
block2 | in: index page |
mtr | in: mtr |
void ibuf_update_free_bits_low | ( | const buf_block_t * | block, |
ulint | max_ins_size, | ||
mtr_t * | mtr | ||
) |
Updates the free bits for an uncompressed page to reflect the present state.
Does this in the mtr given, which means that the latching order rules virtually prevent any further operations for this OS thread until mtr is committed. NOTE: The free bits in the insert buffer bitmap must never exceed the free space on a page. It is safe to set the free bits in the same mini-transaction that updated the page.
block | in: index page |
max_ins_size | in: value of maximum insert size with reorganize before the latest operation performed to the page |
mtr | in/out: mtr |
void ibuf_update_free_bits_zip | ( | buf_block_t * | block, |
mtr_t * | mtr | ||
) |
Updates the free bits for a compressed page to reflect the present state.
Does this in the mtr given, which means that the latching order rules virtually prevent any further operations for this OS thread until mtr is committed. NOTE: The free bits in the insert buffer bitmap must never exceed the free space on a page. It is safe to set the free bits in the same mini-transaction that updated the page.
block | in/out: index page |
mtr | in/out: mtr |
void ibuf_update_max_tablespace_id | ( | void | ) |
Reads the biggest tablespace id from the high end of the insert buffer tree and updates the counter in fil_system.
|
constexpr |
The start address for an insert buffer bitmap page bitmap.
|
constexpr |
true if there are buffered changes for the page
|
constexpr |
Bits indicating the amount of free space.
|
constexpr |
true if page is a part of the ibuf tree, excluding the root page, or is in the free list of the ibuf
|
static |
The mutex protecting the insert buffer bitmaps.
|
constexpr |
Number of bits describing a single page.
const ulint IBUF_CONTRACT_DO_NOT_INSERT = 10 |
If the combined size of the ibuf trees exceeds ibuf->max_size by this many pages, we start to contract it synchronous contract, but do not insert.
const ulint IBUF_CONTRACT_ON_INSERT_NON_SYNC = 0 |
If the combined size of the ibuf trees exceeds ibuf->max_size by this many pages, we start to contract it in connection to inserts there, using non-synchronous contract.
const ulint IBUF_CONTRACT_ON_INSERT_SYNC = 5 |
If the combined size of the ibuf trees exceeds ibuf->max_size by this many pages, we start to contract it in connection to inserts there, using synchronous contract.
uint ibuf_debug |
Flag to control insert buffer debugging.
const ulint IBUF_MAX_N_PAGES_MERGED = IBUF_MERGE_AREA |
In ibuf_contract at most this number of pages is read to memory in one batch, in order to merge the entries for them in the insert buffer.
const ulint IBUF_MERGE_AREA = 8 |
The area in pages from which contract looks for page numbers for merge.
const ulint IBUF_MERGE_THRESHOLD = 4 |
Inside the merge area, pages which have at most 1 per this number less buffered entries compared to maximum volume that can buffered for a single page are merged along with the page whose buffer became full.
|
static |
The mutex protecting the insert buffer structs.
|
static |
The mutex used to block pessimistic inserts to ibuf trees.
|
constexpr |
Set in IBUF_REC_OFFSET_FLAGS if the user index is in COMPACT format or later.
|
constexpr |
starting with 4.1, a marker consisting of 1 byte that is 0
|
constexpr |
the metadata field
|
constexpr |
starting with 4.1, the page number
|
constexpr |
in the pre-4.1 format, the page number.
later, the space_id
|
constexpr |
first user field
|
constexpr |
Combined size of info fields at the beginning of the fourth field.
|
constexpr |
Operation counter.
|
constexpr |
Additional flags.
|
constexpr |
Type of operation.
ulong innodb_change_buffering = IBUF_USE_ALL |
Operations that can currently be buffered.
bool srv_ibuf_disable_background_merge |