I know the question's title is bad, But I have an hard time figure it out my self…
sometimes this query runs in 2-3 seconds and sometimes it's takes even 30 seconds
I have a table named ranking_temp_free
:
I have one Index
except the primary key:
I have no triggers or partitions on this table..
I'm using this Query:
INSERT IGNORE INTO ranking_temp_free
(countryID, categoryID, ranking, popID, app_id, check_time)
VALUES (/*Here comes 50,000 rows of Data*/);
And as I wrote before.. The time that takes the query to finish is not fixed as I wish to be…
Logs:
THERE ARE MORE LOGS BEFORE..
07-02-2013 00:24:37 Sending SQL: insert ignore into ranking_temp_free
07-02-2013 00:24:54 Inserted: 50000 rows
QUERY TIME : 17 SECONDS
07-02-2013 00:25:05 Sending SQL: insert ignore into ranking_temp_free
07-02-2013 00:25:41 Inserted: 50000 rows
QUERY TIME : 36 SECONDS
07-02-2013 00:26:02 Sending SQL: insert ignore into ranking_temp_free
07-02-2013 00:26:07 Inserted: 50000 rows
QUERY TIME : 5 SECONDS
07-02-2013 00:26:28 Sending SQL: insert ignore into ranking_temp_free
07-02-2013 00:26:35 Inserted: 50000 rows
QUERY TIME : 7 SECONDS
07-02-2013 00:26:46 Sending SQL: insert ignore into ranking_temp_free
07-02-2013 00:26:52 Inserted: 50000 rows
QUERY TIME : 6 SECONDS
07-02-2013 00:27:03 Sending SQL: insert ignore into ranking_temp_free
07-02-2013 00:27:17 Inserted: 50000 rows
QUERY TIME : 14 SECONDS
07-02-2013 00:28:19 Sending SQL: insert ignore into ranking_temp_free
07-02-2013 00:28:39 Inserted: 50000 rows
QUERY TIME : 20 SECONDS
AND SO ON.........
It's a simple INSERT
so why the time is different?.
Just to be clear: THERE ARE NO ANY OTHER PROCESSES ON THE SQL SERVER!
EXAMPLE FOR THE TABLE DATA:
Best Answer
We found the solution to the slow random query execution time:
I added this line:
SET TRANSACTION ISOLATION LEVEL READ COMMITTED
right after the DB connect.we are using PHP, So it's looks like this:
All our problem solved with this magic line.
Now our queries run in 40 minutes and not in 2.5 hours as it use too..
thanks all for your help.