比如说我要测试select * from t1,t2的执行时间
两个TABLE都有上千万行,明显打印是不可能的
请问有没有办法不输出query结果只输出query执行时间的方法?

解决方案 »

  1.   

    select count(*) from (select * from t1,t2);这样试一下,虽然会有 count(*)对测试结果有些影响。但基本上做对比测试应该可以了
      

  2.   

    mysql> set profiling=1
        -> ;
    Query OK, 0 rows affected (0.02 sec)mysql> show profiles
        -> ;
    Empty set (0.02 sec)mysql> select * from test;
    +----+-------+---------+-----+
    | id | class | name    | age |
    +----+-------+---------+-----+
    |  1 | A     | aaa     | 20  |
    |  2 | A     | B       | 25  |
    |  3 | B     | ddd     | 30  |
    |  4 | C     | B       | 40  |
    |  5 | B     | sssffff | 50  |
    +----+-------+---------+-----+
    5 rows in set (0.02 sec)mysql> show profile for query
        -> 1;
    +--------------------+----------+
    | Status             | Duration |
    +--------------------+----------+
    | starting           | 0.000147 |
    | Opening tables     | 0.000024 |
    | System lock        | 0.000010 |
    | Table lock         | 0.000015 |
    | init               | 0.000027 |
    | optimizing         | 0.000007 |
    | statistics         | 0.000019 |
    | preparing          | 0.000012 |
    | executing          | 0.000005 |
    | Sending data       | 0.006949 |
    | end                | 0.000009 |
    | query end          | 0.000006 |
    | freeing items      | 0.000097 |
    | logging slow query | 0.000004 |
    | cleaning up        | 0.000005 |
    +--------------------+----------+
    15 rows in set (0.03 sec)mysql> show profile cpu for query  1;
    +--------------------+----------+----------+------------+
    | Status             | Duration | CPU_user | CPU_system |
    +--------------------+----------+----------+------------+
    | starting           | 0.000147 |     NULL |       NULL |
    | Opening tables     | 0.000024 |     NULL |       NULL |
    | System lock        | 0.000010 |     NULL |       NULL |
    | Table lock         | 0.000015 |     NULL |       NULL |
    | init               | 0.000027 |     NULL |       NULL |
    | optimizing         | 0.000007 |     NULL |       NULL |
    | statistics         | 0.000019 |     NULL |       NULL |
    | preparing          | 0.000012 |     NULL |       NULL |
    | executing          | 0.000005 |     NULL |       NULL |
    | Sending data       | 0.006949 |     NULL |       NULL |
    | end                | 0.000009 |     NULL |       NULL |
    | query end          | 0.000006 |     NULL |       NULL |
    | freeing items      | 0.000097 |     NULL |       NULL |
    | logging slow query | 0.000004 |     NULL |       NULL |
    | cleaning up        | 0.000005 |     NULL |       NULL |
    +--------------------+----------+----------+------------+
    15 rows in set (0.00 sec)
    mysql> show profiles;
    +----------+------------+--------------------+
    | Query_ID | Duration   | Query              |
    +----------+------------+--------------------+
    |        1 | 0.00733250 | select * from test |
    +----------+------------+--------------------+
    1 row in set (0.00 sec)
      

  3.   

    你要具体时间吗?好像目前还没有想explain那样的语句