視圖查詢語言優化
現有一個視圖查詢超慢...本人小菜鳥...有沒高手幫我優化下...謝謝了...
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[apm_wip3]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[apm_wip3]
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE view apm_wip3 /*產生WIP資料*/
as SELECT apm_xbzbodxh.xb,
apm_xbzbodxh.zb,
apm_xbzbodxh.zb_mc,
apm_xbzbodxh.od,
apm_xbzbodxh.xh,
apm_xbzbodxh.cp_id,
apm_wip_adjust.sl,
apm_wip.rs1,
apm_wip1.cs,
apm_wip2.rs,
apm_wip01.ljrs,
apm_wip01.ljcl,
apm_wip02.ljccds,
apm_xhcs.s9,
apm_xhcs.s10,
apm_xhcs.s11,
apm_xhcs.S12,
ao_ord_v_pc1.s,
ao_ord2.ord_quan,
ao_ord2.ord_quan1,
ao_ord2.ord_check_delivery,
ao_v_cpjk1.sl as rksl,
lianchang.mosu,
lianchang.proname,
lianchang.printy,
lianchang.pinno,
lianchang.checkspec,
lianchang.distype,
lianchang.bolispec2,
lianchang.custname
FROM apm_xbzbodxh
left outer join apm_wip on ( apm_xbzbodxh.xb = apm_wip.xb and apm_xbzbodxh.zb = apm_wip.zb and apm_xbzbodxh.od = apm_wip.od and apm_xbzbodxh.xh = apm_wip.xh and apm_xbzbodxh.cp_id =apm_wip.cp_id)
left outer join apm_wip2 on ( apm_xbzbodxh.xb = apm_wip2.xb and apm_xbzbodxh.zb = apm_wip2.st2 and apm_xbzbodxh.od = apm_wip2.od and apm_xbzbodxh.xh = apm_wip2.xh and apm_xbzbodxh.cp_id =apm_wip2.cp_id)
left outer join apm_wip1 on ( apm_xbzbodxh.xb = apm_wip1.xb and apm_xbzbodxh.zb = apm_wip1.st1 and apm_xbzbodxh.od = apm_wip1.od and apm_xbzbodxh.xh = apm_wip1.xh and apm_xbzbodxh.cp_id =apm_wip1.cp_id)
left outer join lianchang on apm_xbzbodxh.xh=lianchang.orderno
left outer join apm_wip_adjust on ( apm_xbzbodxh.xb = apm_wip_adjust.xb and apm_xbzbodxh.zb = apm_wip_adjust.zb and apm_xbzbodxh.od = apm_wip_adjust.od and apm_xbzbodxh.xh = apm_wip_adjust.xh and apm_xbzbodxh.cp_id =apm_wip_adjust.cp_id)
left outer join apm_wip01 on ( apm_xbzbodxh.xb = apm_wip01.xb and apm_xbzbodxh.zb = apm_wip01.st1 and apm_xbzbodxh.od = apm_wip01.od and apm_xbzbodxh.xh = apm_wip01.xh and apm_xbzbodxh.cp_id =apm_wip01.cp_id)
left outer join apm_wip02 on ( apm_xbzbodxh.xb = apm_wip02.xb and apm_xbzbodxh.zb = apm_wip02.zb and apm_xbzbodxh.od = apm_wip02.od and apm_xbzbodxh.xh = apm_wip02.xh and apm_xbzbodxh.cp_id =apm_wip02.cp_id)
left outer join ao_ord_v_pc1 on ( apm_xbzbodxh.od = ao_ord_v_pc1.ord_id and apm_xbzbodxh.xh = ao_ord_v_pc1.ord_p_lh and apm_xbzbodxh.cp_id =ao_ord_v_pc1.cp_id)
left outer join ao_ord2 on ( apm_xbzbodxh.od = ao_ord2.ord_id and apm_xbzbodxh.xh = ao_ord2.ord_p_lh and apm_xbzbodxh.cp_id =ao_ord2.cp_id)
left outer join ao_v_CPJK1 on (apm_xbzbodxh.od = ao_v_CPJK1.rk_ord_id and apm_xbzbodxh.xh = ao_v_CPJK1.rk_p_lh and apm_xbzbodxh.cp_id =ao_v_CPJK1.cp_id)
left outer join apm_xhcs on ( apm_xbzbodxh.xh = apm_xhcs.xh)
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO