对于像这样的删除,还是按照我们默认的规则,在量很大的情况下,分批次删除是最快的,加limit 1000(推荐的参考值,可变),加入循环中处理,要比一下子删除快很多很多。
执行call RUS_CommonFriend_delete_1k(用户ID);
默认删除1000行,然后休眠3秒,再轮训,直到把检索的行全删除。
DELIMITER $$
USE RUSDB$$
DROP PROCEDURE IF EXISTS RUS_CommonFriend_delete_1k$$
CREATE PROCEDURE RUS_CommonFriend_delete_1k(IN v_smalluserid INT)
BEGIN
del_1k:LOOP
delete from RUSDB.RUS_CommonFriend where SmallUserId = v_smalluserid limit 1000;
select row_count() into @count;
IF @count = 0 THEN
select CONCAT ('RUSDB.RUS_CommonFriend SmallUserId = ',v_smalluserid,' is ',@count,' rows.') as RUS_CommonFriend_delete_finish;
LEAVE del_1k;
END IF;
select sleep(3);
END LOOP del_1k;
END$$
DELIMITER ;
|
本文转自 liang3391 51CTO博客,原文链接:http://blog.51cto.com/liang3391/820280