Analysis:
As the optimizer can not determine or obtain statistics on the distal end of the table, so the original execution plan will take the default remote table (regardless of size) pulled way local reconnection execution, so if the remote table will be relatively large case slowly, like the above query takes more than one 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 ---这里远端表较大
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:
go after adjustment optimizer execution plan, the control operation in the WB end, and the distal end MBS7_CRM.WI_WAREBASE table index table fields (STYLECODE) lack of connectivity HINTS index plus the following manner, thus creating an index in the following end of the target optimized optimized COST drops from 7 to 20 more than one hundred, the result may be returned within 2 sec, performance increased a lot.
The distal end of the table to create the index:
create index mbs7_crm.ix_WI_WAREBASE_STYLECODE on mbs7_crm.WI_WAREBASE(STYLECODE)
After tuning 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
More DBA performance optimization case, follow us CSDN blog!
Https://topdbs.blog.csdn.net