mysqlinsert执⾏_MySQL⼀条insert语句的执⾏过程UNIV_INTERN
dberr_t
row_ins_clust_index_entry_low(
/*==========================*/
ulint flags, /*!< in: undo logging and locking flags */
ulint mode, /*!< in: BTR_MODIFY_LEAF or BTR_MODIFY_TREE,
depending on whether we wish optimistic or
pessimistic descent down the index tree */
dict_index_t* index, /*!< in: clustered index */
ulint n_uniq, /*!< in: 0 or index->n_uniq */
dtuple_t* entry, /*!< in/out: index entry to insert */
ulint n_ext, /*!< in: number of externally stored columns */
que_thr_t* thr, /*!< in: query thread */
ulint* page_no,/*!< *page_no and *modify_clock are used to decide
whether to call btr_cur_optimistic_insert() during
pessimistic descent down the index tree.
in: If this is optimistic descent, then *page_no
must be ULINT_UNDEFINED. If it is pessimistic
descent, *page_no must be the page_no to which an
optimistic insert was attempted last time
row_ins_index_entry_low() was called.
out: If this is the optimistic descent, *page_no is set
to the page_no to which an optimistic insert was
attempted. If it is pessimistic descent, this value is
not changed. */
ullint* modify_clock) /*!< in/out: *modify_clock == ULLINT_UNDEFINED
during optimistic descent, and the modify_clock
value for the page that was used for optimistic
insert during pessimistic descent */
{
/* 将cursor移动到索引上待插⼊的位置 */
btr_cur_search_to_nth_level(index, 0, entry, PAGE_CUR_LE, mode,
&cursor, 0, __FILE__, __LINE__, &mtr);
/
*根据不同的flag检查主键冲突*/
err = row_ins_duplicate_error_in_clust_online(
n_uniq, entry, &cursor,
&offsets, &offsets_heap);
err = row_ins_duplicate_error_in_clust(
flags, &cursor, entry, thr, &mtr);
/*
如果要插⼊的索引项已存在,则把insert操作改为update操作
索引项已存在,且没有主键冲突,是因为之前的索引项对应的数据被标记为已删除本次插⼊的数据和上次删除的⼀样,⽽索引项并未删除,所以变为update操作
*/
if (row_ins_must_modify_rec(&cursor)) {
/* There is already an index entry with a long enough common
prefix, we must convert the insert into a modify of an
existing record */
mem_heap_t* entry_heap = mem_heap_create(1024);
/* 更新数据到存在的索引项 */
err = row_ins_clust_index_entry_by_modify(
flags, mode, &cursor, &offsets, &offsets_heap,
entry_heap, &big_rec, entry, thr, &mtr);
/*如果索引正在online_ddl,先记录insert*/
if (err == DB_SUCCESS && dict_index_is_online_ddl(index)) {
row_log_table_insert(rec, index, offsets);
}
/*提交mini transaction*/
mtr_commit(&mtr);
mem_heap_free(entry_heap);
} else {
rec_t* insert_rec;
if (mode != BTR_MODIFY_TREE) {
/*进⾏⼀次乐观插⼊*/
err = btr_cur_optimistic_insert(
flags, &cursor, &offsets, &offsets_heap,简述安装mysql的过程
entry, &insert_rec, &big_rec,
n_ext, thr, &mtr);
} else {
/*
如果buffer pool余量不⾜25%,插⼊失败,返回DB_LOCK_TABLE_FULL 处理DB_LOCK_TABLE_FULL错误时,会回滚事务
防⽌⼤事务的锁占满buffer pool(注释⾥写的)
*/
if (buf_LRU_buf_pool_running_out()) {
err = DB_LOCK_TABLE_FULL;
goto err_exit;
}
if (/*太长了,略*/) {
/*进⾏⼀次乐观插⼊*/
err = btr_cur_optimistic_insert(
flags, &cursor,
&offsets, &offsets_heap,
entry, &insert_rec, &big_rec,
n_ext, thr, &mtr);
} else {
err = DB_FAIL;
}
if (err == DB_FAIL) {
/*乐观插⼊失败,进⾏悲观插⼊*/
err = btr_cur_pessimistic_insert(
flags, &cursor,
&offsets, &offsets_heap,
entry, &insert_rec, &big_rec,
n_ext, thr, &mtr);
}
}
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。