[英]why there is a patteren of execution time in mySql procedure execution
我有一个存储过程可以在 mySql 中生成一些输出。
BEGIN
START TRANSACTION;
CREATE TEMPORARY TABLE IF NOT EXISTS tempDays
(
ID int AUTO_INCREMENT PRIMARY KEY,
-- column list
);
CREATE TEMPORARY TABLE IF NOT EXISTS tempPeriods
(
ID int AUTO_INCREMENT PRIMARY KEY,
-- column list
);
INSERT INTO tempDays (-- column list) SELECT -- select list contains n number of rows with some conditions
--
--
-- some queries and temporary table creation
--
--
--
SELECT COUNT(*) INTO @daylimit FROM tempDays;
SELECT 1 INTO @daycounter;
WHILE(@daycounter<=@daylimit)
DO
SELECT COUNT(*) INTO @limitperiods FROM tempPeriods;
SELECT 1 INTO @countperiods;
WHILE(@countperiods<=@limitperiods)
DO
-- some complicated(some sort of IF THEN blocks to take time some execution time) query inside.
SET @countperiods=@countperiods+1;
END WHILE;
SET @daycounter=@daycounter+1;
END WHILE;
SELECT * FROM temptimetable;
TRUNCATE TABLE tempDays;
TRUNCATE TABLE tempPeriods;
END TRANSACTION;
END
这是8个一一调用的执行总结。
Stored procedure 'sample_db.sample_proc' has been executed in 1.565s.
Stored procedure 'sample_db.sample_proc' has been executed in 2.362s.
Stored procedure 'sample_db.sample_proc' has been executed in 1.541s.
Stored procedure 'sample_db.sample_proc' has been executed in 2.198s.
Stored procedure 'sample_db.sample_proc' has been executed in 1.863s.
Stored procedure 'sample_db.sample_proc' has been executed in 3.657s.
Stored procedure 'sample_db.sample_proc' has been executed in 2.306s.
Stored procedure 'sample_db.sample_proc' has been executed in 3.226s.
我们可以看到一个执行时间模式... 1,2,1,2,3,2,3
你能解释一下是否有任何与执行时间相关的东西取决于之前的执行。 我发现一个是,不需要重新创建临时表会导致执行时间减少。 但是如果再次执行它,我们可以看到执行时间增加。 如何? 这是执行图..
时间不是最好的绩效衡量标准。 这可能是由于与您的存储过程没有直接关系的各种因素造成的:IO、内存授予等。特别是考虑到相对较短的运行时间。
您必须能够查看 mysql io 操作的内容、查询的执行计划等,才能确定到底发生了什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.