Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Slowness in remote query

Author  Topic 

juicyapple
Posting Yak Master

176 Posts

Posted - 2009-08-13 : 23:42:48
Hi,

I am facing a problem when run select statement to query other database through linked server, it takes more than 1 hour. But if the query is executed at the original database, it only takes 15 seconds. Any one has this kind of experiece? is this due to the query through linked server?

Thanks.

nathans
Aged Yak Warrior

938 Posts

Posted - 2009-08-14 : 02:59:09
If you are accessing the object directly using linked server name then its possible you are pulling a large amount of data over the wire and then applying conditions after the fact. If this is the case then you are better off sending the query over the wire to be executed on the remote server and only retrieving the resultset over the wire (which hopefully is much smaller than entire table).

For example:

select * from YourServer.YourDB.dbo.YourTable where PK = 1

-- vs

select *
from openquery(YourServer, 'select * from YourDB.dbo.YourTable where PK = 1')



or, exec a remote proc.




Nathan Skerl
Go to Top of Page

juicyapple
Posting Yak Master

176 Posts

Posted - 2009-08-14 : 04:43:37
I tried to create view at the Server1.databaseA, then query the view from Server2.databaseB, manage to reduce the time to about 2 minutes.


quote:
Originally posted by nathans

If you are accessing the object directly using linked server name then its possible you are pulling a large amount of data over the wire and then applying conditions after the fact. If this is the case then you are better off sending the query over the wire to be executed on the remote server and only retrieving the resultset over the wire (which hopefully is much smaller than entire table).

For example:

select * from YourServer.YourDB.dbo.YourTable where PK = 1

-- vs

select *
from openquery(YourServer, 'select * from YourDB.dbo.YourTable where PK = 1')



or, exec a remote proc.




Nathan Skerl

Go to Top of Page
   

- Advertisement -