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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Order By Slow Performance
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

United Kingdom
1 Posts

Posted - 06/28/2013 :  07:43:00  Show Profile  Reply with Quote
I have a small problem that I cannot understand, I am currently studying to undertake exam 70-461 and have been applying some of what I have learned to the workplace. However one thing seems to go against what I have learnt which is the order by statement; According to the Logical Query Processing Phases the 'From' statement is the first to execute followed by the 'Where', 'Group By', 'Having', 'Select' and then finally the 'Order By' . However, when I execute a complex Select statement with multiple joins and no Order By it runs extremely fast, When I apply the Order By it takes in excess of 90 Seconds to run. I then inserted the values into a temporary table without the order by and selected the Results from that temporary table with the order by and the statement will run in less than a second. This is confusing in my mind as the Select is the last thing to run before the Order By and therefore the result of the select phase is the same hence the order by should run in the same time on both queries.

I have toyed with the idea of removing the order by to make the result Relational but the end user requires that it should be ordered set of results.


Aged Yak Warrior

549 Posts

Posted - 06/28/2013 :  08:36:36  Show Profile  Reply with Quote
In your original query where do you have the order by clause? (are you sorting on the final data set or are you sorting the intermediate data sets?)
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000