-->
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: Unnecessary joins in generated SQL
PostPosted: Mon May 25, 2009 1:29 pm 
Newbie

Joined: Sun May 17, 2009 2:14 pm
Posts: 4
I have a many-to-many relationship between employers and individuals, and a many-to-many relationship between individuals and accounts. I'm running the following query:
Code:
select a
from Employer e join e.Individuals i join i.Accounts a
where e.Name = 'ACME'

And I'm getting the following SQL:
Code:
select
  account4_.Id as Id5_,
  account4_.Type as Type5_
from
  [Employer] employer0_
  inner join EmployerIndividual individual1_ on employer0_.Id=individual1_.Employer_id
  inner join Individual individual2_ on individual1_.Individual_id=individual2_.Id
  inner join IndividualAccount accounts3_ on individual2_.Id=accounts3_.Individual_id
  inner join [Account] account4_ on accounts3_.Account_id=account4_.Id
where
  (employer0_.Name=@p0 ); @p0 = 'ACME'

The issue is that I'm getting an unnecessary join to the to the Individual table. The table does not need to appear in the query; instead one could join from the EmployerIndividual table directly to the IndividualAccount table.

My questions are:

1) Is this even an problem when it comes to performance? Should I not be worrying about this?

2) If it is a problem, is there a way to resolve it?

Thanks!

- chad


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.