📄 btr0cur.h
字号:
/******************************************************The index tree cursor(c) 1994-1996 Innobase OyCreated 10/16/1994 Heikki Tuuri*******************************************************/#ifndef btr0cur_h#define btr0cur_h#include "univ.i"#include "dict0dict.h"#include "data0data.h"#include "page0cur.h"#include "btr0types.h"#include "que0types.h"#include "row0types.h"#include "ha0ha.h"/* Mode flags for btr_cur operations; these can be ORed */#define BTR_NO_UNDO_LOG_FLAG 1 /* do no undo logging */#define BTR_NO_LOCKING_FLAG 2 /* do no record lock checking */#define BTR_KEEP_SYS_FLAG 4 /* sys fields will be found from the update vector or inserted entry */#define BTR_CUR_ADAPT#define BTR_CUR_HASH_ADAPT/*************************************************************Returns the page cursor component of a tree cursor. */UNIV_INLINEpage_cur_t*btr_cur_get_page_cur(/*=================*/ /* out: pointer to page cursor component */ btr_cur_t* cursor);/* in: tree cursor *//*************************************************************Returns the record pointer of a tree cursor. */UNIV_INLINErec_t*btr_cur_get_rec(/*============*/ /* out: pointer to record */ btr_cur_t* cursor);/* in: tree cursor *//*************************************************************Invalidates a tree cursor by setting record pointer to NULL. */UNIV_INLINEvoidbtr_cur_invalidate(/*===============*/ btr_cur_t* cursor);/* in: tree cursor *//*************************************************************Returns the page of a tree cursor. */UNIV_INLINEpage_t*btr_cur_get_page(/*=============*/ /* out: pointer to page */ btr_cur_t* cursor);/* in: tree cursor *//*************************************************************Returns the tree of a cursor. */UNIV_INLINEdict_tree_t*btr_cur_get_tree(/*=============*/ /* out: tree */ btr_cur_t* cursor);/* in: tree cursor *//*************************************************************Positions a tree cursor at a given record. */UNIV_INLINEvoidbtr_cur_position(/*=============*/ dict_index_t* index, /* in: index */ rec_t* rec, /* in: record in tree */ btr_cur_t* cursor);/* in: cursor *//************************************************************************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 comparedto 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, thencursor->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. */voidbtr_cur_search_to_nth_level(/*========================*/ dict_index_t* index, /* in: index */ ulint level, /* in: the tree level of search */ dtuple_t* tuple, /* in: data tuple; NOTE: n_fields_cmp in tuple must be set so that it cannot get compared to the node ptr page number field! */ ulint mode, /* in: PAGE_CUR_L, ...; NOTE that if the search is made using a unique prefix of a record, mode should be PAGE_CUR_LE, not PAGE_CUR_GE, as the latter may end up on the previous page of the record! Inserts should always be made using PAGE_CUR_LE to search the position! */ ulint latch_mode, /* in: BTR_SEARCH_LEAF, ..., ORed with BTR_INSERT and BTR_ESTIMATE; cursor->left_page 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! */ btr_cur_t* cursor, /* in/out: tree cursor; the cursor page is s- or x-latched, but see also above! */ ulint has_search_latch,/* in: latch mode the caller currently has on btr_search_latch: RW_S_LATCH, or 0 */ mtr_t* mtr); /* in: mtr *//*********************************************************************Opens a cursor at either end of an index. */voidbtr_cur_open_at_index_side(/*=======================*/ ibool from_left, /* in: TRUE if open to the low end, FALSE if to the high end */ dict_index_t* index, /* in: index */ ulint latch_mode, /* in: latch mode */ btr_cur_t* cursor, /* in: cursor */ mtr_t* mtr); /* in: mtr *//**************************************************************************Positions a cursor at a randomly chosen position within a B-tree. */voidbtr_cur_open_at_rnd_pos(/*====================*/ dict_index_t* index, /* in: index */ ulint latch_mode, /* in: BTR_SEARCH_LEAF, ... */ btr_cur_t* cursor, /* in/out: B-tree cursor */ mtr_t* mtr); /* in: 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 doesnot succeed if there is too little space on the page. If there is justone record on the page, the insert will always succeed; this is toprevent trying to split a page with just one record. */ulintbtr_cur_optimistic_insert(/*======================*/ /* out: DB_SUCCESS, DB_WAIT_LOCK, DB_FAIL, or error number */ ulint flags, /* in: undo logging and locking flags: if not zero, the parameters index and thr should be specified */ btr_cur_t* cursor, /* in: cursor on page after which to insert; cursor stays valid */ dtuple_t* entry, /* in: entry to insert */ rec_t** rec, /* out: pointer to inserted record if succeed */ big_rec_t** big_rec,/* out: big rec vector whose fields have to be stored externally by the caller, or NULL */ que_thr_t* thr, /* in: query thread or NULL */ mtr_t* mtr); /* in: mtr *//*****************************************************************Performs an insert on a page of an index tree. It is assumed that mtrholds an x-latch on the tree and on the cursor page. If the insert ismade on the leaf level, to avoid deadlocks, mtr must also own x-latchesto brothers of page, if those brothers exist. */ulintbtr_cur_pessimistic_insert(/*=======================*/ /* out: DB_SUCCESS or error number */ ulint flags, /* in: 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 */ btr_cur_t* cursor, /* in: cursor after which to insert; cursor stays valid */ dtuple_t* entry, /* in: entry to insert */ rec_t** rec, /* out: pointer to inserted record if succeed */ big_rec_t** big_rec,/* out: big rec vector whose fields have to be stored externally by the caller, or NULL */ que_thr_t* thr, /* in: query thread or NULL */ mtr_t* mtr); /* in: mtr *//*****************************************************************Updates a record when the update causes no size changes in its fields. */ulintbtr_cur_update_in_place(/*====================*/ /* out: DB_SUCCESS or error number */ ulint flags, /* in: undo logging and locking flags */ btr_cur_t* cursor, /* in: cursor on the record to update; cursor stays valid and positioned on the same record */ upd_t* update, /* in: update vector */ ulint cmpl_info,/* in: compiler info on secondary index updates */ que_thr_t* thr, /* in: query thread */ mtr_t* mtr); /* in: mtr *//*****************************************************************Tries to update a record on a page in an index tree. It is assumed that mtrholds an x-latch on the page. The operation does not succeed if there is toolittle space on the page or if the update would result in too empty a page,so that tree compression is recommended. */ulintbtr_cur_optimistic_update(/*======================*/ /* out: DB_SUCCESS, or DB_OVERFLOW if the updated record does not fit, DB_UNDERFLOW if the page would become too empty */ ulint flags, /* in: undo logging and locking flags */ btr_cur_t* cursor, /* in: cursor on the record to update; cursor stays valid and positioned on the same record */ upd_t* update, /* in: update vector; this must also contain trx id and roll ptr fields */ ulint cmpl_info,/* in: compiler info on secondary index updates */ que_thr_t* thr, /* in: query thread */ mtr_t* mtr); /* in: mtr *//*****************************************************************Performs an update of a record on a page of a tree. It is assumedthat mtr holds an x-latch on the tree and on the cursor page. If theupdate is made on the leaf level, to avoid deadlocks, mtr must alsoown x-latches to brothers of page, if those brothers exist. */ulintbtr_cur_pessimistic_update(/*=======================*/ /* out: DB_SUCCESS or error code */ ulint flags, /* in: undo logging, locking, and rollback flags */ btr_cur_t* cursor, /* in: cursor on the record to update */ big_rec_t** big_rec,/* out: big rec vector whose fields have to be stored externally by the caller, or NULL */ upd_t* update, /* in: update vector; this is allowed also contain trx id and roll ptr fields, but the values in update vector have no effect */ ulint cmpl_info,/* in: compiler info on secondary index updates */ que_thr_t* thr, /* in: query thread */ mtr_t* mtr); /* in: mtr *//***************************************************************Marks a clustered index record deleted. Writes an undo log record toundo log on this delete marking. Writes in the trx id field the idof the deleting transaction, and in the roll ptr field pointer to theundo log record created. */ulintbtr_cur_del_mark_set_clust_rec(/*===========================*/ /* out: DB_SUCCESS, DB_LOCK_WAIT, or error number */ ulint flags, /* in: undo logging and locking flags */ btr_cur_t* cursor, /* in: cursor */ ibool val, /* in: value to set */ que_thr_t* thr, /* in: query thread */ mtr_t* mtr); /* in: mtr *//***************************************************************Sets a secondary index record delete mark to TRUE or FALSE. */ulintbtr_cur_del_mark_set_sec_rec(/*=========================*/ /* out: DB_SUCCESS, DB_LOCK_WAIT, or error number */ ulint flags, /* in: locking flag */ btr_cur_t* cursor, /* in: cursor */ ibool val, /* in: value to set */ que_thr_t* thr, /* in: query thread */ mtr_t* mtr); /* in: mtr *//***************************************************************Sets a secondary index record delete mark to FALSE. This function isonly used by the insert buffer insert merge mechanism. */voidbtr_cur_del_unmark_for_ibuf(/*========================*/ rec_t* rec, /* in: record to delete unmark */ mtr_t* mtr); /* in: mtr *//*****************************************************************Tries to compress a page of the tree on the leaf level. It is assumedthat mtr holds an x-latch on the tree and on the cursor page. To avoiddeadlocks, mtr must also own x-latches to brothers of page, if thosebrothers exist. NOTE: it is assumed that the caller has reserved enoughfree extents so that the compression will always succeed if done! */voidbtr_cur_compress(/*=============*/ btr_cur_t* cursor, /* in: cursor on the page to compress; cursor does not stay valid */ mtr_t* mtr); /* in: mtr *//*****************************************************************Tries to compress a page of the tree if it seems useful. It is assumedthat mtr holds an x-latch on the tree and on the cursor page. To avoiddeadlocks, mtr must also own x-latches to brothers of page, if thosebrothers exist. NOTE: it is assumed that the caller has reserved enoughfree extents so that the compression will always succeed if done! */iboolbtr_cur_compress_if_useful(/*=======================*/ /* out: TRUE if compression occurred */ btr_cur_t* cursor, /* in: cursor on the page to compress; cursor does not stay valid if compression occurs */ mtr_t* mtr); /* in: mtr *//***********************************************************Removes the record on which the tree cursor is positioned. It is assumedthat the mtr has an x-latch on the page where the cursor is positioned,but no latch on the whole tree. */iboolbtr_cur_optimistic_delete(/*======================*/ /* out: TRUE if success, i.e., the page did not become too empty */ btr_cur_t* cursor, /* in: cursor on the record to delete; cursor stays valid: if deletion succeeds, on function exit it points to the successor of the deleted record */ mtr_t* mtr); /* in: mtr *//*****************************************************************Removes the record on which the tree cursor is positioned. Triesto compress the page if its fillfactor drops below a thresholdor if it is the only page on the level. It is assumed that mtr holdsan 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 brothersexist. */iboolbtr_cur_pessimistic_delete(/*=======================*/ /* out: TRUE if compression occurred */ ulint* err, /* out: DB_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 */ ibool has_reserved_extents, /* in: TRUE if the caller has already reserved enough free extents so that he knows that the operation will succeed */ btr_cur_t* cursor, /* in: cursor on the record to delete; if compression does not occur, the cursor
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -