关联的效率

 

 1 --A段
 2 ----------------------
 3 select so_d.*
 4        c_bf.FApproveState
 5   from sal_OrderList so_d
 6   left join bas_Bom bom_m 
 7      on (so_d.FMaterialKey = bom_m.FMaterialKey
 8         and so_d.FColorKey = bom_m.FColorKey)
 9   inner join com_BillInfo c_bf 
10      on (bom_m.FFormKey = c_bf.FFormKey) 
11         and (c_bf.FApproveState = 1)  
12 
13 --B段
14 ----------------------
15 select so_d.*
16        c_bf.FApproveState
17   from sal_OrderList so_d
18   left join bas_Bom bom_m
19   inner join com_BillInfo c_bf 
20      on (bom_m.FFormKey = c_bf.FFormKey) 
21         and (c_bf.FApproveState = 1)
22      on (so_d.FMaterialKey = bom_m.FMaterialKey
23         and so_d.FColorKey = bom_m.FColorKey)
 
两段脚本达到的效果是一样的
 
在查询分析器中显示计划的效果A段占用了70%的开销, B段占用30%开销,可见B段效率比A段高
 

 

 

 

 1 --A
 2 select wst.* 
 3   from com_MaterialWasteBook wst
 4     left join B_Material b_m on wst.FMaterialKey = b_m.FKey
 5     left join Color b_clr on wst.FColorKey = b_clr.FKey
 6     left join bas_Items b_sz on wst.FSizeKey = b_sz.FKey
 7   where b_m.FKey is not null
 8   
 9 ---B
10 select wst.* 
11   from com_MaterialWasteBook wst
12     inner join B_Material b_m on wst.FMaterialKey = b_m.FKey
13     inner join Color b_clr on wst.FColorKey = b_clr.FKey
14     inner join bas_Items b_sz on wst.FSizeKey = b_sz.FKey
15   

 上面两段

 查询开销

A 占98%

B 占2%

 

但是实际执行时,在100多W的记录中A执行只需25秒左右,B需要50秒(结果执行多次)

 

posted @ 2011-08-11 11:40  D10.天地弦  阅读(244)  评论(0编辑  收藏  举报