cron
is dangerous. If one instance of cron fails to finish before the next is due, they are likely to fight each other.
It would be better to have a continuously running job that would delete some rows, sleep some, then repeat.
Also, INDEX(datetime)
is very important for avoiding deadlocks.
But, if the datetime test includes more than, say, 20% of the table, the DELETE
will do a table scan. Smaller chunks deleted more often is a workaround.
Another reason for going with smaller chunks is to lock fewer rows.
Bottom line:
INDEX(datetime)
Other deletion techniques: http://mysql.rjweb.org/doc.php/deletebig