Testing performance of queries in mysql

后端 未结 6 762
南方客
南方客 2020-12-12 13:55

I am trying to setup a script that would test performance of queries on a development mysql server. Here are more details:

  • I have root access
  • I am the
6条回答
  •  既然无缘
    2020-12-12 14:42

    Assuming that you can not optimize the LIKE operation itself, you should try to optimize the base query without them minimizing number of rows that should be checked.

    Some things that might be useful for that:

    rows column in EXPLAIN SELECT ... result. Then,

    mysql> set profiling=1;
    mysql> select sql_no_cache * from mytable;
     ...
    mysql> show profile;
    +--------------------+----------+
    | Status             | Duration |
    +--------------------+----------+
    | starting           | 0.000063 |
    | Opening tables     | 0.000009 |
    | System lock        | 0.000002 |
    | Table lock         | 0.000005 |
    | init               | 0.000012 |
    | optimizing         | 0.000002 |
    | statistics         | 0.000007 |
    | preparing          | 0.000005 |
    | executing          | 0.000001 |
    | Sending data       | 0.001309 |
    | end                | 0.000003 |
    | query end          | 0.000001 |
    | freeing items      | 0.000016 |
    | logging slow query | 0.000001 |
    | cleaning up        | 0.000001 |
    +--------------------+----------+
    15 rows in set (0.00 sec)
    

    Then,

    mysql> FLUSH STATUS;
    mysql> select sql_no_cache * from mytable;
    ...
    mysql> SHOW SESSION STATUS LIKE 'Select%';
    +------------------------+-------+
    | Variable_name          | Value |
    +------------------------+-------+
    | Select_full_join       | 0     |
    | Select_full_range_join | 0     |
    | Select_range           | 0     |
    | Select_range_check     | 0     |
    | Select_scan            | 1     |
    +------------------------+-------+
    5 rows in set (0.00 sec)
    

    And another interesting value is last_query_cost, which shows how expensive the optimizer estimated the query (the value is the number of random page reads):

    mysql> SHOW STATUS LIKE 'last_query_cost';
    +-----------------+-------------+
    | Variable_name   | Value       |
    +-----------------+-------------+
    | Last_query_cost | 2635.399000 |
    +-----------------+-------------+
    1 row in set (0.00 sec)
    

    MySQL documentation is your friend.

提交回复
热议问题