-->
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: Performance of query on unique index
PostPosted: Thu May 31, 2007 5:35 am 
Newbie

Joined: Thu May 31, 2007 5:14 am
Posts: 2
I'm using:
- NHibernate v1.2
- MySql 5.0
- MySql .net connector.
- .net framework 2.0

I have a token table (InnoDB) with two columns: id (int, pk), name (varchar, unique index).

I have very bad performance on the following HQL query:

Code:
   uint? result = db.CreateQuery("select t.Id from Token t where t.Name = ?")
      .SetParameter(0, "test")
      .UniqueResult<uint?>();


When I perform it through a MySqlCommand then the performance is much much better:

Code:
   string QUERY = "SELECT Id FROM Token WHERE Name = ?name";
   IDbCommand cmd = db.Connection.CreateCommand();
   cmd.CommandText = QUERY;
   IDbDataParameter p = cmd.CreateParameter();
   p.ParameterName = "?name";
   p.Value = "test";
   p.DbType = DbType.String;
   cmd.Parameters.Add(p);
   uint? result = (uint?)cmd.ExecuteScalar();


When performing these queries in a loop then CPU usage when using the HQL query is 100% and memory usage is excessive too. This isn't a problem with the native approach. Well.. the name isn't fixed then but random.

The documentation states that native queries are sometimes better for performance reasons but I didn't suspect that this type of HQL query would have bad performance.

Am I doing something wrong here? How can I detect what NHibernate is doing? Is it trying to do something 'smart' with the cache? I read the documentation about caching but didn't find good documented samples about this.


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.