这样一个sql要怎么优化呢?
select t.loginName,t.distanceStr,t.sex from (select (st_distance(point(r.lon,r.lat), point(108.979118,34.166634)) * 111195 )
as distanceStr ,r.loginName,
r.sex from ycd_sys_user r where r.id != “55ef37a3dcd3423ab7f1cb8e5de3de1f” )
t where t.distanceStr <=50000
order by t.distanceStr asc limit 20
select t.loginName,t.distanceStr,t.sex from (select (st_distance(point(r.lon,r.lat), point(108.979118,34.166634)) * 111195 )
as distanceStr ,r.loginName,
r.sex from ycd_sys_user r where r.id != “55ef37a3dcd3423ab7f1cb8e5de3de1f” )
t where t.distanceStr <=50000
order by t.distanceStr asc limit 20
解决方案
20
不要查你周围的圆形,就查你为中心的长方形,一下就简单了。
一般来说,你的显示的位置是长方形区域,即便是显示圆形区域,客户端再处理一下就是了
一般来说,你的显示的位置是长方形区域,即便是显示圆形区域,客户端再处理一下就是了
20
对的
dim D=1.414*distance;
where (center.x-p.x<=D and p.x-center.x<=D and center.y-p.y<=D and p.y-center.y<=D)