您好,登錄后才能下訂單哦!
分析:
由于優化器無法判斷或獲得遠端表的統計信息,故原執行計劃默認會采取把遠程表(無論大小)拉到本地再連接的方式執行,
這樣如果遠程表較大的情況將會比較緩慢,像上述查詢耗時在1分鐘以上。
原SQL語句:
Select Wb.*, (Select Wi.Nextarrivedate From Mbs7_Oms.Xs_Warearriveinfo@Dc.Moonbasadb.Com Wi Where Wi.Warecode = Wb.Warecode) As Nextarrivedate From Mbs7_Crm.Wi_Warebase@Dc.Moonbasadb.Com Wb ---這里遠端表較大 Inner Join (Select Wa.Stylecode, Max(Wa.Warecode) As Warecode From Mbs7_Crm.Wi_Warebase@Dc.Moonbasadb.Com Wa Inner Join (Select Stylecode From Dc_Support.Kh_Visitpage Vis Where Vis.Cuscode = :B1 And Vis.Addtime >= Trunc(Sysdate - 31) And Vis.Addtime < Trunc(Sysdate - 30) And Rownum <= 5 Order By Addtime Desc) Vis On Wa.Stylecode = Vis.Stylecode Group By Wa.Stylecode) Wc On Wb.Warecode = Wc.Warecode
解決方案:
用以下HINTS方式加上去后,優化器會調整執行計劃,把運算端控制在WB,并且遠端表MBS7_CRM.WI_WAREBASE表字段的索引(STYLECODE)缺少連接索引,于是在目標端創建以下索引進行優化,優化后COST從7百多下降到20,運行2秒內可返回結果,性能增加不少。
遠端表創建索引:
create index mbs7_crm.ix_WI_WAREBASE_STYLECODE on mbs7_crm.WI_WAREBASE(STYLECODE)
調優后的SQL:
Select /*+DRIVING_SITE(WB)*/ Wb.*, (Select Wi.Nextarrivedate From Mbs7_Oms.Xs_Warearriveinfo@Dc.Moonbasadb.Com Wi Where Wi.Warecode = Wb.Warecode) As Nextarrivedate From Mbs7_Crm.Wi_Warebase@Dc.Moonbasadb.Com Wb ---遠端表較大 Inner Join (Select Wa.Stylecode, Max(Wa.Warecode) As Warecode From Mbs7_Crm.Wi_Warebase@Dc.Moonbasadb.Com Wa Inner Join (Select Stylecode From Dc_Support.Kh_Visitpage Vis Where Vis.Cuscode = :B1 And Vis.Addtime >= Trunc(Sysdate - 31) And Vis.Addtime < Trunc(Sysdate - 30) And Rownum <= 5 Order By Addtime Desc) Vis On Wa.Stylecode = Vis.Stylecode Group By Wa.Stylecode) Wc On Wb.Warecode = Wc.Warecode
?版權聲明:本文為 天凱DBS 的原創文章,轉載請附上原文出處鏈接及本聲明,否則將追究法律責任。
原文鏈接: https://dbs-service.cn/a/173.html
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。