MySQL optimize table command Test example

Source: Internet
Author: User
Tags mysql optimize table

Today, after the bulk deletion of the Myiam datasheet, found that there is no recycling, after checking the data, found to be through the optimize table to reclaim space
Test the following to establish a data table:

The code is as follows Copy Code
CREATE TABLE ' Ttext ' (
' id ' int (one) DEFAULT NULL,
' Context ' text
) Engine=myisam DEFAULT charset=latin1
INSERT into Ttext values (1, ' tiger1′), (2, ' tiger2′), (3, ' tiger3′);

The INSERT INTO Ttext SELECT * Ttext is then repeated, so that the data file is 240MB, and it is possible to confirm that the data with ID 1 occupies 1/3 of the space, and then you can delete the delete from Ttext where id=1;
According to the normal idea, after such an operation, the space should have recycled, but the fact is not.
OPTIMIZE TABLE should be used if to have deleted a large part A
Table or if you are have made many changes to a table with Variable-length
Rows (tables that have VARCHAR, VARBINARY, BLOB, or TEXT columns).
can use OPTIMIZE TABLE to
Reclaim the unused spaces and to defragment the data file.
Through the data can be seen through the Optimize table Ttext to reclaim the corresponding space.
After continuing to look at the official manual, it was found that the operation was very much related to the engine used by the table.
The InnoDB table must be a row that uses a separate tablespace, followed by the mysql5.1.27 start optimize the table is also supported for partitioned tables. You can optimize the partition table.
for the MyISAM engine, using optimize table also has the following features:
If the table has deleted or split rows, repair the table. [Repair Table]
If The index pages are not sorted, sort them. [Index not sorted, sort]
If The table ' s statistics are not up to date (and the repair could not is accomplished by sorting the index), update them . [Update it if the table's statistics are not up to date]

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.