SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

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

lloydz1
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.

BR
Lloydz1

MuMu88
Aged Yak Warrior

547 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  
 New 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.04 seconds. Powered By: Snitz Forums 2000