MySQL Operation and Maintenance 35- Judgment and Treatment of Table Fragmentation

1. Overview of Table Fragmentation

  • MySQL table fragmentation refers to the existence of discontinuous data blocks in the table, which is caused by frequent deletion, update and insertion of data in the table. These operations may cause the data in the table to be scattered in different physical locations, thereby reducing query performance and occupying more storage space.
  • More contiguous, compact data blocks can lead to better performance. Fragmented tables can cause some operations to be slower, such as index range lookups, especially for queries covering index classes.
  • Under normal circumstances, we rarely encounter performance problems caused by table fragmentation, but under sudden large-scale data changes, fragmentation may be more serious.

2. Judgment method of table fragmentation

  1. Judgment method 1: Under normal circumstances, when we perform a full table scan on a large table, if SHOW INNODB STATUS\G shows that the average I/O SIZE is relatively small, such as 20KB, then the table may be fragmented.
  2. Judgment method 2: Under the operating system, we can use the cat command to judge whether the fragmentation is serious. Under normal circumstances, the I/O throughput rate of RAID1+0 composed of six 15K SAS disks can reach 300MB per second. If we use the following command to check that there are only tens of MB per second, then the fragmentation of the table may be serious. The command is as follows:
shell> cat  /dbname/tablename.ibd > /dev/null

3. How to deal with table fragments

  1. Generally, there are three ways to defragment.
    • OPTIMIZE TABLE (recommended)
    • ALTER TABLE TABLE_NAME ENGINE=ENGINE
    • Re-export the imported data.
  2. But please note that the serious fragmentation does not necessarily mean that there is a performance problem. Even if the above fragmentation ratio reaches 20% or even 30%, you should take action after confirming that the performance problem is caused by table fragmentation.

4. Summary

  1. Table fragmentation is the presence of discontinuous data blocks in a table that can cause query performance issues. But in general, table fragmentation is not a big problem. You can check whether there is fragmentation by checking the data file throughput of the table.
  2. Table fragmentation is generally recommended to be resolved with the OPTIMIZE TABLE command.

Guess you like

Origin blog.csdn.net/oddrock/article/details/130302834