MySQL BULK Insert vs. Single Insert efficiency comparison

Source: Internet
Author: User

1. Data insertion Performance (single insert and BULK INSERT) [Java]View PlainCopy 
  1. Public class Test {
  2. private Long ID;
  3. private String test;
  4. Public Long getId () {
  5. return ID;
  6. }
  7. public void SetId (Long id) {
  8. this.id = ID;
  9. }
  10. Public String Gettest () {
  11. return test;
  12. }
  13. public void Settest (String test) {
  14. this.test = test;
  15. }
  16. }

Mapper.xml file

[HTML]View PlainCopy 
  1. <? XML version= "1.0" encoding="UTF-8" ?>
  2. <!  DOCTYPE Mapper Public "-//mybatis.org//dtd mapper 3.0//en" "Http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
  3. <mapper namespace="Com.astrospace.test.mapper.TestMapper" >
  4. <resultmap id="test" type="Com.astrospace.test.dmo.Test" >
  5. <ID property= "id" column="id"/>
  6. <result property="test" column="test" />
  7. </resultmap>
  8. <insert id="Add" parametertype="Com.astrospace.test.dmo.Test">
  9. INSERT into TEST (id,test) VALUES (#{id},#{test});
  10. </Insert>
  11. <insert id="Batchadd" parametertype="java.util.List">
  12. INSERT into TEST (id,test)
  13. VALUES
  14. <foreach collection="list" item="item" index="index" separator="," >
  15. (#{item.id},#{item.test})
  16. </foreach>
  17. </Insert>
  18. </mapper>

Call the Add and Batchadd methods.

Different data volumes were tested 5 times and the results were as follows:

50,000 data per insert Average time: 233748ms
Bulk Insert 50,000 data average time: 2590ms
Contrast: 50 times times less efficient
10,000 data per insert Average time: 22036ms
Bulk INSERT 10,000 data average time: 3330ms
Contrast: 6 times times less efficient
1000 data per insert Average time: 3122ms
BULK INSERT 1000 Data average time: 374ms
Contrast: 8 times times less efficient

The more data, the more efficient it becomes.

MySQL BULK Insert vs. Single Insert efficiency comparison

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.