Currently, I am trying to copy data from TABLE1
to TABLE2
.
In terms of insertions performance, would it be the same or faster if I would to do
BULK INSERT
manually (i.e BULK insert every 10K records into TABLE2 viaINSERT INTO TABLE2 VALUES (1,2), (5,5), ...
), versusINSERT INTO TABLE2 SELECT * FROM TABLE1
Best Answer
You have to go with the BULK INSERT.
WHY NOT
INSERT INTO TABLE2 SELECT * FROM TABLE1
???Running
INSERT INTO TABLE2 SELECT * FROM TABLE1
requires a single transaction.Imaging how populated an undo log will be to perform a single rollback.
If that transaction fails and rolls back, you create lots of table fragmentation.
Why
BULK INSERT
manually ???This takes a lot of pressure off the InnoDB Storage Engine for holding large undo information.
EXAMPLE : mysqldump
Have you ever noticed when reloading a mysqldump, hundreds or thousands of rows at a time are being inserted ? If you grep a mysqldump like this:
You will see many lines with INSERTs. Each INSERT is an extended insert by default. That allows 100's of rows to be inserted per INSERT command. So, the principle you already suggested of BULK INSERT 10K rows at a time is perfectly acceptable.