CREATE PROCEDURE delete_rows()
BEGIN
SELECT @@autocommit INTO @autocommit;
SET SESSION autocommit = ON;
REPEAT
DELETE FROM bigtable WHERE state=2 LIMIT 10000;
SELECT SLEEP(1) INTO @tmp;
UNTIL NOT ROW_COUNT() END REPEAT;
SET SESSION autocommit = @autocommit;
END