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