Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Openquery works much faster than a query straight to a linked table

Trying to figure out why there is such a significant difference between

select * from linkedserver..tablename

and

select * from openquery(linkedserver, select * from tablename).

4 minutes vs 13 seconds.

like image 886
Stephanie Page Avatar asked May 29 '09 19:05

Stephanie Page


People also ask

Is Openquery faster than linked server?

The OPENQUERY is faster than the linked server because when we use the linked server, the SQL Server breaks the query into local and remote queries. The local queries are executed on the local server, and remote queries will be sent to the remote server.

What does Openquery do in SQL?

Executes the specified pass-through query on the specified linked server. This server is an OLE DB data source. OPENQUERY can be referenced in the FROM clause of a query as if it were a table name. OPENQUERY can also be referenced as the target table of an INSERT, UPDATE, or DELETE statement.

Are Linked Servers slower?

Executing a query against views on a linked server remotely takes more time than executing the same query directly against a base table on the linked server.

What is the alternative to linked server?

The alternative to using Linked Servers is to use the OPENQUERY statement, also known as a pass through query. When using an OPENQUERY statement, the WHERE clause gets executed at the remote server and the resultant (mapped) records traverse over the wire instead of an entire sourced data set.


1 Answers

OPENQUERY connects to the destination server and runs the query on that server and returns the resultset. Whereas, I believe the Linked Server query is executed on the local server and runs across the connection.

Hope this helps.

like image 161
Neil Knight Avatar answered Oct 10 '22 12:10

Neil Knight