要对此进行检查,我们需要具有分析信息,该信息指示当前会话过程中执行的语句的资源使用情况。分析信息可以通过SHOW PROFILE和SHOW PROFILES语句获得。
在运行这些语句之前,必须将分析会话变量设置为1,如下所示:
mysql> set profiling = 1;
现在,如果我们将运行SHOW PROFILES语句,它将显示发送到服务器的最新语句列表以及持续时间和查询ID。
mysql> show profiles; +----------+------------+--------------------------------------+ | Query_ID | Duration | Query | +----------+------------+--------------------------------------+ | 1 | 0.01602200 | drop table if exists t1 | | 2 | 0.57223450 | create table t1(id int) | | 3 | 0.00015425 | show profile for query1 | | 4 | 0.22945050 | create table e1(id int) | | 5 | 0.09977025 | insert into e1(id) values(3),(4),(5) | +----------+------------+--------------------------------------+ 5 rows in set (0.00 sec)
现在假设我们要检查特定查询的持续时间,然后可以对查询query_no语句运行SHOW PROFILE。例如,如果我们运行query_id = 5的语句,则输出如下-
mysql> show profile for query 5; +------------------------------+--------------+ | Status | Duration | +------------------------------+--------------+ | starting | 0.000138 | | checking permissions | 0.000024 | | Opening tables | 0.000057 | | System lock | 0.035186 | | init | 0.000035 | | update | 0.021484 | | Waiting for query cache lock | 0.000021 | | update | 0.000005 | | end | 0.000024 | | query end | 0.042700 | | closing tables | 0.000017 | | freeing items | 0.000076 | | logging slow query | 0.000003 | | cleaning up | 0.000002 | +------------------------------+--------------+ 14 rows in set (0.00 sec)