通过profile优化SQL语句

开启profile优化SQL语句:
set profiling=1;
执行SQL语句
show profiles;
show profile for query 2;//根据query_id 查看某个查询的详细时间耗费

SHOW STATUS LIKE ‘last_query_cost‘;//查询上一条语句执行的代价

 

例:

mysql> show profiles;
+----------+------------+----------------------------------------+
| Query_ID | Duration   | Query                                  |
+----------+------------+----------------------------------------+
|        1 | 0.00049325 | select * from t_1_waybill              |
|        2 | 0.00130650 | select SQL_NO_CACHE * from t_1_waybill |
|        3 | 0.05051650 | show profiles for query 2              |
+----------+------------+----------------------------------------+
3 rows in set (0.00 sec)

mysql> show profile for query 1;
+--------------------------------+----------+
| Status                         | Duration |
+--------------------------------+----------+
| starting                       | 0.000032 |
| checking query cache for query | 0.000010 |
| checking privileges on cached  | 0.000010 |
| sending cached result to clien | 0.000435 |
| logging slow query             | 0.000004 |
| cleaning up                    | 0.000003 |
+--------------------------------+----------+
6 rows in set (0.00 sec)

mysql> show profile for query 2;
+--------------------+----------+
| Status             | Duration |
+--------------------+----------+
| starting           | 0.000159 |
| Opening tables     | 0.000034 |
| System lock        | 0.000005 |
| Table lock         | 0.000017 |
| init               | 0.000051 |
| optimizing         | 0.000004 |
| statistics         | 0.000019 |
| preparing          | 0.000009 |
| executing          | 0.000002 |
| Sending data       | 0.000607 |
| end                | 0.000006 |
| query end          | 0.000008 |
| freeing items      | 0.000364 |
| logging slow query | 0.000006 |
| cleaning up        | 0.000017 |
+--------------------+----------+
15 rows in set (0.00 sec)

通过profile优化SQL语句,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。