Home >Database >Mysql Tutorial >mysql order by null

mysql order by null

WBOY
WBOYOriginal
2016-06-07 16:38:471841browse

order by null用途是强制对查询结果禁用排序。通过explain检查查询语句时候,如果看到Extra列中有Using filesort,这是对性能有一定影响的,特别是使用了group by时,就算你没有显示的指定order by,mysql会默认按照分组字段进行排序。某些情况下是没有必要

order by null用途是强制对查询结果禁用排序。通过explain检查查询语句时候,如果看到Extra列中有Using filesort,这是对性能有一定影响的,特别是使用了group by时,就算你没有显示的指定order by,mysql会默认按照分组字段进行排序。某些情况下是没有必要使用排序的,例如在处理表报数据的时候(把原始表数据统计后插入到一个用于报表查询的表),则完全可以可以使用order by null来取消排序。如:

insert into reportTable(day, clicks, revenue)
    select day, count(*), sum(revenue) from clickOriginTalbe
    group by day
    order by null
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn