简体   繁体   English

为什么在mySql过程执行中有执行时间的模式

[英]why there is a patteren of execution time in mySql procedure execution

I have a stored procedure to generate some output in mySql.我有一个存储过程可以在 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 

This is the execution summary of 8 one by one calls.这是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.

we can see that an execution time pattern... 1,2,1,2,3,2,3我们可以看到一个执行时间模式... 1,2,1,2,3,2,3

Can you please explain is there anything related to the execution time depends on previous execution.你能解释一下是否有任何与执行时间相关的东西取决于之前的执行。 One I found is that, there is no need to re-create the temporary table will cause decrease execution time.我发现一个是,不需要重新创建临时表会导致执行时间减少。 But if execute it again we can see execution time increasing.但是如果再次执行它,我们可以看到执行时间增加。 How?如何? this is the execution graph..这是执行图..

Time is not the best performance measure.时间不是最好的绩效衡量标准。 This might occur due to various factors not related directly to your stored procedure: IO, memory grant, etc. Especially considering such relatively short run times.这可能是由于与您的存储过程没有直接关系的各种因素造成的:IO、内存授予等。特别是考虑到相对较短的运行时间。

You would have to be able to see guts of mysql io ops, execution plan for query, etc to be able to determine what is exactly happening.您必须能够查看 mysql io 操作的内容、查询的执行计划等,才能确定到底发生了什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM