I have a query like this:
select key, name from localtab where key not in (select key from remotetab);
The query takes forever, and I don't understand why.
localtab
is local table, and remotetab
is a remote table in another server. key
is an int
column which has a unique index in both tables. When I query the both tables separately, it takes just a few seconds.
tempdb
).select * from remotetab
does take just a few seconds (and all data is transferred in this case). We talk of about 100.000 records.localtab
, rather than 1 transfer and then scan the table for all rows inlocaltab
. This is why what vvvv4d suggests can have very different performance. Also, as I mentioned, the entire table is transferred, so not just the value of the columnkey
, but all the columns.