N
N
niko832011-04-27 23:05:24
MySQL
niko83, 2011-04-27 23:05:24

MySQL, deleting 30M records from a table of 40M records

There is a MyISAM log table with 40 million entries, it's time to delete outdated 30 million entries from it.
The table has 5 columns, all indexes.
The request for deletion seemed
DELETE from table where created < date_sub(NOW(), 20 day);
to be running for more than an hour, I interrupted it, during this time only 2 million records were deleted - for a long time ...
Deleting in portions
DELETE from table where id < 1000;
does not seem to give an increase in speed.

What should be done in such cases?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
K
Konstantin, 2011-04-27
@niko83

ALTER TABLE table DISABLE KEYS;
DELETE from table where created < date_sub(NOW(), 20 day);
ALTER TABLE table ENABLE KEYS;

R
Riateche, 2011-04-28
@Riateche

Try to create a new table and copy 10 million records there, then delete the old one and rename the new one. I support council about DISABLE KEYS.

G
Grigory Peretyaka, 2011-04-28
@Peretyaka

Faced such a problem. In my case it was the indexes. You can try DISABLE KEYS. For some reason, this function did not turn off all indexes for me.
If it does not work out, then you can simply temporarily demolish all the keys, indexes, etc., delete the records, and then put them again. But at this time it is necessary to prevent the data from being written. This is how I did it, but there is probably a better way.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question