MySQL Delete cannot free space with partition instead

Source: Internet
Author: User
Tags mysql delete

As the amount of data in the database becomes larger, if you want to erase a month's data and delete it with the delete command, MySQL will not free up space, must defragment, or rebuild the table with the modification engine to free up space, but because of the large amount of data, each rebuild takes 10-12 hours, too long, Think of using MySQL partition to solve this problem, by deleting the partition, you can delete the data file directly, it can also free up space.

Partitioning knowledge I'll just go ahead and say two.

    1. The partition field does not have a null value because the null value defaults to the garbage partition, so the query scans the partition more than once.

    2. The query criteria is best to take the partition field, otherwise the performance will be very low, need to sweep through all the partitions.


Adding a partition script

Engine=innodb PARTITION by RANGE COLUMNS (date) (

PARTITION p201410 VALUES less than (20141031),

PARTITION p201411 VALUES less than (20141131),

PARTITION p201412 VALUES less than (20141231),

PARTITION p201501 VALUES less than (20150131),

...........................

PARTITION pcatchall VALUES less THAN MAXVALUE

);

Delete Partition

ALTER table Table DROP PARTITION p201010;

Merging partitions

ALTER TABLE b REORGANIZE PARTITION p1,p2 into (P12);

Split partition

ALTER TABLE b REORGANIZE PARTITION p1,p2 into (P12);


Now, partition splitting and merging are not available, so write first.

MySQL Delete cannot free space with partition instead

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.