我正在尝试通过将时间打印到CSV文件来创建数据库在各种任务上花费的时间的图形。
它应该测试以下内容:分别插入10、50、100、500、1000、5000、10.000、50.000、100.000、500.000和1.000.000并将其写入文件。
它总是给我错误2014:命令不同步。有办法解决吗?
DELIMITER $$
USE mydb;
CREATE DEFINER = 'root'@'localhost'culturacultura PROCEDURE script(IN i INT)
BEGIN
DECLARE counter INT;
DECLARE size INT;
DECLARE line INT;
DECLARE startTime TIMESTAMP;
DECLARE endTime TIMESTAMP;
SET counter = 1;
SET size = 10;
SET line = 1;
WHILE (line <= 10) DO
SET startTime = NOW();
WHILE (counter <= size) DO
CASE i
WHEN 1 THEN SET @query1 = CONCAT('INSERT INTO Log(idOperação, Data, Utilizador, Operação, Tabela, idObjecto, Coluna, Valor) VALUES()');
WHEN 2 THEN SET @query1 = CONCAT('INSERT INTO Investigador(Email, Nome, CategoriaProfissional, Passe) VALUES("userEmail', @counter, '@gmail.com", JoãoUser', @counter,', "PHD", "password', @counter, '");');
WHEN 3 THEN SET @query1 = CONCAT('INSERT INTO Cultura(Email, Nome, Descrição) VALUES("userEmail', @counter, '@gmail.com", "Cultura', @counter, '", "Uma descrição qualquer.");');
WHEN 4 THEN SET @query1 = CONCAT('INSERT INTO Variável(Nome) VALUES("Variável', @counter, '");');
WHEN 5 THEN SET @query1 = CONCAT('INSERT INTO VariáveisCultura(idCultura, idVariável, LimiteInferior, LimiteSuperior) VALUES(', @counter, ', ', @counter, ', ', @counter + 1, ', ', @counter + 5, ');');
WHEN 6 THEN SET @query1 = CONCAT('INSERT INTO Medição "user',@counter,'@email.com"@"localhost" IDENTIFIED BY "password',@counter,'" ');
END CASE;
PREPARE stmt FROM @query1;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET @first = @first + 1;
END WHILE;
SET endTime = NOW();
CASE i
WHEN 1 THEN SET @query1 = CONCAT("SELECT TIMESTAMPDIFF(SECOND, @startTime, @endTime) AS Time INTO OUTFILE 'time_log_creation_'",@size,".csv' FIELDS ENCLOSED BY '\"' TERMINATED BY ';' ESCAPED BY '\"'"," LINES TERMINATED BY '\r\n';");
WHEN 2 THEN SET @query1 = CONCAT("SELECT TIMESTAMPDIFF(SECOND, @startTime, @endTime) AS Time INTO OUTFILE 'time_investigador_creation_'",@size,".csv' FIELDS ENCLOSED BY '\"' TERMINATED BY ';' ESCAPED BY '\"'"," LINES TERMINATED BY '\r\n';");
WHEN 3 THEN SET @query1 = CONCAT("SELECT TIMESTAMPDIFF(SECOND, @startTime, @endTime) AS Time INTO OUTFILE 'time_cultura_creation_'",@size,".csv' FIELDS ENCLOSED BY '\"' TERMINATED BY ';' ESCAPED BY '\"'"," LINES TERMINATED BY '\r\n';");
WHEN 4 THEN SET @query1 = CONCAT("SELECT TIMESTAMPDIFF(SECOND, @startTime, @endTime) AS Time INTO OUTFILE 'time_variável_creation_'",@size,".csv' FIELDS ENCLOSED BY '\"' TERMINATED BY ';' ESCAPED BY '\"'"," LINES TERMINATED BY '\r\n';");
WHEN 5 THEN SET @query1 = CONCAT("SELECT TIMESTAMPDIFF(SECOND, @startTime, @endTime) AS Time INTO OUTFILE 'time_associação_creation_'",@size,".csv' FIELDS ENCLOSED BY '\"' TERMINATED BY ';' ESCAPED BY '\"'"," LINES TERMINATED BY '\r\n';");
WHEN 6 THEN SET @query1 = CONCAT("SELECT TIMESTAMPDIFF(SECOND, @startTime, @endTime) AS Time INTO OUTFILE 'time_madição_creation_'",@size,".csv' FIELDS ENCLOSED BY '\"' TERMINATED BY ';' ESCAPED BY '\"'"," LINES TERMINATED BY '\r\n';");
END CASE;
PREPARE stmt FROM @query1;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
TRUNCATE TABLE tablename;
IF(line % 2 = 1) THEN
SET size = size * 5;
ELSE
SET size = size * 2;
END IF;
END WHILE;
END$$
DELIMITER ;
/*CALL script(1);*/
CALL script(2);
CALL script(3);
CALL script(4);
CALL script(5);
/*CALL script(6);*/
DROP PROCEDURE script;