The reason is explained well in the SQLMaps documentation: "Lazy Loading vs. Joins (1:1) It’s important to note that using a join is not always better. If you are in a situation where it is rare to access the related object [-the Child-] then it might actually be faster to avoid the join and the unnecessary loading of all [-Child-] properties. This is especially true for database designs that involve outer joins or nullable and/or non-indexed columns. In these situations it might be better to use the sub-select solution with the lazy loading and bytecode enhancement options enabled (see SQL Map Config settings). The general rule of thumb is: use the join if you’ re more likely going to access the associated properties than not. Otherwise, only use it if lazy loading is not an option."
Fabrizio -----Messaggio originale----- Da: Vic Cekvenich [mailto:[EMAIL PROTECTED] Inviato: mercoledì 9 febbraio 2005 15.13 A: ibatis-user-java@incubator.apache.org Oggetto: Re: What is N+1 Which I could do with a join on SQL side. I can't see how this is something I'd use or how it' scale, but.... I guess somone uses it. THANKS for the education. .V Kris Jenkins wrote: > > > The N+1 selects problem is when you query for n parents, and you need > one extra query for the children. Internally, this happens: > > List parents = sqlMap.queryForList( "getParents", parameter ); > for ( Iterator i = parents.iterator(); i.hasNext(); ) { > Parent p = (Parent) i.next(); > List children = sqlMap.queryForList( "getChild", p.getId() ); > p.setChildren( children ); > } > > So you end up with 1 query for the parent list, plus one extra for > each parent to get the children = n + 1. Rather inefficient. > This is the problem that 2.0.9 fixes. > > Sorry for the confusion. > Kris > -- Forums, Boards, Blogs and News in RiA <http://www.boardVU.com>