我有一个存储过程来在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
请您说明是否有与执行时间相关的任何内容取决于之前的执行情况。我发现一个是,没有必要重新创建临时表会导致执行时间缩短。但如果再次执行它,我们可以看到执行时间增加。怎么样? this is the execution graph..
答案 0 :(得分:0)
时间不是最佳绩效指标。这可能是由于与您的存储过程无直接关系的各种因素造成的:IO,内存授权等。特别是考虑到这种相对较短的运行时间。
你必须能够看到mysql io ops的胆量,查询的执行计划等,以便能够确定究竟发生了什么。