patternsqlMinor
Do synonyms affect remote query performance
Viewed 0 times
synonymsqueryaffectperformanceremote
Problem
I've got a task where I need to migrate an existing database to a new server.
The database in question has stored procedures that query another database on the same server, this second database is not going to be moved.
I would love to use a synonym to point to the other database on the linked server as this will make it really easy to set up and maintain, however I want to know if the synonym is likely to cause performance problems with the execution plan, or if it's only the cross server querying that is the problem.
The database in question has stored procedures that query another database on the same server, this second database is not going to be moved.
I would love to use a synonym to point to the other database on the linked server as this will make it really easy to set up and maintain, however I want to know if the synonym is likely to cause performance problems with the execution plan, or if it's only the cross server querying that is the problem.
Solution
A synonym is just a pointer and gets simplified away prior to optimization. If you have this:
Then these two will optimize the same, producing identical execution plans (both having a
You can test this quite easily.
CREATE SYNONYM dbo.foo FOR OtherServer.db.dbo.blat;Then these two will optimize the same, producing identical execution plans (both having a
Remote Query operator that points at blat):SELECT bar FROM dbo.foo;
SELECT bar FROM OtherServer.db.dbo.blat;You can test this quite easily.
Code Snippets
CREATE SYNONYM dbo.foo FOR OtherServer.db.dbo.blat;SELECT bar FROM dbo.foo;
SELECT bar FROM OtherServer.db.dbo.blat;Context
StackExchange Database Administrators Q#122812, answer score: 7
Revisions (0)
No revisions yet.