I have a query on my FirstServer like this one:
DROP TABLE IF EXISTS #TEMP;
CREATE TABLE #TEMP
(
ItemId NVARCHAR(100),
[Date] DATE
);
INSERT INTO #TEMP(ItemId,[Date])
(
SELECT 'test', '11/11/2011'
)
SELECT tmp.ItemId, tmp.[Date]
FROM #TEMP tmp
WHERE NOT EXISTS
(
SELECT 1 FROM SECONDSERVER.SECONDDB.dbo.Items items
WHERE
items.ItemId = tmp.ItemId
AND tmp.[Date] = items.[Date]
)
END
Execution of it takes 25 s. But if I execute the same code on my SECONDSERVER then execution is 200 ms.
When from my FirstServer I execute simple query:
select top 10 * from SECONDSERVER.SECONDDB.dbo.Items
Then I get results in 300 ms.
Any hints why it takes so long for query with temp table and join?
Remote Scan(causing the entire table to be brought across the Linked Server before being processed). – J.D. Nov 24 '22 at 16:29Can I do something with that? It looks that it takes the whole table from one server to the other and then starts calculation which makes no sense in my case, I would prefer to move my temp data (which is not much) there and perform calculations there but I have no idea how linked serves computations work on sql server
– witkacy1986 Nov 24 '22 at 16:53