我創建一個使用遊標Mysql的過程,但它的運行速度太慢......它是由每秒40條60線之間得到。請參見:程序與光標的mysql太慢..爲什麼?
DELIMITER $$
CREATE PROCEDURE sp_create(IN v_idsorteio INT,OUT afetados INT)
BEGIN
DECLARE done INT default 0;
DECLARE vc_idsocio INT;
DECLARE z INT;
DECLARE cur1 CURSOR FOR select IdSocio from socios where Sorteio=1 and Finalizado='S' and CodClientes IS NOT NULL;
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done=1;
SET z=1;
OPEN cur1;
FETCH cur1 INTO vc_idsocio;
WHILE done=0 DO
-- SELECT register as t;
insert INTO socios_numeros_sorteio (IdSocio,IdSorteio,NumerodeSorteio) VALUES (vc_idsocio,v_idsorteio,z);
FETCH cur1 INTO vc_idsocio;
SET z = z+1;
END WHILE;
CLOSE cur1;
Select z-1 as total INTO afetados;
END$$
DELIMITER ;
我怎樣才能改善呢?
我第二,'INSERT .. SELECT'是學習 – spacediver 2012-07-19 20:20:31
優秀的答案:) – 2012-07-19 20:39:41
的警告是必要對此例如一個偉大的工具。這些插入語句中涉及的表將在插入期間保持鎖定狀態,因此只要鎖就位,就可以防止表上的其他動作(例如,選擇,插入,更新,刪除)。 – 2013-12-26 17:03:05