[MySQL 学习] Innodb Optimistic Delete 简述

接口函数是btr_cur_optimistic_delete
Innodb的Optimistic Delete操作主要是由purge线程来进行的,用户线程仅仅做了删除标记(包括删除记录,更新二级索引以及更新主键),

另外如果插入/更新操作回滚了,用户也会调用到函数btr_cur_optimistic_delete
例如回滚insert操作的调用栈为
trx_general_rollback_for_mysql–>…..->row_undo->row_undo_ins->row_undo_ins_remove_clust_rec->btr_cur_optimistic_delete

当我们正常删除记录时,一般仅仅是做一个标记,例如更新主键值的update函数栈
row_update_for_mysql->row_upd_step->row_upd->row_upd_clust_step->row_upd_clust_rec_by_insert->btr_cur_del_mark_set_clust_rec->btr_rec_set_deleted_flag

随后的purge线程调用栈为:
trx_purge->….->row_purge_step->row_purge->row_purge_del_mark->row_purge_remove_clust_if_poss->row_purge_remove_clust_if_poss_low->btr_cur_optimistic_delete

事实上btr_cur_optimistic_delete的流程也很简单,如果无需重组织btree(btr_cur_can_delete_without_compress),直接调用
a.lock_update_delete(block, rec);  //移除记录锁
b.btr_search_update_hash_on_delete(cursor)//更新adaptive hash index
c.page_cur_delete_rec删除记录
d.更新insett buffer 的free bits (压缩表调用ibuf_update_free_bits_zip,非压缩表调用ibuf_update_free_bits_low)

显然,在这里并没有对压缩页的mlog写入数据,实际上写入mlog是由用户线程执行的,对应函数为page_zip_rec_set_deleted.(;例如:row_upd->row_upd_clust_step->row_upd_del_mark_clust_rec->btr_cur_del_mark_set_clust_rec->page_zip_rec_set_deleted)
他的实现也很简单,只是将记录对应的slot设置一个删除标记位。

原创文章,转载请注明: 转载自Simple Life

本文链接地址: [MySQL 学习] Innodb Optimistic Delete 简述

Post Footer automatically generated by wp-posturl plugin for wordpress.


Comments

Leave a Reply

Your email address will not be published. Name and email are required


Current month ye@r day *