Help Center/ TaurusDB/ Kernel/ DDL Optimization/ Online DDL Usage Guide
Updated on 2026-08-04 GMT+08:00

Online DDL Usage Guide

Scenarios

In the routine O&M and use of databases, data definition language (DDL) operations, such as adding columns or indexes to a table and removing indexes from a table, are common. However, for large tables, these operations may take several hours or even days, and block all DML (INSERT, UPDATE, and DELETE) operations on the original table, severely affecting workload continuity and availability.

To address this key issue, MySQL online DDL allows concurrent data reads and writes on a table during table structure changes, maximizing workload continuity and availability. This section explains how MySQL online DDL works with the InnoDB engine and the principles behind the gh-ost tool, helping you execute DDL operations more securely and efficiently.

Introduction to MySQL Online DDL

In MySQL online DDL operations, you can explicitly specify ALGORITHM to fine-tune table structure changes. The following uses adding an index as an example:

ALTER TABLE table_name  ADD INDEX index_name(column_name), ALGORITHM=INPLACE;

ALGORITHM specifies the DDL execution algorithm. The options are:

  • COPY: All concurrent DML operations are blocked during the DDL operation, which may cause a long database lock. So this option is not recommended.
  • INPLACE: DDL operations can be performed without blocking concurrent DML operations. This option applies to most DDL operations. To check whether a DDL operation supports this algorithm, see How Do I Determine Whether a DDL Operation Supports the INSTANT or INPLACE Algorithm?.
  • INSTANT: DDL operations are completed in seconds by modifying metadata in the data dictionary. There is no need to copy data or rebuild tables. These operations have almost no impact on the original table data and do not block concurrent DML operations. So this option is recommended. However, only a few DDL operations support INSTANT. To check whether a DDL operation supports this algorithm, see How Do I Determine Whether a DDL Operation Supports the INSTANT or INPLACE Algorithm?.

Introduction to gh-ost

If a DDL operation can only use the COPY algorithm (which locks a table for the entire process) and the original table is large or frequently updated, consider using gh-ost for better performance and stability.

gh-ost is an open-source tool specifically designed for MySQL databases to perform online DDL operations. It can avoid long table locks caused by traditional DDL operations, reducing the impact on workloads.

Disclaimer

gh-ost is a third-party open-source tool, not a Huawei Cloud product. To help you better use gh-ost, this document describes the usage constraints, suggestions, and principles of gh-ost. The content is for reference only. For more details, see the official document.

Differences Between MySQL Online DDL and gh-ost

The following table lists the differences between MySQL online DDL and gh-ost.

Table 2 Differences between MySQL online DDL and gh-ost

Item

MySQL Online DDL

gh-ost

Use cases

  • If a DDL operation supports the INSTANT or INPLACE algorithm, MySQL online DDL is recommended.
  • If a DDL operation only supports the COPY algorithm, MySQL online DDL is not recommended, especially for large tables.

If a DDL operation can only use the COPY algorithm and the original table is large or frequently updated, gh-ost is recommended for better performance and stability.

Principles

  • INSTANT algorithm: modifies metadata only.
  • INPLACE algorithm: modifies metadata and data pages in the existing tablespace and synchronizes incremental data through row logs.
  • COPY algorithm: creates a temporary table and copies data.
  1. Create a ghost table.
  2. Consume binlogs to synchronize incremental data.
  3. Copy data from the original table to the ghost table in batches.
  4. Exchange table names atomically.
  5. Clear resources.

Constraints

  • Only the COPY algorithm is supported for a few operations, such as deleting primary keys, adding full-text indexes or spatial indexes, and changing column types.
  • Temporary tables are not supported.
  • The table must have a unique key.
  • Binlog must be enabled, the binlog format must be row, and binlog_row_image must be set to FULL.
  • Temporary tables, foreign keys, and triggers are not supported.

DML blocking duration

  • INSTANT: minimal blocking time
  • INPLACE: brief blocking only at the start and end phases
  • COPY: blocking throughout the entire process

1. During data synchronization, row data is locked in batches. Only DML operations on row data in a batch are blocked.

2. DML operations are briefly blocked when table names are exchanged atomically.

Extra space occupied

  • INSTANT: minimal
  • INPLACE: small (slightly larger when a table needs to be rebuilt)
  • COPY: at least the same as the space occupied by the original table

At least the same as the space occupied by the original table

Replication delay

  • INSTANT: minimal
  • INPLACE: low
  • COPY: high

Medium

FAQs