Skip to content

Instantly share code, notes, and snippets.

Last active November 26, 2021 12:48
What would you like to do?

Each query in MySQL is running as its own transaction, assuming you didn't change this default configuration, and unless you're starting a transaction manually and running multiple deletes in that one transaction.

Because every query is a transaction, MySQL has to save the data being deleted in case of a rollback. Large deletes means saving a TON of data for that potential case.

Additionally, deletes cause a LOT of writes to the binary log. When the delete completes, the query/results of the delete are committed to the binary log, which can take time.

This means that even after the delete query is done, the database may not 'recover' from it for a while.

Many, smaller deletes spread over time as you have in code definitely helps!

However, as mentioned above, there are side effects to large deletes to know about outside of code.

We hired Percona to help us as this issue was locking up a HUGE rds instance we have (with many databases) when we had to delete many millions of rows across those databases.

Here's what we set.

NOTE: Don't blindly copy/paste these. They each have pros and cons. Percona get us recommendations based on our specific usage patterns and database size.

They're worth hiring for at least a one-time review in exchange for a few thousand bucks.

Most relevant changes: (RESEARCH THESE!):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment