vince-from-nice opened a new issue, #14189:
URL: https://github.com/apache/grails-core/issues/14189

   Hello,
   
   In the section 6.3.4 of the official documentation, which speaks about" 
Eager and Lazy Fetching", it's written that using lazy:false (int the flights 
association of Airport) can avoid the N+1 queries issue. 
   
   But IMHO that is not true, setting the association to eager doesn't solve 
the problem by itself. 
   
   Eager/Lazy just mean _when_ the association mut be loaded: 'eager' means 
that the association must be loaded instantly as 'lazy' means it will be loaded 
only when it will be required. But what could really avoid the N+1 problem is 
the _how_ it must be loaded, not the _when_. 
   
   By default the _how_ is set to 'select' which means another SELECT SQL 
statement must be executed in order to fetch the associated entities. To avoid 
the N+1 problem the _how_ must be changed to either 'join' or 'batch' or 
'subselect' (apparently the last one is not possible in Grails).
   
   I think the documentation should be corrected to avoid confusion altough 
it's not easy to explain Hibernate fetching strategies in a few lines...
   
   In fact the used example deals with 3 entities: Airport, Flight and Location 
(it could be simpler with 2 entities only). If the flights association of 
Airport is set to eager, there are still N+1 queries to be executed in order to 
fetch relative locations ! The problem can be avoived by setting join:'fetch' 
on the location association of Flight.
   
   I'm also confused with the next section about "Batch fetching". The batch 
mode is usefull when you load mulitple parent instances because associated 
entities can be fetched in one shoot for many parents (SELECT ... IN 
(ParentIds)). But If you have only one parent entity, which is the case of the 
current example, it doesn't make sense for me. 
   
   Thanks, Vincent.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to