DDL operation guide for PolarDB for MySQL
This topic describes common DDL operations of the cloud-native database PolarDB for MySQL. It helps you look up and understand DDL behavior, assess the risk of DDL operations, and reduce the impact on your workloads.
Overview of DDL operations
In the MySQL ecosystem, DDL covers a complex set of operations, including index, primary key, column, table, foreign key, and generated column operations. DDL operations are time-consuming and hardware-intensive, and many of them lock tables. Improper operations can disrupt normal workloads and cause catastrophic impact.
PolarDB for MySQL has significantly improved DDL performance and lock stability through years of accumulated experience and continuous feature iteration. This topic describes the behavior of common DDL operations in each version of PolarDB for MySQL from the following aspects:
Whether the table is locked (concurrent DML allowed): A non-locking DDL operation (Online DDL) requests a table mutex lock only while it modifies metadata, and the lock generally lasts no more than 1 second. Reads and writes on the target table are allowed during the table schema change, which improves response speed and availability in production environments. In contrast, statements that do not support Online DDL lock the table for the entire duration and do not allow concurrent writes. A long-running DDL operation of this type can significantly impact your workloads.
Whether the table is rebuilt (duration): This type of DDL operation recreates the primary key and all secondary indexes based on the new table schema, which usually takes a long time.
NoteBecause PolarDB for MySQL supports parallel DDL, running a DDL operation with the kernel is much faster than running it with third-party tools such as gh-ost or pt-osc.
Whether only metadata is modified (completes in seconds): Only metadata is modified and table data stays unchanged. The execution time of this type of DDL operation does not grow with the table size and generally completes within seconds.
Whether parallel DDL is supported (multi-thread acceleration): For scenarios such as creating indexes on or rebuilding large tables, PolarDB uses multi-threaded parallel DDL to improve DDL execution efficiency by up to 15 to 20 times. For more information, see Parallel DDL.
Whether performance is affected (lock-free change): Use lock-free change tickets to perform lock-free schema changes does not cause transient disconnections and does not affect your workloads during off-peak hours.
NotePerform this operation during off-peak hours. It may increase IOPS and CPU usage.
DDL execution algorithms
PolarDB for MySQL supports the following three DDL execution algorithms:
INSTANT algorithm: A DDL operation that uses the INSTANT algorithm modifies only the metadata in the data dictionary. It does not modify or copy existing data and does not rebuild the table. The operation is therefore independent of the table size, and the entire DDL process completes within seconds.
INPLACE algorithm: With the INPLACE algorithm, data copying and rebuilding happen inside the engine, so execution is faster. Most DDL operations that use the INPLACE algorithm allow concurrent reads and writes and have little impact on your workloads. In addition, some DDL operations that use the INPLACE algorithm, such as RENAME TABLE and ADD COMMENT, modify only metadata without touching table data and complete within seconds.
COPY algorithm: A DDL operation that uses the COPY algorithm copies all data in the table to a new table. During the data copy, an SNW (SHARED_NO_WRITE) lock is held on the original table. Only read operations are supported and concurrent writes are not allowed during the DDL execution, which has a significant impact on your workloads.
DDL operations that allow concurrent reads and writes are collectively called Online DDL, which has a relatively small impact on your workloads. In most cases, you do not need to manually specify the algorithm for a DDL operation. PolarDB automatically selects the best algorithm in the order of INSTANT, INPLACE, and COPY. You can also use the ALGORITHM and LOCK clauses of the ALTER TABLE statement to fine-tune DDL behavior:
ALGORITHM clause: To run a DDL statement with a specific algorithm, specify the ALGORITHM field. Valid values: DEFAULT, INSTANT, INPLACE, and COPY. If the DDL operation does not support the specified algorithm, an error is returned immediately.
LOCK clause: The LOCK clause adjusts concurrent access to the table during DDL execution. Use it to control the level of concurrent reads and writes while the table is being changed. Valid options and their meanings:
DEFAULT: The kernel allows the maximum level of concurrent reads and writes based on the DDL type.
NONE: Concurrent reads and writes are allowed during DDL execution. An error is returned if they are not supported.
SHARED: Concurrent reads are allowed but writes are blocked. An error is returned if concurrent reads are not supported.
EXCLUSIVE: All concurrent reads and writes are prohibited during DDL execution.
To prevent the table from becoming inaccessible during ALTER TABLE execution, specify the LOCK clause in the ALTER TABLE statement. If the lock behavior of the DDL execution does not meet the specified condition, the operation stops immediately.
Preview DDL execution characteristics with EXPLAIN DDL
This topic lists the execution characteristics of common DDL operations. However, because PolarDB provides a rich set of features, the actual DDL execution behavior can be affected by multiple factors, such as the structure of the target table, the parameter settings of the instance, and whether specific features are enabled.
To make schema changes safer and more predictable, we strongly recommend that you use the EXPLAIN DDL feature to learn the execution characteristics of a DDL operation before you run complex DDL operations.
Run the following syntax to view the execution characteristics of a DDL operation:
{ EXPLAIN | DESCRIBE | DESC } ALTER TABLE ...With EXPLAIN DDL, you can get the following key information:
Whether the current DDL operation can run successfully.
The algorithm type used by the current DDL operation. Valid values:
INSTANT,INPLACE, andCOPY.Whether the current DDL operation needs to rebuild the data of the entire table. A full table rebuild usually takes a long time.
Whether concurrent DML operations are allowed during the current DDL execution.
Whether the current DDL operation is blocked by uncommitted transactions.
Whether the current DDL operation supports parallel DDL acceleration. If it does, the degree of parallelism of the operation is displayed.
With this information in advance, you can assess the impact of a DDL operation more accurately, choose the right time to run it, and avoid the impact of table locking and long execution times on your live workloads. For more information, see EXPLAIN DDL.
DDL behavior characteristics
Index operations
PolarDB for MySQL8.0.2
Operation | Concurrent DML allowed | Rebuilds table | Metadata only | Parallel DDL supported |
Creating a secondary index | Yes | No | No | Supported |
Dropping a secondary index | Yes | No | Yes | N/A |
Renaming a secondary index | Yes | No | Yes | N/A |
Adding a full-text index (FULLTEXT) | No | No Note When you add the first full-text index to a table, an additional table rebuild is triggered if no user-defined FTS_DOC_ID column exists. | No | Not supported |
Adding a spatial index (SPATIAL) | No | No | No | Not supported |
PolarDB for MySQL8.0.1
Operation | Concurrent DML allowed | Rebuilds table | Metadata only | Parallel DDL supported |
Creating a secondary index | Yes | No | No | Supported |
Dropping a secondary index | Yes | No | Yes | N/A |
Renaming a secondary index | Yes | No | Yes | N/A |
Adding a full-text index (FULLTEXT) | No | No Note When you add the first full-text index to a table, an additional table rebuild is triggered if no user-defined FTS_DOC_ID column exists. | No | Not supported |
Adding a spatial index (SPATIAL) | No | No | No | Not supported |
PolarDB for MySQL5.7
Operation | Concurrent DML allowed | Rebuilds table | Metadata only | Parallel DDL supported |
Creating a secondary index | Yes | No | No | Supported |
Dropping a secondary index | Yes | No | Yes | N/A |
Renaming a secondary index | Yes | No | Yes | N/A |
Adding a full-text index (FULLTEXT) | No | No Note When you add the first full-text index to a table, an additional table rebuild is triggered if no user-defined FTS_DOC_ID column exists. | No | Not supported |
Adding a spatial index (SPATIAL) | No | No | No | Not supported |
PolarDB for MySQL5.6
Operation | Concurrent DML allowed | Rebuilds table | Metadata only | Parallel DDL supported |
Creating a secondary index | Yes | No | No | Not supported |
Dropping a secondary index | Yes | No | Yes | N/A |
Adding a full-text index (FULLTEXT) | No | No Note When you add the first full-text index to a table, an additional table rebuild is triggered if no user-defined FTS_DOC_ID column exists. | No | Not supported |
Adding a spatial index (SPATIAL) | No | No | No | Not supported |
Primary key operations
PolarDB for MySQL8.0.2
Operation | Concurrent DML allowed | Rebuilds table | Metadata only | Parallel DDL supported |
Adding a primary key | Yes | Yes | No | Supported |
Dropping a primary key | No | Yes | No | Not supported |
Dropping the existing primary key and adding a new one | Yes | Yes | No | Supported |
PolarDB for MySQL8.0.1
Operation | Concurrent DML allowed | Rebuilds table | Metadata only | Parallel DDL supported |
Adding a primary key | Yes | Yes | No | Supported |
Dropping a primary key | No | Yes | No | Not supported |
Dropping the existing primary key and adding a new one | Yes | Yes | No | Supported |
PolarDB for MySQL5.7
Operation | Concurrent DML allowed | Rebuilds table | Metadata only | Parallel DDL supported |
Adding a primary key | Yes | Yes | No | Supported |
Dropping a primary key | No | Yes | No | Not supported |
Dropping the existing primary key and adding a new one | Yes | Yes | No | Supported |
PolarDB for MySQL5.6
Operation | Concurrent DML allowed | Rebuilds table | Metadata only | Parallel DDL supported |
Adding a primary key | Yes | Yes | No | Not supported |
Dropping a primary key | No | Yes | No | Not supported |
Dropping the existing primary key and adding a new one | Yes | Yes | No | Not supported |
In the following scenarios, concurrent DML is allowed only when the cluster parameter sql_mode contains STRICT_TRANS_TABLES or STRICT_ALL_TABLES:
Adding a primary key
Dropping the existing primary key and adding a new one
Column operations
PolarDB for MySQL8.0.2
Operation | Concurrent DML allowed | Rebuilds table | Metadata only | Parallel DDL supported |
Adding a column | Yes | No1 | Yes1 | Supported1 |
Dropping a column | Yes | Yes | No | Supported |
Renaming a column | Yes | No | Yes | N/A |
Reordering columns | Yes | Yes | No | Supported |
Setting the default value of a column | Yes | No | Yes | N/A |
Changing a column comment | Yes | No | Yes | N/A |
Changing a column type | No | Yes | No | Not supported |
Extending the length of a VARCHAR column | Yes2 | No | Yes | N/A |
Changing the character set from UTF8mb3 to UTF8mb4 | No | No3 | Yes3 | Not supported |
Dropping the default value of a column | Yes | No | Yes | N/A |
Changing the auto-increment value | Yes | No | Yes | N/A |
Changing a column to NULL | Yes | Yes | No | Supported |
Changing a column to NOT NULL | No | Yes | No | Not supported |
Modifying the definition of an ENUM or SET column | Yes | No | Yes4 | N/A |
Instant column addition at the end of a table feature supports adding a column only to the end of the table. If the table has no explicit primary key, set the
implicit_primary_keyparameter to OFF to prevent the instant add column operation from failing because of the implicit primary key column at the end of the table. Instant add column is not supported on compressed tables (ROW_FORMAT=COMPRESSED), tables with full-text indexes, or temporary tables. If the cluster does not support instant add column, adding a column runs the DDL with the INPLACE algorithm, which requires a full table rebuild. Concurrent reads and writes are allowed during the rebuild. You can also use parallel DDL to accelerate the operation.When you extend the length of a VARCHAR column, the number of bytes used to store the column length must stay the same for fast column extension to work. Specifically, a VARCHAR column of 0 to 255 bytes needs only one byte to store its length, whereas a VARCHAR column of 256 bytes or more needs two bytes. Only if the extension stays within the same byte range, such as within 0 to 255 bytes or from 256 bytes to a larger value, can ALTER TABLE modify only metadata. When you extend a VARCHAR column from less than 256 bytes to 256 bytes or more, PolarDB uses Copy DDL by default, which locks the table for the entire duration. DML write operations are not supported and only read operations are allowed.
If you are not sure whether your VARCHAR modification meets these conditions, use
ALGORITHM=INPLACEto run the current DDL operation with the INPLACE algorithm. If fast column extension is not supported, an error is returned immediately. Example: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.VARCHAR is a variable-length storage type and the disk stores only the actual length. When you use VARCHAR fields, consider setting the maximum length to 256 bytes or more from the start, so that extending the field later does not require the COPY algorithm.
When the following conditions are met, changing the character set of a column from UTF8mb3 to UTF8mb4 modifies only metadata and does not modify data. Otherwise, the COPY algorithm is required to rebuild the table, and the table stays locked for the entire rebuild. The target table can only be read and cannot be written to.
The column type is CHAR, VARCHAR, ENUM, or TEXT.
No index exists on the column being modified.
The maximum storage length of the column is less than 256 bytes both before and after the character set conversion, or greater than 255 bytes both before and after.
You can specify ALGORITHM=INPLACE to force the DDL operation to run without rebuilding the table. If the operation requires the COPY algorithm, an error is returned immediately. Example:
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.Only when the storage size of the data type does not change and elements are appended to the end of the ENUM or SET can the operation modify only metadata without rebuilding the entire table. Otherwise, the COPY algorithm is required to rebuild the table.
PolarDB for MySQL8.0.1
Operation | Concurrent DML allowed | Rebuilds table | Metadata only | Parallel DDL supported |
Adding a column | Yes | No1 | Yes1 | Supported1 |
Dropping a column | Yes | Yes | No | Supported |
Renaming a column | Yes | No | Yes | N/A |
Reordering columns | Yes | Yes | No | Supported |
Setting the default value of a column | Yes | No | Yes | N/A |
Changing a column comment | Yes | No | Yes | N/A |
Changing a column type | No | Yes | No | Not supported |
Extending the length of a VARCHAR column | Yes2 | No | Yes | N/A |
Changing the character set from UTF8mb3 to UTF8mb4 | No | No3 | Yes3 | Not supported |
Dropping the default value of a column | Yes | No | Yes | N/A |
Changing the auto-increment value | Yes | No | Yes | N/A |
Changing a column to NULL | Yes | Yes | No | Supported |
Changing a column to NOT NULL | No | Yes | No | Not supported |
Modifying the definition of an ENUM or SET column | Yes | No | Yes4 | N/A |
Instant column addition at the end of a table feature supports adding a column only to the end of the table. If the table has no explicit primary key, set the
implicit_primary_keyparameter to OFF to prevent the instant add column operation from failing because of the implicit primary key column at the end of the table. Instant add column is not supported on compressed tables (ROW_FORMAT=COMPRESSED), tables with full-text indexes, or temporary tables. If the cluster does not support instant add column, adding a column runs the DDL with the INPLACE algorithm, which requires a full table rebuild. Concurrent reads and writes are allowed during the rebuild. You can also use parallel DDL to accelerate the operation.In addition, if your table has a columnstore index, instant add column is not supported because adding a column requires rebuilding the columnstore index. You can set the
loose_imci_enable_add_column_instant_ddlparameter to ON to enable instant add column. In this case, PolarDB rebuilds the columnstore index asynchronously in the background. The columnstore index is temporarily unavailable during the rebuild. For more information, see Execute DDL statements to dynamically create and delete an IMCI.When you extend the length of a VARCHAR column, the number of bytes used to store the column length must stay the same for fast column extension to work. Specifically, a VARCHAR column of 0 to 255 bytes needs only one byte to store its length, whereas a VARCHAR column of 256 bytes or more needs two bytes. Only if the extension stays within the same byte range, such as within 0 to 255 bytes or from 256 bytes to a larger value, can ALTER TABLE modify only metadata. When you extend a VARCHAR column from less than 256 bytes to 256 bytes or more, PolarDB uses Copy DDL by default, which locks the table for the entire duration. DML write operations are not supported and only read operations are allowed.
If you are not sure whether your VARCHAR modification meets these conditions, use
ALGORITHM=INPLACEto run the current DDL operation with the INPLACE algorithm. If fast column extension is not supported, an error is returned immediately. Example: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.VARCHAR is a variable-length storage type and the disk stores only the actual length. When you use VARCHAR fields, consider setting the maximum length to 256 bytes or more from the start, so that extending the field later does not require the COPY algorithm.
When the
loose_innodb_support_instant_modify_charsetparameter is set to ON and the following conditions are met, changing the character set of a column from UTF8mb3 to UTF8mb4 modifies only metadata and does not modify data. Otherwise, the COPY algorithm is required to rebuild the table, and the table stays locked for the entire rebuild. The target table can only be read and cannot be written to.The column type is CHAR, VARCHAR, ENUM, or TEXT.
No index exists on the column being modified.
The maximum storage length of the column is less than 256 bytes both before and after the character set conversion, or greater than 255 bytes both before and after.
You can specify ALGORITHM=INPLACE to force the DDL operation to run without rebuilding the table. If the operation requires the COPY algorithm, an error is returned immediately. Example:
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.Only when the storage size of the data type does not change and elements are appended to the end of the ENUM or SET can the operation modify only metadata without rebuilding the entire table. Otherwise, the COPY algorithm is required to rebuild the table.
PolarDB for MySQL5.7
Operation | Concurrent DML allowed | Rebuilds table | Metadata only | Parallel DDL supported |
Adding a column | Yes | No1 | Yes1 | Supported1 |
Dropping a column | Yes | Yes | No | Supported |
Renaming a column | Yes | No | Yes | N/A |
Reordering columns | Yes | Yes | No | Supported |
Setting the default value of a column | Yes | No | Yes | N/A |
Changing a column comment | Yes | No | Yes | N/A |
Changing a column type | No | Yes | No | Not supported |
Extending the length of a VARCHAR column | Yes2 | No | Yes | N/A |
Changing the character set from UTF8mb3 to UTF8mb4 | No | Yes | No | Not supported |
Dropping the default value of a column | Yes | No | Yes | N/A |
Changing the auto-increment value | Yes | No | Yes | N/A |
Changing a column to NULL | Yes | Yes | No | Supported |
Changing a column to NOT NULL | No | Yes | No | Not supported |
Modifying the definition of an ENUM or SET column | Yes | No | Yes3 | N/A |
To enable the Instant column addition at the end of a table feature, set the
loose_innodb_support_instant_add_columnparameter to ON. Only adding a column to the end of the table is supported. If the table has no explicit primary key, set theimplicit_primary_keyparameter to OFF to prevent the instant add column operation from failing because of the implicit primary key column at the end of the table. Instant add column is not supported on compressed tables (ROW_FORMAT=COMPRESSED), tables with full-text indexes, or temporary tables. If the cluster does not support instant add column, adding a column runs the DDL with the INPLACE algorithm, which requires a full table rebuild. Concurrent reads and writes are allowed during the rebuild. You can also use parallel DDL to accelerate the operation.When you extend the length of a VARCHAR column, the number of bytes used to store the column length must stay the same for fast column extension to work. Specifically, a VARCHAR column of 0 to 255 bytes needs only one byte to store its length, whereas a VARCHAR column of 256 bytes or more needs two bytes. Only if the extension stays within the same byte range, such as within 0 to 255 bytes or from 256 bytes to a larger value, can ALTER TABLE modify only metadata. When you extend a VARCHAR column from less than 256 bytes to 256 bytes or more, PolarDB uses Copy DDL by default, which locks the table for the entire duration. DML write operations are not supported and only read operations are allowed.
If you are not sure whether your VARCHAR modification meets these conditions, use
ALGORITHM=INPLACEto run the current DDL operation with the INPLACE algorithm. If fast column extension is not supported, an error is returned immediately. Example: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.VARCHAR is a variable-length storage type and the disk stores only the actual length. When you use VARCHAR fields, consider setting the maximum length to 256 bytes or more from the start, so that extending the field later does not require the COPY algorithm.
Only when the storage size of the data type does not change and elements are appended to the end of the ENUM or SET can the operation modify only metadata without rebuilding the entire table. Otherwise, the COPY algorithm is required to rebuild the table.
PolarDB for MySQL5.6
Operation | Concurrent DML allowed | Rebuilds table | Metadata only | Parallel DDL supported |
Adding a column | Yes | No1 | Yes1 | Not supported |
Dropping a column | Yes | Yes | No | Not supported |
Renaming a column | Yes | No | Yes | N/A |
Reordering columns | Yes | Yes | No | Not supported |
Setting the default value of a column | Yes | No | Yes | N/A |
Changing a column comment | Yes | No | Yes | N/A |
Changing a column type | No | Yes | No | Not supported |
Extending the length of a VARCHAR column | No | Yes | No | Not supported |
Changing the character set from UTF8mb3 to UTF8mb4 | No | Yes | No | Not supported |
Dropping the default value of a column | Yes | No | Yes | N/A |
Changing the auto-increment value | Yes | No | Yes | N/A |
Changing a column to NULL | Yes | Yes | No | Not supported |
Changing a column to NOT NULL | No | Yes | No | Not supported |
Modifying the definition of an ENUM or SET column | Yes | No | Yes2 | N/A |
To enable the Instant column addition at the end of a table feature, set the
loose_innodb_support_instant_add_columnparameter to ON. This feature supports adding a column only to the end of the table. If the table has no explicit primary key, set theimplicit_primary_keyparameter to OFF to prevent the instant add column operation from failing because of the implicit primary key column at the end of the table. In addition, instant add column is not supported on compressed tables (ROW_FORMAT=COMPRESSED), tables with full-text indexes, temporary tables, or partitioned tables. If the cluster does not support instant add column, adding a column runs the DDL with the INPLACE algorithm, which requires a full table rebuild. Concurrent reads and writes are allowed during the rebuild.NotePolarDB for MySQLThe instant add column feature in 5.6 is in canary release. To use it, go to Quota Center, use Quota ID
polardb_mysql_iac_56to find the quota name, and click Apply in the Actions column to enable the feature.This operation can modify metadata alone without rebuilding the entire table only when the storage size of the data type does not change and elements are appended to the end of the ENUM or SET. Otherwise, the COPY algorithm is required to rebuild the table.
Table operations
PolarDB for MySQL8.0.2
Operation | Concurrent DML allowed | Rebuilds table | Metadata only | Parallel DDL supported |
Changing ROW_FORMAT | Yes | Yes | No | Supported |
Changing KEY_BLOCK_SIZE | Yes | Yes | No | Supported |
Configuring persistent statistics | Yes | No | Yes | N/A |
Declaring a character set | Yes | No | Yes | N/A |
Converting a character set | No | Yes | No | Not supported |
Optimizing a table | Yes | Yes Note When you use | No | Supported |
Rebuilding a table | Yes | Yes | No | Supported |
Renaming a table | Yes | No | Yes | N/A |
Changing a table comment | Yes | No | Yes | N/A |
Creating a table (CREATE TABLE) | \ | \ | Yes | N/A |
PolarDB for MySQL8.0.1
Operation | Concurrent DML allowed | Rebuilds table | Metadata only | Parallel DDL supported |
Changing ROW_FORMAT | Yes | Yes | No | Supported |
Changing KEY_BLOCK_SIZE | Yes | Yes | No | Supported |
Configuring persistent statistics | Yes | No | Yes | N/A |
Declaring a character set | Yes | No | Yes | N/A |
Converting a character set | No | Yes | No | Not supported |
Optimizing a table | Yes | Yes Note When you use | No | Supported |
Rebuilding a table | Yes | Yes | No | Supported |
Renaming a table | Yes | No | Yes | N/A |
Changing a table comment | Yes | No | Yes | N/A |
Creating a table (CREATE TABLE) | \ | \ | Yes | N/A |
PolarDB for MySQL5.7
Operation | Concurrent DML allowed | Rebuilds table | Metadata only | Parallel DDL supported |
Changing ROW_FORMAT | Yes | Yes | No | Not supported |
Changing KEY_BLOCK_SIZE | Yes | Yes | No | Not supported |
Configuring persistent statistics | Yes | No | Yes | N/A |
Declaring a character set | Yes | No | Yes | N/A |
Converting a character set | No | Yes | No | Not supported |
Optimizing a table | Yes | Yes Note When you use | No | Supported |
Rebuilding a table | Yes | Yes | No | Supported |
Renaming a table | Yes | No | Yes | N/A |
Changing a table comment | Yes | No | Yes | N/A |
Creating a table (CREATE TABLE) | \ | \ | Yes | N/A |
PolarDB for MySQL5.6
Operation | Concurrent DML allowed | Rebuilds table | Metadata only | Parallel DDL supported |
Changing ROW_FORMAT | Yes | Yes | No | Not supported |
Changing KEY_BLOCK_SIZE | Yes | Yes | No | Not supported |
Configuring persistent statistics | Yes | No | Yes | N/A |
Declaring a character set | Yes | No | Yes | N/A |
Converting a character set | No | Yes | No | Not supported |
Optimizing a table | Yes | Yes Note When you use | No | Not supported |
Rebuilding a table | Yes | Yes | No | Not supported |
Renaming a table | Yes | No | Yes | N/A |
Changing a table comment | Yes | No | Yes | N/A |
Creating a table (CREATE TABLE) | \ | \ | Yes | N/A |
When you run CREATE TABLE in bulk, split the statements into smaller batches and run them during off-peak hours, away from O&M windows such as cluster scale-outs. Running them intensively may briefly occupy metadata lock (MDL) resources, but has no direct impact on existing data or workloads.
Generated column operations
PolarDB for MySQL8.0.2
Operation | Concurrent DML allowed | Rebuilds table | Metadata only | Parallel DDL supported |
Adding a STORED column | No Note Adding a STORED column expression involves the SQL/server layer, so Online DDL is not supported when you add a STORED column. | Yes | No | Not supported |
Reordering STORED columns | No | Yes | No | Not supported |
Dropping a STORED column | Yes | Yes | No | Supported |
Adding a VIRTUAL column | Yes | No | Yes | N/A |
Reordering VIRTUAL columns | No | Yes | No | Not supported |
Dropping a VIRTUAL column | Yes | No | Yes | N/A |
PolarDB for MySQL8.0.1
Operation | Concurrent DML allowed | Rebuilds table | Metadata only | Parallel DDL supported |
Adding a STORED column | No Note Adding a STORED column expression involves the SQL/server layer, so Online DDL is not supported when you add a STORED column. | Yes | No | Not supported |
Reordering STORED columns | No | Yes | No | Not supported |
Dropping a STORED column | Yes | Yes | No | Supported |
Adding a VIRTUAL column | Yes | No | Yes | N/A |
Reordering VIRTUAL columns | No | Yes | No | Not supported |
Dropping a VIRTUAL column | Yes | No | Yes | N/A |
PolarDB for MySQL5.7
Operation | Concurrent DML allowed | Rebuilds table | Metadata only | Parallel DDL supported |
Adding a STORED column | No Note Adding a STORED column expression involves the SQL/server layer, so Online DDL is not supported when you add a STORED column. | Yes | No | Not supported |
Reordering STORED columns | No | Yes | No | Not supported |
Dropping a STORED column | Yes | Yes | No | Supported |
Adding a VIRTUAL column | Yes | No | Yes | N/A |
Reordering VIRTUAL columns | No | Yes | No | Not supported |
Dropping a VIRTUAL column | Yes | No | Yes | N/A |
PolarDB for MySQL5.6
PolarDB for MySQL5.6 does not support generated columns.
Foreign key operations
PolarDB for MySQL8.0.2
Operation | Concurrent DML allowed | Rebuilds table | Metadata only | Parallel DDL supported |
Adding a foreign key | Yes1 | No1 | Yes1 | N/A |
Dropping a foreign key | Yes1 | No1 | Yes1 | N/A |
PolarDB for MySQL8.0.1
Operation | Concurrent DML allowed | Rebuilds table | Metadata only | Parallel DDL supported |
Adding a foreign key | Yes1 | No1 | Yes1 | N/A |
Dropping a foreign key | Yes1 | No1 | Yes1 | N/A |
PolarDB for MySQL5.7
Operation | Concurrent DML allowed | Rebuilds table | Metadata only | Parallel DDL supported |
Adding a foreign key | Yes1 | No1 | Yes1 | N/A |
Dropping a foreign key | Yes1 | No1 | Yes1 | N/A |
PolarDB for MySQL5.6
Operation | Concurrent DML allowed | Rebuilds table | Metadata only | Parallel DDL supported |
Adding a foreign key | Yes1 | No1 | Yes1 | N/A |
Dropping a foreign key | Yes1 | No1 | Yes1 | N/A |
INPLACE DDL is supported only when foreign_key_checks is disabled and only metadata is modified. Otherwise, only COPY DDL is supported and the table is locked for the entire duration.
Partitioned table operations
PolarDB for MySQL8.0.2
Operation | Concurrent DML allowed | Rebuilds table | Metadata only | Parallel DDL supported |
Adding partitions (ADD) | Yes1 | No2 | Yes | Not supported |
Dropping partitions (DROP) | Yes1 | No2 | No | Not supported |
Discarding partition tablespaces (DISCARD) | No | No | No | Not supported |
Importing partition tablespaces (IMPORT) | No | No | No | Not supported |
Truncating partitions (TRUNCATE) | Yes | No | No | Not supported |
Coalescing partitions (COALESCE) | No | Yes3 | No | Not supported |
Redistributing partitions (REORGANIZE) | Yes1 | No7 | No | Not supported |
Exchanging partitions (EXCHANGE) | Yes1 | No | Yes | Not supported |
Analyzing partitions (ANALYZE) | Yes | No | No8 | Not supported |
Checking partitions (CHECK) | Yes | No | No9 | Not supported |
Optimizing partitions (OPTIMIZE) | Yes4 | Yes4 | No | Supported4 |
Rebuilding partitions (REBUILD) | Yes1 | No7 | No | Not supported |
Repairing partitions (REPAIR) | Yes | No10 | No | Not supported |
Converting a table into a partitioned table | No | Yes | Yes5 | Not supported |
Converting a partitioned table into a table | No | Yes | No | Not supported |
Creating a PARTIAL INDEX | Yes | No6 | No | Supported |
Partition-level metadata locks (MDL) are introduced. After you set the
loose_partition_level_mdl_enabledparameter to true, running a DDL operation does not affect DML on partitions that are not involved. For more information, see Online partition maintenance.RANGE and LIST partitions do not require a table rebuild when added or dropped.HASH and KEY partitions require a table rebuild when added, and HASH and KEY partitions cannot be dropped.
Only HASH and KEY partitions are supported.
When you run OPTIMIZE PARTITION on a table in the InnoDB engine, the entire partitioned table is rebuilt. Reads and writes on the target table are supported during the rebuild. In this case, you can set the
innodb_parallel_build_primary_indexparameter to ON and use the Parallel DDL feature to speed up the rebuild.Instant conversion supports only Convert a non-partitioned table into a range-partitioned table.
PolarDB for MySQL supports creating and dropping indexes at partition granularity. For more information, see What is a partial index.
Redistributing or rebuilding partitions rebuilds only the partitions that require data redistribution or rebuild. Other partitions are not affected.
Analyzing a partition modifies only statistics and does not modify the metadata or data of the table.
Checking a partition does not modify metadata or data.
Repairing partitions rebuilds only the partitions that require repair.
PolarDB for MySQL8.0.1
Operation | Concurrent DML allowed | Rebuilds table | Metadata only | Parallel DDL supported |
Adding partitions (ADD) | No | No1 | Yes | Not supported |
Dropping partitions (DROP) | No | No2 | No | Not supported |
Discarding partition tablespaces (DISCARD) | No | No | No | Not supported |
Importing partition tablespaces (IMPORT) | No | No | No | Not supported |
Truncating partitions (TRUNCATE) | Yes | No | No | Not supported |
Coalescing partitions (COALESCE) | No | Yes | No | Not supported |
Redistributing partitions (REORGNIZATE) | No | No4 | No | Not supported |
Exchanging partitions (EXCHANGE) | Yes | Yes | Yes | Not supported |
Analyzing partitions (ANALYZE) | Yes | Yes | No5 | Not supported |
Checking partitions (CHECK) | Yes | No | No6 | Not supported |
Optimizing partitions (OPTIMIZE) | Yes3 | Yes3 | No | Supported3 |
Rebuilding partitions (REBUILD) | No | No4 | No | Not supported |
Repairing partitions (REPAIR) | Yes | No4 | No | Not supported |
Converting a table into a partitioned table | No | Yes | No | Not supported |
Converting a partitioned table into a table | No | Yes | No | Not supported |
RANGE and LIST partitions do not require a table rebuild when added.HASH and KEY partitions require a table rebuild when added.
HASH and KEY partitions cannot be dropped.
When you run OPTIMIZE PARTITION on a table in the InnoDB engine, the entire partitioned table is rebuilt. Reads and writes on the target table are supported during the rebuild. In this case, you can set the
innodb_parallel_build_primary_indexparameter to ON and use the Parallel DDL feature to speed up the rebuild.Redistributing, rebuilding, and repairing partitions rebuild only the partitions that require redistribution, rebuild, or repair. Other partitions are not involved.
Analyzing a partition modifies only statistics and does not modify the metadata or data of the table.
Checking a partition does not modify metadata or data.
PolarDB for MySQL5.7
Operation | Concurrent DML allowed | Rebuilds table | Metadata only | Parallel DDL supported |
Adding partitions (ADD) | No | No1 | Yes | Not supported |
Dropping partitions (DROP) | No | No1 | No | Not supported |
Discarding partition tablespaces (DISCARD) | No | No | No | Not supported |
Importing partition tablespaces (IMPORT) | No | No | No | Not supported |
Truncating partitions (TRUNCATE) | Yes | No | No | Not supported |
Coalescing partitions (COALESCE) | No | Yes | No | Not supported |
Redistributing partitions (REORGNIZATE) | No | No2 | No | Not supported |
Exchanging partitions (EXCHANGE) | Yes | No | Yes | Not supported |
Analyzing partitions (ANALYZE) | Yes | No | No3 | Not supported |
Checking partitions (CHECK) | Yes | No | No4 | Not supported |
Optimizing partitions (OPTIMIZE) | No | Yes | No | Not supported |
Rebuilding partitions (REBUILD) | No | No2 | No | Not supported |
Repairing partitions (REPAIR) | Yes | No2 | No | Not supported |
Converting a table into a partitioned table | No | Yes | No | Not supported |
Converting a partitioned table into a table | No | Yes | No | Not supported |
RANGE and LIST partitions do not require a table rebuild when added or dropped.HASH and KEY partitions require a table rebuild when added, and HASH and KEY partitions cannot be dropped.
Redistributing, rebuilding, and repairing partitions rebuild only the partitions that require redistribution, rebuild, or repair. Other partitions are not involved.
Analyzing a partition modifies only statistics and does not modify the metadata or data of the table.
Checking a partition does not modify metadata or data.
PolarDB for MySQL5.6
Operation | Concurrent DML allowed | Rebuilds table | Metadata only | Parallel DDL supported |
Adding partitions (ADD) | No | No1 | Yes | Not supported |
Dropping partitions (DROP) | No | No1 | No | Not supported |
Discarding partition tablespaces (DISCARD) | No | No | No | Not supported |
Importing partition tablespaces (IMPORT) | No | No | No | Not supported |
Truncating partitions (TRUNCATE) | Yes | No | No | Not supported |
Coalescing partitions (COALESCE) | No | Yes | No | Not supported |
Redistributing partitions (REORGNIZATE) | No | No2 | No | Not supported |
Exchanging partitions (EXCHANGE) | Yes | No | Yes | Not supported |
Analyzing partitions (ANALYZE) | Yes | No | No3 | Not supported |
Checking partitions (CHECK) | Yes | No | No4 | Not supported |
Optimizing partitions (OPTIMIZE) | No | Yes | No | Not supported |
Rebuilding partitions (REBUILD) | No | No2 | No | Not supported |
Repairing partitions (REPAIR) | Yes | No2 | No | Not supported |
Converting a table into a partitioned table | No | Yes | No | Not supported |
Converting a partitioned table into a table | No | Yes | No | Not supported |
RANGE and LIST partitions do not require a table rebuild when added or dropped.HASH and KEY partitions require a table rebuild when added, and HASH and KEY partitions cannot be dropped.
Redistributing, rebuilding, and repairing partitions rebuild only the partitions that require redistribution, rebuild, or repair. Other partitions are not involved.
Analyzing a partition modifies only statistics and does not modify the metadata or data of the table.
Checking a partition does not modify metadata or data.
DDL execution methods
When PolarDB for MySQL runs a DDL operation with the INPLACE or INSTANT algorithm, the kernel method (Online DDL) is the preferred choice. This method runs fast and is highly stable.
When PolarDB for MySQL runs a DDL operation with the COPY algorithm, the table is locked for the entire duration and cannot be read or written during execution. In this case, consider using a third-party tool such as the lock-free change feature of Data Management (DMS) or gh-ost. These tools allow reads and writes during DDL execution but are usually slower. On large tables or in high-concurrency scenarios, execution can fail if too much incremental data accumulates.
The following table compares running DDL operations with the kernel method and with third-party tools:
Execution method | Concurrent reads and writes allowed | Execution speed | Binary logging required | Parallel acceleration |
Kernel (Online DDL) | Yes | Fast | No | Supported |
Third-party tools (DMS lock-free change, gh-ost, and others) | Yes | Slow | Yes | Not supported |
Even if you use a third-party tool to run a DDL operation, an MDL-X lock is still acquired during the table switch (metadata modification), which causes a brief table lock. As needed, you can enable the Nonblocking DDL feature or the Preemptive DDL feature to avoid table locking.
Contact us
If you have any questions about DDL operations, you can search for the DingTalk group number and join the group for consultation. You can directly @ the experts in the group with your questions. The group also has a PolarDB for MySQL assistant online 24/7 to answer your questions. DingTalk group number: 15375044501.