Analysis:
Because the optimizer cannot judge or obtain the statistics of the remote table, the original execution plan will execute by default by pulling the remote table (regardless of its size) to the local and reconnecting, so if the remote table is large, it will be relatively slow, and the above query will take more than 1 minute.
Original SQL statement:
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 ---The remote table here is large 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
Solution:
After adding the following hits, the optimizer will adjust the execution plan, control the operation end to WB, and the index (STYLECODE) of the field in the remote table mbs7 ﹣ crm.wi ﹣ warebase is lack of connection index. Therefore, the following indexes are created at the target end for optimization. After optimization, the COST is reduced from 700 to 20, and the result can be returned within 2 seconds, with a lot of performance increase.
Remote table creation index:
create index mbs7_crm.ix_WI_WAREBASE_STYLECODE on mbs7_crm.WI_WAREBASE(STYLECODE)
Tuned 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 ---Large distal surface 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
More DBA performance optimization cases, please follow our CSDN blog!
https://topdbs.blog.csdn.net