Mysqlaltertable memo _ MySQL

Source: Internet
Author: User
Mysqlaltertable memo in most cases, a temporary backup (temporarily named B) of the target table (temporarily named a) will be copied during alter table operations ), all the alter operations are performed on the backup file (B), then the target table (a) is deleted, and the backup table (B) is renamed 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.