日期:2014-05-16  浏览次数:20444 次

innodb对B树游标的定位过程以及对“小于(等于)B树最小记录”的特殊处理

?

innodbB树进行游标定位时,主要通过函数btr_cur_search_to_nth_level进行,该函数从根页开始向下层页迭代,直到指定的层级level,最终将B树游标定位在第一个大/小于(等于)tuple的位置,先不考虑页面latch、锁、自适应哈希索引、插入缓冲的影响,仅看B树游标定位:

UNIV_INTERN

void

btr_cur_search_to_nth_level(

/*========================*/

???????? dict_index_t*? index,?????? /*!< in: index */

???????? ulint????????? level,???????? /*!< in: the tree level of search */

???????? const 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, ...;

???????????????????????????????????? Inserts should always be made using

???????????????????????????????????? PAGE_CUR_LE to search the position! */

???????? ulint????????? latch_mode, /*!< in: 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! */

???????? btr_cur_t*??????? cursor, /*!< in/out: tree cursor; the cursor page is

?????????????????