MySQL Docs say :
The size of the table slows down the insertion of indexes by log N, assuming B-tree indexes.
Does this mean that for insertion of each new row, the insertion speed will be slowed down by a factor of log N where N, I assume is number of rows? even if I insert all rows in just one query? i.e. :
INSERT INTO mytable VALUES (1,1,1), (2,2,2), (3,3,3), .... ,(n,n,n)
Where n is ~70,000
I currently have ~1.47 million rows in a table with the following structure :
CREATE TABLE mytable (
`id` INT,
`value` MEDIUMINT(5),
`date` DATE,
PRIMARY_KEY(`id`,`date`)
) ENGINE = InnoDB
When I insert in the above mentioned fashion in a transaction, the commit time taken is ~275 seconds. How can I optimize this, since new data is to be added everyday and the insert time will just keep on slowing down.
Also, is there anything apart from just queries that might help? maybe some configuration settings?
Possible Method 1 - Removing Indices
I read that removing indices just before insert might help insert speed. And after inserts, I add the index again. But here the only index is primary key, and dropping it won't help much in my opinion. Also, while the primary key is dropped , all the select queries will be crippling slow.
I do not know of any other possible methods.
Edit : Here are a few tests on inserting ~60,000 rows in the table with ~1.47 mil rows:
Using the plain query described above : 146 seconds
Using MySQL's LOAD DATA infile : 145 seconds
Using MySQL's LOAD DATA infile and splitting the csv files as suggested by David Jashi in his answer: 136 seconds for 60 files with 1000 rows each, 136 seconds for 6 files with 10,000 rows each
Removing and re-adding primary key : key removal took 11 seconds, 0.8 seconds for inserting data BUT 153 seconds for re-adding primary key, totally taking ~165 seconds
See Question&Answers more detail:
os