I have a big table all_records
with 100 million records and many columns.
I want to insert roughly 30 million records inside this table to another table records_not_used_now
based on time-consuming operations of multi columns (the operations are named as f(n) in the following query). Then delete those records from the original table all_records
.
The query is like this:
insert into records_not_used_now
select * from all_records where f(n) > 0;
delete from all_records where f(n) > 0;
However, as the f(n) > 0 judgment costs computation time, I do not want to do it twice. Is there any query in MySQL that can select the record out of the table and then delete them at the same time? The query helps to avoid running the same judgment and scanning the table twice.