All Products
Search
Document Center

PolarDB:DDL operation guide for PolarDB for MySQL

Last Updated:Mar 28, 2026

PolarDB for MySQL supports DDL operations across six categories: indexes, primary keys, columns, tables, foreign keys, generated columns, and partitions. Before running any schema change in production, understand how each operation behaves—whether it locks the table, triggers a full rebuild, or completes in seconds by touching only metadata.

What can go wrong with a DDL operation

A single ALTER TABLE statement can do any of the following:

  • Hold an exclusive table lock for its entire duration, blocking all reads and writes

  • Trigger a full table rebuild that takes hours on large tables

  • Cause connection queuing: later queries pile up behind the DDL, timing out or disrupting your application

  • Spike IOPS and CPU usage, affecting other workloads on the same cluster

PolarDB for MySQL has made significant improvements to DDL performance and lock behavior across versions. This guide helps you identify the risk profile of each operation before you run it.

DDL execution algorithms

PolarDB automatically selects the most efficient algorithm in order: INSTANT → INPLACE → COPY. Understanding each algorithm helps you predict the impact of a DDL operation.

AlgorithmHow it worksImpact
INSTANTModifies only metadata in the data dictionary. No data is copied or rebuilt.Completes in seconds, independent of table size. Concurrent reads and writes are allowed.
INPLACERebuilds or reorganizes data within the storage engine. Most INPLACE operations allow concurrent reads and writes. Some INPLACE operations (for example, RENAME TABLE and ADD COMMENT) only touch metadata and complete in seconds.Minimal impact. Concurrent DML is usually permitted.
COPYCopies all data from the original table to a new table. Holds a shared-no-write (SNW) lock throughout.Blocks all writes for the entire duration. Read operations are still permitted.

DDL operations that allow concurrent reads and writes during execution are called Online DDL. Online DDL minimizes production impact.

Control algorithm selection with ALTER TABLE clauses

To override automatic algorithm selection or enforce a specific lock behavior, use the ALGORITHM and LOCK clauses in ALTER TABLE:

ALGORITHM clause — forces a specific algorithm. If the DDL operation does not support the specified algorithm, an error is returned immediately. Valid values: DEFAULT, INSTANT, INPLACE, COPY.

LOCK clause — controls concurrent access during DDL execution. Valid values:

ValueBehavior
DEFAULTGrants the maximum concurrent access the DDL type supports.
NONERequires concurrent reads and writes. Returns an error if not supported.
SHAREDAllows concurrent reads, blocks writes. Returns an error if concurrent reads are not supported.
EXCLUSIVEBlocks all concurrent reads and writes.

Specifying LOCK prevents the table from becoming inaccessible during execution: if the actual lock behavior does not meet the specified requirement, the operation stops immediately.

PolarDB supports parallel DDL for large-table operations such as creating indexes and rebuilding tables. Parallel DDL uses multiple threads and can improve execution speed by up to 15–20 times compared to single-threaded execution. For more information, see Parallel DDL.

Contact us

If you have any questions about DDL operations, please contact technical support.

Preview DDL behavior before execution

Because DDL behavior can be affected by table structure, parameter configurations, and enabled features, the actual behavior may differ from the tables in this guide. Use EXPLAIN DDL to preview exactly how a DDL statement will execute before running it.

{ EXPLAIN | DESCRIBE | DESC } ALTER TABLE ...

EXPLAIN DDL returns:

  • Whether the DDL can execute successfully

  • The algorithm it will use (INSTANT, INPLACE, or COPY)

  • Whether it will rebuild the entire table

  • Whether concurrent DML is allowed during execution

  • Whether it will be blocked by uncommitted transactions

  • Whether parallel DDL acceleration is supported, and the degree of parallelism if so

For more information, see EXPLAIN DDL.

DDL behavior by operation

The tables below show DDL behavior across PolarDB for MySQL versions. Four columns describe the behavior of each operation:

  • Concurrent DML — whether concurrent reads and writes are permitted during execution

  • Rebuilds table — whether the operation triggers a full table rebuild (long-running for large tables)

  • Metadata only — whether the operation modifies only metadata (completes in seconds)

  • Parallel DDL — whether the operation supports parallel DDL acceleration

Index operations

OperationConcurrent DMLRebuilds tableMetadata onlyParallel DDL
Create a secondary indexYesNoNo8.0.2 / 8.0.1 / 5.7: Supported; 5.6: Not supported
Delete a secondary indexYesNoYesNot applicable
Rename a secondary indexYesNoYesNot applicable
Add a full-text index (FULLTEXT)NoNo¹NoNot supported
Add a spatial index (SPATIAL)NoNoNoNot supported

¹ When adding the first full-text index to a table, an additional table rebuild is triggered if there is no user-defined FTS_DOC_ID column.

Primary key operations

OperationConcurrent DMLRebuilds tableMetadata onlyParallel DDL
Add a primary keyYes¹YesNo8.0.2 / 8.0.1 / 5.7: Supported; 5.6: Not supported
Delete a primary keyNoYesNoNot supported
Delete the original primary key and add a new oneYes¹YesNo8.0.2 / 8.0.1 / 5.7: Supported; 5.6: Not supported

¹ Concurrent DML is allowed only when the sql_mode cluster parameter includes STRICT_TRANS_TABLES or STRICT_ALL_TABLES.

Column operations

The tables below list version-specific behavior. See the Limitations and exceptions section after the tables for important constraints on instant add column, VARCHAR length extension, and character set conversion.

PolarDB for MySQL 8.0.2

OperationConcurrent DMLRebuilds tableMetadata onlyParallel DDL
Add a columnYesNo¹Yes¹Supported¹
Delete a columnYesYesNoSupported
Rename a columnYesNoYesNot applicable
Reorder columnsYesYesNoSupported
Set a column's default valueYesNoYesNot applicable
Modify a column commentYesNoYesNot applicable
Modify a column typeNoYesNoNot supported
Extend VARCHAR lengthYes²NoYesNot applicable
Change character set from UTF8mb3 to UTF8mb4NoNo³Yes³Not supported
Delete a column's default valueYesNoYesNot applicable
Modify the auto-increment valueYesNoYesNot applicable
Change a column to NULLYesYesNoSupported
Change a column to NOT NULLNoYesNoNot supported
Modify the definition of an ENUM/SET columnYesNoYes⁴Not applicable

PolarDB for MySQL 8.0.1

OperationConcurrent DMLRebuilds tableMetadata onlyParallel DDL
Add a columnYesNo¹Yes¹Supported¹
Delete a columnYesYesNoSupported
Rename a columnYesNoYesNot applicable
Reorder columnsYesYesNoSupported
Set a column's default valueYesNoYesNot applicable
Modify a column commentYesNoYesNot applicable
Modify a column typeNoYesNoNot supported
Extend VARCHAR lengthYes²NoYesNot applicable
Change character set from UTF8mb3 to UTF8mb4NoNo³Yes³Not supported
Delete a column's default valueYesNoYesNot applicable
Modify the auto-increment valueYesNoYesNot applicable
Change a column to NULLYesYesNoSupported
Change a column to NOT NULLNoYesNoNot supported
Modify the definition of an ENUM/SET columnYesNoYes⁴Not applicable

PolarDB for MySQL 5.7

OperationConcurrent DMLRebuilds tableMetadata onlyParallel DDL
Add a columnYesNo¹Yes¹Supported¹
Delete a columnYesYesNoSupported
Rename a columnYesNoYesNot applicable
Reorder columnsYesYesNoSupported
Set a column's default valueYesNoYesNot applicable
Modify a column commentYesNoYesNot applicable
Modify a column typeNoYesNoNot supported
Extend VARCHAR lengthYes²NoYesNot applicable
Change character set from UTF8mb3 to UTF8mb4NoYesNoNot supported
Delete a column's default valueYesNoYesNot applicable
Modify the auto-increment valueYesNoYesNot applicable
Change a column to NULLYesYesNoSupported
Change a column to NOT NULLNoYesNoNot supported
Modify the definition of an ENUM/SET columnYesNoYes³Not applicable

PolarDB for MySQL 5.6

OperationConcurrent DMLRebuilds tableMetadata onlyParallel DDL
Add a columnYesNo¹Yes¹Not supported
Delete a columnYesYesNoNot supported
Rename a columnYesNoYesNot applicable
Reorder columnsYesYesNoNot supported
Set a column's default valueYesNoYesNot applicable
Modify a column commentYesNoYesNot applicable
Modify a column typeNoYesNoNot supported
Extend VARCHAR lengthNoYesNoNot supported
Change character set from UTF8mb3 to UTF8mb4NoYesNoNot supported
Delete a column's default valueYesNoYesNot applicable
Modify the auto-increment valueYesNoYesNot applicable
Change a column to NULLYesYesNoNot supported
Change a column to NOT NULLNoYesNoNot supported
Modify the definition of an ENUM/SET columnYesNoYes²Not applicable

Limitations and exceptions

Instant add column

When the instant add column feature is available, adding a column modifies only metadata and completes in seconds, regardless of table size. The behavior varies by version:

VersionHow to enableAdditional notes
8.0.2Enabled by default
8.0.1Enabled by defaultIf the table has a columnstore index, set loose_imci_enable_add_column_instant_ddl to ON. PolarDB then rebuilds the columnstore index asynchronously in the background. During the rebuild, the columnstore index is temporarily unavailable.
5.7Set loose_innodb_support_instant_add_column to ON
5.6Set loose_innodb_support_instant_add_column to ONCurrently in canary release. To enable, go to Quota Center, search for quota ID polardb_mysql_iac_56, and click Apply. Not supported on partitioned tables.

All versions share the following constraints:

  • Columns can only be added to the end of the table.

  • If the table has no primary key, set implicit_primary_key to OFF to prevent the operation from failing due to an implicit primary key at the end of the table.

  • Not supported on compressed tables (ROW_FORMAT=COMPRESSED), tables with full-text indexes, or temporary tables.

When instant add column is not supported, the system falls back to the INPLACE algorithm, triggering a table rebuild. Concurrent reads and writes are still permitted during the rebuild, and parallel DDL can be used to accelerate it.

For more information, see instant add column.

Extending VARCHAR length

PolarDB stores a VARCHAR column's length using 1 byte for columns up to 255 bytes, and 2 bytes for columns of 256 bytes or more. Extending a VARCHAR column modifies only metadata when the extension stays within the same length range (0–255 bytes, or 256 bytes to a larger size). If the extension crosses the boundary—from less than 256 bytes to 256 bytes or more—PolarDB uses the COPY algorithm by default, locking the table for the entire duration. Write operations are blocked; reads are still permitted.

To verify that a VARCHAR modification qualifies for a metadata-only change, specify ALGORITHM=INPLACE. If the INPLACE algorithm is not supported, an error is returned immediately instead of falling back to COPY:

ALTER TABLE table_name ALGORITHM=INPLACE, CHANGE COLUMN c1 c1 VARCHAR(256);
ERROR 0A000: ALGORITHM=INPLACE is not supported. Reason: Cannot change column type INPLACE. Try ALGORITHM=COPY.

To avoid this situation in the future, set the maximum length of VARCHAR columns to 256 bytes or more when designing your schema.

Changing character set from UTF8mb3 to UTF8mb4

On 8.0.2, changing a column's character set from UTF8mb3 to UTF8mb4 modifies only metadata when all of the following conditions are met:

  • The column type is CHAR, VARCHAR, ENUM, or TEXT.

  • No index exists on the modified column.

  • The maximum storage length of the column is in the same range before and after the conversion (both less than 256 bytes, or both 256 bytes or more).

On 8.0.1, the same conditions apply, and additionally the parameter loose_innodb_support_instant_modify_charset must be set to ON.

On 5.7 and 5.6, the COPY algorithm is always used, rebuilding the table for the entire duration.

If the conditions are not met on 8.0.2 or 8.0.1, the COPY algorithm is used. To confirm whether a change qualifies for a metadata-only operation, specify ALGORITHM=INPLACE. If not supported, an error is returned immediately:

ALTER TABLE test MODIFY COLUMN b char(1) CHARACTER SET utf8mb4 DEFAULT NULL, ALGORITHM=INPLACE;
ERROR 1846 (0A000): ALGORITHM=INPLACE is not supported. Reason: Cannot change column type INPLACE. Try ALGORITHM=COPY.

ENUM/SET column definition changes

Modifying an ENUM or SET column modifies only metadata when the storage size of the data type does not change and you append elements to the end of the ENUM or SET. Any other change requires the COPY algorithm to rebuild the table.

Table operations

OperationConcurrent DMLRebuilds tableMetadata onlyParallel DDL
Modify ROW_FORMATYesYesNo8.0.2 / 8.0.1 / 5.7: Supported; 5.6: Not supported
Modify KEY_BLOCK_SIZEYesYesNo8.0.2 / 8.0.1 / 5.7: Supported; 5.6: Not supported
Set persistent statisticsYesNoYesNot applicable
Declare a character setYesNoYesNot applicable
Convert a character setNoYesNoNot supported
Optimize a table¹YesYesNo8.0.2 / 8.0.1 / 5.7: Supported; 5.6: Not supported
Rebuild a tableYesYesNo8.0.2 / 8.0.1 / 5.7: Supported; 5.6: Not supported
Rename a tableYesNoYesNot applicable
Modify a table commentYesNoYesNot applicable

¹ When defragmenting a table with ALTER TABLE table_name ENGINE=InnoDB, ALGORITHM=INPLACE, LOCK=NONE, the INPLACE algorithm is not supported for tables with full-text indexes.

Generated column operations

PolarDB for MySQL 5.6 does not support generated columns.

Versions 8.0.2, 8.0.1, and 5.7 have identical behavior:

OperationConcurrent DMLRebuilds tableMetadata onlyParallel DDL
Add a STORED columnNo¹YesNoNot supported
Change the order of a STORED columnNoYesNoNot supported
Delete a STORED columnYesYesNoSupported
Add a VIRTUAL columnYesNoYesNot applicable
Change the order of a VIRTUAL columnNoYesNoNot supported
Delete a VIRTUAL columnYesNoYesNot applicable

¹ Adding a STORED column involves the SQL/Server layer, so Online DDL is not supported.

Foreign key operations

Behavior is identical across all versions (8.0.2, 8.0.1, 5.7, 5.6):

OperationConcurrent DMLRebuilds tableMetadata onlyParallel DDL
Add a foreign keyYes¹No¹Yes¹Not applicable
Delete a foreign keyYes¹No¹Yes¹Not applicable

¹ INPLACE DDL is supported only when foreign_key_checks is disabled and only metadata is modified. Otherwise, only the COPY algorithm is supported, locking the table for the entire duration.

Partitioned table operations

PolarDB for MySQL 8.0.2

OperationConcurrent DMLRebuilds tableMetadata onlyParallel DDL
Add a partition (ADD)Yes¹No²YesNot supported
Delete a partition (DROP)Yes¹No²NoNot supported
Discard a partition tablespace (DISCARD)NoNoNoNot supported
Import a partition tablespace (IMPORT)NoNoNoNot supported
Truncate a partition (TRUNCATE)YesNoNoNot supported
Merge partitions (COALESCE)NoYes³NoNot supported
Reorganize a partition (REORGANIZE)Yes¹No⁴NoNot supported
Exchange a partition (EXCHANGE)Yes¹NoYesNot supported
Analyze a partition (ANALYZE)YesNoNo⁵Not supported
Check a partition (CHECK)YesNoNo⁶Not supported
Optimize a partition (OPTIMIZE)Yes⁷Yes⁷NoSupported⁷
Rebuild a partition (REBUILD)Yes¹No⁴NoNot supported
Repair a partition (REPAIR)YesNo⁸NoNot supported
Convert a table to a partitioned tableNoYesYes⁹Not supported
Convert a partitioned table to a standard tableNoYesNoNot supported
Create a partial indexYesNo¹⁰NoSupported

¹ When loose_partition_level_mdl_enabled is set to true, partition-level metadata locks (MDL) ensure that DDL operations do not affect DML on unaffected partitions. For more information, see Online partition maintenance.

² For RANGE and LIST partitioned tables, adding or deleting partitions does not require a table rebuild. For HASH and KEY partitioned tables, adding partitions requires a table rebuild. Deleting partitions from HASH and KEY partitioned tables is not supported.

³ Only HASH and KEY partitions are supported.

⁴ Reorganizing or rebuilding a partition rebuilds only the specified partitions that require data redistribution and rebuilding. Other partitions are not affected.

⁵ Analyzing a partition modifies statistics only, not metadata or table data.

⁶ Checking a partition does not modify metadata or data.

⁷ When running OPTIMIZE PARTITION on an InnoDB table, the entire partitioned table is rebuilt. Reads and writes are permitted during the rebuild. Set innodb_parallel_build_primary_index to ON to use parallel DDL to accelerate the rebuild.

⁸ Repairing a partition rebuilds only the specified partitions that need repair.

⁹ Instant conversion supports only quickly converting a standard table into a range-partitioned table.

¹⁰ PolarDB for MySQL supports creating and deleting partition-level indexes. For more information, see Partial index.

PolarDB for MySQL 8.0.1

OperationConcurrent DMLRebuilds tableMetadata onlyParallel DDL
Add a partition (ADD)NoNo¹YesNot supported
Delete a partition (DROP)NoNo²NoNot supported
Discard a partition tablespace (DISCARD)NoNoNoNot supported
Import a partition tablespace (IMPORT)NoNoNoNot supported
Truncate a partition (TRUNCATE)YesNoNoNot supported
Merge partitions (COALESCE)NoYesNoNot supported
Reorganize a partition (REORGANIZE)NoNo³NoNot supported
Exchange a partition (EXCHANGE)YesYesYesNot supported
Analyze a partition (ANALYZE)YesYesNo⁴Not supported
Check a partition (CHECK)YesNoNo⁵Not supported
Optimize a partition (OPTIMIZE)Yes⁶Yes⁶NoSupported⁶
Rebuild a partition (REBUILD)NoNo³NoNot supported
Repair a partition (REPAIR)YesNo³NoNot supported
Convert a table to a partitioned tableNoYesNoNot supported
Convert a partitioned table to a standard tableNoYesNoNot supported

¹ For RANGE and LIST partitioned tables, adding partitions does not require a table rebuild. For HASH and KEY partitioned tables, adding partitions requires a table rebuild.

² Deleting partitions from HASH and KEY partitioned tables is not supported.

³ Reorganizing, rebuilding, and repairing a partition rebuilds only the specified partitions. Other partitions are not affected.

⁴ Analyzing a partition modifies statistics only, not metadata or table data.

⁵ Checking a partition does not modify metadata or data.

⁶ When running OPTIMIZE PARTITION on an InnoDB table, the entire partitioned table is rebuilt. Reads and writes are permitted during the rebuild. Set innodb_parallel_build_primary_index to ON to use parallel DDL to accelerate the rebuild.

PolarDB for MySQL 5.7

OperationConcurrent DMLRebuilds tableMetadata onlyParallel DDL
Add a partition (ADD)NoNo¹YesNot supported
Delete a partition (DROP)NoNo¹NoNot supported
Discard a partition tablespace (DISCARD)NoNoNoNot supported
Import a partition tablespace (IMPORT)NoNoNoNot supported
Truncate a partition (TRUNCATE)YesNoNoNot supported
Merge partitions (COALESCE)NoYesNoNot supported
Reorganize a partition (REORGANIZE)NoNo²NoNot supported
Swap partitionYesNoYesNot supported
Analyze a partition (ANALYZE)YesNoNo³Not supported
Check a partition (CHECK)YesNoNo⁴Not supported
Optimize a partition (OPTIMIZE)NoYesNoNot supported
Rebuild a partition (REBUILD)NoNo²NoNot supported
Repair a partition (REPAIR)YesNo²NoNot supported
Convert a table to a partitioned tableNoYesNoNot supported
Convert a partitioned table to a standard tableNoYesNoNot supported

¹ For RANGE and LIST partitioned tables, adding or deleting partitions does not require a table rebuild. For HASH and KEY partitioned tables, adding partitions requires a table rebuild. Deleting partitions from HASH and KEY partitioned tables is not supported.

² Reorganizing, rebuilding, and repairing a partition rebuilds only the specified partitions. Other partitions are not affected.

³ Analyzing a partition modifies statistics only, not metadata or table data.

⁴ Checking a partition does not modify metadata or data.

PolarDB for MySQL 5.6

OperationConcurrent DMLRebuilds tableMetadata onlyParallel DDL
Add a partition (ADD)NoNo¹YesNot supported
Delete a partition (DROP)NoNo¹NoNot supported
Discard a partition tablespace (DISCARD)NoNoNoNot supported
Import a partition tablespace (IMPORT)NoNoNoNot supported
Truncate a partition (TRUNCATE)YesNoNoNot supported
Merge partitions (COALESCE)NoYesNoNot supported
Reorganize a partition (REORGANIZE)NoNo²NoNot supported
Exchange a partition (EXCHANGE)YesNoYesNot supported
Analyze a partition (ANALYZE)YesNoNo³Not supported
Check a partition (CHECK)YesNoNo⁴Not supported
Optimize a partition (OPTIMIZE)NoYesNoNot supported
Rebuild a partition (REBUILD)NoNo²NoNot supported
Repair a partition (REPAIR)YesNo²NoNot supported
Convert a table to a partitioned tableNoYesNoNot supported
Convert a partitioned table to a standard tableNoYesNoNot supported

¹ For RANGE and LIST partitioned tables, adding or deleting partitions does not require a table rebuild. For HASH and KEY partitioned tables, adding partitions requires a table rebuild. Deleting partitions from HASH and KEY partitioned tables is not supported.

² Reorganizing, rebuilding, and repairing a partition rebuilds only the specified partitions. Other partitions are not affected.

³ Analyzing a partition modifies statistics only, not metadata or table data.

⁴ Checking a partition does not modify metadata or data.

Choose an execution method

When a DDL operation uses the INSTANT or INPLACE algorithm, run it directly using the kernel (Online DDL). This is the fastest and most stable approach.

When a DDL operation uses the COPY algorithm, the table is locked for the entire duration. In this case, consider using lock-free DDL in DMS or a tool such as gh-ost to allow reads and writes during execution. These approaches are slower and may fail on large tables or high-concurrency workloads due to excessive incremental data.

MethodConcurrent reads and writesSpeedBinary logging requiredParallel acceleration
Kernel (Online DDL)YesFastNoSupported
Lock-free DDL in DMS, gh-ostYesSlowYesNot supported
Even with third-party tools, an MDL-X lock is acquired during table switching (when metadata is modified), temporarily blocking the table. To address this, enable the nonblocking DDL feature or the preemptive DDL feature.
Important

Lock-free DDL operations may increase IOPS and CPU usage. Run them during off-peak hours.

Related topics

If you have questions about DDL operations, contact technical support.