MyBatis BULK INSERT Oracle Massive data logging performance problem Resolution

Source: Internet
Author: User
Tags bulk insert

Environment: MyBatis + oracle11g R2


1. Use Direct path insertion ("/*+append_values */" in the following SQL statement) and use keyword "union ALL":


<insert id= "Adduidcodebatch"  parametertype= "java.util.List" >      INSERT INTO/*+append_values */        T_ Uid_code (C_uid_code,         C_serail_len,         c_batch_code,         c_type,         c_create_time,         c_super_code         , C_security_code,         c_serial_code         )       <foreach collection= "list" item= "item" index= "index" separator= " UNION ALL ">    select #{item.uidcode},         #{item.kcode},               #{item.batchcode},         #{item.type},         Sysdate,         #{item.supercode},         #{item.securitycode},         #{item.serialcode} from  dual       </ Foreach>      </insert>  

2.dao layer implementation: Before a one-time commit, this will increase with the number of inserts, the speed of the operation is very slow, so should be inserted in batches:


public void Save (list<uidcodebean> uidcodelist) throws Exception {sqlsession batchsqlsession = null;try { Batchsqlsession = Sqlsessionfactory.opensession (Executortype.batch, false);//Get batch mode Sqlsessionint BatchCount = 1000 ;//The number of commits per batch int batchlastindex = batchcount-1;//The last subscript for each batch for (int index = 0; index < uidcodelist.size ()-1;) {if (BATC Hlastindex > Uidcodelist.size ()-1) {Batchlastindex = Uidcodelist.size ()-1;batchsqlsession.insert (NAMESPACE+). Adduidcodebatch ", Uidcodelist.sublist (Index, Batchlastindex)); Batchsqlsession.commit (); System.out.println ("Index:" +index+ "Batchlastindex:" +batchlastindex); break;//data insertion complete, exit loop}else{                Batchsqlsession.insert (namespace+ ". Adduidcodebatch", Uidcodelist.sublist (Index, batchlastindex)); Batchsqlsession.commit (); System.out.println ("Index:" +index+ "Batchlastindex:" +batchlastindex); index = Batchlastindex + 1;// Set Next batch Subscript Batchlastindex = index + (batchCount-1);}}} Finally{batchsqlsession.close ();}}





MyBatis BULK INSERT Oracle Massive data logging performance problem Resolution

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.