0

I would like to know which solution is faster than the other. So, imagine we'd like to INSERT 10000 rows into a table. We have the following 2 solutions:

Solution 1: Run the INSERT query 10000 times:

INSERT INTO myTable (a,b,c) VALUES ("a","b","c"); x 10000

Solution 2: Run one INSERT query with 10000 rows at once:

INSERT INTO myTable (a,b,c) VALUES 
("a","b","c"),
("a","b","c"),
("a","b","c"),
 ...,
("a","b","c");
1

2 Answers 2

1

Solution 2 : it need just one connection to the database, the solution 1 need 1000 connections and it's so mush.

Sign up to request clarification or add additional context in comments.

2 Comments

What if we run all 10000 INSERTs with one connection? 1. open connection; 2. perform 10000 INSERTs ; 3. close connection
you can do for exemple a loop and insert 1000 by 1000
1

Solution 1 is around 10 times slower than solution 2.

From the guy with the mysql database server with 100gb data and 5000 request per second.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.