文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>对于存储过程的调优过程

对于存储过程的调优过程

时间:2009-08-17  来源:cenalulu

普通的query的调优方式一般是查看slow-log,或者long-query-time = 0然后用mk-log-paser进行分析。
假设需要对一个存储过程进行调优。那么如果使用slow-log将会看到很多如下的结果:

SQL:
  1. mysql> SELECT whatstheweatherlike(5);
  2. +----------------------------------------------------------+
  3. | whatstheweatherlike(5)                                   |
  4. +----------------------------------------------------------+
  5. | Its 5°C, time IS 02:28:05, feels [LIKE] almost summer!   |
  6. +  ----------------------------------------------------------+

  7.  row IN SET (0.00 sec)
  8.  
  9. host # tail /var/log/mysql/mysql-slow.log

  10.  Time: 090115  2:25:28
  11. # User@Host: me[me] @ localhost []
  12. # Thread_id: 3432  Schema: test
  13. # Query_time: 0.000695  Lock_time: 0.000284  Rows_sent: 1  Rows_examined: 0  Rows_affected: 0  Rows_read: 1
  14. # QC_Hit: No  Full_scan: No  Full_join: No  Tmp_table: No  Tmp_table_on_disk: No
  15. # Filesort: No  Filesort_on_disk: No  Merge_passes: 0
  16. # No InnoDB statistics available for this query
  17. SELECT whatstheweatherlike(5);
  18.  User@Host: me[me] @ localhost []
  19. # Thread_id: 3432  Schema: test
  20. # Query_time: 0.000695  Lock_time: 0.000284  Rows_sent: 1  Rows_examined: 0  Rows_affected: 0  Rows_read: 1
  21. # QC_Hit: No  Full_scan: No  Full_join: No  Tmp_table: No  Tmp_table_on_disk: No
  22. # Filesort: No  Filesort_on_disk: No  Merge_passes: 0
  23. # No InnoDB statistics available for this query
  24. SELECT whatstheweatherlike(5);
  25.  Thread_id: 3432  Schema: test
  26. # Query_time: 0.000695  Lock_time: 0.000284  Rows_sent: 1  Rows_examined: 0  Rows_affected: 0  Rows_read: 1
  27. # QC_Hit: No  Full_scan: No  Full_join: No  Tmp_table: No  Tmp_table_on_disk: No
  28. # Filesort: No  Filesort_on_disk: No  Merge_passes: 0
  29. # No InnoDB statistics available for this query
  30. SELECT whatstheweatherlike(5);
  31.  Query_time: 0.000695  Lock_time: 0.000284  Rows_sent: 1  Rows_examined: 0  Rows_affected: 0  Rows_read: 1
  32. # QC_Hit: No  Full_scan: No  Full_join: No  Tmp_table: No  Tmp_table_on_disk: No
  33. # Filesort: No  Filesort_on_disk: No  Merge_passes: 0
  34. # No InnoDB statistics available for this query
可见只显示了对stored-routine的时间记录,并没有对内部的语句的详细运行状况的提示。
这种情况下,可以使用profile进行调优。

过程如下:
  1. mysql> SET profiling=1;
  2. Query OK, 0 rows affected (0.00 sec)
  3.  
  4. mysql> SELECT whatstheweatherlike(3);
  5. +-----------------------------------------------------------+
  6. | whatstheweatherlike(3)                                    |
  7. +-----------------------------------------------------------+
  8. | Its 3°C, time IS 02:43:25, feels [LIKE] snow IS melting   |
  9. +   -----------------------------------------------------------+

  10.  row IN SET (0.00 sec)
  11.  
  12. mysql> SHOW profiles;
  13. +----------+------------+-------------------------------------------------------------+

  14.  Query_ID | Duration   | Query                                                       |
  15. +----------+------------+-------------------------------------------------------------+

  16.         1 | 0.00005100 | SELECT CURTIME() INTO time                                  |
  17. |        2 | 0.00014100 | SELECT feeling INTO feels FROM weather WHERE temp = in_temp |
  18. +----------+------------+-------------------------------------------------------------+

  19. rows IN SET (0.00 sec)
这样就能看到存储过程内部语句的执行情况了。
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载