order by建议使用索引

今天在sql 查询中一个表中查询花了至少20秒时间,数据为620000行,sql语句如下:

测试一:使用order by 

单单只是查询0,10行数据,耗时27.888s

select a.id,a.county_id,a.county_name,a.town_id,a.town_name,a.village_id,a.village_name,b.province as province_name,b.name as city_name from place a left join city b on a.city_id=b.code where a.id is not null order by a.village_id asc limit 0, 10

sql 大数据查询慎用 order by

测试二:不使用order by

select a.id,a.county_id,a.county_name,a.town_id,a.town_name,a.village_id,a.village_name,b.province as province_name,b.name as city_name from place a left join city b on a.city_id=b.code where a.id is not null limit 0, 10

同样是查询0,10行数据,耗时0.084s

 sql 大数据查询慎用 order by

以上仅供参考,数据更大时需要进行更精细的优化

相关文章:

  • 2022-12-23
  • 2021-09-21
  • 2021-12-09
  • 2022-12-23
  • 2022-12-23
  • 2021-06-30
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-11
  • 2021-07-02
  • 2021-12-03
  • 2021-10-26
  • 2022-03-04
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案