I am having a performance issue when inserting some data in a mysql table. The table has a bunch of columns, let's say DATE,A,B,C,D,E,F where DATE,A,B,C,D,E is the primary key. Every day, I insert 70k rows in that table (with a different date), and this table contains 18 million rows now. The method I use to insert the rows is just sending 70k INSERT queries.
The problem I am having is that the queries started to take a lot more time than they used to. Going from a few minutes to a few hours. I profiled the inserts and this is the charts I got:
Speed of each insert (in sec) vs. Number of insert for that day:
A few strange facts:
- Most queries take less than 2 ms to execute
- The speed of slow queries increases linearly with the number of rows in the table for that date
- This behavior only happens at night, after a bunch of processes have happened on the database. Inserting during the day is fast, so is weekends
- The overall speed doesn't depend on what else is running on the database, in fact, nothing else is running on the database when this happens
- There is nothing in the query that can explain that a query is fast or no, the fast ones are very similar to the slow one, and from one day to another are not the same set.
- the behavior does not change from one day to the next.
Any idea what could cause this?
** Edit ** the columns in the index are in the following order:
DATE NOT NULL,
DATE NOT NULL,
VARCHAR (10) NOT NULL,
VARCHAR (45) NOT NULL,
VARCHAR (45) NOT NULL,
VARCHAR (3) NOT NULL,
VARCHAR (45) NOT NULL,
DOUBLE NOT NULL,
VARCHAR (10) NOT NULL,
VARCHAR (45) NOT NULL,
VARCHAR (45) NOT NULL,
VARCHAR (45) NOT NULL,
The Dates are either the same as today, or left empty, the double is always the same number (no clue who designed this table)