-->
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.  [ 1 post ] 
Author Message
 Post subject: Baffled: Hibernate count() much slower than in SQLSquirrel
PostPosted: Tue Aug 29, 2006 7:46 pm 
Beginner
Beginner

Joined: Thu Dec 09, 2004 3:19 pm
Posts: 34
Hibernate version:
2.1

In testing query performance we're trying to improve the count() query performance on one case with a large data set. All the SQL here is what's spewed out from Hibernate.

This query took about 25 seconds:
HQL:
Code:
select count ( * )  from ChannelViewActivity cva where cva.createdAtDate between :startDate and :endDate


SQL:
Code:
select count(*) as x0_0_ from MC.CHANNEL_VIEW_ACTIVITY channelvie0_, MC.ACTIVITY channelvie0__1_ where channelvie0_.ACTIVITY_ID=channelvie0__1_.ACTIVITY_ID and ((channelvie0__1_.CREATED_AT between ? and ? ))


In testing with SQLSquirrel (cut/past the SQL above), we found switching from count(*) to count(channelvie0_.ACTIVITY_ID) cut the query time from 25 seconds to less than 1 second. (I don't really understand the underlying database reason for the speed increase, so maybe there's a reason I shouldn't count() this way?).

So, we changed the HQL query to use:
Code:
select count ( cva.key ) from ChannelViewActivity cva where cva.createdAtDate between :startDate and :endDate


The SQL generated was identical to the above SQL, except the count(*) was now the desired count(channelvie0_.ACTIVITY_ID). I expected the query to process in ~1 second, just like in SQLSQuirrel. It didn't though. The execution through Hibernate still takes about 25 seconds. No performance increase.

I'm completely baffled. In every case in the past, SQLSquirrel's performance on an SQL statement generated by Hibernate was basically the same as in Hibernate. No surprise.

Here are some log lines from the query. As near as I can tell, it spends 25 seconds waiting for the database to respond with a results set, but SQLSQuirrel, executing the same SQL, only takes 1 second.

Why the performance difference? Is there something I did wrong specifying my HQL query that would account for it?

2006-08-29 16:13:25,955 [SocketListener0-8] DEBUG QueryTranslator HQL: select count ( cva.key ) from com.ncube.nable.platform.activity.type.ChannelViewActivity cva where cva.createdAtDate between :cvastart_createdAtDate and :cvaend_createdAtDate
2006-08-29 16:13:25,955 [SocketListener0-8] DEBUG QueryTranslator SQL: select count(channelvie0_.ACTIVITY_ID) as x0_0_ from MC.CHANNEL_VIEW_ACTIVITY channelvie0_, MC.ACTIVITY channelvie0__1_ where channelvie0_.ACTIVITY_ID=channelvie0__1_.ACTIVITY_ID and ((channelvie0__1_.CREATED_AT between ? and ? ))
2006-08-29 16:13:25,955 [SocketListener0-8] DEBUG BatcherImpl about to open: 0 open PreparedStatements, 0 open ResultSets
2006-08-29 16:13:25,955 [SocketListener0-8] DEBUG SQL select count(channelvie0_.ACTIVITY_ID) as x0_0_ from MC.CHANNEL_VIEW_ACTIVITY channelvie0_, MC.ACTIVITY channelvie0__1_ where channelvie0_.ACTIVITY_ID=channelvie0__1_.ACTIVITY_ID and ((channelvie0__1_.CREATED_AT between ? and ? ))
2006-08-29 16:13:25,955 [SocketListener0-8] DEBUG BatcherImpl preparing statement
2006-08-29 16:13:25,955 [SocketListener0-8] DEBUG TimestampType binding '2006-08-27 16:13:18' to parameter: 1
2006-08-29 16:13:25,955 [SocketListener0-8] DEBUG TimestampType binding '2006-08-29 16:13:18' to parameter: 2
2006-08-29 16:13:53,705 [SocketListener0-8] DEBUG Loader processing result set
2006-08-29 16:13:53,705 [SocketListener0-8] DEBUG Loader result row:
2006-08-29 16:13:53,705 [SocketListener0-8] DEBUG IntegerType returning '505' as column: x0_0_


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

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.