How OPTIMIZE TABLE Works in MySQL

Asked 2 years ago, Updated 2 years ago, 59 views

OPTIMIZE TABLE said, "Only when DELETE lines create a lot of wasted space."

How to interact with the InnoDB table for adults

For example, suppose DELETE and INSERT are performed the same number of times, and there is a table with a high metabolism with a constant number of rows.Do you need OPTIMIZE TABLE at this time?

I was not sure if INSERT would overwrite the wasted space generated by DELETE with a new line, or if it would never be available until OPTIMIZE TABLE, or otherwise.

mysql

2022-09-30 20:49

1 Answers

For example, the explanation of the following article is detailed.To put it bluntly...

  • DELETE removes it temporarily, but it does not mean it will not be reused permanently.
  • If you are concerned about fragmentation after running a large number of DELETE, running OPTIMIZE TABLE can improve performance and free disk space.

Optimize tables with the 35th OPTIMIZE TABLE: MySQL Road Construction News

Deleted with DELETE syntax

I deleted all cases using DELETE syntax. (omitted) You can see that the file size has not changed.

Deleted with the TRUNCATE syntax

In addition to the DELETE syntax, there is also a TRUNCATE syntax for data deletion.If you use this to delete tables in bulk, the conversation will change and the disk space will be automatically freed.

Try OPTIMIZE TABLE

Now, if you delete the data using the DELETE syntax in the preceding paragraph, you can see that the disk space has not been freed even though it has been deleted from the database.InnoDB actually uses and reuses the area it has, but fragmentation will inevitably occur after a large number of deletions are made at once.If you want to optimize your data area, use OPTIMIZE TABLE.

Understanding MySQL Physical Deletion Degrades and Workarounds

In the fragmented table, a missing record was selected and statistics were updated, possibly causing extreme performance degradation.
(omitted)
The performance of the query was improved by reconstructing the space in the physical file containing the table so that only real records are present.


2022-09-30 20:49

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.