I'm having performance issues with my SQL sub query.
As a hard-coded query, it takes about 1 second to run:
SELECT ColumnA
,ColumnB
,ColumnC
FROM [LinkedServer].[Database].[Schema].[View]
WHERE ColumnA IN
(
'ABC',
'DEF',
'HIJ',
'KLM'
)
However, the following code takes over a minute to run:
SELECT ColumnA
,ColumnB
,ColumnC
FROM [LinkedServer].[Database].[Schema].[View]
WHERE ColumnA IN
(
SELECT ColumnA FROM #TempTable
)
The temp table contains the same 4 rows as the hard-coded example. The view on the linked server contains approx. 700,000 rows (and, unfortunately, is outside of my control). The ColumnA data types are the same and both tables are indexed.
Any ideas on how to improve the performance of this query?
Many thanks.