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

下班前再问个语句的优化
这个语句感觉已经很简单了。 但是要40秒以上,哪里可以优化??

BA_GDSBARCODE e(index idx_BA_GDSBARCODE_1)
这个强制索引应该不是问题,如果不走这个索引,数据直接就出不来


 

set statistics io on
set statistics time on
 

select distinct a.gdsid,a.spm,a.ggxh,e.barcode,0,'',a.pp,c.ppmc,c.parentid,c.parentmc,a.tjlb,d.tjlbm,e.gys,'',  
       b.prop1,b.prop2,b.prop3,b.prop4,b.prop5,b.prop6,b.cd,b.grade,b.size,b.unit,b.pricer,'','',
       b.prop7,b.prop8,b.prop9,b.prop10,'N',0,0,0,
       case when len(a.barcode) > 9 and (substring(a.barcode,1,1)<>'S') then a.barcode else '/' end         
  from BA_GDSBARCODE e(index idx_BA_GDSBARCODE_1), 
       BA_GDS a, 
       BA_GDSPROP_APP b, 
       BA_BRAND c, 
       BA_STATCLS d, 
       BA_SUPPLIER f  
 where a.gdsid=b.gdsid  
   and a.pp=c.pp  
   and a.gdsid = e.gdsid 
   and a.tjlb = d.tjlb 
   and e.gys = f.supid  
   and b.orgid = '2704'   
   and c.parentid='00007' 
  

-- IO消耗
Table: BA_GDSBARCODE scan count 1774, logical reads: (regular=260727 apf=0 total=260727), physical reads: (regular=272 apf=42 total=314), apf IOs used=42
Table: BA_GDS scan count 11032, logical reads: (regular=21544 apf=0 total=21544), physical reads: (regular=0 apf=0 total=0), apf IOs used=0
Table: BA_GDSPROP_APP scan count 1, logical reads: (regular=855 apf=0 total=855), physical reads: (regular=0 apf=0 total=0), apf IOs used=0
Table: BA_BRAND scan count 11032, logical reads: (regular=33114 apf=0 total=33114), physical reads: (regular=0 apf=0 total=0), apf IOs used=0
Table: BA_STATCLS scan count 1774, logical reads: (regular=3559 apf=0 total=3559), physical reads: (regular=0 apf=0 total=0), apf IOs used=0
Table: BA_SUPPLIER scan count 405184, logical reads: (regular=1215552 apf=0 total=1215552), physical reads: (regular=0 apf=0 total=0), apf IOs used=0