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
 aggregate query with hash match

Author  Topic 

mcolli00
Starting Member

19 Posts

Posted - 2011-03-21 : 11:24:16
Hi

I am having trouble with a stored proc that contains the following sql statement. I am getting a 66% hash match from the group by clause and a 34% index scan on squarefeet column's index. Do you know how to reduce the hash match to loop or something with better performance by changing this query logic?

Note: The squareFeet column is int data type and has numerous null values in it.

Thanks in advance!
MC

select sum(SquareFeet)
from area
group by area_fk

X002548
Not Just a Number

15586 Posts

Posted - 2011-03-21 : 11:29:45
want to post the DDL with the indexes?

Not sure what good that SQL statement does for you anyway

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2011-03-21 : 13:51:54
Query, table definitions and index definitions please. If you can find somewhere to upload the execution plan (saved as .sqlplan file and zipped) that would be a bonus.

btw, a loop join does not necessarily have better performance than a hash join. On larger row counts it generally has a far, far, far worse performance.

http://sqlinthewild.co.za/index.php/2009/11/24/the-most-optimal-join-type/

p.s. That query you've posted cannot have a hash match in the exec plan (unless that's a view). It can have a hash aggregate, but not a hash match (join)

--
Gail Shaw
SQL Server MVP
Go to Top of Page

mcolli00
Starting Member

19 Posts

Posted - 2011-03-21 : 17:44:53
Yes you are correct. It was a hash aggregate. I couldn't update the objects for privacy reasons. I have resolved the issue -- a covering index did the trick.

Thanks to all of those who replied.

MC
Go to Top of Page
   

- Advertisement -