MySQL rolls back the insert statement, leading to a doubling of ibd files'

Source: Internet
Author: User

MySQL rolls back the insert statement, leading to a doubling of ibd files'

MySQL rolls back the insert statement, which causes the ibd file to increase by a factor of one. A simple test:

Start transaction;
Insert into tb1 values (3, repeat ('A', 65000), 'x', 1 );
-- Commit;
Rollback;

These are the sizes of files after tb1.ibd is inserted, before rollback, and after rollback:

Someone asked in the QQ group: Why does rollback increase the disk space of tb1.idb?

---------------------------------------

The reason is simple:

131072-98304 = 163840-131072 = 32768
So: Roll Back insert = delete + re-insert, while delete refers to setting flag, so... content to double.

To roll back an insert operation, you must first insert the value before the delete operation, and then re-insert the value. delete is a logical deletion, that is, setting a flag without actually deleting it. This is the reason.

However, because the transaction has not been committed and data has not been written to the disk, why does the disk space occupied by tb1.idb increase twice? Obviously, this is because the disk space of tb1.idb is pre-allocated. That is to say, when the statement is executed, the disk space has been allocated, but the transaction has not been committed, the checkpoint cannot fl uncommitted data into the disk, so the disk space is allocated, but the insert data is not written to the disk. At this time, the insert data still exists in the buffer. Disk Space is pre-allocated.

This article permanently updates the link address:

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.