作为开发者必须掌握的mysql操作sql语句优化-showprocesslistandexplain(五)

2014-11-24 10:18:28 · 作者: · 浏览: 6
oup-by

表明可以在索引中找到分组所需的所有数据,不需要查询实际的表。

 
   
  1. mysql> explain select user_id from t_order group by user_id;
  2. +----+-------------+---------+-------+---------------+---------+---------+------+------+--------------------------+
  3. | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
  4. +----+-------------+---------+-------+---------------+---------+---------+------+------+--------------------------+
  5. | 1 | SIMPLE | t_order | range | NULL | user_id | 5 | NULL | 3 | Using index for group-by |
  6. +----+-------------+---------+-------+---------------+---------+---------+------+------+--------------------------+
  7. 1 row in set (0.00 sec)

除了上面的三个说明,还需要注意rows的数值,多行之间的数值是乘积的关系,可以估算大概要处理的行数,如果乘积很大,那就很有优化的必要了。