MySQL 9.0.0
Source Code Documentation
btr0cur.h File Reference

The index tree cursor. More...

#include <stddef.h>
#include <sys/types.h>
#include "btr0types.h"
#include "dict0dict.h"
#include "gis0type.h"
#include "page0cur.h"
#include "univ.i"
#include "ha0ha.h"
#include "que0types.h"
#include "row0types.h"
#include "btr0cur.ic"

Go to the source code of this file.

Classes

struct  btr_latch_leaves_t
 
struct  btr_path_t
 A slot in the path array. More...
 
struct  btr_cur_t
 The tree cursor: the definition appears here only for the compiler to know struct size! More...
 

Macros

#define BTR_CUR_PAGE_COMPRESS_LIMIT(index)    ((UNIV_PAGE_SIZE * (ulint)((index)->merge_threshold)) / 100)
 In the pessimistic delete, if the page data size drops below this limit, merging it to a neighbor is tried. More...
 

Enumerations

enum  {
  BTR_NO_UNDO_LOG_FLAG = 1 , BTR_NO_LOCKING_FLAG = 2 , BTR_KEEP_SYS_FLAG = 4 , BTR_KEEP_POS_FLAG = 8 ,
  BTR_CREATE_FLAG = 16 , BTR_KEEP_IBUF_BITMAP = 32
}
 Mode flags for btr_cur operations; these can be ORed. More...
 
enum  btr_cur_method {
  BTR_CUR_UNSET = 0 , BTR_CUR_HASH = 1 , BTR_CUR_HASH_NOT_ATTEMPTED , BTR_CUR_HASH_FAIL ,
  BTR_CUR_BINARY , BTR_CUR_INSERT_TO_IBUF , BTR_CUR_DEL_MARK_IBUF , BTR_CUR_DELETE_IBUF ,
  BTR_CUR_DELETE_REF
}
 Values for the flag documenting the used search method. More...
 

Functions

static page_cur_tbtr_cur_get_page_cur (const btr_cur_t *cursor)
 Returns the page cursor component of a tree cursor. More...
 
static buf_block_tbtr_cur_get_block (const btr_cur_t *cursor)
 Returns the buffer block on which the tree cursor is positioned. More...
 
static rec_tbtr_cur_get_rec (const btr_cur_t *cursor)
 Returns the record pointer of a tree cursor. More...
 
static page_zip_des_tbtr_cur_get_page_zip (btr_cur_t *cursor)
 Returns the compressed page on which the tree cursor is positioned. More...
 
static page_tbtr_cur_get_page (btr_cur_t *cursor)
 Returns the page of a tree cursor. More...
 
static void btr_cur_position (dict_index_t *index, rec_t *rec, buf_block_t *block, btr_cur_t *cursor)
 Positions a tree cursor at a given record. More...
 
bool btr_cur_optimistic_latch_leaves (buf_block_t *block, uint64_t modify_clock, ulint *latch_mode, btr_cur_t *cursor, const char *file, ulint line, mtr_t *mtr)
 Optimistically latches the leaf page or pages requested. More...
 
void btr_cur_search_to_nth_level (dict_index_t *index, ulint level, const dtuple_t *tuple, page_cur_mode_t mode, ulint latch_mode, btr_cur_t *cursor, ulint has_search_latch, const char *file, ulint line, mtr_t *mtr)
 Searches an index tree and positions a tree cursor on a given level. More...
 
void btr_cur_search_to_nth_level_with_no_latch (dict_index_t *index, ulint level, const dtuple_t *tuple, page_cur_mode_t mode, btr_cur_t *cursor, const char *file, ulint line, mtr_t *mtr, bool mark_dirty=true)
 Searches an index tree and positions a tree cursor on a given level. More...
 
void btr_cur_open_at_index_side (bool from_left, dict_index_t *index, ulint latch_mode, btr_cur_t *cursor, ulint level, ut::Location location, mtr_t *mtr)
 Opens a cursor at either end of an index. More...
 
void btr_cur_open_at_index_side_with_no_latch (bool from_left, dict_index_t *index, btr_cur_t *cursor, ulint level, ut::Location location, mtr_t *mtr)
 Opens a cursor at either end of an index. More...
 
bool btr_cur_open_at_rnd_pos (dict_index_t *index, ulint latch_mode, btr_cur_t *cursor, const char *file, ulint line, mtr_t *mtr)
 Positions a cursor at a randomly chosen position within a B-tree. More...
 
dberr_t btr_cur_optimistic_insert (ulint flags, btr_cur_t *cursor, ulint **offsets, mem_heap_t **heap, dtuple_t *entry, rec_t **rec, big_rec_t **big_rec, que_thr_t *thr, mtr_t *mtr)
 Tries to perform an insert to a page in an index tree, next to cursor. More...
 
dberr_t btr_cur_pessimistic_insert (uint32_t flags, btr_cur_t *cursor, ulint **offsets, mem_heap_t **heap, dtuple_t *entry, rec_t **rec, big_rec_t **big_rec, que_thr_t *thr, mtr_t *mtr)
 Performs an insert on a page of an index tree. More...
 
bool btr_cur_update_alloc_zip_func (page_zip_des_t *page_zip, page_cur_t *cursor, dict_index_t *index, ulint *offsets, ulint length, bool create, mtr_t *mtr)
 See if there is enough place in the page modification log to log an update-in-place. More...
 
bool btr_cur_update_alloc_zip (page_zip_des_t *page_zip, page_cur_t *cursor, dict_index_t *index, ulint *offsets, ulint len, bool cr, mtr_t *mtr)
 
dberr_t btr_cur_update_in_place (ulint flags, btr_cur_t *cursor, ulint *offsets, const upd_t *update, ulint cmpl_info, que_thr_t *thr, trx_id_t trx_id, mtr_t *mtr)
 Updates a record when the update causes no size changes in its fields. More...
 
void btr_cur_update_in_place_log (ulint flags, const rec_t *rec, dict_index_t *index, const upd_t *update, trx_id_t trx_id, roll_ptr_t roll_ptr, mtr_t *mtr)
 Writes a redo log record of updating a record in-place. More...
 
dberr_t btr_cur_optimistic_update (ulint flags, btr_cur_t *cursor, ulint **offsets, mem_heap_t **heap, const upd_t *update, ulint cmpl_info, que_thr_t *thr, trx_id_t trx_id, mtr_t *mtr)
 Tries to update a record on a page in an index tree. More...
 
dberr_t btr_cur_pessimistic_update (ulint flags, btr_cur_t *cursor, ulint **offsets, mem_heap_t **offsets_heap, mem_heap_t *entry_heap, big_rec_t **big_rec, upd_t *update, ulint cmpl_info, que_thr_t *thr, trx_id_t trx_id, undo_no_t undo_no, mtr_t *mtr, btr_pcur_t *pcur=nullptr)
 Performs an update of a record on a page of a tree. More...
 
dberr_t btr_cur_del_mark_set_clust_rec (ulint flags, buf_block_t *block, rec_t *rec, dict_index_t *index, const ulint *offsets, que_thr_t *thr, const dtuple_t *entry, mtr_t *mtr)
 Marks a clustered index record deleted. More...
 
dberr_t btr_cur_del_mark_set_sec_rec (ulint flags, btr_cur_t *cursor, bool val, que_thr_t *thr, mtr_t *mtr)
 Sets a secondary index record delete mark to true or false. More...
 
bool btr_cur_compress_if_useful (btr_cur_t *cursor, bool adjust, mtr_t *mtr)
 Tries to compress a page of the tree if it seems useful. More...
 
bool btr_cur_optimistic_delete_func (btr_cur_t *cursor, ulint flags, mtr_t *mtr)
 
bool btr_cur_optimistic_delete (btr_cur_t *cursor, ulint flags, mtr_t *mtr)
 Removes the record on which the tree cursor is positioned on a leaf page. More...
 
bool btr_cur_pessimistic_delete (dberr_t *err, bool has_reserved_extents, btr_cur_t *cursor, uint32_t flags, bool rollback, trx_id_t trx_id, undo_no_t undo_no, ulint rec_type, mtr_t *mtr, btr_pcur_t *pcur, purge_node_t *node)
 Removes the record on which the tree cursor is positioned. More...
 
const bytebtr_cur_parse_update_in_place (const byte *ptr, const byte *end_ptr, page_t *page, page_zip_des_t *page_zip, dict_index_t *index)
 Parses a redo log record of updating a record in-place. More...
 
const bytebtr_cur_parse_del_mark_set_clust_rec (const byte *ptr, const byte *end_ptr, page_t *page, page_zip_des_t *page_zip, dict_index_t *index)
 Parses the redo log record for delete marking or unmarking of a clustered index record. More...
 
const bytebtr_cur_parse_del_mark_set_sec_rec (const byte *ptr, const byte *end_ptr, page_t *page, page_zip_des_t *page_zip)
 Parses the redo log record for delete marking or unmarking of a secondary index record. More...
 
int64_t btr_estimate_n_rows_in_range (dict_index_t *index, const dtuple_t *tuple1, page_cur_mode_t mode1, const dtuple_t *tuple2, page_cur_mode_t mode2)
 Estimates the number of rows in a given index range. More...
 
bool btr_estimate_number_of_different_key_vals (dict_index_t *index)
 Estimates the number of different key values in a given index, for each n-column prefix of the index where 1 <= n <= dict_index_get_n_unique(index). More...
 
bytebtr_rec_copy_externally_stored_field_func (trx_t *trx, dict_index_t *index, const rec_t *rec, const ulint *offsets, const page_size_t &page_size, ulint no, ulint *len, size_t *lob_version, bool is_sdi, mem_heap_t *heap)
 Copies an externally stored field of a record to mem heap. More...
 
void btr_cur_set_deleted_flag_for_ibuf (rec_t *rec, page_zip_des_t *page_zip, bool val, mtr_t *mtr)
 Sets a secondary index record's delete mark to the given value. More...
 
static void btr_rec_set_deleted_flag (rec_t *rec, page_zip_des_t *page_zip, bool flag)
 The following function is used to set the deleted bit of a record. More...
 
btr_latch_leaves_t btr_cur_latch_leaves (buf_block_t *block, const page_id_t &page_id, const page_size_t &page_size, ulint latch_mode, btr_cur_t *cursor, mtr_t *mtr)
 Latches the leaf page or pages requested. More...
 
bool materialize_instant_default (const dict_index_t *index, const rec_t *rec)
 If default value of INSTANT ADD column is to be materialize in updated row. More...
 

Variables

constexpr uint32_t BTR_PATH_ARRAY_N_SLOTS = 250
 size of path array (in slots) More...
 
constexpr uint32_t BTR_CUR_RETRY_DELETE_N_TIMES = 100
 If pessimistic delete fails because of lack of file space, there is still a good change of success a little later. More...
 
constexpr uint32_t BTR_CUR_RETRY_SLEEP_TIME_MS = 50
 If pessimistic delete fails because of lack of file space, there is still a good change of success a little later. More...
 
ulint btr_cur_n_non_sea
 Number of searches down the B-tree in btr_cur_search_to_nth_level(). More...
 
ulint btr_cur_n_sea
 Number of successful adaptive hash index lookups in btr_cur_search_to_nth_level(). More...
 
ulint btr_cur_n_non_sea_old
 Old value of btr_cur_n_non_sea. More...
 
ulint btr_cur_n_sea_old
 Old value of btr_cur_n_sea. More...
 
uint btr_cur_limit_optimistic_insert_debug
 

Detailed Description

The index tree cursor.

Created 10/16/1994 Heikki Tuuri

Macro Definition Documentation

◆ BTR_CUR_PAGE_COMPRESS_LIMIT

#define BTR_CUR_PAGE_COMPRESS_LIMIT (   index)     ((UNIV_PAGE_SIZE * (ulint)((index)->merge_threshold)) / 100)

In the pessimistic delete, if the page data size drops below this limit, merging it to a neighbor is tried.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Mode flags for btr_cur operations; these can be ORed.

Enumerator
BTR_NO_UNDO_LOG_FLAG 

do no undo logging

BTR_NO_LOCKING_FLAG 

do no record lock checking

BTR_KEEP_SYS_FLAG 

sys fields will be found in the update vector or inserted entry

BTR_KEEP_POS_FLAG 

btr_cur_pessimistic_update() must keep cursor position when moving columns to big_rec

BTR_CREATE_FLAG 

the caller is creating the index or wants to bypass the index->info.online creation log

BTR_KEEP_IBUF_BITMAP 

the caller of btr_cur_optimistic_update() or btr_cur_update_in_place() will take care of updating IBUF_BITMAP_FREE

◆ btr_cur_method

Values for the flag documenting the used search method.

Enumerator
BTR_CUR_UNSET 

Flag for initialization only, not in real use.

BTR_CUR_HASH 

successful shortcut using the hash index

BTR_CUR_HASH_NOT_ATTEMPTED 

a search using hash index was not performed.

BTR_CUR_HASH_FAIL 

failure using hash, success using binary search.

The record pointing by the cursor may need to be updated in AHI.

BTR_CUR_BINARY 

success using the binary search

BTR_CUR_INSERT_TO_IBUF 

performed the intended insert to the insert buffer

BTR_CUR_DEL_MARK_IBUF 

performed the intended delete mark in the insert/delete buffer

BTR_CUR_DELETE_IBUF 

performed the intended delete in the insert/delete buffer

BTR_CUR_DELETE_REF 

row_purge_poss_sec() failed

Function Documentation

◆ btr_cur_compress_if_useful()

bool btr_cur_compress_if_useful ( btr_cur_t cursor,
bool  adjust,
mtr_t mtr 
)

Tries to compress a page of the tree if it seems useful.

It is assumed that mtr holds an x-latch on the tree and on the cursor page. To avoid deadlocks, mtr must also own x-latches to brothers of page, if those brothers exist. NOTE: it is assumed that the caller has reserved enough free extents so that the compression will always succeed if done!

Returns
true if compression occurred in/out: mini-transaction

It is assumed that mtr holds an x-latch on the tree and on the cursor page. To avoid deadlocks, mtr must also own x-latches to brothers of page, if those brothers exist. NOTE: it is assumed that the caller has reserved enough free extents so that the compression will always succeed if done!

Returns
true if compression occurred
Parameters
cursorin/out: cursor on the page to compress; cursor does not stay valid if !adjust and compression occurs
adjustin: true if should adjust the cursor position even if compression occurs
mtrin/out: mini-transaction

◆ btr_cur_del_mark_set_clust_rec()

dberr_t btr_cur_del_mark_set_clust_rec ( ulint  flags,
buf_block_t block,
rec_t rec,
dict_index_t index,
const ulint offsets,
que_thr_t thr,
const dtuple_t entry,
mtr_t mtr 
)

Marks a clustered index record deleted.

Writes an undo log record to undo log on this delete marking. Writes in the trx id field the id of the deleting transaction, and in the roll ptr field pointer to the undo log record created.

Returns
DB_SUCCESS, DB_LOCK_WAIT, or error number in/out: mini-transaction

Writes an undo log record to undo log on this delete marking. Writes in the trx id field the id of the deleting transaction, and in the roll ptr field pointer to the undo log record created.

Returns
DB_SUCCESS, DB_LOCK_WAIT, or error number
Parameters
flagsin: undo logging and locking flags
blockin/out: buffer block of the record
recin/out: record
indexin: clustered index of the record
offsetsin: rec_get_offsets(rec)
thrin: query thread
entryin: dtuple for the deleting record, also contains the virtual cols if there are any
mtrin/out: mini-transaction

◆ btr_cur_del_mark_set_sec_rec()

dberr_t btr_cur_del_mark_set_sec_rec ( ulint  flags,
btr_cur_t cursor,
bool  val,
que_thr_t thr,
mtr_t mtr 
)

Sets a secondary index record delete mark to true or false.

Returns
DB_SUCCESS, DB_LOCK_WAIT, or error number in/out: mini-transaction
DB_SUCCESS, DB_LOCK_WAIT, or error number
Parameters
flagsin: locking flag
cursorin: cursor
valin: value to set
thrin: query thread
mtrin/out: mini-transaction

◆ btr_cur_get_block()

static buf_block_t * btr_cur_get_block ( const btr_cur_t cursor)
inlinestatic

Returns the buffer block on which the tree cursor is positioned.

Returns
pointer to buffer block in: tree cursor

◆ btr_cur_get_page()

static page_t * btr_cur_get_page ( btr_cur_t cursor)
inlinestatic

Returns the page of a tree cursor.

Returns
pointer to page in: tree cursor

◆ btr_cur_get_page_cur()

static page_cur_t * btr_cur_get_page_cur ( const btr_cur_t cursor)
inlinestatic

Returns the page cursor component of a tree cursor.

Returns
pointer to page cursor component in: tree cursor

◆ btr_cur_get_page_zip()

static page_zip_des_t * btr_cur_get_page_zip ( btr_cur_t cursor)
inlinestatic

Returns the compressed page on which the tree cursor is positioned.

Returns
pointer to compressed page, or NULL if the page is not compressed in: tree cursor

◆ btr_cur_get_rec()

static rec_t * btr_cur_get_rec ( const btr_cur_t cursor)
inlinestatic

Returns the record pointer of a tree cursor.

Returns
pointer to record in: tree cursor

◆ btr_cur_latch_leaves()

btr_latch_leaves_t btr_cur_latch_leaves ( buf_block_t block,
const page_id_t page_id,
const page_size_t page_size,
ulint  latch_mode,
btr_cur_t cursor,
mtr_t mtr 
)

Latches the leaf page or pages requested.

Parameters
[in]blockLeaf page where the search converged
[in]page_idPage id of the leaf
[in]page_sizePage size
[in]latch_modeBTR_SEARCH_LEAF, ...
[in]cursorCursor
[in]mtrMini-transaction
Returns
blocks and savepoints which actually latched.

◆ btr_cur_open_at_index_side()

void btr_cur_open_at_index_side ( bool  from_left,
dict_index_t index,
ulint  latch_mode,
btr_cur_t cursor,
ulint  level,
ut::Location  location,
mtr_t mtr 
)

Opens a cursor at either end of an index.

Parameters
[in]from_leftTrue if open to the low end, false if to the high end
[in]indexIndex
[in]latch_modeLatch mode
[in,out]cursorCursor
[in]levelLevel to search for (0=leaf)
[in]locationLocation where called
[in,out]mtrMini-transaction

◆ btr_cur_open_at_index_side_with_no_latch()

void btr_cur_open_at_index_side_with_no_latch ( bool  from_left,
dict_index_t index,
btr_cur_t cursor,
ulint  level,
ut::Location  location,
mtr_t mtr 
)

Opens a cursor at either end of an index.

Avoid taking latches on buffer, just pin (by incrementing fix_count) to keep them in buffer pool. This mode is used by intrinsic table as they are not shared and so there is no need of latching.

Parameters
[in]from_lefttrue if open to low end, false if open to high end.
[in]indexIndex
[in,out]cursorCursor
[in]levelLevel to search for (0=leaf)
[in]locationLocation where called
[in,out]mtrMini-transaction

◆ btr_cur_open_at_rnd_pos()

bool btr_cur_open_at_rnd_pos ( dict_index_t index,
ulint  latch_mode,
btr_cur_t cursor,
const char *  file,
ulint  line,
mtr_t mtr 
)

Positions a cursor at a randomly chosen position within a B-tree.

Returns
true if the index is available and we have put the cursor, false if the index is unavailable in: mtr
true if the index is available and we have put the cursor, false if the index is unavailable
Parameters
indexin: index
latch_modein: BTR_SEARCH_LEAF, ...
cursorin/out: B-tree cursor
filein: file name
linein: line where called
mtrin: mtr

◆ btr_cur_optimistic_delete()

bool btr_cur_optimistic_delete ( btr_cur_t cursor,
ulint  flags,
mtr_t mtr 
)
inline

Removes the record on which the tree cursor is positioned on a leaf page.

It is assumed that the mtr has an x-latch on the page where the cursor is positioned, but no latch on the whole tree.

Parameters
[in]cursorcursor on leaf page, on the record to delete; cursor stays valid: if deletion succeeds, on function exit it points to the successor of the deleted record
[in]flagsBTR_CREATE_FLAG or 0
[in]mtrif this function returns true on a leaf page of a secondary index, the mtr must be committed before latching any further pages
Returns
true if success, i.e., the page did not become too empty

◆ btr_cur_optimistic_delete_func()

bool btr_cur_optimistic_delete_func ( btr_cur_t cursor,
ulint  flags,
mtr_t mtr 
)

◆ btr_cur_optimistic_insert()

dberr_t btr_cur_optimistic_insert ( ulint  flags,
btr_cur_t cursor,
ulint **  offsets,
mem_heap_t **  heap,
dtuple_t entry,
rec_t **  rec,
big_rec_t **  big_rec,
que_thr_t thr,
mtr_t mtr 
)

Tries to perform an insert to a page in an index tree, next to cursor.

It is assumed that mtr holds an x-latch on the page. The operation does not succeed if there is too little space on the page. If there is just one record on the page, the insert will always succeed; this is to prevent trying to split a page with just one record.

Returns
DB_SUCCESS, DB_WAIT_LOCK, DB_FAIL, or error number in/out: mini-transaction; if this function returns DB_SUCCESS on a leaf page of a secondary index in a compressed tablespace, the caller must mtr_commit(mtr) before latching any further pages

It is assumed that mtr holds an x-latch on the page. The operation does not succeed if there is too little space on the page. If there is just one record on the page, the insert will always succeed; this is to prevent trying to split a page with just one record.

Returns
DB_SUCCESS, DB_WAIT_LOCK, DB_FAIL, or error number
Parameters
flagsin: undo logging and locking flags: if not zero, the parameters index and thr should be specified
cursorin: cursor on page after which to insert; cursor stays valid
offsetsout: offsets on *rec
heapin/out: pointer to memory heap, or NULL
entryin/out: entry to insert
recout: pointer to inserted record if succeed
big_recout: big rec vector whose fields have to be stored externally by the caller, or NULL
thrin: query thread or NULL
mtrin/out: mini-transaction; if this function returns DB_SUCCESS on a leaf page of a secondary index in a compressed tablespace, the caller must mtr_commit(mtr) before latching any further pages

◆ btr_cur_optimistic_latch_leaves()

bool btr_cur_optimistic_latch_leaves ( buf_block_t block,
uint64_t  modify_clock,
ulint latch_mode,
btr_cur_t cursor,
const char *  file,
ulint  line,
mtr_t mtr 
)

Optimistically latches the leaf page or pages requested.

Parameters
[in]blockGuessed buffer block
[in]modify_clockModify clock value
[in,out]latch_modeBTR_SEARCH_LEAF, ...
[in,out]cursorCursor
[in]fileFile name
[in]lineLine where called
[in]mtrMini-transaction
Returns
true if success

◆ btr_cur_optimistic_update()

dberr_t btr_cur_optimistic_update ( ulint  flags,
btr_cur_t cursor,
ulint **  offsets,
mem_heap_t **  heap,
const upd_t update,
ulint  cmpl_info,
que_thr_t thr,
trx_id_t  trx_id,
mtr_t mtr 
)

Tries to update a record on a page in an index tree.

It is assumed that mtr holds an x-latch on the page. The operation does not succeed if there is too little space on the page or if the update would result in too empty a page, so that tree compression is recommended. We assume here that the ordering fields of the record do not change.

Parameters
[in]flagsundo logging and locking flags
[in]cursorcursor on the record to update; cursor stays valid and positioned on the same record
[out]offsetsoffsets on cursor->page_cur.rec
[in,out]heappointer to nullptr or memory heap
[in]updateupdate vector; this must also contain trx id and roll ptr fields
[in]cmpl_infocompiler info on secondary index updates
[in]thrquery thread, or nullptr if flags & (BTR_NO_UNDO_LOG_FLAG | BTR_NO_LOCKING_FLAG | BTR_CREATE_FLAG | BTR_KEEP_SYS_FLAG)
[in]trx_idtransaction id
[in,out]mtrmini-transaction; if this is a secondary index, the caller must mtr_commit(mtr) before latching any further pages
Returns
error code, including
Return values
DB_SUCCESSon success
DB_OVERFLOWif the updated record does not fit
DB_UNDERFLOWif the page would become too empty
DB_ZIP_OVERFLOWif there is not enough space left on the compressed page (IBUF_BITMAP_FREE was reset outside mtr)

◆ btr_cur_parse_del_mark_set_clust_rec()

const byte * btr_cur_parse_del_mark_set_clust_rec ( const byte ptr,
const byte end_ptr,
page_t page,
page_zip_des_t page_zip,
dict_index_t index 
)

Parses the redo log record for delete marking or unmarking of a clustered index record.

Returns
end of log record or NULL in: index corresponding to page
end of log record or NULL
Parameters
ptrin: buffer
end_ptrin: buffer end
pagein/out: page or NULL
page_zipin/out: compressed page, or NULL
indexin: index corresponding to page

◆ btr_cur_parse_del_mark_set_sec_rec()

const byte * btr_cur_parse_del_mark_set_sec_rec ( const byte ptr,
const byte end_ptr,
page_t page,
page_zip_des_t page_zip 
)

Parses the redo log record for delete marking or unmarking of a secondary index record.

Returns
end of log record or NULL in/out: compressed page, or NULL
end of log record or NULL
Parameters
ptrin: buffer
end_ptrin: buffer end
pagein/out: page or NULL
page_zipin/out: compressed page, or NULL

◆ btr_cur_parse_update_in_place()

const byte * btr_cur_parse_update_in_place ( const byte ptr,
const byte end_ptr,
page_t page,
page_zip_des_t page_zip,
dict_index_t index 
)

Parses a redo log record of updating a record in-place.

Returns
end of log record or NULL in: index corresponding to page
end of log record or NULL
Parameters
ptrin: buffer
end_ptrin: buffer end
pagein/out: page or NULL
page_zipin/out: compressed page, or NULL
indexin: index corresponding to page

◆ btr_cur_pessimistic_delete()

bool btr_cur_pessimistic_delete ( dberr_t err,
bool  has_reserved_extents,
btr_cur_t cursor,
uint32_t  flags,
bool  rollback,
trx_id_t  trx_id,
undo_no_t  undo_no,
ulint  rec_type,
mtr_t mtr,
btr_pcur_t pcur,
purge_node_t node 
)

Removes the record on which the tree cursor is positioned.

Tries to compress the page if its fillfactor drops below a threshold or if it is the only page on the level. It is assumed that mtr holds an x-latch on the tree and on the cursor page. To avoid deadlocks, mtr must also own x-latches to brothers of page, if those brothers exist.

Parameters
[out]errDB_SUCCESS or DB_OUT_OF_FILE_SPACE; the latter may occur because we may have to update node pointers on upper levels, and in the case of variable length keys these may actually grow in size
[in]has_reserved_extentstrue if the caller has already reserved enough free extents so that he knows that the operation will succeed
[in]cursorCursor on the record to delete; if compression does not occur, the cursor stays valid: it points to successor of deleted record on function exit
[in]flagsBTR_CREATE_FLAG or 0
[in]rollbackTrue if performing rollback, false otherwise.
[in]trx_idThe current transaction id.
[in]undo_noUndo number of the transaction. This is needed for rollback to savepoint of partially updated LOB.
[in]rec_typeUndo record type.
[in]mtrThe mini transaction
[in]pcurPersistent cursor on the record to delete.
[in,out]nodepurge node or nullptr
Returns
true if compression occurred

◆ btr_cur_pessimistic_insert()

dberr_t btr_cur_pessimistic_insert ( uint32_t  flags,
btr_cur_t cursor,
ulint **  offsets,
mem_heap_t **  heap,
dtuple_t entry,
rec_t **  rec,
big_rec_t **  big_rec,
que_thr_t thr,
mtr_t mtr 
)

Performs an insert on a page of an index tree.

It is assumed that mtr holds an x-latch on the tree and on the cursor page. If the insert is made on the leaf level, to avoid deadlocks, mtr must also own x-latches to brothers of page, if those brothers exist.

Returns
DB_SUCCESS or error number in/out: mini-transaction

It is assumed that mtr holds an x-latch on the tree and on the cursor page. If the insert is made on the leaf level, to avoid deadlocks, mtr must also own x-latches to brothers of page, if those brothers exist.

Returns
DB_SUCCESS or error number
Parameters
flagsin: undo logging and locking flags: if not zero, the parameter thr should be specified; if no undo logging is specified, then the caller must have reserved enough free extents in the file space so that the insertion will certainly succeed
cursorin: cursor after which to insert; cursor stays valid
offsetsout: offsets on *rec
heapin/out: pointer to memory heap that can be emptied, or NULL
entryin/out: entry to insert
recout: pointer to inserted record if succeed
big_recout: big rec vector whose fields have to be stored externally by the caller, or NULL
thrin: query thread or NULL
mtrin/out: mini-transaction

◆ btr_cur_pessimistic_update()

dberr_t btr_cur_pessimistic_update ( ulint  flags,
btr_cur_t cursor,
ulint **  offsets,
mem_heap_t **  offsets_heap,
mem_heap_t entry_heap,
big_rec_t **  big_rec,
upd_t update,
ulint  cmpl_info,
que_thr_t thr,
trx_id_t  trx_id,
undo_no_t  undo_no,
mtr_t mtr,
btr_pcur_t pcur = nullptr 
)

Performs an update of a record on a page of a tree.

It is assumed that mtr holds an x-latch on the tree and on the cursor page. If the update is made on the leaf level, to avoid deadlocks, mtr must also own x-latches to brothers of page, if those brothers exist.

Parameters
[in]flagsUndo logging, locking, and rollback flags
[in,out]cursorcursor on the record to update; cursor may become invalid if *big_rec == NULL || !(flags & BTR_KEEP_POS_FLAG)
[out]offsetsOffsets on cursor->page_cur.rec
[in,out]offsets_heapPointer to memory heap that can be emptied, or NULL
[in,out]entry_heapMemory heap for allocating big_rec and the index tuple.
[out]big_recBig rec vector whose fields have to be stored externally by the caller, or NULL
[in,out]updateUpdate vector; this is allowed to also contain trx id and roll ptr fields. Non-updated columns that are moved offpage will be appended to this.
[in]cmpl_infoCompiler info on secondary index updates
[in]thrQuery thread, or NULL if flags & (BTR_NO_UNDO_LOG_FLAG | BTR_NO_LOCKING_FLAG | BTR_CREATE_FLAG | BTR_KEEP_SYS_FLAG)
[in]trx_idTransaction id
[in]undo_noUndo number of the transaction. This is needed for rollback to savepoint of partially updated LOB.
[in,out]mtrMini-transaction; must be committed before latching any further pages
[in]pcurThe persistent cursor on the record to update.
Returns
DB_SUCCESS or error code

◆ btr_cur_position()

static void btr_cur_position ( dict_index_t index,
rec_t rec,
buf_block_t block,
btr_cur_t cursor 
)
inlinestatic

Positions a tree cursor at a given record.

Parameters
[in]indexindex
[in]recrecord in tree
[in]blockbuffer block of rec
[in]cursorcursor

◆ btr_cur_search_to_nth_level()

void btr_cur_search_to_nth_level ( dict_index_t index,
ulint  level,
const dtuple_t tuple,
page_cur_mode_t  mode,
ulint  latch_mode,
btr_cur_t cursor,
ulint  has_search_latch,
const char *  file,
ulint  line,
mtr_t mtr 
)

Searches an index tree and positions a tree cursor on a given level.

NOTE: n_fields_cmp in tuple must be set so that it cannot be compared to node pointer page number fields on the upper levels of the tree! Note that if mode is PAGE_CUR_LE, which is used in inserts, then cursor->up_match and cursor->low_match both will have sensible values. If mode is PAGE_CUR_GE, then up_match will a have a sensible value. in: mtr

NOTE: n_fields_cmp in tuple must be set so that it cannot be compared to node pointer page number fields on the upper levels of the tree! Note that if mode is PAGE_CUR_LE, which is used in inserts, then cursor->up_match and cursor->low_match both will have sensible values. If mode is PAGE_CUR_GE, then up_match will a have a sensible value.

If mode is PAGE_CUR_LE , cursor is left at the place where an insert of the search tuple should be performed in the B-tree. InnoDB does an insert immediately after the cursor. Thus, the cursor may end up on a user record, or on a page infimum record.

Parameters
indexin: index
levelin: the tree level of search
tuplein: data tuple; NOTE: n_fields_cmp in tuple must be set so that it cannot get compared to the node ptr page number field!
modein: PAGE_CUR_L, ...; Inserts should always be made using PAGE_CUR_LE to search the position!
latch_modein: BTR_SEARCH_LEAF, ..., ORed with at most one of BTR_INSERT, BTR_DELETE_MARK, BTR_DELETE, or BTR_ESTIMATE; cursor->left_block is used to store a pointer to the left neighbor page, in the cases BTR_SEARCH_PREV and BTR_MODIFY_PREV; NOTE that if has_search_latch is != 0, we maybe do not have a latch set on the cursor page, we assume the caller uses his search latch to protect the record!
cursorin/out: tree cursor; the cursor page is s- or x-latched, but see also above!
has_search_latchin: info on the latch mode the caller currently has on search system: RW_S_LATCH, or 0
filein: file name
linein: line where called
mtrin: mtr

◆ btr_cur_search_to_nth_level_with_no_latch()

void btr_cur_search_to_nth_level_with_no_latch ( dict_index_t index,
ulint  level,
const dtuple_t tuple,
page_cur_mode_t  mode,
btr_cur_t cursor,
const char *  file,
ulint  line,
mtr_t mtr,
bool  mark_dirty 
)

Searches an index tree and positions a tree cursor on a given level.

This function will avoid placing latches while traversing the path and so should be used only for cases where-in latching is not needed.

Parameters
[in]indexIndex
[in]levelThe tree level of search
[in]tupleData tuple; Note: n_fields_cmp in compared to the node ptr page node field
[in]modePAGE_CUR_L, .... Insert should always be made using PAGE_CUR_LE to search the position.
[in,out]cursorTree cursor; points to record of interest.
[in]fileFile name
[in]lineLine where called from
[in,out]mtrMini-transaction
[in]mark_dirtyif true then mark the block as dirty

◆ btr_cur_set_deleted_flag_for_ibuf()

void btr_cur_set_deleted_flag_for_ibuf ( rec_t rec,
page_zip_des_t page_zip,
bool  val,
mtr_t mtr 
)

Sets a secondary index record's delete mark to the given value.

This function is only used by the insert buffer merge mechanism. in/out: mini-transaction

This function is only used by the insert buffer merge mechanism.

Parameters
recin/out: record
page_zipin/out: compressed page corresponding to rec, or NULL when the tablespace is uncompressed
valin: value to set
mtrin/out: mini-transaction

◆ btr_cur_update_alloc_zip()

bool btr_cur_update_alloc_zip ( page_zip_des_t page_zip,
page_cur_t cursor,
dict_index_t index,
ulint offsets,
ulint  len,
bool  cr,
mtr_t mtr 
)
inline

◆ btr_cur_update_alloc_zip_func()

bool btr_cur_update_alloc_zip_func ( page_zip_des_t page_zip,
page_cur_t cursor,
dict_index_t index,
ulint offsets,
ulint  length,
bool  create,
mtr_t mtr 
)

See if there is enough place in the page modification log to log an update-in-place.

Parameters
[in,out]page_zipCompressed page.
[in,out]cursorB-tree page cursor.
[in]indexThe index corresponding to cursor.
[in,out]offsetsOffsets of the cursor record.
[in]lengthsize needed
[in]createtrue=delete-and-insert, false=update-in-place
[in,out]mtrMini-transaction.
Return values
falseif out of space; IBUF_BITMAP_FREE will be reset outside mtr if the page was re-compressed
trueif enough place;

IMPORTANT: The caller will have to update IBUF_BITMAP_FREE if this is a secondary index leaf page. This has to be done either within the same mini-transaction, or by invoking ibuf_reset_free_bits() before mtr_commit(mtr).

◆ btr_cur_update_in_place()

dberr_t btr_cur_update_in_place ( ulint  flags,
btr_cur_t cursor,
ulint offsets,
const upd_t update,
ulint  cmpl_info,
que_thr_t thr,
trx_id_t  trx_id,
mtr_t mtr 
)

Updates a record when the update causes no size changes in its fields.

Parameters
[in]flagsUndo logging and locking flags
[in]cursorCursor on the record to update; cursor stays valid and positioned on the same record
[in,out]offsetsOffsets on cursor->page_cur.rec
[in]updateUpdate vector
[in]cmpl_infoCompiler info on secondary index updates
[in]thrQuery thread, or null if flags & (btr_no_locking_flag | btr_no_undo_log_flag | btr_create_flag | btr_keep_sys_flag)
[in]trx_idTransaction id
[in,out]mtrMini-transaction; if this is a secondary index, the caller must mtr_commit(mtr) before latching any further pages
Returns
locking or undo log related error code, or
Return values
DB_SUCCESSon success
DB_ZIP_OVERFLOWif there is not enough space left on the compressed page (IBUF_BITMAP_FREE was reset outside mtr)

◆ btr_cur_update_in_place_log()

void btr_cur_update_in_place_log ( ulint  flags,
const rec_t rec,
dict_index_t index,
const upd_t update,
trx_id_t  trx_id,
roll_ptr_t  roll_ptr,
mtr_t mtr 
)

Writes a redo log record of updating a record in-place.

Parameters
[in]flagsUndo logging and locking flags
[in]recRecord
[in]indexIndex of the record
[in]updateUpdate vector
[in]trx_idTransaction id
[in]roll_ptrRoll ptr
[in]mtrMini-transaction

◆ btr_estimate_n_rows_in_range()

int64_t btr_estimate_n_rows_in_range ( dict_index_t index,
const dtuple_t tuple1,
page_cur_mode_t  mode1,
const dtuple_t tuple2,
page_cur_mode_t  mode2 
)

Estimates the number of rows in a given index range.

Parameters
[in]indexindex
[in]tuple1range start, may also be empty tuple
[in]mode1search mode for range start
[in]tuple2range end, may also be empty tuple
[in]mode2search mode for range end
Returns
estimated number of rows

◆ btr_estimate_number_of_different_key_vals()

bool btr_estimate_number_of_different_key_vals ( dict_index_t index)

Estimates the number of different key values in a given index, for each n-column prefix of the index where 1 <= n <= dict_index_get_n_unique(index).

The estimates are stored in the array index->stat_n_diff_key_vals[] (indexed 0..n_uniq-1) and the number of pages that were sampled is saved in index->stat_n_sample_sizes[]. If innodb_stats_method is nulls_ignored, we also record the number of non-null values for each prefix and stored the estimates in array index->stat_n_non_null_key_vals.

Returns
true if the index is available and we get the estimated numbers, false if the index is unavailable. in: index

The estimates are stored in the array index->stat_n_diff_key_vals[] (indexed 0..n_uniq-1) and the number of pages that were sampled is saved in index->stat_n_sample_sizes[]. If innodb_stats_method is nulls_ignored, we also record the number of non-null values for each prefix and stored the estimates in array index->stat_n_non_null_key_vals.

Returns
true if the index is available and we get the estimated numbers, false if the index is unavailable.
Parameters
indexin: index

◆ btr_rec_copy_externally_stored_field_func()

byte * btr_rec_copy_externally_stored_field_func ( trx_t trx,
dict_index_t index,
const rec_t rec,
const ulint offsets,
const page_size_t page_size,
ulint  no,
ulint len,
size_t *  lob_version,
bool  is_sdi,
mem_heap_t heap 
)

Copies an externally stored field of a record to mem heap.

Parameters
[in]trxthe trx doing the operation.
[in]indexindex containing the LOB.
[in]recrecord in a clustered index; must be protected by a lock or a page latch
[in]offsetsarray returned by rec_get_offsets()
[in]page_sizeBLOB page size
[in]nofield number
[out]lenlength of the field
[out]lob_versionversion of lob
[in]is_sditrue for SDI Indexes
[in,out]heapmem heap
Returns
the field copied to heap, or NULL if the field is incomplete

◆ btr_rec_set_deleted_flag()

static void btr_rec_set_deleted_flag ( rec_t rec,
page_zip_des_t page_zip,
bool  flag 
)
inlinestatic

The following function is used to set the deleted bit of a record.

Parameters
[in,out]recphysical record
[in,out]page_zipcompressed page (or NULL)
[in]flagnonzero if delete marked

◆ materialize_instant_default()

bool materialize_instant_default ( const dict_index_t index,
const rec_t rec 
)

If default value of INSTANT ADD column is to be materialize in updated row.

Parameters
[in]indexrecord descriptor
[in]recrecord
Returns
true if instant add column(s) to be materialized.

Variable Documentation

◆ btr_cur_limit_optimistic_insert_debug

uint btr_cur_limit_optimistic_insert_debug
extern

◆ btr_cur_n_non_sea

ulint btr_cur_n_non_sea
extern

Number of searches down the B-tree in btr_cur_search_to_nth_level().

◆ btr_cur_n_non_sea_old

ulint btr_cur_n_non_sea_old
extern

Old value of btr_cur_n_non_sea.

Copied by srv_refresh_innodb_monitor_stats(). Referenced by srv_printf_innodb_monitor().

◆ btr_cur_n_sea

ulint btr_cur_n_sea
extern

Number of successful adaptive hash index lookups in btr_cur_search_to_nth_level().

◆ btr_cur_n_sea_old

ulint btr_cur_n_sea_old
extern

Old value of btr_cur_n_sea.

Copied by srv_refresh_innodb_monitor_stats(). Referenced by srv_printf_innodb_monitor().

◆ BTR_CUR_RETRY_DELETE_N_TIMES

constexpr uint32_t BTR_CUR_RETRY_DELETE_N_TIMES = 100
constexpr

If pessimistic delete fails because of lack of file space, there is still a good change of success a little later.

Try this many times.

◆ BTR_CUR_RETRY_SLEEP_TIME_MS

constexpr uint32_t BTR_CUR_RETRY_SLEEP_TIME_MS = 50
constexpr

If pessimistic delete fails because of lack of file space, there is still a good change of success a little later.

Sleep this many milliseconds between retries.

◆ BTR_PATH_ARRAY_N_SLOTS

constexpr uint32_t BTR_PATH_ARRAY_N_SLOTS = 250
constexpr

size of path array (in slots)