-->
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.  [ 4 posts ] 
Author Message
 Post subject: Table per Class mapping performance
PostPosted: Thu Oct 06, 2005 10:56 pm 
Hi, I'm trying to use NHibernate to handle a object inheritence mapping. Because all subclasses have different properties, I'm using the Table per Class approach.

Now, Assume P is the parent class, S1 and S2 are childrens (in the application there might be as many as 30 types of children). And another class A has a collection of P (which can be any concrete class S1 or S2). Now, the problem is, when I'm loading an instance of A, there will be many select SQL queries: one to fetch from P table, and then one for each row of the result returned. In addition, the second type of query joins P, S1 and S2. Because A can have upto 100s of Ps, I'm worried that this could downgrade performance considerably.

Because P table actually has a discriminator column for S1 and S2, I have been thinking about doing the following:
a) select PK and type from P manully group by their type.
b) for each type in the result, issue a "select in" to fetch addtional information.

However, I'd like to know whether there is any way to do this (or any other way to improve performance) without manually manange the queries (even if it's HQL).

Thanks!


Top
  
 
 Post subject:
PostPosted: Fri Oct 07, 2005 3:45 am 
Contributor
Contributor

Joined: Sun Jun 26, 2005 5:03 am
Posts: 51
Location: London, UK
I'd start off with table-per-hierarchy (TBH) rather than table-per-class (TBC) - it doesn't really matter if the attributes are not shared amongst the subclasses, but it will dramatically cut down on the number of joins, which are expensive.

Taking your example, you would have a 30-table join using TBC as opposed to one using TBH. The only caveat is if your database engine actually reserves the space for all of the field, but most don't these days

_________________
Paul Hatcher
NHibernate Team


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 07, 2005 9:44 am 
Thanks for the reply.
At this point, I'm less worried about the join than the fact that I'm sending one query per record. If the select statement has already joined all the tables, is there a way to use SELECT... IN... to batch them so that I reduce the overall # of queries?

paulh wrote:
I'd start off with table-per-hierarchy (TBH) rather than table-per-class (TBC) - it doesn't really matter if the attributes are not shared amongst the subclasses, but it will dramatically cut down on the number of joins, which are expensive.

Taking your example, you would have a 30-table join using TBC as opposed to one using TBH. The only caveat is if your database engine actually reserves the space for all of the field, but most don't these days


Top
  
 
 Post subject:
PostPosted: Fri Oct 07, 2005 10:24 am 
I have found the solution: with lazy fetch and set batch-size=20, I'm able to reduce the number of queries. Thanks!


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