今天在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
测试二:不使用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
以上仅供参考,数据更大时需要进行更精细的优化