How to improve InnoDB DELETE performance?
You could delete data in batches.
In SQL Server, the syntax is delete top X
rows from a table. You then do it in a loop, with a transaction for each batch (if you have more than one statement, of course), so to keep transactions short and maintain locks only for short periods.
In MySQL syntax: DELETE FROM userTable LIMIT 1000
There are restrictions on that (can't use LIMIT
in deletes with joins, for instance) but in this case you might be able to do it that way.
There is an additional danger to using LIMIT
with DELETE
when it comes to replication; the rows deleted are sometimes not deleted in the same order on the slave as it was deleted on the master.
Try using a temp table approach. Try something like this :
Step 1) CREATE TABLE track_table_new LIKE track_table;
Step 2) INSERT INTO track_table_new SELECT * FROM track_table WHERE action='DELETE' AND date_insert >= DATE_SUB(CURDATE(), INTERVAL 30 day);
Step 3) ALTER TABLE track_table RENAME track_table_old;
Step 4) ALTER TABLE track_table_new RENAME track_table;
Step 5) DROP TABLE track_table_old;
I did not include the tuple field in Step 2. Please see if this produces the desired effect. If this is what you want, you may want to ditch the tuple field altogether unless you use the tuple field for other reasons.