默认情况下,mysql对所有的gruop by col1,col2...的字段进行排序。如果查询包含group by但用户想要避免排序结果的消耗,则可以指定order by null禁止排序。

 

explain select payment_date,sum(amount) from payment group by payment_date\G;

 

优化 gruop by  语句

 

 

 

 explain select payment_date,sum(amount) from payment group by payment_date order by null\G;

 

优化 gruop by  语句

 

 

从上面的例子可以看出,第一个SQL的执行时间为0.05sec,  而第二个SQL的执行时间为0.00sec。

相关文章:

  • 2021-10-08
  • 2021-06-29
  • 2023-01-12
  • 2022-12-23
  • 2021-12-24
  • 2021-06-22
猜你喜欢
  • 2021-09-14
  • 2022-12-23
  • 2023-01-17
  • 2023-01-29
  • 2021-06-18
  • 2021-11-02
相关资源
相似解决方案