-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Query performance issue
PostPosted: Fri May 25, 2007 5:43 pm 
Newbie

Joined: Sun Sep 18, 2005 3:44 pm
Posts: 9
Hi,

I'm running this SQL query using SqlCommand over a 4 milion records table:

SELECT SUM(nc), sid FROM Readings WHERE (sid IN (1, 2, 3) AND (date >= @from) AND (date <= @to) GROUP BY sid

and it takes 5 seconds to complete.

Running this HQL query agains the same table:

select sum(rec.nc), rec.sid from Reading rec where (rec.sid in (1, 2, 3) and (rec.Date >= :from) and (rec.Date <= :to) group by rec.sid

completes in over 20 seconds...

What am I missing?

Thanks


Hibernate version:
1.2.0
Name and version of the database you are using:
SQL Server 2005


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 25, 2007 5:50 pm 
Newbie

Joined: Sun Sep 18, 2005 3:44 pm
Posts: 9
Sorry,

select rec.sid, sum(rec.nc) from Reading rec where (rec.sid in (1, 2, 3) and (rec.Date >= :from) and (rec.Date <= :to) group by rec.sid

returned in over 20 seconds BUT

select sum(rec.nc), rec.sid from Reading rec where (rec.sid in (1, 2, 3) and (rec.Date >= :from) and (rec.Date <= :to) group by rec.sid

returned in 5.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 25, 2007 6:49 pm 
Senior
Senior

Joined: Sat Sep 10, 2005 3:46 pm
Posts: 178
whats the difference between the 2 besides the order of the columns?

rec.sid, sum(rec.nc) vs sum(rec.nc), rec.sid


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 25, 2007 7:57 pm 
Newbie

Joined: Sun Sep 18, 2005 3:44 pm
Posts: 9
I'm lost, after restarting SQL Server 2005 both HQL queries are performing bad... over 20 sec... after running for a while is back to 5 sec


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 25, 2007 11:27 pm 
Regular
Regular

Joined: Tue Aug 08, 2006 4:28 am
Posts: 96
Location: Hong Kong
It looks like caching issue (e.g. Query Plan Cache) in SQL Server.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.