It takes a lot of time for mysql to insert multiple data records.

Source: Internet
Author: User

It takes a lot of time for mysql to insert multiple data records.

  • SQL script

Select * from users;

  • Method 1:

Insert into users (name, age, course_id) VALUES ("test", 1, "0 ");
Insert into users (name, age, course_id) VALUES ("test", 1, "0 ");
Insert into users (name, age, course_id) VALUES ("test", 1, "0 ");
Insert into users (name, age, course_id) VALUES ("test", 1, "0 ");
Insert into users (name, age, course_id) VALUES ("test", 1, "0 ");
Insert into users (name, age, course_id) VALUES ("test", 1, "0 ");
Insert into users (name, age, course_id) VALUES ("test", 1, "0 ");
Insert into users (name, age, course_id) VALUES ("test", 1, "0 ");
Insert into users (name, age, course_id) VALUES ("test", 1, "0 ");
Insert into users (name, age, course_id) VALUES ("test", 1, "0 ");
Insert into users (name, age, course_id) VALUES ("test", 1, "0 ");
Insert into users (name, age, course_id) VALUES ("test", 1, "0 ");
Insert into users (name, age, course_id) VALUES ("test", 1, "0 ");
Insert into users (name, age, course_id) VALUES ("test", 1, "0 ");
Insert into users (name, age, course_id) VALUES ("test", 1, "0 ");
Insert into users (name, age, course_id) VALUES ("test", 1, "0 ");
Insert into users (name, age, course_id) VALUES ("test", 1, "0 ");
Insert into users (name, age, course_id) VALUES ("test", 1, "0 ");
Insert into users (name, age, course_id) VALUES ("test", 1, "0 ");
Insert into users (name, age, course_id) VALUES ("test", 1, "0 ");
Insert into users (name, age, course_id) VALUES ("test", 1, "0 ");
Insert into users (name, age, course_id) VALUES ("test", 1, "0 ");
Insert into users (name, age, course_id) VALUES ("test", 1, "0 ");
Insert into users (name, age, course_id) VALUES ("test", 1, "0 ");

  • Method 2:

Insert into users (name, age, course_id) VALUES ("test", 1, "0"), ("test", 1, "0"), ("test ", 1, "0"), ("test", 1, "0 "),

("Test", 1, "0"), ("test", 1, "0"), ("test", 1, "0 "), ("test", 1, "0 "),
("Test", 1, "0"), ("test", 1, "0"), ("test", 1, "0 "), ("test", 1, "0 "),
("Test", 1, "0"), ("test", 1, "0"), ("test", 1, "0 "), ("test", 1, "0 "),
("Test", 1, "0"), ("test", 1, "0"), ("test", 1, "0 "), ("test", 1, "0 "),
("Test", 1, "0"), ("test", 1, "0"), ("test", 1, "0 "), ("test", 1, "0 ")

  • Time loss

When inserting the above 24 data records, we found that the execution efficiency of the two items was significantly different (nearly 10 times)

Method 1:

Method 2:

 

  • Extension:

Is the internal implementation of the batch processing in jdbc implemented in the form of method 2? If you are interested, you can view the source code of this part...

  

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.