I have to delete about 28 million records from a InnoDB table in MySQL.
I am wondering what happens if I am doing a select statement on the same table during the delete operation.
I guess the delete will take some time to complete.
I am using MySQL version 5.6.
I don't want to delete all records I will have a where condition or maybe having.
Thank you for your time.
Best Answer
Instead of deleting a large percentage of the rows you might better negate your WHERE-condition and INSERT/SELECT the remaining rows into a new table. Then DROP the original table and RENAME new to old (or TRUNCATE and re-INSERT). This way there's only a very small period (DROP/RENAME) where the table is not available. It's a very common process in a Data Warehouse where you deal with really large numbers of rows.
You need to run both the INSERT/SELECT and the DROP TABLE within a single transaction, so no other session is able to do any DML between the INSER and the DROP. I don't know the exact mySQL/InnoDb syntax and transaction behavior, but this is a skeleton (of course you need to test before):