我正在尝试运行一个从远程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分钟!)才能获得结果。有关如何使用链接服务器的不同方法提高性能或实现相同逻辑的任何建议吗?
答案 0 :(得分: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