[Mysql] How long does it take to modify the table structure and add a value to an enum field in a-million records table?

Source: Internet
Author: User
The Mysql5.5 table is InnoDB and the field is named "type". It is a common field and is not included in any index primary key. The type field already has two values & #039; a & #039;, & #039; B & #039;. I want to add a value for it now & #039; c & #039;, so the modification statement: {code ...} I want to know how to execute the preceding statement... the Mysql5.5 table is InnoDB and the field is named typeIs a common field and is not contained in any index/primary key.

typeThe field already has two values.'A','B'Now I want to add a value for it.'C'So there is a modification statement:

ALTER TABLE `table` MODIFY COLUMN `type` enum('a','b','c');

How long does it take for me to execute the preceding statement?

I mainly want to know that because this field does not involve indexes, does the modification time have to be related to the records of the table?

Let me estimate for you. I have a plan to prepare for the downtime. Thank you!

Reply content:

The Mysql5.5 table is InnoDB and the field is namedtypeIs a common field and is not contained in any index/primary key.

typeThe field already has two values.'A','B'Now I want to add a value for it.'C'So there is a modification statement:

ALTER TABLE `table` MODIFY COLUMN `type` enum('a','b','c');

How long does it take for me to execute the preceding statement?

I mainly want to know that because this field does not involve indexes, does the modification time have to be related to the records of the table?

Let me estimate for you. I have a plan to prepare for the downtime. Thank you!

I recently talked about this in high-performance mysql (the third edition. Modify column will lead to table reconstruction (internal implementation is to create a table with the latest structure, then import data, then delete the old table, rename the new table to the old table name ), therefore, if alter table xxx alter column is used slowly, it is directly modified. frm file so it will soon. It has nothing to do with the amount of table data.

The other method works the same way. It is modified. frm file: 1. create a new table for the new organization 2. flush tables with read lock. disable tables in use and disable any tables from being opened. 3. Switch the. frm file 4. unlock tables to release the lock in step 2.

I haven't tried it in the last few nights. I should test it too.

Static long getAlterTable () {if (Database not backed up) {do backup getAlterTable ();} else {return test alter table time }};

You can see that percona modifies the table structure online. Online modification is supported.

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.