[前][次][番号順一覧][スレッド一覧]

mysql:15940

From: HIRATSUKA Sadao <HIRATSUKA Sadao <hiratsuka.sadao@xxxxxxxxxx>>
Date: Thu, 21 Feb 2013 09:51:01 +0900
Subject: [mysql 15940] Re: mysql-5.6.9 vs mysql-5.1.68

こんにちは、平塚です。

MyISAMでしたら、INSERT後にANALYZEを行った方が良いです。

■MySQL 5.5.29

mysql> explain select name,tm,v from t2 where name='n1' and tm<='20:05:00';
+----+-------------+-------+------+---------------+------+---------+-------+------+-------------+
| id | select_type | table | type | possible_keys | key  | key_len | ref   | rows | Extra       |
+----+-------------+-------+------+---------------+------+---------+-------+------+-------------+
|  1 | SIMPLE      | t2    | ref  | ix            | ix   | 67      | const |    2 | Using where |
+----+-------------+-------+------+---------------+------+---------+-------+------+-------------+
1 row in set (0.00 sec)

mysql> analyze table t2;
+----------+---------+----------+----------+
| Table    | Op      | Msg_type | Msg_text |
+----------+---------+----------+----------+
| scott.t2 | analyze | status   | OK       |
+----------+---------+----------+----------+
1 row in set (0.00 sec)

mysql> explain select name,tm,v from t2 where name='n1' and tm<='20:05:00';
+----+-------------+-------+------+---------------+------+---------+-------+------+-------------+
| id | select_type | table | type | possible_keys | key  | key_len | ref   | rows | Extra       |
+----+-------------+-------+------+---------------+------+---------+-------+------+-------------+
|  1 | SIMPLE      | t2    | ref  | ix            | ix   | 67      | const |   11 | Using where |
+----+-------------+-------+------+---------------+------+---------+-------+------+-------------+
1 row in set (0.00 sec)

■MySQL 5.6.10

mysql> explain select name,tm,v from t2 where name='n1' and tm<='20:05:00';
+----+-------------+-------+------+---------------+------+---------+-------+------+-----------------------+
| id | select_type | table | type | possible_keys | key  | key_len | ref   | rows | Extra                 |
+----+-------------+-------+------+---------------+------+---------+-------+------+-----------------------+
|  1 | SIMPLE      | t2    | ref  | ix            | ix   | 67      | const |    2 | Using index condition |
+----+-------------+-------+------+---------------+------+---------+-------+------+-----------------------+
1 row in set (0.00 sec)

mysql> analyze table t2;
+----------+---------+----------+----------+
| Table    | Op      | Msg_type | Msg_text |
+----------+---------+----------+----------+
| scott.t2 | analyze | status   | OK       |
+----------+---------+----------+----------+
1 row in set (0.00 sec)

mysql> explain select name,tm,v from t2 where name='n1' and tm<='20:05:00';
+----+-------------+-------+------+---------------+------+---------+-------+------+-----------------------+
| id | select_type | table | type | possible_keys | key  | key_len | ref   | rows | Extra                 |
+----+-------------+-------+------+---------------+------+---------+-------+------+-----------------------+
|  1 | SIMPLE      | t2    | ref  | ix            | ix   | 67      | const |   11 | Using index condition |
+----+-------------+-------+------+---------------+------+---------+-------+------+-----------------------+
1 row in set (0.00 sec)

==

それから、EXPLAINのrowsはあくまで見積もりレコード数ですので、
実際に非効率になったかどうかは、information_schemaから確認すると良いです。

SELECT variable_name, variable_value
FROM information_schema.global_status
WHERE variable_name LIKE 'Handler\_read%';

■MySQL 5.5.29

+-----------------------+----------------+ ----------------+----------------+
| variable_name         | variable_value |  (after)        | (diff)         |
+-----------------------+----------------+ ----------------+----------------+
| HANDLER_READ_FIRST    | 3              |  3              | 0              |
| HANDLER_READ_KEY      | 23375600       |  23375601       | 1              |
| HANDLER_READ_LAST     | 0              |  0              | 0              |
| HANDLER_READ_NEXT     | 23375554       |  23375565       | 11             |
| HANDLER_READ_PREV     | 0              |  0              | 0              |
| HANDLER_READ_RND      | 40046          |  40046          | 0              |
| HANDLER_READ_RND_NEXT | 314025         |  314033         | 8              |
+-----------------------+----------------+ ----------------+----------------+

■MySQL 5.6.10

+-----------------------+----------------+ ----------------+----------------+
| variable_name         | variable_value |  (after)        | (diff)         |
+-----------------------+----------------+ ----------------+----------------+
| HANDLER_READ_FIRST    | 15             |  15             | 0              |
| HANDLER_READ_KEY      | 18             |  19             | 1              |
| HANDLER_READ_LAST     | 0              |  0              | 0              |
| HANDLER_READ_NEXT     | 21             |  27             | 6              |
| HANDLER_READ_PREV     | 0              |  0              | 0              |
| HANDLER_READ_RND      | 0              |  0              | 0              |
| HANDLER_READ_RND_NEXT | 5793           |  5801           | 8              |
+-----------------------+----------------+ ----------------+----------------+

見る限りMySQL 5.6.10の方が効率的です。

とくに調べていませんが、
Using index conditionが効いて減った読み取りレコード数と、
Using index condition自体のオーバーヘッドとの勝負ではないかと
考えています。

それとMySQL 5.6ではquery_cache_typeのデフォルト値が0になったので、
そちらにもご注意ください。

-- 
平塚貞夫 hiratsuka.sadao@xxxxxxxxxx



[前][次][番号順一覧][スレッド一覧]

     15935 2013-02-19 17:49 [Etsuo SUMIYA <sumiya] mysql-5.6.9 vs mysql-5.1.68             
     15938 2013-02-20 23:10 ┗[とみたまさひろ <tomm]                                       
   @ 15939 2013-02-21 00:19  ┗["yoku ts." <yoku0825]                                     
->   15940 2013-02-21 09:51   ┗[HIRATSUKA Sadao <hir]                                   
     15943 2013-02-27 17:14    ┗[Etsuo SUMIYA <sumiya]                                 
     15944 2013-02-27 23:21     ┗["yoku ts." <yoku0825]                               
     15946 2013-02-28 18:10      ┗[Etsuo SUMIYA <sumiya]                             
     15947 2013-02-28 18:35       ┗["yoku ts." <yoku0825]                           
     15948 2013-03-01 11:45        ┗["yoku ts." <yoku0825]