mysql 强制不排序

order by null
order by null: 强制不排序
有的sql语句在执行完毕之后把结果给排序了,而我们对该结果没要求有排序效果,
这个排序是多余的,反而还消耗mysql的资源。为了使得获得数据的自然性、不要排序、降低mysql资源的开销,可以强制不排序。

例如:
获得每个分类下商品的总数量:
select c.cat_id,count(g.goods_id) from sw_goods g join sw_category c on g.goods_category_id=c.cat_id group by g.goods_category_id
(上边查询结果根据cat_id做了排序)

select c.cat_id,count(g.goods_id) from sw_goods g join sw_category c on g.goods_category_id=c.cat_id group by g.goods_category_id ORDER BY null
(上边查询结果没有根据cat_id做排序)

猜你喜欢

转载自blog.csdn.net/u013043762/article/details/80294816