日期:2014-05-17  浏览次数:20386 次

请教一个语句的优化
哪位帮看看,给点建议



insert szy_ok
select distinct a.gdsid,a.gdsmc,a.xh,a.gys,fmid
from CITY b,szy_jg1 a  
where a.gdsid=b.gdsid AND a.gys=b.gys      
    and b.city =  '900'
    and b.fmid  in  ('0001','0002','0003') and b.flg1 <>'X'  
and not exists (select 1 from szy_ok c where c.gdsid = b.gdsid and c.gys = b.gys and c.rtptype = b.fmid)       
union 
select distinct a.gdsid,a.gdsmc,a.xh,a.gys,fmid
from LABEL b,szy_jg1 a  
where a.gdsid=b.gdsid AND a.gys=b.gys      
    and b.city =  '900'
    and b.fmid  in  ('0001','0002','0003') and b.flg1 <>'X'  
    and not exists (select 1 from szy_ok c where c.gdsid = b.gdsid and c.gys = b.gys and c.rtptype = b.fmid) 



--IO消耗
Table: CITY scan count 403720, logical reads: (regular=1697756 apf=0 total=1697756), physical reads: (regular=0 apf=0 total=0), apf IOs used=0
Table: szy_jg1 scan count 1, logical reads: (regular=27183 apf=0 total=27183), physical reads: (regular=0 apf=0 total=0), apf IOs used=0
Table: szy_ok scan count 149415, logical reads: (regular=23128183 apf=0 total=23128183), physical reads: (regular=0 apf=0 total=0), apf IOs used=0
Table: LABEL scan count 1, logical reads: (regular=279 apf=4 total=283), physical reads: (regular=0 apf=0 total=0), apf IOs used=0
Table: szy_jg1 scan count 5117, logical reads: (regular=15998 apf=0 total=15998), physical reads: (regular=0 apf=0 total=0), apf IOs used=0
Table: szy_ok scan count 5117, logical reads: (regular=793135 apf=0 total=793135), physical reads: (regular=0 apf=0 total=0), apf IOs used=0

SQL Server cpu time: 201200 ms.  SQL Server elapsed time: 207066 ms.


--表数据
sp_spaceused CITY     --4824054