How to optimize a delete query with a subselect? This query needs to delete over 17 million rows, from a table containing 20 million.

DELETE FROM statements 
where agreement_id IN (
    select id FROM agreements 
    WHERE created &lt; DATE_SUB(CURDATE(), INTERVAL 6  MONTH)
);

DELETE FROM agreements 
WHERE created &lt; DATE_SUB(CURDATE(), INTERVAL 6  MONTH)


It takes hours to run, am I missing something that could speed things up a bit?

The subselect by itself takes a few seconds, I don't understand why the delete takes so long.
Use Multiple-Table Syntax of DELETE statement.

DELETE s.*, a.*
FROM statements s, agreements a
WHERE s.agreement_id = a.id
  AND a.created &lt; CURDATE() - INTERVAL 6 MONTH