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 2008 Forums
 Other SQL Server 2008 Topics
 optimizing disctinct query
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Auris
Starting Member

United Kingdom
7 Posts

Posted - 04/10/2012 :  08:42:02  Show Profile  Reply with Quote
Hi there

i have a fairly simple query

SELECT DISTINCT col1, col2, col3, col4, col5, col6, col7 FROM MyData

query returs 3.6 mln records, thats for reporting, it completes in about 2min 45seconds which is awful. So how can i optimize it ? as you can see the distinct is used on 7 columns, i have tryed to create unique non clustered index that has all 7 columns, that reduces the execution to 1 min 45s but still it is a lot, and i take a look at the execution plan for some reason even with an index in place it does index scan, not index seek. Please advice? app is timeouting 2/3 of the time i need to figure this out how to improve the performance. Urgent!

Thank you guys.

Life is hard. It's even harder if you're stupid.

webfred
Flowing Fount of Yak Knowledge

Germany
8514 Posts

Posted - 04/10/2012 :  11:00:44  Show Profile  Visit webfred's Homepage  Reply with Quote
without a where clause there is no need for an index seek...because you want to get all data there is nothing to seek.
the problem is the DISTINCT.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

Auris
Starting Member

United Kingdom
7 Posts

Posted - 04/10/2012 :  11:27:02  Show Profile  Reply with Quote
ok thanks for the ideas, i have rewritten the entire stored procedure that generated the data for the report, not its way better and yeah you are right the distinct really do suck with that much data. Thanks for quick response.


quote:
Originally posted by webfred

without a where clause there is no need for an index seek...because you want to get all data there is nothing to seek.
the problem is the DISTINCT.


No, you're never too old to Yak'n'Roll if you're too young to die.



Life is hard. It's even harder if you're stupid.
Go to Top of Page

Ifor
Constraint Violating Yak Guru

476 Posts

Posted - 04/10/2012 :  11:36:02  Show Profile  Reply with Quote
Umm...
Do you really produce a report with 3.6 million lines?
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.06 seconds. Powered By: Snitz Forums 2000