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

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Performance optimization

Author  Topic 

ConradK
Posting Yak Master

140 Posts

Posted - 2010-06-11 : 14:23:12
Okay, when I run this code

select
count(agg.description)

from
(
select

DescriptionFields.Description
from DescriptionFields
)agg

6 seconds

when I run this code

select
count(agg.description)

from
(
select
distinct
DescriptionFields.Description
from DescriptionFields
)agg

many minutes and counting.

I need the results of the ladder, not the former, but need to be able to do this oftehen and at will. Any ideas as to how to acheive the same results with less time?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-06-11 : 14:35:30
You do not need the derived tables.

1. SELECT COUNT(*) FROM DescriptionFields
2. SELECT COUNT(Description) FROM DescriptionFields GROUP BY Description

Is the Description column indexed?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

ConradK
Posting Yak Master

140 Posts

Posted - 2010-06-11 : 14:48:51
will that significantly improve performance?
Go to Top of Page

ConradK
Posting Yak Master

140 Posts

Posted - 2010-06-11 : 14:51:52
I want to know how many unique descriptions are in this table
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-06-11 : 14:59:15
Well that's what I posted for #2. I was rewriting your queries as a derived table is not necessary.

To improve performance, the Description column needs to be indexed. How big is that column by the way?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -