溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

二十四:從庫數(shù)據(jù)的查找和參數(shù)slave_rows_search_algorithms(筆記)

發(fā)布時間:2020-08-10 17:52:38 來源:ITPUB博客 閱讀:207 作者:gaopengtttt 欄目:MySQL數(shù)據(jù)庫

歡迎關(guān)注我的《深入理解MySQL主從原理 32講 》,如下:

二十四:從庫數(shù)據(jù)的查找和參數(shù)slave_rows_search_algorithms(筆記)
如果圖片不能顯示可查看下面鏈接:
https://www.jianshu.com/p/d636215d767f

一、索引操找和定位棧幀

slave_rows_search_algorithms默認(rèn)。

一些debug的斷點(diǎn):

  • ha_innobase::index_read:這個函數(shù)是訪問索引的時候定位到值所在的位置用到的函數(shù),因?yàn)楸仨氁雷x取索引的開始位置才能向下訪問。
  • ha_innobase::index_next_same:訪問索引的下一條數(shù)據(jù)封裝的 ha_innobase::general_fetch 函數(shù)。
  • btr_cur_search_to_nth_level:索引定位查找接口

1、主庫

delete from tkkk where a=15;
刪除3條記錄

  • ha_innobase::index_read :定位 并且進(jìn)行索引定位
    #0  btr_cur_search_to_nth_level (index=0x7ffedc1d3180, level=0, tuple=0x7ffedc1d4260, mode=PAGE_CUR_GE, latch_mode=1, cursor=0x7ffedc1d4070, has_search_latch=0, 
      file=0x23a5988 "/mysqldata/percona-server-locks-detail-5.7.22/storage/innobase/row/row0sel.cc", line=5176, mtr=0x7fffec5ea240)
      at /mysqldata/percona-server-locks-detail-5.7.22/storage/innobase/btr/btr0cur.cc:770
    #1  0x0000000001bec437 in btr_pcur_open_with_no_init_func (index=0x7ffedc1d3180, tuple=0x7ffedc1d4260, mode=PAGE_CUR_GE, latch_mode=1, cursor=0x7ffedc1d4070, 
      has_search_latch=0, file=0x23a5988 "/mysqldata/percona-server-locks-detail-5.7.22/storage/innobase/row/row0sel.cc", line=5176, mtr=0x7fffec5ea240)
      at /mysqldata/percona-server-locks-detail-5.7.22/storage/innobase/include/btr0pcur.ic:521
    #2  0x0000000001bf73f1 in row_search_mvcc (buf=0x7ffedc030a50 "\377", mode=PAGE_CUR_GE, prebuilt=0x7ffedc1d3e50, match_mode=1, direction=0)
      at /mysqldata/percona-server-locks-detail-5.7.22/storage/innobase/row/row0sel.cc:5176
    #3  0x0000000001a53113 in ha_innobase::index_read (this=0x7ffedc02f020, buf=0x7ffedc030a50 "\377", key_ptr=0x7ffedc1d7c00 "", key_len=5, find_flag=HA_READ_KEY_EXACT)
      at /mysqldata/percona-server-locks-detail-5.7.22/storage/innobase/handler/ha_innodb.cc:9536
    #4  0x0000000000f933c2 in handler::index_read_map (this=0x7ffedc02f020, buf=0x7ffedc030a50 "\377", key=0x7ffedc1d7c00 "", keypart_map=1, find_flag=HA_READ_KEY_EXACT)
      at /mysqldata/percona-server-locks-detail-5.7.22/sql/handler.h:2942
    #5  0x0000000000f83dac in handler::ha_index_read_map (this=0x7ffedc02f020, buf=0x7ffedc030a50 "\377", key=0x7ffedc1d7c00 "", keypart_map=1, 
      find_flag=HA_READ_KEY_EXACT) at /mysqldata/percona-server-locks-detail-5.7.22/sql/handler.cc:3248
    #6  0x0000000000f8e844 in handler::read_range_first (this=0x7ffedc02f020, start_key=0x7ffedc02f108, end_key=0x7ffedc02f128, eq_range_arg=true, sorted=true)
      at /mysqldata/percona-server-locks-detail-5.7.22/sql/handler.cc:7750
    #7  0x0000000000f8c775 in handler::multi_range_read_next (this=0x7ffedc02f020, range_info=0x7fffec5eb6a0)
      at /mysqldata/percona-server-locks-detail-5.7.22/sql/handler.cc:6817
    #8  0x0000000000f8d68d in DsMrr_impl::dsmrr_next (this=0x7ffedc02f490, range_info=0x7fffec5eb6a0) at /mysqldata/percona-server-locks-detail-5.7.22/sql/handler.cc:7204
    #9  0x0000000001a6689a in ha_innobase::multi_range_read_next (this=0x7ffedc02f020, range_info=0x7fffec5eb6a0)
      at /mysqldata/percona-server-locks-detail-5.7.22/storage/innobase/handler/ha_innodb.cc:22211
    #10 0x00000000017bdbd8 in QUICK_RANGE_SELECT::get_next (this=0x7ffedc1cfa40) at /mysqldata/percona-server-locks-detail-5.7.22/sql/opt_range.cc:11237
    #11 0x00000000014e27f5 in rr_quick (info=0x7fffec5eb990) at /mysqldata/percona-server-locks-detail-5.7.22/sql/records.cc:399
    #12 0x00000000017f42a1 in Sql_cmd_delete::mysql_delete (this=0x7ffedc007148, thd=0x7ffedc000b90, limit=18446744073709551615)
      at /mysqldata/percona-server-locks-detail-5.7.22/sql/sql_delete.cc:452
    
  • 回表

    #0  btr_cur_search_to_nth_level (index=0x7ffedc1d1c00, level=0, tuple=0x7ffedc1d43c8, mode=PAGE_CUR_LE, latch_mode=1, cursor=0x7ffedc1d4168, has_search_latch=0, 
      file=0x23a5988 "/mysqldata/percona-server-locks-detail-5.7.22/storage/innobase/row/row0sel.cc", line=3546, mtr=0x7fffec5ea240)
      at /mysqldata/percona-server-locks-detail-5.7.22/storage/innobase/btr/btr0cur.cc:770
    #1  0x0000000001bec437 in btr_pcur_open_with_no_init_func (index=0x7ffedc1d1c00, tuple=0x7ffedc1d43c8, mode=PAGE_CUR_LE, latch_mode=1, cursor=0x7ffedc1d4168, 
      has_search_latch=0, file=0x23a5988 "/mysqldata/percona-server-locks-detail-5.7.22/storage/innobase/row/row0sel.cc", line=3546, mtr=0x7fffec5ea240)
      at /mysqldata/percona-server-locks-detail-5.7.22/storage/innobase/include/btr0pcur.ic:521
    #2  0x0000000001bf3b3c in row_sel_get_clust_rec_for_mysql (prebuilt=0x7ffedc1d3e50, sec_index=0x7ffedc1d3180, rec=0x7fffcf69016e "\200", thr=0x7ffedc1d4948, 
      out_rec=0x7fffec5eaaf0, offsets=0x7fffec5eaac8, offset_heap=0x7fffec5eaad0, vrow=0x0, mtr=0x7fffec5ea240)
      at /mysqldata/percona-server-locks-detail-5.7.22/storage/innobase/row/row0sel.cc:3546
    #3  0x0000000001bf915f in row_search_mvcc (buf=0x7ffedc030a50 "\377", mode=PAGE_CUR_GE, prebuilt=0x7ffedc1d3e50, match_mode=1, direction=0)
      at /mysqldata/percona-server-locks-detail-5.7.22/storage/innobase/row/row0sel.cc:5932
    #4  0x0000000001a53113 in ha_innobase::index_read (this=0x7ffedc02f020, buf=0x7ffedc030a50 "\377", key_ptr=0x7ffedc1d7c00 "", key_len=5, find_flag=HA_READ_KEY_EXACT)
      at /mysqldata/percona-server-locks-detail-5.7.22/storage/innobase/handler/ha_innodb.cc:9536
    #5  0x0000000000f933c2 in handler::index_read_map (this=0x7ffedc02f020, buf=0x7ffedc030a50 "\377", key=0x7ffedc1d7c00 "", keypart_map=1, find_flag=HA_READ_KEY_EXACT)
      at /mysqldata/percona-server-locks-detail-5.7.22/sql/handler.h:2942
    #6  0x0000000000f83dac in handler::ha_index_read_map (this=0x7ffedc02f020, buf=0x7ffedc030a50 "\377", key=0x7ffedc1d7c00 "", keypart_map=1, 
      find_flag=HA_READ_KEY_EXACT) at /mysqldata/percona-server-locks-detail-5.7.22/sql/handler.cc:3248
    #7  0x0000000000f8e844 in handler::read_range_first (this=0x7ffedc02f020, start_key=0x7ffedc02f108, end_key=0x7ffedc02f128, eq_range_arg=true, sorted=true)
      at /mysqldata/percona-server-locks-detail-5.7.22/sql/handler.cc:7750
    #8  0x0000000000f8c775 in handler::multi_range_read_next (this=0x7ffedc02f020, range_info=0x7fffec5eb6a0)
      at /mysqldata/percona-server-locks-detail-5.7.22/sql/handler.cc:6817
    
  • 刪除操作

    #0  btr_cur_search_to_nth_level (index=0x7ffedc1d3180, level=0, tuple=0x7ffedc1d65a0, mode=PAGE_CUR_LE, latch_mode=4098, cursor=0x7fffec5eae80, has_search_latch=0, 
      file=0x23a38c8 "/mysqldata/percona-server-locks-detail-5.7.22/storage/innobase/row/row0row.cc", line=1073, mtr=0x7fffec5ea970)
      at /mysqldata/percona-server-locks-detail-5.7.22/storage/innobase/btr/btr0cur.cc:770
    #1  0x0000000001be4233 in btr_pcur_open_low (index=0x7ffedc1d3180, level=0, tuple=0x7ffedc1d65a0, mode=PAGE_CUR_LE, latch_mode=4098, cursor=0x7fffec5eae80, 
      file=0x23a38c8 "/mysqldata/percona-server-locks-detail-5.7.22/storage/innobase/row/row0row.cc", line=1073, mtr=0x7fffec5ea970)
      at /mysqldata/percona-server-locks-detail-5.7.22/storage/innobase/include/btr0pcur.ic:465
    #2  0x0000000001be67b9 in row_search_index_entry (index=0x7ffedc1d3180, entry=0x7ffedc1d65a0, mode=4098, pcur=0x7fffec5eae80, mtr=0x7fffec5ea970)
      at /mysqldata/percona-server-locks-detail-5.7.22/storage/innobase/row/row0row.cc:1073
    #3  0x0000000001c1b792 in row_upd_sec_index_entry (node=0x7ffedc1d4a10, thr=0x7ffedc1d4d48)
      at /mysqldata/percona-server-locks-detail-5.7.22/storage/innobase/row/row0upd.cc:2241
    #4  0x0000000001c1bd5f in row_upd_sec_step (node=0x7ffedc1d4a10, thr=0x7ffedc1d4d48)
      at /mysqldata/percona-server-locks-detail-5.7.22/storage/innobase/row/row0upd.cc:2364
    #5  0x0000000001c1d9e1 in row_upd (node=0x7ffedc1d4a10, thr=0x7ffedc1d4d48) at /mysqldata/percona-server-locks-detail-5.7.22/storage/innobase/row/row0upd.cc:3071
    #6  0x0000000001c1dd41 in row_upd_step (thr=0x7ffedc1d4d48) at /mysqldata/percona-server-locks-detail-5.7.22/storage/innobase/row/row0upd.cc:3188
    #7  0x0000000001bbaf8c in row_update_for_mysql_using_upd_graph (mysql_rec=0x7ffedc030a50 "\361\017", prebuilt=0x7ffedc1d3e50)
      at /mysqldata/percona-server-locks-detail-5.7.22/storage/innobase/row/row0mysql.cc:3040
    #8  0x0000000001bbb28d in row_update_for_mysql (mysql_rec=0x7ffedc030a50 "\361\017", prebuilt=0x7ffedc1d3e50)
      at /mysqldata/percona-server-locks-detail-5.7.22/storage/innobase/row/row0mysql.cc:3131
    #9  0x0000000001a52493 in ha_innobase::delete_row (this=0x7ffedc02f020, record=0x7ffedc030a50 "\361\017")
      at /mysqldata/percona-server-locks-detail-5.7.22/storage/innobase/handler/ha_innodb.cc:9141
    #10 0x0000000000f90d11 in handler::ha_delete_row (this=0x7ffedc02f020, buf=0x7ffedc030a50 "\361\017")
      at /mysqldata/percona-server-locks-detail-5.7.22/sql/handler.cc:8543
    #11 0x00000000017f410f in Sql_cmd_delete::mysql_delete (this=0x7ffedc007148, thd=0x7ffedc000b90, limit=18446744073709551615)
      at /mysqldata/percona-server-locks-detail-5.7.22/sql/sql_delete.cc:468
    #12 0x00000000017f7098 in Sql_cmd_delete::execute (this=0x7ffedc007148, thd=0x7ffedc000b90) at /mysqldata/percona-server-locks-detail-5.7.22/sql/sql_delete.cc:1386
    #13 0x00000000015cc801 in mysql_execute_command (thd=0x7ffedc000b90, first_level=true) at /mysqldata/percona-server-locks-detail-5.7.22/sql/sql_parse.cc:3756
    
  • 訪問下一條數(shù)據(jù)

不會觸發(fā)二級索引的 定位函數(shù)

  • 回表

    #0  btr_cur_search_to_nth_level (index=0x7ffedc1d1c00, level=0, tuple=0x7ffedc1d43c8, mode=PAGE_CUR_LE, latch_mode=1, cursor=0x7ffedc1d4168, has_search_latch=0, 
      file=0x23a5988 "/mysqldata/percona-server-locks-detail-5.7.22/storage/innobase/row/row0sel.cc", line=3546, mtr=0x7fffec5ea290)
      at /mysqldata/percona-server-locks-detail-5.7.22/storage/innobase/btr/btr0cur.cc:770
    #1  0x0000000001bec437 in btr_pcur_open_with_no_init_func (index=0x7ffedc1d1c00, tuple=0x7ffedc1d43c8, mode=PAGE_CUR_LE, latch_mode=1, cursor=0x7ffedc1d4168, 
      has_search_latch=0, file=0x23a5988 "/mysqldata/percona-server-locks-detail-5.7.22/storage/innobase/row/row0sel.cc", line=3546, mtr=0x7fffec5ea290)
      at /mysqldata/percona-server-locks-detail-5.7.22/storage/innobase/include/btr0pcur.ic:521
    #2  0x0000000001bf3b3c in row_sel_get_clust_rec_for_mysql (prebuilt=0x7ffedc1d3e50, sec_index=0x7ffedc1d3180, rec=0x7fffcf69017e "\200", thr=0x7ffedc1d4948, 
      out_rec=0x7fffec5eab40, offsets=0x7fffec5eab18, offset_heap=0x7fffec5eab20, vrow=0x0, mtr=0x7fffec5ea290)
      at /mysqldata/percona-server-locks-detail-5.7.22/storage/innobase/row/row0sel.cc:3546
    #3  0x0000000001bf915f in row_search_mvcc (buf=0x7ffedc030a50 "\361\017", mode=PAGE_CUR_GE, prebuilt=0x7ffedc1d3e50, match_mode=1, direction=1)
      at /mysqldata/percona-server-locks-detail-5.7.22/storage/innobase/row/row0sel.cc:5932
    #4  0x0000000001a53fac in ha_innobase::general_fetch (this=0x7ffedc02f020, buf=0x7ffedc030a50 "\361\017", direction=1, match_mode=1)
      at /mysqldata/percona-server-locks-detail-5.7.22/storage/innobase/handler/ha_innodb.cc:9854
    #5  0x0000000001a542af in ha_innobase::index_next_same (this=0x7ffedc02f020, buf=0x7ffedc030a50 "\361\017", key=0x7ffedc1d7c08 "", keylen=5)
      at /mysqldata/percona-server-locks-detail-5.7.22/storage/innobase/handler/ha_innodb.cc:9945
    #6  0x0000000000f85bea in handler::ha_index_next_same (this=0x7ffedc02f020, buf=0x7ffedc030a50 "\361\017", key=0x7ffedc1d7c08 "", keylen=5)
      at /mysqldata/percona-server-locks-detail-5.7.22/sql/handler.cc:3555
    #7  0x0000000000f8e965 in handler::read_range_next (this=0x7ffedc02f020) at /mysqldata/percona-server-locks-detail-5.7.22/sql/handler.cc:7793
    #8  0x0000000000f8c6bc in handler::multi_range_read_next (this=0x7ffedc02f020, range_info=0x7fffec5eb6a0)
      at /mysqldata/percona-server-locks-detail-5.7.22/sql/handler.cc:6796
    #9  0x0000000000f8d68d in DsMrr_impl::dsmrr_next (this=0x7ffedc02f490, range_info=0x7fffec5eb6a0) at /mysqldata/percona-server-locks-detail-5.7.22/sql/handler.cc:7204
    #10 0x0000000001a6689a in ha_innobase::multi_range_read_next (this=0x7ffedc02f020, range_info=0x7fffec5eb6a0)
      at /mysqldata/percona-server-locks-detail-5.7.22/storage/innobase/handler/ha_innodb.cc:22211
    #11 0x00000000017bdbd8 in QUICK_RANGE_SELECT::get_next (this=0x7ffedc1cfa40) at /mysqldata/percona-server-locks-detail-5.7.22/sql/opt_range.cc:11237
    #12 0x00000000014e27f5 in rr_quick (info=0x7fffec5eb990) at /mysqldata/percona-server-locks-detail-5.7.22/sql/records.cc:399
    #13 0x00000000017f42a1 in Sql_cmd_delete::mysql_delete (this=0x7ffedc007148, thd=0x7ffedc000b90, limit=18446744073709551614)
      at /mysqldata/percona-server-locks-detail-5.7.22/sql/sql_delete.cc:452
    #14 0x00000000017f7098 in Sql_cmd_delete::execute (this=0x7ffedc007148, thd=0x7ffedc000b90) at /mysqldata/percona-server-locks-detail-5.7.22/sql/sql_delete.cc:1386
    #15 0x00000000015cc801 in mysql_execute_command (thd=0x7ffedc000b90, first_level=true) at /mysqldata/percona-server-locks-detail-5.7.22/sql/sql_parse.cc:3756
    #16 0x00000000015d2fde in mysql_parse (thd=0x7ffedc000b90, parser_state=0x7fffec5ed600) at /mysqldata/percona-server-locks-detail-5.7.22/sql/sql_parse.cc:5901
    #17 0x00000000015c6b72 in dispatch_command (thd=0x7ffedc000b90, com_data=0x7fffec5edd70, command=COM_QUERY)
      at /mysqldata/percona-server-locks-detail-5.7.22/sql/sql_parse.cc:1490
    #18 0x00000000015c58ff in do_command (thd=0x7ffedc000b90) at /mysqldata/percona-server-locks-detail-5.7.22/sql/sql_parse.cc:1021
    #19 0x000000000170e578 in handle_connection (arg=0x674cc40) at /mysqldata/percona-server-locks-detail-5.7.22/sql/conn_handler/connection_handler_per_thread.cc:312
    #20 0x0000000001945538 in pfs_spawn_thread (arg=0x67a1530) at /mysqldata/percona-server-locks-detail-5.7.22/storage/perfschema/pfs.cc:2190
    #21 0x00007ffff7bcfaa1 in start_thread () from /lib64/libpthread.so.0
    #22 0x00007ffff6b37c4d in clone () from /lib64/libc.so.6
    
  • 刪除

    #0  btr_cur_search_to_nth_level (index=0x7ffedc1d1c00, level=0, tuple=0x7ffedc1d6900, mode=PAGE_CUR_LE, latch_mode=2, cursor=0x7ffedc02f678, has_search_latch=0, 
      file=0x23aca80 "/mysqldata/percona-server-locks-detail-5.7.22/storage/innobase/row/row0upd.cc", line=2864, mtr=0x7fffec5ea8f0)
      at /mysqldata/percona-server-locks-detail-5.7.22/storage/innobase/btr/btr0cur.cc:770
    #1  0x0000000001cdf27c in btr_pcur_open_with_no_init_func (index=0x7ffedc1d1c00, tuple=0x7ffedc1d6900, mode=PAGE_CUR_LE, latch_mode=2, cursor=0x7ffedc02f678, 
      has_search_latch=0, file=0x23aca80 "/mysqldata/percona-server-locks-detail-5.7.22/storage/innobase/row/row0upd.cc", line=2864, mtr=0x7fffec5ea8f0)
      at /mysqldata/percona-server-locks-detail-5.7.22/storage/innobase/include/btr0pcur.ic:521
    #2  0x0000000001ce01b6 in btr_pcur_restore_position_func (latch_mode=2, cursor=0x7ffedc02f678, 
      file=0x23aca80 "/mysqldata/percona-server-locks-detail-5.7.22/storage/innobase/row/row0upd.cc", line=2864, mtr=0x7fffec5ea8f0)
      at /mysqldata/percona-server-locks-detail-5.7.22/storage/innobase/btr/btr0pcur.cc:395
    #3  0x0000000001c1d0ad in row_upd_clust_step (node=0x7ffedc1d4a10, thr=0x7ffedc1d4d48)
      at /mysqldata/percona-server-locks-detail-5.7.22/storage/innobase/row/row0upd.cc:2864
    #4  0x0000000001c1d860 in row_upd (node=0x7ffedc1d4a10, thr=0x7ffedc1d4d48) at /mysqldata/percona-server-locks-detail-5.7.22/storage/innobase/row/row0upd.cc:3042
    #5  0x0000000001c1dd41 in row_upd_step (thr=0x7ffedc1d4d48) at /mysqldata/percona-server-locks-detail-5.7.22/storage/innobase/row/row0upd.cc:3188
    #6  0x0000000001bbaf8c in row_update_for_mysql_using_upd_graph (mysql_rec=0x7ffedc030a50 "\361\017", prebuilt=0x7ffedc1d3e50)
      at /mysqldata/percona-server-locks-detail-5.7.22/storage/innobase/row/row0mysql.cc:3040
    #7  0x0000000001bbb28d in row_update_for_mysql (mysql_rec=0x7ffedc030a50 "\361\017", prebuilt=0x7ffedc1d3e50)
      at /mysqldata/percona-server-locks-detail-5.7.22/storage/innobase/row/row0mysql.cc:3131
    #8  0x0000000001a52493 in ha_innobase::delete_row (this=0x7ffedc02f020, record=0x7ffedc030a50 "\361\017")
      at /mysqldata/percona-server-locks-detail-5.7.22/storage/innobase/handler/ha_innodb.cc:9141
    #9  0x0000000000f90d11 in handler::ha_delete_row (this=0x7ffedc02f020, buf=0x7ffedc030a50 "\361\017")
      at /mysqldata/percona-server-locks-detail-5.7.22/sql/handler.cc:8543
    #10 0x00000000017f410f in Sql_cmd_delete::mysql_delete (this=0x7ffedc007148, thd=0x7ffedc000b90, limit=18446744073709551614)
      at /mysqldata/percona-server-locks-detail-5.7.22/sql/sql_delete.cc:468
    #11 0x00000000017f7098 in Sql_cmd_delete::execute (this=0x7ffedc007148, thd=0x7ffedc000b90) at /mysqldata/percona-server-locks-detail-5.7.22/sql/sql_delete.cc:1386
    #12 0x00000000015cc801 in mysql_execute_command (thd=0x7ffedc000b90, first_level=true) at /mysqldata/percona-server-locks-detail-5.7.22/sql/sql_parse.cc:3756
    #13 0x00000000015d2fde in mysql_parse (thd=0x7ffedc000b90, parser_state=0x7fffec5ed600) at /mysqldata/percona-server-locks-detail-5.7.22/sql/sql_parse.cc:5901
    #14 0x00000000015c6b72 in dispatch_command (thd=0x7ffedc000b90, com_data=0x7fffec5edd70, command=COM_QUERY)
      at /mysqldata/percona-server-locks-detail-5.7.22/sql/sql_parse.cc:1490
    #15 0x00000000015c58ff in do_command (thd=0x7ffedc000b90) at /mysqldata/percona-server-locks-detail-5.7.22/sql/sql_parse.cc:1021
    #16 0x000000000170e578 in handle_connection (arg=0x674cc40) at /mysqldata/percona-server-locks-detail-5.7.22/sql/conn_handler/connection_handler_per_thread.cc:312
    #17 0x0000000001945538 in pfs_spawn_thread (arg=0x67a1530) at /mysqldata/percona-server-locks-detail-5.7.22/storage/perfschema/pfs.cc:2190
    #18 0x00007ffff7bcfaa1 in start_thread () from /lib64/libpthread.so.0
    #19 0x00007ffff6b37c4d in clone () from /lib64/libc.so.6
    

2、備庫

  • 第一行數(shù)據(jù)定位 ha_innobase::index_read

    #0  btr_cur_search_to_nth_level (index=0x7ffe78a90f30, level=0, tuple=0x7ffe78933290, mode=PAGE_CUR_GE, latch_mode=1, cursor=0x7ffe789330a0, has_search_latch=0, 
      file=0x239d910 "/root/mysqlall/percona-server-locks-detail-5.7.22/storage/innobase/row/row0sel.cc", line=5176, mtr=0x7fffec062630)
      at /root/mysqlall/percona-server-locks-detail-5.7.22/storage/innobase/btr/btr0cur.cc:770
    #1  0x0000000001b6e89b in btr_pcur_open_with_no_init_func (index=0x7ffe78a90f30, tuple=0x7ffe78933290, mode=PAGE_CUR_GE, latch_mode=1, cursor=0x7ffe789330a0, 
      has_search_latch=0, file=0x239d910 "/root/mysqlall/percona-server-locks-detail-5.7.22/storage/innobase/row/row0sel.cc", line=5176, mtr=0x7fffec062630)
      at /root/mysqlall/percona-server-locks-detail-5.7.22/storage/innobase/include/btr0pcur.ic:521
    #2  0x0000000001b79855 in row_search_mvcc (buf=0x7ffe78011810 "\361\017", mode=PAGE_CUR_GE, prebuilt=0x7ffe78932e80, match_mode=1, direction=0)
      at /root/mysqlall/percona-server-locks-detail-5.7.22/storage/innobase/row/row0sel.cc:5176
    #3  0x00000000019d5493 in ha_innobase::index_read (this=0x7ffe7892f2f0, buf=0x7ffe78011810 "\361\017", key_ptr=0x7ffe78934150 "", key_len=5, 
      find_flag=HA_READ_KEY_EXACT) at /root/mysqlall/percona-server-locks-detail-5.7.22/storage/innobase/handler/ha_innodb.cc:9536
    #4  0x0000000000f934aa in handler::index_read_map (this=0x7ffe7892f2f0, buf=0x7ffe78011810 "\361\017", key=0x7ffe78934150 "", keypart_map=18446744073709551615, 
      find_flag=HA_READ_KEY_EXACT) at /root/mysqlall/percona-server-locks-detail-5.7.22/sql/handler.h:2942
    #5  0x0000000000f83e94 in handler::ha_index_read_map (this=0x7ffe7892f2f0, buf=0x7ffe78011810 "\361\017", key=0x7ffe78934150 "", keypart_map=18446744073709551615, 
      find_flag=HA_READ_KEY_EXACT) at /root/mysqlall/percona-server-locks-detail-5.7.22/sql/handler.cc:3248
    #6  0x00000000018583ed in Rows_log_event::next_record_scan (this=0x7ffe7415d150, first_read=true)
      at /root/mysqlall/percona-server-locks-detail-5.7.22/sql/log_event.cc:10495
    #7  0x0000000001858cce in Rows_log_event::do_index_scan_and_update (this=0x7ffe7415d150, rli=0x7ffe7401fe10)
      at /root/mysqlall/percona-server-locks-detail-5.7.22/sql/log_event.cc:10706
    #8  0x000000000185b0b5 in Rows_log_event::do_apply_event (this=0x7ffe7415d150, rli=0x7ffe7401fe10)
      at /root/mysqlall/percona-server-locks-detail-5.7.22/sql/log_event.cc:11564
    #9  0x000000000186acf2 in Log_event::do_apply_event_worker (this=0x7ffe7415d150, w=0x7ffe7401fe10)
      at /root/mysqlall/percona-server-locks-detail-5.7.22/sql/log_event.cc:765
    #10 0x00000000018e7672 in Slave_worker::slave_worker_exec_event (this=0x7ffe7401fe10, ev=0x7ffe7415d150)
      at /root/mysqlall/percona-server-locks-detail-5.7.22/sql/rpl_rli_pdb.cc:1890
    #11 0x00000000018e97ed in slave_worker_exec_job_group (worker=0x7ffe7401fe10, rli=0x7ffe7c026760)
      at /root/mysqlall/percona-server-locks-detail-5.7.22/sql/rpl_rli_pdb.cc:2671
    #12 0x00000000018c077a in handle_slave_worker (arg=0x7ffe7401fe10) at /root/mysqlall/percona-server-locks-detail-5.7.22/sql/rpl_slave.cc:6239
    #13 0x0000000001945620 in pfs_spawn_thread (arg=0x7ffe740249b0) at /root/mysqlall/percona-server-locks-detail-5.7.22/storage/perfschema/pfs.cc:2190
    #14 0x00007ffff7bc6aa1 in start_thread () from /lib64/libpthread.so.0
    #15 0x00007ffff6719bcd in clone () from /lib64/libc.so.6
    
  • 回表

    #0  btr_cur_search_to_nth_level (index=0x7ffe7892fde0, level=0, tuple=0x7ffe789333f8, mode=PAGE_CUR_LE, latch_mode=1, cursor=0x7ffe78933198, has_search_latch=0, 
      file=0x239d910 "/root/mysqlall/percona-server-locks-detail-5.7.22/storage/innobase/row/row0sel.cc", line=3546, mtr=0x7fffec062630)
      at /root/mysqlall/percona-server-locks-detail-5.7.22/storage/innobase/btr/btr0cur.cc:770
    #1  0x0000000001b6e89b in btr_pcur_open_with_no_init_func (index=0x7ffe7892fde0, tuple=0x7ffe789333f8, mode=PAGE_CUR_LE, latch_mode=1, cursor=0x7ffe78933198, 
      has_search_latch=0, file=0x239d910 "/root/mysqlall/percona-server-locks-detail-5.7.22/storage/innobase/row/row0sel.cc", line=3546, mtr=0x7fffec062630)
      at /root/mysqlall/percona-server-locks-detail-5.7.22/storage/innobase/include/btr0pcur.ic:521
    #2  0x0000000001b75fa0 in row_sel_get_clust_rec_for_mysql (prebuilt=0x7ffe78932e80, sec_index=0x7ffe78a90f30, rec=0x7fff33b5415e "\200", thr=0x7ffe78933978, 
      out_rec=0x7fffec062ee0, offsets=0x7fffec062eb8, offset_heap=0x7fffec062ec0, vrow=0x0, mtr=0x7fffec062630)
      at /root/mysqlall/percona-server-locks-detail-5.7.22/storage/innobase/row/row0sel.cc:3546
    #3  0x0000000001b7b5c3 in row_search_mvcc (buf=0x7ffe78011810 "\361\017", mode=PAGE_CUR_GE, prebuilt=0x7ffe78932e80, match_mode=1, direction=0)
      at /root/mysqlall/percona-server-locks-detail-5.7.22/storage/innobase/row/row0sel.cc:5932
    #4  0x00000000019d5493 in ha_innobase::index_read (this=0x7ffe7892f2f0, buf=0x7ffe78011810 "\361\017", key_ptr=0x7ffe78934150 "", key_len=5, 
      find_flag=HA_READ_KEY_EXACT) at /root/mysqlall/percona-server-locks-detail-5.7.22/storage/innobase/handler/ha_innodb.cc:9536
    #5  0x0000000000f934aa in handler::index_read_map (this=0x7ffe7892f2f0, buf=0x7ffe78011810 "\361\017", key=0x7ffe78934150 "", keypart_map=18446744073709551615, 
      find_flag=HA_READ_KEY_EXACT) at /root/mysqlall/percona-server-locks-detail-5.7.22/sql/handler.h:2942
    #6  0x0000000000f83e94 in handler::ha_index_read_map (this=0x7ffe7892f2f0, buf=0x7ffe78011810 "\361\017", key=0x7ffe78934150 "", keypart_map=18446744073709551615, 
      find_flag=HA_READ_KEY_EXACT) at /root/mysqlall/percona-server-locks-detail-5.7.22/sql/handler.cc:3248
    #7  0x00000000018583ed in Rows_log_event::next_record_scan (this=0x7ffe7415d150, first_read=true)
      at /root/mysqlall/percona-server-locks-detail-5.7.22/sql/log_event.cc:10495
    #8  0x0000000001858cce in Rows_log_event::do_index_scan_and_update (this=0x7ffe7415d150, rli=0x7ffe7401fe10)
      at /root/mysqlall/percona-server-locks-detail-5.7.22/sql/log_event.cc:10706
    #9  0x000000000185b0b5 in Rows_log_event::do_apply_event (this=0x7ffe7415d150, rli=0x7ffe7401fe10)
      at /root/mysqlall/percona-server-locks-detail-5.7.22/sql/log_event.cc:11564
    #10 0x000000000186acf2 in Log_event::do_apply_event_worker (this=0x7ffe7415d150, w=0x7ffe7401fe10)
      at /root/mysqlall/percona-server-locks-detail-5.7.22/sql/log_event.cc:765
    #11 0x00000000018e7672 in Slave_worker::slave_worker_exec_event (this=0x7ffe7401fe10, ev=0x7ffe7415d150)
      at /root/mysqlall/percona-server-locks-detail-5.7.22/sql/rpl_rli_pdb.cc:1890
    #12 0x00000000018e97ed in slave_worker_exec_job_group (worker=0x7ffe7401fe10, rli=0x7ffe7c026760)
      at /root/mysqlall/percona-server-locks-detail-5.7.22/sql/rpl_rli_pdb.cc:2671
    #13 0x00000000018c077a in handle_slave_worker (arg=0x7ffe7401fe10) at /root/mysqlall/percona-server-locks-detail-5.7.22/sql/rpl_slave.cc:6239
    #14 0x0000000001945620 in pfs_spawn_thread (arg=0x7ffe740249b0) at /root/mysqlall/percona-server-locks-detail-5.7.22/storage/perfschema/pfs.cc:2190
    #15 0x00007ffff7bc6aa1 in start_thread () from /lib64/libpthread.so.0
    #16 0x00007ffff6719bcd in clone () from /lib64/libc.so.6
    
  • 刪除這行
    #0  btr_cur_search_to_nth_level (index=0x7ffe78a90f30, level=0, tuple=0x7ffe78a91c00, mode=PAGE_CUR_LE, latch_mode=4098, cursor=0x7fffec063090, has_search_latch=0, 
      file=0x239b7e0 "/root/mysqlall/percona-server-locks-detail-5.7.22/storage/innobase/row/row0row.cc", line=1073, mtr=0x7fffec062b80)
      at /root/mysqlall/percona-server-locks-detail-5.7.22/storage/innobase/btr/btr0cur.cc:770
    #1  0x0000000001b66697 in btr_pcur_open_low (index=0x7ffe78a90f30, level=0, tuple=0x7ffe78a91c00, mode=PAGE_CUR_LE, latch_mode=4098, cursor=0x7fffec063090, 
      file=0x239b7e0 "/root/mysqlall/percona-server-locks-detail-5.7.22/storage/innobase/row/row0row.cc", line=1073, mtr=0x7fffec062b80)
      at /root/mysqlall/percona-server-locks-detail-5.7.22/storage/innobase/include/btr0pcur.ic:465
    #2  0x0000000001b68c1d in row_search_index_entry (index=0x7ffe78a90f30, entry=0x7ffe78a91c00, mode=4098, pcur=0x7fffec063090, mtr=0x7fffec062b80)
      at /root/mysqlall/percona-server-locks-detail-5.7.22/storage/innobase/row/row0row.cc:1073
    #3  0x0000000001b9dbf6 in row_upd_sec_index_entry (node=0x7ffe78933a40, thr=0x7ffe78933d78)
      at /root/mysqlall/percona-server-locks-detail-5.7.22/storage/innobase/row/row0upd.cc:2241
    #4  0x0000000001b9e1c3 in row_upd_sec_step (node=0x7ffe78933a40, thr=0x7ffe78933d78)
      at /root/mysqlall/percona-server-locks-detail-5.7.22/storage/innobase/row/row0upd.cc:2364
    #5  0x0000000001b9fe45 in row_upd (node=0x7ffe78933a40, thr=0x7ffe78933d78) at /root/mysqlall/percona-server-locks-detail-5.7.22/storage/innobase/row/row0upd.cc:3071
    #6  0x0000000001ba01a5 in row_upd_step (thr=0x7ffe78933d78) at /root/mysqlall/percona-server-locks-detail-5.7.22/storage/innobase/row/row0upd.cc:3188
    #7  0x0000000001b3d3f0 in row_update_for_mysql_using_upd_graph (mysql_rec=0x7ffe78011810 "\361\017", prebuilt=0x7ffe78932e80)
      at /root/mysqlall/percona-server-locks-detail-5.7.22/storage/innobase/row/row0mysql.cc:3040
    #8  0x0000000001b3d6f1 in row_update_for_mysql (mysql_rec=0x7ffe78011810 "\361\017", prebuilt=0x7ffe78932e80)
      at /root/mysqlall/percona-server-locks-detail-5.7.22/storage/innobase/row/row0mysql.cc:3131
    #9  0x00000000019d4813 in ha_innobase::delete_row (this=0x7ffe7892f2f0, record=0x7ffe78011810 "\361\017")
      at /root/mysqlall/percona-server-locks-detail-5.7.22/storage/innobase/handler/ha_innodb.cc:9141
    #10 0x0000000000f90df9 in handler::ha_delete_row (this=0x7ffe7892f2f0, buf=0x7ffe78011810 "\361\017")
      at /root/mysqlall/percona-server-locks-detail-5.7.22/sql/handler.cc:8543
    #11 0x000000000185f96a in Delete_rows_log_event::do_exec_row (this=0x7ffe7415d150, rli=0x7ffe7401fe10)
      at /root/mysqlall/percona-server-locks-detail-5.7.22/sql/log_event.cc:13157
    #12 0x0000000001858059 in Rows_log_event::do_apply_row (this=0x7ffe7415d150, rli=0x7ffe7401fe10)
      at /root/mysqlall/percona-server-locks-detail-5.7.22/sql/log_event.cc:10395
    #13 0x0000000001859025 in Rows_log_event::do_index_scan_and_update (this=0x7ffe7415d150, rli=0x7ffe7401fe10)
      at /root/mysqlall/percona-server-locks-detail-5.7.22/sql/log_event.cc:10784
    #14 0x000000000185b0b5 in Rows_log_event::do_apply_event (this=0x7ffe7415d150, rli=0x7ffe7401fe10)
      at /root/mysqlall/percona-server-locks-detail-5.7.22/sql/log_event.cc:11564
    #15 0x000000000186acf2 in Log_event::do_apply_event_worker (this=0x7ffe7415d150, w=0x7ffe7401fe10)
      at /root/mysqlall/percona-server-locks-detail-5.7.22/sql/log_event.cc:765
    #16 0x00000000018e7672 in Slave_worker::slave_worker_exec_event (this=0x7ffe7401fe10, ev=0x7ffe7415d150)
      at /root/mysqlall/percona-server-locks-detail-5.7.22/sql/rpl_rli_pdb.cc:1890
    

二、hash 算法

Rows_log_event::do_apply_event
 ->GTID 跳過邏輯
 ->打開表
 ->table 映射
 ->設(shè)置訪問位圖read_set 和 write_set
 ->準(zhǔn)備Delete_rows_log_event::do_before_row_operations
   ->匹配索引Rows_log_event::row_operations_scan_and_key_setup
     ->decide_row_lookup_algorithm_and_key 決定用什么掃描方式
     如果是hash需要初始化hash結(jié)構(gòu)m_hash.init()
 ->循環(huán)event中的每一條數(shù)據(jù)
   ->調(diào)用相應(yīng)的方法接口
     ->hash 方法 Rows_log_event::do_hash_scan_and_update
      ->將每條數(shù)據(jù)加入hash 區(qū)域 Rows_log_event::do_hash_row 
        如果有索引還會維護(hù)一個集合
      ->如過是Event中的最后一條數(shù)據(jù)調(diào)用Rows_log_event::do_scan_and_update
        掃描整個表或者遍歷集合進(jìn)行索引查找定位查找數(shù)據(jù)
        和HASH結(jié)構(gòu)進(jìn)行對比
        對比成功在HASH結(jié)構(gòu)中刪除
        調(diào)用刪除接口刪除數(shù)據(jù)

一個測試

主要測試從庫在有主鍵和沒有主鍵下接口調(diào)用:
slave_rows_search_algorithms=’INDEX_SCAN,HASH_SCAN’;

建表

 create table tmpk(a int primary key,name varchar(20));

數(shù)據(jù)

mysql> select * from tmpk;
+---+------+
| a | name |
+---+------+
| 1 | gao  |
| 2 | gao  |
| 3 | gao  |
| 4 | gao  |
+---+------+

從庫:

mysql> set global slave_rows_search_algorithms='INDEX_SCAN,HASH_SCAN';  
Query OK, 0 rows affected (0.00 sec)

主庫刪除一條數(shù)據(jù):

mysql> delete from tmpk where a=1;
Query OK, 1 row affected (0.08 sec)

從庫調(diào)用接口:

(gdb) bt
#0  Rows_log_event::do_index_scan_and_update (this=0x7ffe70162a20, rli=0x7ffe70024a90) at /root/mysqlall/percona-server-locks-detail-5.7.22/sql/log_event.cc:10603
#1  0x000000000185b0b5 in Rows_log_event::do_apply_event (this=0x7ffe70162a20, rli=0x7ffe70024a90)
    at /root/mysqlall/percona-server-locks-detail-5.7.22/sql/log_event.cc:11564
#2  0x000000000186acf2 in Log_event::do_apply_event_worker (this=0x7ffe70162a20, w=0x7ffe70024a90)
    at /root/mysqlall/percona-server-locks-detail-5.7.22/sql/log_event.cc:765
#3  0x00000000018e7672 in Slave_worker::slave_worker_exec_event (this=0x7ffe70024a90, ev=0x7ffe70162a20)
    at /root/mysqlall/percona-server-locks-detail-5.7.22/sql/rpl_rli_pdb.cc:1890
#4  0x00000000018e97ed in slave_worker_exec_job_group (worker=0x7ffe70024a90, rli=0x67633b0)
    at /root/mysqlall/percona-server-locks-detail-5.7.22/sql/rpl_rli_pdb.cc:2671
#5  0x00000000018c077a in handle_slave_worker (arg=0x7ffe70024a90) at /root/mysqlall/percona-server-locks-detail-5.7.22/sql/rpl_slave.cc:6239
#6  0x0000000001945620 in pfs_spawn_thread (arg=0x7ffe700296d0) at /root/mysqlall/percona-server-locks-detail-5.7.22/storage/perfschema/pfs.cc:2190
#7  0x00007ffff7bc6aa1 in start_thread () from /lib64/libpthread.so.0
#8  0x00007ffff6719bcd in clone () from /lib64/libc.so.6
(gdb) c

從庫刪除主鍵:

mysql> alter table tmpk drop primary key;
Query OK, 3 rows affected (1.23 sec)
Records: 3  Duplicates: 0  Warnings: 0

主庫再次刪除一條數(shù)據(jù):

mysql> delete from tmpk where a=2;
Query OK, 1 row affected (0.12 sec)

從庫調(diào)用接口變?yōu)榱薶ash算法:

(gdb) bt
#0  Rows_log_event::do_hash_scan_and_update (this=0x7ffe70162d50, rli=0x7ffe70024a90) at /root/mysqlall/percona-server-locks-detail-5.7.22/sql/log_event.cc:11043
#1  0x000000000185b0b5 in Rows_log_event::do_apply_event (this=0x7ffe70162d50, rli=0x7ffe70024a90)
    at /root/mysqlall/percona-server-locks-detail-5.7.22/sql/log_event.cc:11564
#2  0x000000000186acf2 in Log_event::do_apply_event_worker (this=0x7ffe70162d50, w=0x7ffe70024a90)
    at /root/mysqlall/percona-server-locks-detail-5.7.22/sql/log_event.cc:765
#3  0x00000000018e7672 in Slave_worker::slave_worker_exec_event (this=0x7ffe70024a90, ev=0x7ffe70162d50)
    at /root/mysqlall/percona-server-locks-detail-5.7.22/sql/rpl_rli_pdb.cc:1890
#4  0x00000000018e97ed in slave_worker_exec_job_group (worker=0x7ffe70024a90, rli=0x67633b0)
    at /root/mysqlall/percona-server-locks-detail-5.7.22/sql/rpl_rli_pdb.cc:2671
#5  0x00000000018c077a in handle_slave_worker (arg=0x7ffe70024a90) at /root/mysqlall/percona-server-locks-detail-5.7.22/sql/rpl_slave.cc:6239
#6  0x0000000001945620 in pfs_spawn_thread (arg=0x7ffe700296d0) at /root/mysqlall/percona-server-locks-detail-5.7.22/storage/perfschema/pfs.cc:2190
#7  0x00007ffff7bc6aa1 in start_thread () from /lib64/libpthread.so.0
#8  0x00007ffff6719bcd in clone () from /lib64/libc.so.6
向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI