Chinaunix首页 | 论坛 | 博客
  • 博客访问: 569103
  • 博文数量: 86
  • 博客积分: 2581
  • 博客等级: 少校
  • 技术积分: 793
  • 用 户 组: 普通用户
  • 注册时间: 2009-01-05 20:09
文章分类

全部博文(86)

文章存档

2009年(86)

我的朋友

分类: Mysql/postgreSQL

2009-08-17 16:53:32

普通的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)
这样就能看到存储过程内部语句的执行情况了。


阅读(1965) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~