I know that turning off autocommit can improve bulk insert performance a lot according to:

Is it better to use AUTOCOMMIT = 0

And I have made experiments to confirm that conclusion. But what I want to know is, why turning off autocommit can improve bulk inserts? And what happens internally in inno db when a transaction is commited?

  • What do you mean with bulk insert, is it one insert that inserts many rows, or several inserts? Commented Nov 3, 2019 at 16:46
  • I added an Answer to the Question you linked to.
    – Rick James
    Commented Nov 3, 2019 at 19:42

2 Answers 2


There are 3 ways to do transactions. All 3 of the following involve transactions.

SET autocommit = ON;

INSERT ... VALUES (1,2), (2,3), ...;  -- This is one transaction
another INSERT/UPDATE/etc;  -- This is another transaction


SET autocommit = OFF;

INSERT ... VALUES (1,2), (2,3), ...;
another INSERT/UPDATE/etc;  
COMMIT;     -- Terminate the ONE transaction (with 2 statements)


INSERT ... VALUES (1,2), (2,3), ...;
another INSERT/UPDATE/etc;
COMMIT;     -- Terminate the ONE transaction (with 2 statements)

If you are doing a bulk INSERT, you probably want it to be a transaction unto itself, since you have already combined a lot of 1-row inserts into a "bulk" insert.


  • A transaction has some overhead.
  • A statement has some overhead.


  • Fastest: Bulk INSERT (one statement in one transaction)
  • Medium: A bunch of 1-row INSERT statements between BEGIN and COMMIT is
  • Slowest: 1-row INSERTs, each one being a separate transaction.

Tip: Don't use autocommit=0 because you might forget to issue the COMMIT.


If autocommit is turned off, you can always do a ROLLBACK to get back to the state the database was in before you started doing something. COMMIT makes sure all changes to the database are written permanently, doing this for every INSERT takes more time than doing this for a lot of INSERTs, because not only the records needs to be inserted, also the indexes needs to be updated. Doing this last piece for a lot of records is more efficient than doing this for 1 record at a time.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.