DDL is one of the most common operations in MySQL. As MySQL has evolved, its DDL capabilities have continuously improved. This topic introduces the development process of MySQL DDL capabilities, explains common DDL operations, and provides optimization techniques and best practices for DDL operations in AliSQL.
DDL capability development
MySQL 5.5 and earlier: Only supports the COPY algorithm.
Execution process: Creates a temporary table, copies data row by row, and then swaps tables.
Limitation: The table is read-only during DDL execution and cannot be written to.
MySQL 5.6 & 5.7: Supports the INPLACE algorithm.
Execution process: The engine layer handles DDL without requiring a temporary table.
Advantage: Supports reading and writing to the table during DDL execution.
Limitation: The table may be briefly locked (no read or write operations) at the beginning and end of DDL execution, and temporary space is consumed.
MySQL 8.0: Supports the INSTANT algorithm.
Execution process: Only modifies metadata without copying data.
Advantage: Completes in seconds, significantly reducing the impact of DDL on business operations.
Limitation: Supports limited DDL types (adding and dropping columns). At the beginning and end of DDL execution, an MDL X lock (no read or write operations) is still briefly required on the table.

All algorithms require an MDL X lock during the start and end phases of DDL execution (phases 1 and 3 in the above diagram), resulting in a brief table lock (no read or write operations). AliSQL has optimized MDL lock waiting. For more information, see AliSQL DDL optimization features.
MySQL common DDL operations
MySQL supports specifying an algorithm when executing DDL operations. If not specified, MySQL selects the best algorithm based on the DDL operation type. The following describes the execution logic and impact of common operations (with the default InnoDB engine).
Table operations
DDL operation | DDL command | Default algorithm and whether it can be modified | Read/write property during DDL execution | Potential impact |
Rename table | RENAME | Supports algorithm modification, default value:
| Read/write | Only modifies metadata, no impact. |
Rebuild table | OPTIMIZE / ALTER ENGINE | Does not support algorithm modification, default value for 5.6, 5.7, and 8.0: INPLACE. | Read/write Note During AliSQL 8.0 data archiving, the table is read-only and cannot be written to. |
|
Update statistics | ANALYZE | Does not support algorithm modification. | Read/write | Only updates statistics information, but in some scenarios, it may cause business blocking. For more information, see the ANALYZE TABLE blocking scenarios in the Special cases tab. |
Modify character set | CONVERT CHARSET |
| Read-only, write operations are not allowed. |
|
Modify table comment | ALTER COMMENT | Does not support algorithm modification, default value for 5.6, 5.7, and 8.0: INPLACE. | Read/write | Only modifies metadata, no impact. |
Column operations
DDL operation | DDL command | Default algorithm and whether it can be modified | Read/write property during DDL execution | Potential impact |
Rename column | RENAME | Supports algorithm modification, default value:
| Read/write | Only modifies metadata, no impact. |
Add column | ADD | Supports algorithm modification, default value:
| Read/write |
|
Drop column | DROP | Supports algorithm modification, default value:
| Read/write | |
Modify column type | CHANGE / MODIFY | Supports algorithm modification, default value for 5.6, 5.7, and 8.0: COPY. VARCHAR special scenarios support INPLACE. For more information, see Using the INPLACE algorithm when modifying VARCHAR field length. | Read-only, write operations are not allowed. |
|
Modify column character set | ALTER CHARSET |
| Read-only, write operations are not allowed. | |
Modify column comment | ALTER COMMENT | Supports algorithm modification, default value:
| Read/write | Only modifies metadata, no impact. |
Index operations
DDL operation | DDL command | Default algorithm and whether it can be modified | Read/write property during DDL execution | Potential impact |
Rename index | RENAME | Supports algorithm modification, default value:
| Read/write | Only modifies metadata, no impact. |
Create index | ADD / CREATE | Supports algorithm modification, default value for 5.6, 5.7, and 8.0: INPLACE. | Read/write |
|
Drop index | DROP | Supports algorithm modification, default value for 5.6, 5.7, and 8.0: INPLACE. | Read/write | Only modifies metadata, no impact. |
Special cases
Using the INPLACE algorithm when modifying VARCHAR field length
VARCHAR type fields have a critical value for length. When you need to use the INPLACE algorithm to modify the length of a VARCHAR type field, you must ensure that both the length before and after modification are less than or equal to the critical value, or both are greater than the critical value. If you need to change across the critical value, you must use the COPY algorithm. Different character sets have different critical values (number of characters):
Character set | Critical value (number of characters) | Length change range | Available algorithms |
utf8 / utf8mb3 | 85 | Length before and after modification both in | INPLACE, COPY |
Length before and after modification both in | |||
Cross-critical value change | COPY | ||
utf8mb4 | 63 | Length before and after modification both in | INPLACE, COPY |
Length before and after modification both in | |||
Cross-critical value change | COPY | ||
latin1 | 255 | Length before and after modification both in | INPLACE, COPY |
Length before and after modification both in | |||
Cross-critical value change | COPY |
Using the INPLACE algorithm when modifying character sets (CONVERT CHARSET)
Character set modification operations modify all columns with character set information in the table. Currently, MySQL columns with character set information include CHAR, VARCHAR, TEXT, ENUM, and SET. When you need to use the INPLACE algorithm to modify character sets, you must meet the following conditions:
MySQL version 8.0 or later.
If the table contains CHAR or VARCHAR type fields, these columns cannot be indexed (or part of an index), and the column length must be less than or equal to the minimum of the two critical values (before and after character set modification) or greater than the maximum of the two critical values.
Taking the change from utf8 / utf8mb3 character set to utf8mb4 character set as an example:
The critical value for
utf8 / utf8mb3character set is 85.The critical value for
utf8mb4character set is 63.
When the table contains CHAR or VARCHAR type fields that are not index columns, the corresponding field length needs to be in the range of (0,63] or (85,65535] to use the INPLACE algorithm for character set modification.
ANALYZE TABLE blocking scenarios
Issue: If the table has unfinished slow SQL statements, all table access after ANALYZE needs to wait for the slow SQL to finish before refreshing the table cache.
Solution: This issue has been fixed in MySQL 8.0.
DDL execution time estimation
Method 1: Estimation based on Performance Schema (PFS)
Starting from MySQL 5.7, DDL-related Stage statistics were added to PFS. You can view DDL progress through processlist and the events_stages_current table in the P_S database, and estimate the remaining time.
Applicable scenario: Real-time monitoring of DDL progress during execution.
Query statement:
SELECT * FROM information_schema.processlist WHERE ID = <Replace with actual ID>; SELECT THREAD_ID, EVENT_ID, EVENT_NAME, WORK_COMPLETED, WORK_ESTIMATED,(WORK_COMPLETED/WORK_ESTIMATED)*100 AS PROGRESS FROM performance_schema.events_stages_current WHERE THREAD_ID = <Replace with actual ID>;NoteExecute the
SHOW Processlistcommand to obtain the ID based on the executed SQL.Example: For a local Sysbench 10 GB table, the query result shows
TIME=116,PROGRESS=83.9961%, as shown in the following figure:
Calculated time = TIME / PROGRESS= 116 / (83.9961%) = 138.1 sActual execution time: 2 min 3.14 s = 123.14 s

Method 2: Estimation based on tablespace size
Applicable scenario: Estimation without enabling PFS (which consumes memory and affects performance, RDS MySQL disables it by default).
Steps:
Query table size:
SELECT * FROM information_schema.tables WHERE TABLE_SCHEMA = <Replace with actual database name> AND TABLE_NAME = <Replace with actual table name>;Based on the DATA_LENGTH size obtained from the query, directly estimate the DDL time. Taking the OPTIMIZE TABLE operation as an example:
Cloud disk instances (premium performance disk and ESSD cloud disk): Estimate at a speed of 30~60 MB/s.
High-performance local disk instances: Estimate at a speed of 50~100 MB/s.
NoteThe speeds of 30~60 MB/s and 50~100 MB/s are estimated values based on the IO capability of the instance and may vary in practice.
(Optional) Index impact: If the table has many secondary indexes, you also need to consider the time for sorting and building secondary indexes. Estimate the index building time at 1/3 of the main table speed.
Example: For a local Sysbench 10 GB table, the query result is as follows:

Calculated time = DATA_LENGTH / 1024 / 1024 / 100 + INDEX_LENGTH / 1024 / 1024 / 100 × 3= 10270785536 / 1024 / 1024 / 100 + 665829376 / 1024 / 1024 / 100 × 3 = 117 sActual execution time: 2 min 3.14 s = 123.14 s

AliSQL DDL best practices
Basic principles
DDL is a change operation. Try to avoid business peak hours.
DDL operations that support the INSTANT algorithm, or other operations that only modify metadata, can be executed safely (to avoid being unable to obtain MDL X locks at the beginning and end of the operation, still pay close attention to slow queries and large transactions).
DDL operations that only support the COPY algorithm make the table read-only during execution and do not allow write operations. Execute these operations with caution.
Other DDL operations that support the INPLACE algorithm allow the table to be read and written during execution, but you need to comprehensively evaluate the execution time, space usage, and potential replication delay issues.
AliSQL DDL optimization features
Large table deletion optimization
Feature: Asynchronously cleans up large files to avoid file system jitter.
Parameter:
innodb_data_file_purge=ON(enabled by default).
Buffer Pool management optimization
Feature: Reduces DDL execution time and lowers the performance impact of DDL operations.
Parameter:
loose_innodb_rds_faster_ddl=ON(needs to be manually enabled).
Feature: Metadata change without rebuilding the table.
Parameter:
loose_innodb_instant_ddl_enabled=ON(enabled by default in MySQL 8.0, needs to be manually enabled in version 5.7 and below).
Other optimizations
AHI cleanup optimization: Optimizes performance issues caused by AHI cleanup during table and index deletion. Parameter: innodb_rds_drop_ahi_ahead, default is OFF.
Unique index conflict optimization: Optimizes issues where unique index conflicts cause DDL failures during DDL operations.
MDL lock wait logic optimization: Optimizes the blocking wait for MDL X locks to non-blocking wait, solving the problem of business-wide blocking caused by DDL operations that cannot obtain MDL locks for a long time.
ANALYZE TABLE optimization: Solves the problem where ANALYZE TABLE may cause business blocking in MySQL 5.7.
Parallel DDL: Fixes DDL performance regression issues.
References
Upgrade to the latest version of AliSQL to get all optimization features