Answer the question
In order to leave comments, you need to log in
How to eliminate table brakes after a big delete?
Hello!
There is a table with the following structure (I did not specify unnecessary fields):
CREATE TABLE `logs` (
`INSERT_DATE` datetime DEFAULT NULL,
`DATA` text NOT NULL,
KEY `INSERT_DATE` (`INSERT_DATE`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
SELECT INSERT_DATE, DATA from logs WHERE INSERT_DATE >= '2015-04-16' AND INSERT_DATE < '2015-04-17'
DELETE FROM logs WHERE INSERT_DATE >= '2015-04-16' AND INSERT_DATE < '2015-04-17'
optimize table logs;
Answer the question
In order to leave comments, you need to log in
Partitions, fast and easy. Every day, according to the script, you can add a partition the next day, and when you need to delete a thread of a table, you just drop the partition, and the rest of the data remains. No need to rename tables or delete old ones. The table remains alive and available, there are no moments when it may not be available (for example, at the time of renaming).
Data on partitions is distributed just by the value of the key, so there will be no problems.
Rebuilding indexes, slow disk.
Look in the direction of renaming the old table, creating an empty new one for new records, and then deleting the old unnecessary one. Then no reindexing, no long work with the disk - beauty!
If these are logs, then:
a) why is there an index?
b) think about whether you need to store raw data at all, or can you immediately aggregate something?
Plus Leonid Sysoletin , the solution with the daily table is alive.
For logs, it would be possible to do sharding by day. Tables: Logs_1, Logs_2, Logs_3, etc.
Drop old tables (it's instant!)
The table number can be the day of the week, the day of the month or the year.
Bicycle, but (because the task is simple) can be dumped into files, one day - one file, it will work much faster (transfer / reading over the network can be accelerated up to x100) + saving disk and memory. If desired, you can do compression - will save disk and faster transmission over the network.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question