我目前正在运行OPENQUERY
,其结构与此类似:
SELECT DISTINCT
P.x,
P.y,
etc...
FROM
[DATA].[dbo].[dataP] P
inner join
OPENQUERY(localDb, 'SELECT ...
LEFT JOIN(...
Left join (...
INNER JOIN...
INNER JOIN(...') OQ
on (OQ.x = P.x)
where P.x > 0
是否有更好的优化开放查询的做法?
答案 0 :(得分:1)
创建临时表或CTE以存储OPENQUERY的结果,然后加入它。
SELECT *
INTO #temp
FROM OPENQUERY(localDb, 'SELECT ...
LEFT JOIN(...
Left join (...
INNER JOIN...
INNER JOIN(...') OQ
然后在您的主查询中:
SELECT DISTINCT
P.x,
P.y,
etc...
FROM
[DATA].[dbo].[dataP] P
inner join
#temp as OQ
on (OQ.x = P.x)
where P.x > 0
为OPENQUERY添加任何可能的过滤条件以减少远程服务器上的结果集也是有帮助的。