二十四:从库数据的查找和参数slave_rows_search_algorithms(笔记)

发布时间:2020-08-10 17:52:38 作者:gaopengtttt
来源:ITPUB博客 阅读:207

欢迎关注我的《深入理解MySQL主从原理 32讲 》,如下:

二十四:从库数据的查找和参数slave_rows_search_algorithms(笔记)
如果图片不能显示可查看下面链接:
https://www.jianshu.com/p/d636215d767f

一、索引操找和定位栈帧

slave_rows_search_algorithms默认。

一些debug的断点:

1、主库

delete from tkkk where a=15;
删除3条记录

不会触发二级索引的 定位函数

2、备库

二、hash 算法

Rows_log_event::do_apply_event
 ->GTID 跳过逻辑
 ->打开表
 ->table 映射
 ->设置访问位图read_set 和 write_set
 ->准备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结构m_hash.init()
 ->循环event中的每一条数据
   ->调用相应的方法接口
     ->hash 方法 Rows_log_event::do_hash_scan_and_update
      ->将每条数据加入hash 区域 Rows_log_event::do_hash_row 
        如果有索引还会维护一个集合
      ->如过是Event中的最后一条数据调用Rows_log_event::do_scan_and_update
        扫描整个表或者遍历集合进行索引查找定位查找数据
        和HASH结构进行对比
        对比成功在HASH结构中删除
        调用删除接口删除数据

一个测试

主要测试从库在有主键和没有主键下接口调用:
slave_rows_search_algorithms=’INDEX_SCAN,HASH_SCAN’;

建表

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

数据

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)

主库删除一条数据:

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

从库调用接口:

(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

主库再次删除一条数据:

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

从库调用接口变为了hash算法:

(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
推荐阅读:
  1. 数据库知识笔记
  2. 从库数据查找和参数slave_rows_search_alg

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

algorithms 查找 rows

上一篇:Uncosted MMT with missing rows in WIP_PERIODS_BALANCES

下一篇:Oracle RAC+DG环境搭建(CentOS 7+Oracle 12C)( 十) 部署 DataGuard

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》