默認狀況下,Mysql 對全部 group by 的字段進行排序,若是查詢包括 group by ,用戶想要避免排序結果的消耗。能夠指定 order by null 禁止排序。mysql
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,因此查詢會較第二個查詢耗時。sql