Skip to main content
2 of 4
Updated in response to comment.
Greg
  • 381
  • 6
  • 13

Updating/Inserting 2000 rows takes over 12 hours to complete

I have three tables of around 10 million rows each in MySQL on Amazon RDS and I am finding the insert/update performance to be VERY slow. Each table contains unrelated data.

Each table is regularly updated with about 2000 rows each time. The rows either update existing values or insert new ones. I am finding that updating or inserting 2000 rows is taking over 12 hours to perform.

The database has 100GB of General SSD storage which means that it can sustain 300 IOPS. CPU utilisation is below 20% and RAM is 50% free.

I am using an index and a primary key which was constructed from two columns within the table using: CONSTRAINT PK_1 PRIMARY KEY (DATE, NAME)

I am using the below query:

 INSERT INTO Table (DATE, NAME, COLUMN_1, ..., COLUMN_40) VALUES ('2015-05-26','David', VALUE_1, ... , VALUE_40), ... ('2015-05-26','Tom', VALUE_1, ... , VALUE_40) ON DUPLICATE KEY UPDATE COLUMN_1=VALUES(COLUMN_1), ... , COLUMN_40=VALUES(COLUMN_40); 

The reason why I have chosen to use the above statement instead of a REPLACE INTO statement is because whilst the table is 40 columns wide, I only receive 10 of those columns at once. The values of the rows can also change for up to a week.

By default the data was being inserted into the three tables sequentially. I have tried inserting the data in parallel however there was no observed improvement in the performance.

I don't understand why it takes over 12 hours to insert 2000 rows. What are my options to improving performance?

Greg
  • 381
  • 6
  • 13