select *from (
select a.start_id startStation,
a.start_latstartLat,
a.start_lonstartLon,
c.end_latendLat,
c.end_lonendLon,
a.end_idoneStationEnd,
a.line_idoneline,
b.start_idtwoStationStart ,
b.end_idtwoStationEnd,
b.line_id twoline ,
c.start_id threeStationStart,
c.end_id threeEndStation,
c.line_idthreeline,
2 transferType,
distance(a.end_lat,a.end_lon,b.start_lat,b.start_lon) + distance(b.end_lat,b.end_lon,c.start_lat,c.start_lon) walkDistance,
ROWNUM RN
from ((select * from bustransferplan where start_id = #start.stationId#) a inner join
bustransferplan b on
a.end_heap = b.start_heap and a.line_id != b.line_id
inner join
(select * from bustransferplan where end_id = #end.stationId#) c on
b.end_heap = c.start_heap and b.line_id != c.line_id)
order by walkDistance
) whererownum <= 5
bustransferplan 数据大约在25W,这条SQL就是自关联,现在我建立索引INDEX(end_heap ,start_heap), INDEX(start_id),INDEX(end_id) ,现在结果出来基本要5秒钟左右哦,我一直觉得order by walkDistance有问题,数据一超过1000以上就很慢,这种动态排序不可避免,索引也没法建立(也可能是我无知,HOHO,非DBA),大家帮我看下有无什么方式去优化下这条SQL,这条SQL对我们现在系统十分重要,THINKS!
|