Optimization: data fragmentation

A: data fragmentation reasons

Mysql different engines because of fragmentation are also different.

In InnoDB, the, so space has not been released really recovered.

1: Remove some of the rows that are only marked as "deleted" and not really physically removed from the index, so I can not release recycling. InnoDB's Purge asynchronous thread to clean up these useless index keys and rows. But these still did not release space back to the operating system re-use, which can result there are many empty pages. If the dynamic table structure contains a length field, then these voids may not even be re-used to save the new InnoDB row, because of insufficient space length of the space

2: a lot of random delete operation, resulting in discontinuous empty space in the data file. When inserting data, which will use up the empty space, thus resulting in a discontinuous data storage location. Physical storage order of the different logical sort order, which is the data fragments

3: For a large number of UPDATE, will produce file fragmentation, Innodb minimum allocation of physical storage units are page (page), but may also lead to page splitting UPDATE (page split), the frequent split pages, page becomes sparse, and it is filled with irregular, so that the final data will be fragmented

 

Two: the type of data fragmentation

1: row fragmentation (Row fragmentation)

Refers to data line is stored as a plurality of segments of a plurality of places. Even if the query accesses only one row from the index. Row fragmentation can lead to performance degradation.

2: interline fragment (Intra-row fragmentaion)

It refers to a fragment between the lines on the order of logical pages, or rows are not stored sequentially on the disk. Between the lines it has a great influence on the fragmentation operation and full table scan clustered index such as a scan, because these operations can benefit from the original order of the data stored on the disk.

3: The remaining space debris (Free space fragmentation)

Free space fragmentation refers to the data pages have a lot of free space. This causes the server to read large amounts of unnecessary data. Resulting in waste.

For MyISAM tables, three types of fragmentation can happen. But InnoDB will not be short of the line pieces; InnoDB will move the line and wrote a short segment. InnoDb moved a short line segment and re-written

 

Three: Discovery data fragmentation serious table

1: Method

1.1:使用show table status from xxxx like 'xxxx' \G;

The first xxx: the name of the database table is located, the second xxx: table name to query. This method has limitations, only a single-table query the fragmentation, fragmentation can not query all tables in a database or the entire instance under 

1.2: Query fragmented information information_schema.TABLES get a table

2: The main parameters

data_length: data length;

index_length: index length;

free_data: So here is the size of free space or debris;

With pt-online-schema-change tool can organize online table structure, collect debris and other operations

 

Four: treatment options

1:OPTIMIZE TABLE

It recombinant physically stored tables and indexes, to reduce storage space and improve the use efficiency of the IO access table, the OPTIMIZE temporarily lock the operating table, and the greater the amount of data, it takes longer time. After OPTIMIZE TABLE, change table storage engine with relevant

MyISAM

PTIMIZE TABLE works as follows:

      If the table has rows or split rows deleted (split rows), repair the table.

If you are not on the index page sorted, sort them.

  If the statistical information table is not the latest (and can not be sorted by the index to complete the repair), update them.

InnoDB

Published by OPTIMIZE TABLE touch rebuilt and completed under the ALTER TABLE ... FORCE cover. Exclusive table lock only briefly during the preparation phase and the commit phase of operation. During the preparation phase, update metadata and create an intermediate table. During the submission period, will be submitted to the table metadata changes.

OPTIMIZE TABLE tables using table replication reconstruction method under the following conditions:

 When enable old_alter_table system variables

When enable mysqld --skip-new options

 

OPTIMIZE TABLE for InnoDB tables do not support FULLTEXT index contains the online DDL. Instead of using the method to copy table.

 

InnoDB uses page allocation method for storing data, and not as prone to excessive fragmentation like traditional storage engines (such as MyISAM). In considering whether to run optimization, consider server will handle workload transactions:

 It is expected to have a certain degree of fragmentation. InnoDB fill only 93% of the page, leaving space for the updates without having to split the page.

  Deletions may be left blank, fill the pages as expected, which may make it worthwhile to optimize the table.

 

2:ALTER TABLE table_name ENGINE = Innodb;

This is actually a NULL operation, ostensibly to do nothing, in fact, to reassemble the fragments of when to perform optimization, the actual implementation is an empty ALTER command, but this command will also play a role in the optimization of its will rebuild the entire table, delete unused blank space

 

3: pt-online-schema-change tool can organize online table structure, collect debris and other operations

 

 

Compare

For InnoDB engine, ALTER TABLE xxxx ENGINE = INNODB is performed an empty ALTER TABLE operation. The OPTIMIZE TABLE is equivalent to the ALTER TABLE ... FORCE. Reference described above, in some cases, OPTIMIZE TABLE or ALTER TABLE xxxx ENGINE = INNODB substantially the same. However, in some cases, ALTER TABLE xxxx ENGINE = INNODB better. For example old_alter_table system variable is not enabled and so on. In addition to MyISAM type table, using the ALTER TABLE xxxx ENGINE = INNODB is significantly better than OPTIMIZE TABLE this method.

 

 

 

Published 50 original articles · won praise 2 · Views 2279

Guess you like

Origin blog.csdn.net/eafun_888/article/details/104738675