| How to speed up DELETE with innodb table [message #3721] |
Wed, 19 November 2008 06:36  |
TommyDIY Messages: 7 Registered: January 2008 |
Junior Member |
|
|
Hi
We have a logging table that contains a months worth of data (about 10Million records) and we run a clean up script everyday that deletes a days worth of records (about 250k) so that we only have the last 31 days worth of information retained. This is taking hours to run!!
OS: Ubuntu 32bit version
MySQL version: 5.0.51a-3ubuntu5.1-log
RAM: 4GB
Some (hopefully) useful MySQL info has been included in the info.txt along with output from top, vmstat and iostat
We have tried various DELETE querys
DELETE FROM log WHERE DATEDIFF(current_date(),dt)>31;
and even added a AUTO INC index called myid to see if that speeds up things
SELECT @l_id:=MIN(myid) FROM log;
SELECT @m_id:=MAX(myid) FROM log WHERE DATEDIFF(current_date(),dt)>31;
DELETE FROM log WHERE myid between @l_id and @m_id;
A select works very fast
mysql> SELECT count(*) FROM cpelog WHERE myid between @l_id and @m_id;
+----------+
| count(*) |
+----------+
| 259200 |
+----------+
1 row in set (0.19 sec)
What can we do to speed up the delete?
Do I have too many indexes as I see that the index size is is greater that the table data size and approaching the 4GB physcial limit to my RAM?I see that that my SWAP does not seems to be used though so sure if that is the problem.
Any help most appreciated.
Cheers
Tom
Attachment: info.txt
(Size: 8.24KB, Downloaded 58 time(s))
|
|
|
|
|
| Re: How to speed up DELETE with innodb table [message #3736 is a reply to message #3721 ] |
Tue, 25 November 2008 10:51  |
bstjean Messages: 2 Registered: December 2006 Location: Canada |
Junior Member |
|
|
Have you tried deleting in "chunks", not all at once, by repeating your delete statement as in :
DELETE FROM log WHERE DATEDIFF(current_date(),dt)>31 LIMIT 5000
*Sometimes* this gives better results. Besides, you ensure your application is somehow responsive all the time (as long as the number of records is not too big)...
One other thing, you might be better with a constant instead of a function call in your WHERE clause.
So something like (assuming we're '2008-11-25':
DELETE FROM log WHERE dt < '2008-10-25'
can use an index on column dt
|
|
|