Online and offline DDL operations
Online DDL allows applications to continue accessing a table while its schema is being changed. Offline DDL reorganizes data or holds an exclusive lock, blocking reads and writes to the table while the operation is in progress. Whether a DDL operation must reorganize data can also depend on the table schema, index type, partitioning method, and whether multiple operations are combined in one statement.
Common online DDL operations
The following operations usually change only metadata or can be completed online:
| Category | Operation | Description |
|---|---|---|
| Index | Add, drop, or rename an index | The time required to add an index depends on the amount of data. Reads and writes remain available while the operation is in progress. |
| Index | Add, drop, or rename indexes in the same statement | The total duration is determined by the slowest operation. |
| Column | Add a column at the end of a table | Changes metadata only. |
| Column | Add a virtual generated column | Changes metadata only. |
| Column | Change a column default or NULL attribute | Whether existing data must be validated depends on the specific change. |
| Column | Rename a column | Changes metadata only. Application SQL must be updated to use the new column name. |
| Table | Rename a table, or change its row format, block size, compression method, or parallelism | Primarily changes table metadata. |
| Partition | Add a Range or List partition | Changes partition metadata only. |
Common offline DDL operations
The following operations usually reorganize data or hold a table lock for an extended period. Schedule a maintenance window for them:
| Category | Operation | Description |
|---|---|---|
| Column | Reorder columns | Rewrites existing data. |
| Column | Add or modify an auto-increment column | Reorganizes or validates existing data. |
| Column | Change a column data type | Converts and rewrites existing data. |
| Column | Add or drop a primary key | Reorganizes data. |
| Column | Add or drop a stored generated column | Reorganizes data. |
| Column | Drop a column | Reorganizes data. |
| Table | Convert the character set or collation | Converts and rewrites character data. |
| Table | Run TRUNCATE TABLE or DROP TABLE | The duration depends on active transactions and metadata locks. |
| Partition | Change the partitioning scheme | Reorganizes partition data. |
| Partition | Drop, truncate, or exchange a partition | Holds a partition-level or table-level metadata lock. |
Recommendations
- Test the DDL operation in an environment with a production-like schema and data volume, and record its duration, lock waits, and additional disk usage.
- When combining multiple DDL operations, treat the entire statement as offline if any operation requires data reorganization.
- Before execution, make sure that no long-running transaction is using the target table. During execution, use
SHOW PROCESSLISTto monitor waits. - Before running a DDL operation that might reorganize a large table, reserve sufficient disk space and schedule a maintenance window.
- The
ALGORITHMandLOCKclauses are supported only for MySQL syntax compatibility. Do not use them to determine whether seekdb will execute a DDL operation online.