对于存储过程的调优过程
时间:2009-08-17 来源:cenalulu
普通的query的调优方式一般是查看slow-log,或者long-query-time = 0然后用mk-log-paser进行分析。
假设需要对一个存储过程进行调优。那么如果使用slow-log将会看到很多如下的结果:
SQL:
假设需要对一个存储过程进行调优。那么如果使用slow-log将会看到很多如下的结果:
SQL:
-
mysql> SELECT whatstheweatherlike(5);+----------------------------------------------------------+| whatstheweatherlike(5) |+----------------------------------------------------------+| Its 5°C, time IS 02:28:05, feels [LIKE] almost summer! |+ ----------------------------------------------------------+
row IN SET (0.00 sec)host # tail /var/log/mysql/mysql-slow.log
Time: 090115 2:25:28# User@Host: me[me] @ localhost []# Thread_id: 3432 Schema: test# Query_time: 0.000695 Lock_time: 0.000284 Rows_sent: 1 Rows_examined: 0 Rows_affected: 0 Rows_read: 1# QC_Hit: No Full_scan: No Full_join: No Tmp_table: No Tmp_table_on_disk: No# Filesort: No Filesort_on_disk: No Merge_passes: 0# No InnoDB statistics available for this querySELECT whatstheweatherlike(5);User@Host: me[me] @ localhost []# Thread_id: 3432 Schema: test# Query_time: 0.000695 Lock_time: 0.000284 Rows_sent: 1 Rows_examined: 0 Rows_affected: 0 Rows_read: 1# QC_Hit: No Full_scan: No Full_join: No Tmp_table: No Tmp_table_on_disk: No# Filesort: No Filesort_on_disk: No Merge_passes: 0# No InnoDB statistics available for this querySELECT whatstheweatherlike(5);Thread_id: 3432 Schema: test# Query_time: 0.000695 Lock_time: 0.000284 Rows_sent: 1 Rows_examined: 0 Rows_affected: 0 Rows_read: 1# QC_Hit: No Full_scan: No Full_join: No Tmp_table: No Tmp_table_on_disk: No# Filesort: No Filesort_on_disk: No Merge_passes: 0# No InnoDB statistics available for this querySELECT whatstheweatherlike(5);Query_time: 0.000695 Lock_time: 0.000284 Rows_sent: 1 Rows_examined: 0 Rows_affected: 0 Rows_read: 1# QC_Hit: No Full_scan: No Full_join: No Tmp_table: No Tmp_table_on_disk: No# Filesort: No Filesort_on_disk: No Merge_passes: 0# No InnoDB statistics available for this query 可见只显示了对stored-routine的时间记录,并没有对内部的语句的详细运行状况的提示。
这种情况下,可以使用profile进行调优。
过程如下:
-
mysql> SET profiling=1;Query OK, 0 rows affected (0.00 sec)mysql> SELECT whatstheweatherlike(3);+-----------------------------------------------------------+| whatstheweatherlike(3) |+-----------------------------------------------------------+| Its 3°C, time IS 02:43:25, feels [LIKE] snow IS melting |+ -----------------------------------------------------------+
row IN SET (0.00 sec)mysql> SHOW profiles;+----------+------------+-------------------------------------------------------------+
Query_ID | Duration | Query |+----------+------------+-------------------------------------------------------------+
1 | 0.00005100 | SELECT CURTIME() INTO time || 2 | 0.00014100 | SELECT feeling INTO feels FROM weather WHERE temp = in_temp |+----------+------------+-------------------------------------------------------------+
rows IN SET (0.00 sec) 这样就能看到存储过程内部语句的执行情况了。
相关阅读 更多 +