Linked-Server Queries: Reduce Data Movement Before Tuning
Find where linked-server queries actually execute, push selective work to the remote source, and test semantics, credentials, and failure behavior.
A query joining a small local table to a large remote table may look harmless in an application review. Across a linked server, however, the important cost is often the amount of data crossing the connection and the number of remote requests. A selective final result does not prove selective remote execution. Diagnose where filtering and aggregation happen before adding local indexes or increasing timeouts.
Locate the expensive boundary
Capture the actual local plan for a representative execution and inspect the remote operator and its submitted query. Compare rows arriving from the remote source with rows surviving local filters. If two hundred final rows require transferring millions of wide rows, the network boundary is a stronger lead than a local sort taking milliseconds.
A four-part name does not automatically mean all work runs locally. SQL Server can delegate work, but the resulting placement depends on the query, provider, available information, and supported operations. Equally, a remote query operator does not prove an efficient remote plan. Investigate the source instance using its own execution evidence and indexes.
Measure elapsed time, remote request count, transferred row width, and source workload under the same parameters. One remote call per local row can be worse than one bounded batch even when each individual call is fast. Do not test only a tiny customer when the production problem occurs for the largest account.
Make the remote work explicit
The example is a template for an already configured SQL Server linked server named ReportingLink and a remote Sales database. It has no setup or credential changes. Adapt the schema in a test environment. The date range and aggregation live inside the pass-through text, so only customer totals cross back to the caller.
SELECT CustomerId, TotalAmount
FROM OPENQUERY([ReportingLink],
'SELECT CustomerId,
SUM(CONVERT(decimal(19,4), Amount)) AS TotalAmount
FROM Sales.dbo.Orders
WHERE OrderDate >= ''20260101''
AND OrderDate < ''20260201''
GROUP BY CustomerId');
Here Amount must have the intended exact numeric type and fit the decimal aggregation. Both date boundaries belong to the remote data's documented time convention. Compare the result with a trusted local calculation on a small fixture containing boundary dates, multiple orders, and negative adjustments. A faster query returning the wrong reporting period is not an improvement.
OPENQUERY uses a literal query string, does not accept variables as its arguments, and has an 8 KB query-text limit. Do not address that limitation by concatenating unchecked user input into nested quotes. For a variable workload, consider a deliberately exposed remote stored procedure with typed parameters, or an approved staging interface. Test provider support and required RPC configuration for that separate design rather than changing server options blindly.
If local keys drive the request, consider whether a controlled remote staging set can express the whole batch. Give staged rows an operation identifier, define cleanup, and protect concurrent callers from mixing their keys. That design needs write permission and lifecycle management; it is not a free replacement for a read-only linked query.
Preserve meaning and bounded failures
Different collations and data types can change comparisons or force conversions. Verify case, accents, Unicode, nulls, and precision with a fixture. Do not declare collations compatible merely to obtain a nicer plan unless that assertion is actually true for the relevant comparisons. Inspect the generated remote text after any rewrite.
Use a remote identity with the minimum required access and test as the real application login. A successful administrator query does not validate login mapping or delegation for a service account. Keep credentials out of query text and incident screenshots. Document who owns the provider and certificate configuration so connection failures have a clear escalation path.
Finally, distinguish remote reads from cross-server writes. A write inside a local transaction may involve distributed transaction behavior depending on the operation and settings. Disabling transaction promotion to silence an error can change the atomicity contract. Simulate connection interruption and ambiguous completion in a test system, and design retries around the actual transaction boundary. For frequent large reports, a maintained local reporting copy may offer a simpler, measurable freshness contract than repeated live distributed joins.
Technical references: Microsoft Learn: OPENQUERY · Microsoft Learn: Remote execution options · Microsoft Learn: Server options.