[英]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.