4.2.1 核心结构和流程1)数据结构 复制//核心结构如下 /** Persistent cursor */ struct btr_pcur_t; /** B-tree cursor */ struct btr_cur_t; /** B-tree search information for the adaptive hash index */ struct btr_search_t;1.2.3.4.5.6.7. 2)插入:其核心流程包含两步:1.查找插入位置;2.有空间就直接插入,没有空间就分裂节点递归插入 复制/** 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. @return DB_SUCCESS, DB_WAIT_LOCK, DB_FAIL, or error number */ dberr_t btr_cur_optimistic_insert( 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 */ ulint **offsets, /*!< out: offsets on *rec */ mem_heap_t **heap, /*!< in/out: pointer to memory heap, or NULL */ dtuple_t *entry, /*!< in/out: 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/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 */1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27. 3)查找:其从根节点逐层向下查找,最后返回匹配的游标。 复制/** 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. 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. */ 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! */ page_cur_mode_t 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 s- or x-latched, but see also above! */ ulint has_search_latch, /*!< in: info on the latch mode the caller currently has on search system: RW_S_LATCH, or 0 */ const char *file, /*!< in: file name */ ulint line, /*!< in: line where called */ mtr_t *mtr) /*!< in: mtr */1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.31.32.33.34.35.36.37.38.39. 4)删除:其核心操作如下:查找删除位置;如果删除后节点仍然满足最小键值数量要求,直接删除(乐观删除),如果删除后节点不满足最小键值数量要求,合并节点并递归删除(悲观删除)。 复制/** 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. @param[in] cursor cursor 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 @param[in] flags BTR_CREATE_FLAG or 0 @param[in] mtr if this function returns true on a leaf page of a secondary index, the mtr must be committed before latching any further pages @return true if success, i.e., the page did not become too empty */ inline bool btr_cur_optimistic_delete(btr_cur_t *cursor, ulint flags [[maybe_unused]], mtr_t *mtr) { return btr_cur_optimistic_delete_func(cursor, IF_DEBUG(flags, ) mtr); }1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.