2013年9月6日星期五

explain 看到同一sql 使用不同索引


同一条 sql, explain 不同, type 的值不同,数据量不一样 
 
c2c2012> explain select count(`out_views`) as o, count(`in_views`) as i, count(`last_out_views`) as lo, count(`last_in_views`) as li, count(`earn_total`) as e, count(`new_earn_total`) as ne from `c2c_cpm_earn_total_log` where 1=1 AND `super` = 1 AND user_type = '5' AND dateline >= '2013-08-30 00:00:00' AND dateline <= '2013-08-30 23:59:59';
+----+-------------+------------------------+-------------+--------------------------+-----------------+---------+------+-------+-----------------------------------------------+
| id | select_type | table                  | type        | possible_keys            | key             | key_len | ref  | rows  | Extra                                         |
+----+-------------+------------------------+-------------+--------------------------+-----------------+---------+------+-------+-----------------------------------------------+
|  1 | SIMPLE      | c2c_cpm_earn_total_log | index_merge | dateline,super,user_type | user_type,super | 1,1     | NULL | 27358 | Using intersect(user_type,super); Using where |
+----+-------------+------------------------+-------------+--------------------------+-----------------+---------+------+-------+-----------------------------------------------+
1 row in set (0.00 sec)

c2c2012> explain select count(`out_views`) as o, count(`in_views`) as i, count(`last_out_views`) as lo, count(`last_in_views`) as li, count(`earn_total`) as e, count(`new_earn_total`) as ne from `c2c_cpm_earn_total_log` where 1=1 AND `super` = 1 AND user_type = '4' AND dateline >= '2013-08-30 00:00:00' AND dateline <= '2013-08-30 23:59:59';
+----+-------------+------------------------+-------+--------------------------+----------+---------+------+-------+-------------+
| id | select_type | table                  | type  | possible_keys            | key      | key_len | ref  | rows  | Extra       |
+----+-------------+------------------------+-------+--------------------------+----------+---------+------+-------+-------------+
|  1 | SIMPLE      | c2c_cpm_earn_total_log | range | dateline,super,user_type | dateline | 4       | NULL | 72778 | Using where |
+----+-------------+------------------------+-------+--------------------------+----------+---------+------+-------+-------------+
1 row in set (0.00 sec)

c2c2012>
 
 
   开发反馈从 phpmyadmin explain 执行的结果是一样的,事实肯定是以客户端为准,不知道 phpmyadmin 是通过程序直接判断sql 使用的索引呢?

没有评论:

发表评论