您好,登錄后才能下訂單哦!
本篇文章給大家分享的是有關(guān)Mysql RELICATION對存過的處理是怎樣的,小編覺得挺實用的,因此分享給大家學(xué)習(xí),希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。
昨天鷹眼需求從一個大表(27G)刪除47026788數(shù)據(jù);
用存儲過程通過主鍵刪除實現(xiàn);用了1個小時50分鐘;
QPS=47026788/(60*110)=7125.2709
這個速度已經(jīng)滿快了,都是隨機讀;[@more@]
當(dāng)時我在想,MASTER用近兩個小時,是不是SLAVE也用這么長時間么;
到SLAVE一看,根本沒有SQL在跑;
而且表里數(shù)據(jù)已經(jīng)被清空;
通過測試,我們發(fā)現(xiàn)MASTER在應(yīng)用存過時,在BINLOG里記錄的是真正最后執(zhí)行的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執(zhí)行完后,就會馬上應(yīng)用到SLAVE;
下面是一個刪除數(shù)據(jù)的存儲過程范例:
================================================
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對存過的處理是怎樣的,小編相信有部分知識點可能是我們?nèi)粘9ぷ鲿姷交蛴玫降?。希望你能通過這篇文章學(xué)到更多知識。更多詳情敬請關(guān)注億速云行業(yè)資訊頻道。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。