2013-10-08 55 views
0

我想運行一個查詢從遠程oracle服務器檢索數據,然後檢查檢索的數據是否已經存在於我的數據庫中,然後我將它從結果中刪除。鏈接的服務器查詢性能

SELECT DISTINCT 
      col1, 
      col2, 
     col3, 
     col4 , 
     col5, 
     col6 , 
     col7, 
     col8 , 
     col9 , 
     col10, 
     col11 
     FROM remoteserver.tab1 dist 
     JOIN remoteserver.tab2 headers 
     ON headers.id1 = dist.id2 
     JOIN remoteserver.tab3 vendors 
     ON headers.id1 = vendors.id3 
     JOIN remoteserver.tab4 comb 
     ON dist.id2 = comb.id4 
      where 
    cond1 and cond2 and cond3 and cond4 
    SELECT DISTINCT 
      col1, 
      col2, 
      col3, 
      col4, 
      col5, 
      col6, 
      col7, 
      col8, 
      col9, 
      col10, 
      col11 
    FROM myserver.tab1 

這只是我運行查詢的大小的闡述,問題是,它需要很長的時間(大約20分鐘!),得到的結果。有關如何使用鏈接服務器的不同方法提高性能或實現相同邏輯的任何建議?

+1

你看過使用openrowset嗎? – HLGEM

+0

您發佈的內容是否存在性能問題? – Paparazzi

+0

@Blam是的,這是需要20分鐘才能返回結果的查詢! –

回答

0

我使用openrowset解決了這個問題,這極大地提高了性能。

select * from (linkedserver, 
'SELECT DISTINCT 
      col1, 
      col2, 
     col3, 
     col4 , 
     col5, 
     col6 , 
     col7, 
     col8 , 
     col9 , 
     col10, 
     col11 
     FROM remoteserver.tab1 dist 
     JOIN remoteserver.tab2 headers 
     ON headers.id1 = dist.id2 
     JOIN remoteserver.tab3 vendors 
     ON headers.id1 = vendors.id3 
     JOIN remoteserver.tab4 comb 
     ON dist.id2 = comb.id4' 
      where 
    cond1 and cond2 and cond3 and cond4 
    SELECT DISTINCT 
      col1, 
      col2, 
      col3, 
      col4, 
      col5, 
      col6, 
      col7, 
      col8, 
      col9, 
      col10, 
      col11 
    FROM myserver.tab1 
相關問題