Monday, February 20, 2012

Overhead for Aliases

Hello,

I have a question, is there any performance overhead for using Aliases in a SQL query?

I mean would there be any difference in performance between the following two statements:

Select

Students.StudentID ,

Students.Name ,

Students.Code

from

Students inner join

Countries on Students.CountryID= Students.CountryID

Where

Students.IsDeleted=1

--

Select

std.StudentID ,

std.Name ,

std.Code

from

Students AS std inner join

Countries AS cntr on std.CountryID= cntr.CountryID

Where

std.IsDeleted=1

No, not as far as I have ever seen. There should be no performance impact|||Cool. But is there any explanation why? How does SQL Server treat aliases? does it affect the execution plan or something?|||What you have said is correct: an alias has no affect on the execution plan.|||

I also agree with you..

But I worried about the following BLOG. When I try to execute on Mac it is really Random result..

http://weblogs.sqlteam.com/brettk/archive/2007/03/27/60141.aspx

|||No, aliases do not cause a performance issue.

The blog referenced shows a difference when NOT using aliases. I would suspect, but don't know, the difference is in the compile time, not execution. The compiler has to figure out what database the field is coming from, if you don't qualify it with an alias. This takes time.

Also, the datetime variable has a maximum resolution of 3.33 ms. So a test as small as the blog describes is meaningless.

No comments:

Post a Comment