MySQL alter table memo

Source: Internet
Author: User

In most cases, when the alter table operation is performed, a temporary backup of the target table (temporarily named a) is copied (temporarily named B). The alter operation is performed on the backup file (B) and then delete the target table (a). Rename the backup table (B) as the target table (). When alter table is executed, other sessions can read the target table (a), but the update and write operations will be blocked until B is named, can be redirected to a without losing any DML operations. This temporary table B is created in the same database as the target table.

The following is the test process:

Alter table cdb_posts drop index FID;
Drop index FID on cdb_posts;
Alter table cdb_posts add index idx_fid (FID );
Create index idx_fid on cdb_posts (FID );

These operations are the same:

Copy to temporary table

Temporary table file created:

How to quickly create an index with a large amount of data, I have posted on the internet that, first create an empty table B, add the index field, and then insert .... select ....., then rename the old table, rename B to the target table, and then delete the old table. At first, I tested this in a million table, and the efficiency was worse than simply ALTER TABLE add index ..., alter table add index time: 9min19. 36sec: Cost: 11min17. 69sec

Reference: mysql-alter table usage

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.