mysql> EXPLAIN select * from sys_log group by title;
+----+-------------+---------+------------+------+---------------+------+---------+------+-------+----------+---------------------------------+
| id | select_type | table   | partitions | type | possible_keys | key  | key_len | ref  | rows  | filtered | Extra                           |
+----+-------------+---------+------------+------+---------------+------+---------+------+-------+----------+---------------------------------+
|  1 | SIMPLE      | sys_log | NULL       | ALL  | NULL          | NULL | NULL    | NULL | 23733 |   100.00 | Using temporary; Using filesort |
+----+-------------+---------+------------+------+---------------+------+---------+------+-------+----------+---------------------------------+
mysql> EXPLAIN select * from sys_log group by title order by null;
+----+-------------+---------+------------+------+---------------+------+---------+------+-------+----------+-----------------+
| id | select_type | table   | partitions | type | possible_keys | key  | key_len | ref  | rows  | filtered | Extra           |
+----+-------------+---------+------------+------+---------------+------+---------+------+-------+----------+-----------------+
|  1 | SIMPLE      | sys_log | NULL       | ALL  | NULL          | NULL | NULL    | NULL | 23733 |   100.00 | Using temporary |
+----+-------------+---------+------------+------+---------------+------+---------+------+-------+----------+-----------------+


从上面的例子可以看出,第一个查询的 Extra 多了一个 filesort,所以查询会较第二个查询耗时。

02-24 10:01