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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Poor performance with MIN and MAX functions

Author  Topic 

haz33
Starting Member

15 Posts

Posted - 2007-12-18 : 09:47:14
Hi, I'm hoping someone can help me with this.

I have a view that combines multiple tables. There are about 36,000 rows in that view. One of the fields is an integer. If I select all of that field's values from the view, the data is returned in under a second. Likewise, if I do a COUNT or an AVG function on that field, the row is returned in under a second.

Now, if I attempt to use the MIN or MAX function, all of a sudden, the query takes 22 seconds to run and return an answer. Why would this occur? Why are the COUNT and AVG functions so fast and the MIN and MAX functions so slow?

I'm not terribly knowledgeable about using the Execution Plan within SQL Server, so if something needs to be done there, I might need a little guidance.

Thanks in advance!

-Erik

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2007-12-18 : 09:51:52
Are you grouping on any field?
Go to Top of Page

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2007-12-18 : 09:53:13
Can you post your query?
Go to Top of Page

haz33
Starting Member

15 Posts

Posted - 2007-12-18 : 09:56:40
visakh16:
I was grouping on a field originally. But even if I do a simple "SELECT MAX(field) FROM table", it still takes the same amount of time.

RickD:
There's really nothing to the query...

select min(w_address) as Expr1 from d_wiring where r_name='TSR'

I should note, however, that d_wiring is a view.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2007-12-18 : 10:08:20
Can you view execution plans for AVG() & MIN MAX and see if there are any significant differences ( look for step with high query costs)
Go to Top of Page

haz33
Starting Member

15 Posts

Posted - 2007-12-18 : 10:40:36
It looks like I found it in the execution plan. I was calling a particular table more times than I needed to. Once I fixed the query, then the performance greatly improved.

Thanks for the help!
Go to Top of Page
   

- Advertisement -