Mysql RELICATION对存过的处理是怎样的

32次阅读
没有评论

共计 1790 个字符,预计需要花费 5 分钟才能阅读完成。

本篇文章给大家分享的是有关 Mysql RELICATION 对存过的处理是怎样的,丸趣 TV 小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着丸趣 TV 小编一起来看看吧。

昨天鹰眼需求从一个大表(27G)删除 47026788 数据;
用存储过程通过主键删除实现;用了 1 个小时 50 分钟;
 QPS=47026788/(60*110)=7125.2709
这个速度已经满快了,都是随机读;[@more@]

当时我在想,MASTER 用近两个小时,是不是 SLAVE 也用这么长时间么;

到 SLAVE 一看,根本没有 SQL 在跑;
而且表里数据已经被清空;

通过测试,我们发现 MASTER 在应用存过时,在 BINLOG 里记录的是真正最后执行的 DML 操作;
比如:
#101202 13:58:43 server id 2  end_log_pos 15842         Query   thread_id=4058  exec_time=0     error_code=0
SET TIMESTAMP=1291269523/*!*/;
delete from test where id = NAME_CONST(v_entry_id ,238)
/*!*/;
# at 15842
#101202 13:58:43 server id 2  end_log_pos 15974         Query   thread_id=4058  exec_time=0     error_code=0
SET TIMESTAMP=1291269523/*!*/;
delete from test where id = NAME_CONST(v_entry_id ,240)
/*!*/;
# at 15974
#101202 13:58:43 server id 2  end_log_pos 16106         Query   thread_id=4058  exec_time=0     error_code=0
SET TIMESTAMP=1291269523/*!*/;
delete from test where id = NAME_CONST(v_entry_id ,242)
/*!*/;

所以只要 MASTER 执行完后,就会马上应用到 SLAVE;

下面是一个删除数据的存储过程范例:
================================================
use test;
drop procedure if exists delete_expired;
delimiter //
CREATE PROCEDURE delete_expired(in in_date date)
   BEGIN
   declare done int default 0;
   declare rowcnt int default 0 ;
   declare v_entry_id int;
   declare cur_del cursor  For select id from test ;
   DECLARE CONTINUE HANDLER FOR SQLSTATE 02000 SET done = 1;      
   open cur_del;
   start transaction;
   cursor_loop:loop
       fetch cur_del into v_entry_id;
       if done=1 then leave cursor_loop ;
       end if ;
       delete from test where id =v_entry_id;
       set rowcnt=rowcnt+1;
       if rowcnt=1000 then
         set rowcnt =0 ;
         commit;
         start transaction;
       end if ;
   end loop cursor_loop ;
    commit ;
    close cur_del;
   END ;//
DELIMITER ;

call delete_expired (2010-01-10
drop procedure if exists delete_expired ;
===========================================================

以上就是 Mysql RELICATION 对存过的处理是怎样的,丸趣 TV 小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注丸趣 TV 行业资讯频道。

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-07-19发表,共计1790字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)