-->
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.  [ 3 posts ] 
Author Message
 Post subject: Performance goes down when HQL contains aggregate.
PostPosted: Thu May 05, 2005 4:25 pm 
Beginner
Beginner

Joined: Thu Jan 06, 2005 6:21 pm
Posts: 23
Hibernate version:3.0.2

Mapping documents:
<hibernate-mapping>

<class name="com.securimine.beans.model.ModelGroupView" table="SECVIEWModelGroup" mutable="false" lazy="false">

<id name="id" type="java.lang.Integer" column="group_id">
<generator class="increment"/>
</id>

<property name="numberOfEvents" type="java.lang.Long" update="false" insert="false" formula="count(*)"/>

</class>

</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():

List result;
ModelGroupViewI row;
String queryStr = "from ModelGroupView ca group by ca.id order by ca.id asc";

HibernateUtil.beginTransaction();
Session session = HibernateUtil.getSession();
try {
result = session.createQuery(queryStr).list();
} catch (HibernateException ex) {
throw new InfrastructureException(ex);
} finally {
HibernateUtil.closeSession();
}

Name and version of the database you are using:MS SQL 8.0

When queryStr = "from ModelGroupView ca group by ca.id order by ca.id asc"
the generated SQL is
select modelgroup0_.group_id as group1_, count(*) as formula0_
from SECVIEWModelGroup modelgroup0_
group by modelgroup0_.group_id
order by modelgroup0_.group_id asc

The Statistics give me:
[main] INFO org.hibernate.stat.StatisticsImpl - max query time: 2656ms


Now if I remove the numberOfEvents property from the mapping
<hibernate-mapping>

<class name="com.securimine.beans.model.ModelGroupView" table="SECVIEWModelGroup" mutable="false" lazy="false">

<id name="id" type="java.lang.Integer" column="group_id">
<generator class="increment"/>
</id>

</class>

</hibernate-mapping>


Then queryStr = "from ModelGroupView ca order by ca.id asc"
the generated SQL is
select modelgroup0_.group_id as group1_
from SECVIEWModelGroup modelgroup0_
order by modelgroup0_.group_id asc

The Statistics give me:
[main] INFO org.hibernate.stat.StatisticsImpl - max query time: 63ms

If I run both generated query in SQL Script Analyser, I get a running time of 0.0s (which is not really accurate,
but basically they are both really fast and way under 1 second.

For some reason, having the aggregate function using hibernate increase the execution time to almost 3 second.

I looked into it a little but I still don't know what the reason is.
Is there anythin that hibernate is doing because of the different HQL that would take time?
Both generated SQL should execute in the same amount of time (roughly 60ms).
So is hibernate doing some extra processing when there is an aggregate function?

I'll keep investigating but if anyone has an idea why is that, I'll be glad to hear it.

thanks,

Richard


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 05, 2005 5:07 pm 
Beginner
Beginner

Joined: Thu Jan 06, 2005 6:21 pm
Posts: 23
The slow part is in the AbstractBatcher class:

public ResultSet getResultSet(PreparedStatement ps) throws SQLException {
ResultSet rs = ps.executeQuery();
resultSetsToClose.add(rs);
logOpenResults();
return rs;
}

For some reason ps.executeQuery() is slow in that case.
What I can't explain is why it is slow using hibernate and it is fast using SQL Query analyzer...
Maybe something wrong with Jtds configuration?


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 05, 2005 5:46 pm 
Beginner
Beginner

Joined: Thu Jan 06, 2005 6:21 pm
Posts: 23
The problem comes from Jtds driver. So I'll investigate in that way.
Sorry for the post in Hibernate forum.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.