日期:2014-05-16  浏览次数:20799 次

菜鸟,求大神优化Oracle数据查询效率
select l.shipid, l.shiplockid, l.upordown, s.shipspeed from LockCheckin l, ship s where l.LockCheckinid not in (select LockCheckinid from SCHEDULEEXECS) and l.shipid=s.shipid(+) order by shiplockid

这是小弟写的sql,其中LockCheckin 和 SCHEDULEEXECS 都是百万级,偶尔会达到千万级的表,小弟知道not in的效率非常之差,详情大神们看看如何能提高数据查询效率

------解决方案--------------------
SQL code

--LockCheckin中的shipid,LockCheckinid建立聯合索引
--ship中的shipid建立索引
--SCHEDULEEXECS中的LockCheckinid建立索引
--這些只是為了測試速度,測完後再恢復為你之前的
select l.shipid, l.shiplockid, l.upordown, s.shipspeed 
from LockCheckin l, ship s 
where l.shipid=s.shipid(+) 
and not exists (select 1 from SCHEDULEEXECS where SCHEDULEEXECS.LockCheckinid=l.LockCheckinid)
order by shiplockid