Online Copy DDL
PolarDB for MySQL introduces the Online Copy DDL feature, which effectively reduces the business disruptions caused by traditional Copy DDL operations (such as MODIFY COLUMN and conversions between standard tables and partitioned tables) that hold an MDL lock throughout execution.
Background information
During standard Copy DDL execution, MySQL holds an MDL-SNW (Shared No Write) lock, continuously blocking all write operations (INSERT/UPDATE/DELETE) on the table. This can cause connection buildup and, in severe cases, system collapse. Online Copy DDL optimizes the locking mechanism during the data copy phase, allowing concurrent read and write operations while ensuring data consistency. This significantly improves business availability during DDL execution.
Scope
PolarDB for MySQL version 8.0.2 with revision 8.0.2.2.33.1 or later. You can query the version number to confirm the cluster version.
The Online Copy DDL feature is currently in canary release. To use this feature, go to the Quota Center, find the quota name by the quota ID polarm_82_online_copy_ddl, and then click Request in the Operation column to enable the feature. When you submit the request, provide the ID of the cluster that you want to enable (in the format of pc-xxx).
Limits
Supported operations:
Conversions between standard tables and partitioned tables.
MODIFY COLUMNstatements. Modifying the column position at the same time is not supported.
Unsupported operations or objects:
Tables that contain JSON columns.
Tables that contain spatial indexes (SPATIAL INDEX).
Tables that contain Global Secondary Indexes (GSIs).
Hybrid partitioned tables.
Sessions that have executed
LOCK TABLESon the table.DDL statements that explicitly specify
ALGORITHM=COPYwithLOCK=SHAREDorLOCK=EXCLUSIVE.
Before you execute a DDL operation, you can use the EXPLAIN DDL feature to directly determine whether the current DDL operation supports Online Copy DDL.
Usage
After you apply for a quota, the following parameters are automatically enabled for you to use Online Copy DDL. You cannot manually modify these parameters at this time.
Parameter | Level | Description |
| Global | The main switch of Online Copy DDL. Valid values:
|
| Global | The Online Copy DDL switch that applies only to
|
Method 1: Explicitly specify the algorithm (recommended)
Specify ALGORITHM=COPY, LOCK=NONE to force Online Copy DDL:
CREATE TABLE t(a int);
ALTER TABLE t MODIFY COLUMN a BIGINT DEFAULT NULL, ALGORITHM=COPY, LOCK=NONE;When you use the preceding statements, if the ERROR 1846 (0A000): LOCK=NONE is not supported. Reason: COPY algorithm requires a lock. Try LOCK=SHARED. error is returned, the current column type modification cannot be performed with the Online Copy DDL algorithm. Check whether the loose_polar_support_online_copy_ddl_algorithm parameter is enabled and carefully review the limits.
Method 2: Automatically select the optimal algorithm (default behavior)
If you do not specify an algorithm or use DEFAULT, the system automatically selects the most suitable execution method:
-- Method 1: Explicitly specify DEFAULT
ALTER TABLE t MODIFY COLUMN a BIGINT DEFAULT NULL, ALGORITHM=DEFAULT, LOCK=DEFAULT;
-- Method 2: Omit the clauses entirely (equivalent)
ALTER TABLE t MODIFY COLUMN a BIGINT DEFAULT NULL;The system first attempts Online Copy DDL. If the conditions are not met, the system automatically falls back to traditional Copy DDL (which locks the table) to ensure that the DDL operation can eventually complete.