ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Abdullah Kauchali" <abdullah.kauch...@isanusi.com>
Subject RE: Avoiding N+1 Selects
Date Tue, 20 Feb 2007 11:13:09 GMT
Hi Brad,

 

Have a look at the "WITH" statement (it is ANSI specified) and CTE's (common
table expressions).  Here is an example with SQL 2005.

 

http://msdn2.microsoft.com/en-us/library/ms186243.aspx

 

I am sure the logic will also work off Oracle versions that support the WITH
statement (maybe with minor modifications).

 

I am sure this will get you the full tree with a single round-trip to the
database.  However, I don't know how the ResultMaps will work with them.  

 

  _____  

From: Brad Handy [mailto:brad.handy@gmail.com] 
Sent: Tuesday, February 20, 2007 3:11 AM
To: user-java@ibatis.apache.org
Subject: Avoiding N+1 Selects

 

 

 

 

 

 

 

 

 

 

 

 

 

 

I have a table which has all of the parent/child relationships in the same
table.  I would like to avoid the N+1 selects with this construct, but it's
unclear from the documentation if this can be done.

Let's say I have the following relationships defined in the table: 

Grand Parent
   Parent 1
      Child 1
      Child 2
   Parent 2
   Parent 3
      Child 3
      Child 4


When creating the child objects for "Grand Parent", will the same "Parent*"
objects be used to add the children "Child*" objects to the appropriate
parents? 



Brad


Mime
View raw message