سؤال

I have a view (View A) that pulls in columns from a number of tables. It also pulls in a column from another view (View B) which gets its data from a Linked Server table.

Now, View B runs fine, pulling back 11,000 rows in about a second. View A also runs fine. However, if I INNER JOIN from View A to View B on a column that comes from the Linked Server, the entire query runs so slow it times out.

If I INNER JOIN from View A to View B on a column that does NOT come from the Linked Server, it runs fine.

So I traced the issue to joining on a column which resides on the Linked Server. I just have no idea how to fix it.

Can anyone give me any pointers?

هل كانت مفيدة؟

المحلول

The circumstances were slightly different, but both my co-workers and I have seen evidence that if you have something like this:

select something 
from LinkedServer.DataBase.Owner.Table
where whatever

then sql server will select the entire table from the other server first, and apply the where clause afterwards. That might be happening to you.

We solve the problem by using openquery instead of the fully qualified method shown above, and by putting the openquery results into a temp table. Then we join to the temp table.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top