Effective Online DDL: Making Critical Database Schema Changes with Zero Downtime

Online Data Definition Language (DDL) is a crucial feature for modern databases. It allows schema changes without significant downtime or locking that could disrupt database operations. This means these operations carry out while the database continues to be available for reads and writes, minimizing downtime and avoiding disruption to ongoing activities.

Online DDL is particularly important for applications requiring high availability and where maintenance windows are not feasible or are too disruptive. This capability is crucial for large, operational databases that need to scale, evolve, and undergo schema changes without affecting the user experience or service availability.

In this blog post, we’ll explore what online DDL is and then dive into how TiDB, a distributed SQL database, efficiently handles online DDL operations.

What is Online DDL?

Online DDL performs schema changes such as adding columns, creating indexes, or modifying table structures while minimizing the impact on the database’s availability and performance. Traditional DDL operations in relational database management systems (RDBMSs) often require locking tables, which can lead to downtime or slow performance, but online DDL aims to mitigate these issues.

A distributed SQL database implements online DDL using the protocol introduced by the Google F1 paper. In short, DDL changes break up into smaller transition stages so they can prevent data corruption scenarios, and the system tolerates an individual node being behind up to one DDL version at a time.

Key Aspects of Online DDL

​​How MySQL Handles Online DDL

MySQL, particularly with the InnoDB storage engine, has robust support for online DDL. Here’s how MySQL addresses online DDL:

Non-blocking Schema Changes

MySQL’s InnoDB engine allows many schema changes without blocking access to the table. For instance, adding a column or creating an index is done without locking the entire table, as shown below.

Non-blocking schema changes with online DLL in MySQL.

Online Index Creation

MySQL supports creating indexes concurrently, meaning the table remains available for reads and writes while the index builds.

Online index creation with online ddl in MySQL.

Phased Approach

MySQL uses a phased approach for applying schema changes, ensuring minimal disruption and maintaining performance: