DB Link因 driving_site導致的效能問題

tolywang發表於2011-09-09


    今天接到一個朋友電話,  原來兩個schema 是在一個庫下面, 為 Oracle 9.2.0.8版本, 
所以兩個schema 表之間的連線都是本地 ,   後來業務及主機效能問題,   將一個
schema 切出去成為一個資料庫,    使用了較新的 Oracle 10g 版本,   原來連線的一些
表就需要使用dblink 來操作了 (dblink 是在10g 庫上) ,   結果執行感覺慢很多,  看了
一下,  他們9i, 10g 庫都是有分析的 ,  只是9i 分析不是job定期做,  而是手工,  10g 是
自動分析 .  

      查詢了一些資料 ,  發現 dblink執行有兩種方式,一種是在遠端資料庫執行完,
然後結果返回到本地,另一種是把遠端的表資料傳輸到本地,然後在本地執行。

DRIVING_SITE
The DRIVING_SITE hint forces query execution to be done at a different site than that selected
by Oracle. This hint can be used with either rule-based or cost-based optimization.

For example:
SELECT /*+DRIVING_SITE(departments)*/  * 
FROM     employees,    
WHERE   employees.department_id = departments.department_id;  

If this query is executed without the hint,  then rows from departments are sent to
the local site, and the join is executed there. With the hint, the rows from
employees are sent to the remote site, and the query is executed there, returning
the result to the local site.
This hint is useful if you are using distributed query optimization.

DRIVING_SITE 提示強制在和Oracle選擇不同的一端執行語句, 這個Hint可以用在
rule-based及cost-based 最佳化模式下。 

如果上面的語句沒有 /*+DRIVING_SITE(departments)*/ 提示,  遠端的表 departments
的行要被傳輸到local site ,  在local site 執行連線語句,  如果有這個提示,  那麼本地的
employees 表的行會被傳到遠端site,  查詢在遠端site執行,   然後返回結果到本地,  這個
hint 在分散式查詢最佳化中還是有用的 。

合理使用DRIVING_SITE,可以在分散式查詢中大大減少網路流量。

      從他們不慢到慢的變化上可以看出應該和兩方面有關係,  一個是dblink ,  還有
一個就是9i 升級到 10g 後執行計劃的變化 ,   檢視DBLINK 其實沒有參照物,  因為
原來使用的是同一個庫 ,  不存在dblink ,   所以可以從執行計劃入手 .   

後來加入hint 之後執行正常,  不過還是不建議多用hint , 某個SQL,  選擇將表放在local
端還是remote 端對於語句執行也是有決定作用的 .  


----------------------------------------------------------------------- 
備註: 
insert into會導致driving_site提示 (hint) 無效,那麼可以用一個檢視的辦法解決
問題:在目標端建立一個關於本查詢中無引數的檢視,然後在本地透過dblink
呼叫檢視,這樣先在遠端執行出結果傳輸到本地。
-----------------------------------------------------------------------   

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/35489/viewspace-712973/,如需轉載,請註明出處,否則將追究法律責任。

相關文章