-->
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.  [ 6 posts ] 
Author Message
 Post subject: Performance issues with bulk delete operation
PostPosted: Wed Oct 26, 2005 5:52 pm 
Newbie

Joined: Mon May 16, 2005 8:25 am
Posts: 7
Location: Hertford, UK
3.1rc2:
DB2 V7:

I have a simple scenario where I am performing a bulk delete operation via a DAO 500 times (for different business keys).

Using an HQL bulk delete it takes 2000 times longer to execute the queries than using JDBC (146 seconds compared to 0.08 seconds).

The HQL way looks like

Code:
public class AssetLifeHistoryDAO extends AbstractDAO {

   private Query q = null;
   
   public void deleteSortieRecords(String serialNumber, String equipmentType) throws Exception {
      

      if ( q == null ){
         Session s = BdsConnection.currentSession();
         q = s.createQuery("delete from lits.bds.ess.AssetLifeHistory"+
         " where "+
            " id.assetSerialNo = :serialNo and "+
            " id.equipmentType = :equipmentType and "+
            " sortieFlag = 'Y' and"+         
            " id.lmu <> :lmu");
      }
      
      q.setString("serialNo", serialNumber);
      q.setString("equipmentType", equipmentType);
      q.setString("lmu", "FLYING-HRS DEC MINS");
   
      q.executeUpdate();      
   }
}


and the alternative JDBC method (using the hibernate created JDBC connection)

Code:
public class AssetLifeHistoryDAO extends AbstractDAO {


   private PreparedStatement p = null;
   
   public void deleteSortieRecords(String serialNumber, String equipmentType) throws Exception {
      
      if ( p == null ){
         Session s = BdsConnection.currentSession();
         
         String sql = "DELETE FROM lits.t_asset_life_his where mach_no=? and machcl_cde=? and mruom_cde <> ? and srt_flg='Y'";
         Connection c = s.connection();
         p = c.prepareCall(sql);
      }
      p.setString(1, serialNumber);
      p.setString(2, equipmentType);
      p.setString(3, "FLYING-HRS DEC MINS");
      
      p.execute();

   }
}


With show_sql set to true the delete queries sent to the database are identical. I guess Hibernate is doing something else too ?

Any help would be appreciated (for now I will use the JDBC option).


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 26, 2005 6:18 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
I find this incredibly difficult to believe.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 26, 2005 6:27 pm 
Newbie

Joined: Mon May 16, 2005 8:25 am
Posts: 7
Location: Hertford, UK
Don't worry it's had me baffled for hours. Not matter how many different ways I try it I get the same result.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 26, 2005 10:25 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
what does the log show?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 27, 2005 5:25 am 
Newbie

Joined: Mon May 16, 2005 8:25 am
Posts: 7
Location: Hertford, UK
OK, it seems to be an issue with caching. If I put a session.clear() before doing the 500 bulk delete operations it goes like the wind.

To complete the picture (in a simplified example) the software has two tables A and B where B has a foreign key to A. The default lazy values are being used for collections.

The software updates 500 As. It then tries to do a bulk delete on B using the partial business keys from the 500 As.

From the hibnerate log I can see that there have been no attempts to read the Bs at any time. Just having the As in cache seems to cause the problem.

For me the problem is solved because doing the session.clear() is a viable option.

Just wondering whether this is the expected behaviour in this scenario.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 27, 2005 7:16 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
what does the log show?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

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.