开发者

What is the faster way to delete old records

I have a table开发者_如何学Python 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?


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


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 :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜