Mysql deletes data but the file size remains the same——Summary of Lecture 13

Original link

First check whether the innodb_file_per_table of mysql is enabled. If it is ON, the data will be a separate file, and the drop table will free up space.

show variables like '%per_table%';

But if it is delete * all data, this will not reduce the space occupied by the data, and will mark the reusable data in the system without deleting the data.

Data space reuse is also divided into record reuse and page reuse. The reuse of records is relatively limited, just steal the picture. Delete R4, and there will be an extra space on page A, and this position can be reused when there are 300-600 primary key insertions. (Note that R4 is also marked for deletion, and the actual file size will not be really reduced.) Record reuse can only be in this range, so the records are relatively limited. Page reuse means that the page element A is gone and can be used at will.
insert image description here

I used to be curious about why the primary key is inserted in order. In fact, one reason is also because of the page split problem. Just like in the above picture, suppose page A is full, and another 520ID comes in. If it is inserted, the page will split. One is that the speed will slow down, and the other is that Causes internal fragmentation of the page, so tables that are frequently added and deleted will also rebuild the table to resolve internal fragmentation

alter table A engine=innodb

Guess you like

Origin blog.csdn.net/dxgzg/article/details/121088859