All Products
Search
Document Center

PolarDB:Instant ADD COLUMN

Last Updated:Apr 07, 2025

When you add a column to a table by using the traditional method, the entire table is rebuilt, which consumes a large amount of system resources. To address the issue, PolarDB for MySQL provides the instant ADD COLUMN feature that allows you to instantly add columns to a table regardless of the table size.

The instant ADD COLUMN feature leverages the INSTANT algorithm to perform DDL operations. It modifies only the metadata in the data dictionary. It does not modify or copy existing data or rebuild the entire table. Therefore, a DDL operation is completed within seconds regardless of the table size.

Prerequisites

Your cluster runs one of the following database engine versions:

  • PolarDB for MySQL 5.6 whose revision version is 5.6.1.0.43 or later.

    Note

    The instant ADD COLUMN feature is in canary release for PolarDB for MySQL 5.6. To use the feature in PolarDB for MySQL 5.6, go to Quota Center, find the quota whose ID is polardb_mysql_iac_56, and then click Apply.

  • PolarDB for MySQL 5.7 whose revision version is 5.7.1.0.6 or later.

    Note

    To use the instant ADD COLUMN feature in PolarDB for MySQL 5.7 clusters, you must set the loose_innodb_support_instant_add_column parameter to ON.

  • PolarDB for MySQL 8.0.

    Note

    By default, PolarDB for MySQL 8.0 clusters support the instant ADD COLUMN feature. You do not need to configure parameters to enable the feature.

For information about how to query the database engine version of a cluster, see the "Query the engine version" section of the Engine versions topic.

Limits

  • You can use the instant ADD COLUMN feature to add a column only to the end of a table.

  • You can use the instant ADD COLUMN feature to add virtual columns to a table only in PolarDB for MySQL 8.0 clusters, but not in PolarDB for MySQL 5.6 or 5.7 clusters.

  • You can use the instant ADD COLUMN feature to add columns to a partitioned table in PolarDB for MySQL 5.7 and 8.0 clusters, but not in PolarDB for MySQL 5.6 clusters.

    Note

    The feature that allows you to instantly add columns to a partitioned table is in canary release for PolarDB for MySQL 5.7. To use the feature in PolarDB for MySQL 5.7, go to Quota Center, find the quota whose ID is polarM_57_iac_on_partition_table, and then click Apply.

  • You cannot use the instant ADD COLUMN feature to add columns to a table in which full-text indexes are created.

  • You can use the instant ADD COLUMN feature to add columns to a table for which in-memory column indexes (IMCIs) are created. The cluster must meet the following requirements:

    • For a PolarDB for MySQL cluster whose version is earlier than 8.0.1.1.42 or earlier than 8.0.2.2.23, you must set imci_enable_add_column_instant_ddl to ON. When you use the instant ADD COLUMN feature, IMCIs of the table are rebuilt in the background. The IMCIs are not available during the rebuild process.

    • For a PolarDB for MySQL cluster whose version is 8.0.1.1.42 or later, or is 8.0.2.2.23 or later, you must set imci_enable_add_column_instant_ddl to OFF.

  • You cannot use the instant ADD COLUMN feature to add columns to a table that has the implicit_primary_key option enabled but does not have custom primary key columns.

  • You cannot include the instant ADD COLUMN operation and other DDL operations (such as creating indexes) in the same SQL statement.

Usage

Configure the parameter

  • For PolarDB for MySQL 5.6 and 5.7 clusters, you must set the loose_innodb_support_instant_add_column parameter to ON. For information about how to configure parameters for a cluster, see Configure cluster and node parameters.

    Parameter

    Level

    Description

    loose_innodb_support_instant_add_column

    Global

    Specifies whether to enable the instant ADD COLUMN feature. Valid values:

    • ON

    • OFF

  • For PolarDB for MySQL 8.0 clusters, you do not need to configure any parameter.

Execute statements

  • Specify the ALGORITHM=INSTANT clause to forcibly enable the instant ADD COLUMN feature. Example:

    ALTER TABLE <table_name> ADD COLUMN <column_name> int, ALGORITHM=INSTANT;
    Note

    If a column cannot be added by using the instant ADD COLUMN feature and the ERROR 0A000: ALGORITHM=INSTANT is not supported for this operation. Try ALGORITHM=COPY/INPLACE. error message is returned, the INSTANT algorithm is not supported. In this case, we recommend that you check whether the loose_innodb_support_instant_add_column parameter is set to ON and whether the operation is restricted. For more information, see Limits.

  • If you do not specify an algorithm or specify the default algorithm, PolarDB selects the fastest algorithm for adding columns. Example:

    ALTER TABLE <table_name> ADD COLUMN <column_name> int, ALGORITHM=DEFAULT;
    ALTER TABLE <table_name> ADD COLUMN <column_name> int;
    Note

    PolarDB selects the algorithms for adding columns in the following priority order: INSTANT > INPLACE > COPY.

View columns added by using the INSTANT algorithm

  • For PolarDB for MySQL 5.6 and 5.7 clusters, a table named INNODB_SYS_INSTANT_COLUMNS table is added to the INFORMATION_SCHEMA database. The table records the information about instantly added columns, including the column name, column sequence number, and default value (binary value). You can execute the following statement to view information about the new instantly added columns.

    SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_INSTANT_COLUMNS;
    Note

    After you instantly add columns to the table and perform DDL operations that need to recreate the table, such as DROP COLUMN, the system deletes the information about the instantly added columns from the INNODB_SYS_INSTANT_COLUMNS table.

  • For PolarDB for MySQL 8.0 clusters, execute the following statement to view the columns of a table. If a column is added by using the instant ADD COLUMN feature, the value of the has_default parameter is 1.

    SELECT * FROM INFORMATION_SCHEMA.INNODB_COLUMNS WHERE TABLE_ID = (SELECT TABLE_ID FROM INFORMATION_SCHEMA.INNODB_TABLES WHERE NAME = "<database_name>/<table_name>");

Contact us

If you have any questions about DDL operations, contact us.