Question

I have a table with about 35 million rows. each has about 35 integer values and one time value (last updated) The table has two indexes primary - uses two integer values from the table columns Secondary - uses the 1st integer from the primary + another integer value.

I would like to delete old records (about 20 millions of them) according to the date field.

What is the fastest way: 1. Delete as is according the the date field? 2. Create another index by date and then delete by date.

There will be one time deletion of large portion of the data and then incremental weekly deletion of much smaller parts.

Is there another way to do it more efficiently?

Was it helpful?

Solution

it might be quicker to create a new table containing the rows you want to keep, drop the old table and then rename the new table

OTHER TIPS

For weekly deletions an index on date field would speed things up.

Fastest (but not easiest) - i think - is to keep your records segmented into multiple tables based on date, e.g. given week, and then have a union table of all those tables for the regular queries across the whole thing (so your queries would be unaltered). You would each week, create new tables and redefine the union table.

When you wish to drop old records, you simply recreate the union table to leave the records in the old tables out, and then drop those left out (remember to truncate before you drop depending on you filesystem). This is probably the fastest way to get there with MySQL.

A mess to manage though :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top