tencent cloud

All product documents
TencentDB for MySQL
Second-Level Column Addition
Last updated: 2024-11-27 11:20:24
Second-Level Column Addition
Last updated: 2024-11-27 11:20:24

Overview

The quick column addition feature allows you to quickly add columns to a big table by only modifying the data dictionary, which eliminates the need of data replication during column adding and greatly reduces the column adding time for big tables and the impact on the system.

Supported Versions

Kernel version: MySQL 5.7 20190830 and later.
Kernel version: MySQL 8.0 20200630 and later.

Use Cases

This feature is suitable for adding columns to a table with a high volume of data.

Performance Data

In tests with a table of 5 GB data, the time for adding a column is reduced from 40 seconds to below 1 second.

Instructions

Before the feature of adding columns in seconds is used, it is necessary to set the parameter innodb_fast_ahi_cleanup_for_drop_table to ON.

INSTANT ADD COLUMN syntax Add the algorithm=instant clause to ALTER TABLE to add a column as follows:
ALTER TABLE t1 ADD COLUMN c INT, ADD COLUMN d INT DEFAULT 1000, ALGORITHM=INSTANT;
The innodb_alter_table_default_algorithm parameter is added, which can be set to inplace or instant. This parameter is inplace by default and can be configured to adjust the default algorithm of ALTER TABLE as follows:
SET @@global.innodb_alter_table_default_algorithm=instant;
If no algorithm is specified, the default algorithm configured by this parameter will be used for ALTER TABLE operations.
Note:
The setting of the parameter innodb_alter_table_default_algorithm is only applicable to MySQL version 5.7. For MySQL version 8.0, the default algorithm for executing Alter Table operations in kernel subversion 20230630 and later is instant, with this parameter unable to be set.

Restrictions on INSTANT ADD COLUMN

A statement can contain only column addition operations.
A new column will be added to the end, and column order cannot be changed.
INSTANT ADD COLUMN is not supported in tables with the COMPRESSED row format.
INSTANT ADD COLUMN is not supported in tables with a full-text index.
INSTANT ADD COLUMN is not supported for temp tables.
Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback

Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 available.

7x24 Phone Support