Skip to main content

Online DDL and offline DDL operations

Online DDL

  • Definition: During DDL operations, users can still access the database for reading and writing.
  • Advantages: Minimal impact on business operations, allows DDL operations while the system is running, suitable for high-availability scenarios.
  • Characteristics: Typically supports concurrent access and fewer locks, reducing downtime.

Offline DDL

  • Definition: During DDL operations, the relevant tables are locked, preventing user access to the database's data.
  • Advantages: Simple and easy to implement, suitable for scenarios with minimal business impact.
  • Characteristics: Causes some downtime during DDL operations, affecting normal queries and transaction processing.

Transactional Consistency

  • Transaction: A set of operations that either all succeed or all fail, ensuring data consistency during execution.
  • Online DDL and offline DDL operations are typically independent, and DDL operations may not be transactionally controlled in some database management systems (especially offline DDL).

Transaction waiting strategy

  • Online DDL: Usually, you do not need to wait for the current transaction to end. It can be executed concurrently.
  • Offline DDL: Usually, you need to wait for the current transaction to end. This is because the relevant tables are locked during execution.

The following table lists the Online DDL operations supported by seekdb.

CategoryOperationTime ConsumptionRemarksDDL Support After Creating a Materialized View Log (mlog)
Index OperationsAdd IndexDepends on the data volume. Data reorganization is required.Mainly involves global and local indexes, global indexes with partitions, and spatial indexes.Supported
Index OperationsDrop IndexDepends on whether there are active transactions.N/ASupported
Index OperationsRename IndexOnly metadata modification is required.N/ASupported
Index OperationsMixed Index OperationsDepends on the data volume. Index data completion is required.For example, ALTER TABLE t1 ADD INDEX i4(c1), DROP INDEX i2, RENAME INDEX i1 TO i1x.Supported
Column OperationsAdd/Modify/Delete Skip Index TypeOnly table schema modification is required.N/ANot supported
Column OperationsAdd Column at the EndOnly metadata modification is required.For example, adding a LOB (TEXT) column, such as ALTER TABLE tbl1 ADD c3 LOB.Supported
Column OperationsAdd Column in the Middle (BEFORE/AFTER/FIRST)Depends on the data volume. Data reorganization is required.Supported
Column OperationsAdd VIRTUAL ColumnOnly metadata modification is required.N/ANot supported
Column OperationsModify Column to NOT NULLDepends on the data volume. Data query is required.N/ANot supported
Column OperationsModify Column to NULLOnly metadata modification is required.N/ANot supported
Column OperationsSet Column Default ValueOnly metadata modification is required.N/ANot supported
Column OperationsRemove Column Default ValueOnly metadata modification is required.N/ANot supported
Column OperationsModify Auto-Increment Column ValueOnly metadata modification is required.N/ANot supported
Column OperationsRename ColumnOnly metadata modification is required.N/ANot supported
Column OperationsIncrease Column Type Length or PrecisionOnly metadata modification is required.For example, increasing the length of INT, extending VARCHAR, or converting NUMBER types.Not supported
Column OperationsMixed Column OperationsDepends on the longest time-consuming operation.For individual column operations, Online DDL is supported. For mixed column operations, most are Online DDL. To confirm whether an operation is Online DDL, refer to How to Determine Whether a DDL Operation is Online DDL in the following section.Not supported
Foreign Key Constraint OperationsAdd Foreign Key, CHECK, or NOT NULL ConstraintDepends on the data volume. Data query is required.N/ASupported for adding foreign key constraints, not supported for adding CHECK or NOT NULL constraints
Foreign Key Constraint OperationsDrop Foreign Key, CHECK, or NOT NULL ConstraintDepends on the data volume. Data query is required.N/ASupported for dropping foreign key constraints, not supported for dropping CHECK or NOT NULL constraints
Table OperationsRename TableOnly metadata modification is required.N/ANot supported
Table OperationsModify Row FormatOnly metadata modification is required.N/ANot supported
Table OperationsModify Block SizeOnly metadata modification is required.N/ANot supported
Table OperationsModify Compression AlgorithmOnly metadata modification is required.N/ANot supported
Table OperationsOptimize TablespaceOnly metadata modification is required.N/ANot supported
Table OperationsConvert Rowstore to Columnstore :::tip Add the DELAYED keyword when you execute the ALTER TABLE statement. This is Online DDL. ::: .Only table schema modification is required.N/ANot supported
Table OperationsConvert Rowstore to Hybrid Rowstore/Columnstore :::tip Add the DELAYED keyword when you execute the ALTER TABLE statement. This is Online DDL. ::: .Only table schema modification is required.N/ANot supported
Partition OperationsAdd PartitionOnly metadata modification is required.N/ANot supported
Partition OperationsModify Automatic Partitioning AttributesOnly metadata modification is required.For example:
  • ALTER TABLE t1 PARTITION BY RANGE() SIZE('xxx');
  • ALTER TABLE t1 PARTITION BY RANGE();
  • ALTET TABLE t1 PARTITION BY RANGE() SIZE('ulimited');
  • ALTER TABLE t1 PARTITION BY RANGE (xxx) SIZE('xxx');
Not supported

The following table lists the Offline DDL operations supported by seekdb.

CategoryOperationTime ConsumedRemarksDDL Support After Creating a Materialized Log (Mlog)DDL Support After Creating a Full-Text/Multivalued/Vector Index
Column OperationBEFORE/AFTER/FIRSTRelated to the amount of data, and data reorganization is required.Not supportedSupported
Column OperationAdd an auto-increment columnRelated to the amount of data, and data reorganization is required.NoneNot supportedSupported
Column OperationChange a column to an auto-increment columnRelated to the amount of data, and data reorganization is required.NoneNot supportedSupported
Column OperationChange the column typeRelated to the amount of data, and data reorganization is required.Not supportedSupported
Column OperationChange a column to a primary keyRelated to the amount of data, and data reorganization is required.NoneNot supportedSupported
Column OperationAdd or drop a STORED generated columnRelated to the amount of data, and data reorganization is required.NoneNot supportedSupported
Column OperationDrop a columnRelated to the amount of data, and data reorganization is required.NoneNot supportedSupported
Column OperationDrop a VIRTUAL columnRelated to the amount of data, and data reorganization is required.NoneNot supportedSupported
Column OperationMixed column operationsIf offline column operations are performed, they will be upgraded to offline DDL.NoneNot supportedSupported
Primary Key OperationAdd or drop a primary keyRelated to the amount of data, and data reorganization is required.NoneNot supportedSupported
Table OperationTRUNCATE a tableRelated to whether there are active transactions.NoneNot supportedSupported
Table OperationChange the character setRelated to the amount of data, and data reorganization is required.Not supportedSupported
Table OperationDrop a tableRelated to whether there are active transactions.NoneNot supportedSupported
Table OperationConvert a rowstore table to a columnstore table :::tip If the DELAYED option is not specified in the ALTER TABLE statement, the operation is offline DDL. ::: .Related to the amount of data, and data reorganization is required.NoneNot supportedSupported
Table OperationConvert a rowstore table to a row-column hybrid table :::tip If the DELAYED option is not specified in the ALTER TABLE statement, the operation is offline DDL. ::: .Related to the amount of data, and data reorganization is required.NoneNot supportedSupported
Table OperationConvert a columnstore table to a rowstore tableRelated to the amount of data, and data reorganization is required.NoneNot supportedSupported
Table OperationConvert a columnstore table to a row-column hybrid tableRelated to the amount of data, and data reorganization is required.NoneNot supportedSupported
Table OperationConvert a row-column hybrid table to a columnstore tableRelated to the amount of data, and data reorganization is required.NoneNot supportedSupported
Table OperationConvert a row-column hybrid table to a rowstore tableRelated to the amount of data, and data reorganization is required.NoneNot supportedSupported
Partition OperationModify the partitioning ruleRelated to the amount of data, and data reorganization is required.NoneNot supportedSupported
Partition OperationDrop a partitionRelated to whether there are active transactions.A table lock at the partition level is added to the partition.Not supportedSupported
Partition OperationTRUNCATE a partitionRelated to whether there are active transactions.A table lock at the partition level is added to the partition.Not supportedSupported
Partition OperationPartition exchangeRelated to whether there are active transactions.A table lock at the partition level is added to the partition.Not supportedNot supported
Partition OperationManually split a partitionRelated to the amount of data, and data reorganization is required.NoneNot supportedNot supported
Partition OperationModify the auto-partitioning attributes and partitioning ruleRelated to the amount of data.For example: ALTER TABLE t1 PARTITION BY RANGE(xxx) SIZE('xxx') (PARTITION...);Not supportedSupported

How to determine whether a DDL operation is an online DDL

In seekdb, whether a DDL operation is online or offline has a significant impact on business operations. This topic describes how to determine whether a DDL operation is an online DDL, and provides the operation steps and considerations. For some DDL operations, such as column type changes or hybrid DDL operations, it is uncertain whether they are online DDL before execution. We recommend that you verify the operations by using the following methods.

Methods for determining whether a DDL operation is an online DDL

Some DDL operations cover a wide range of operations and cannot be completely listed as online or offline DDL. We recommend that you determine whether a DDL operation is online when it involves multiple DDL operations.

Principle of offline DDL:

Offline DDL operations in seekdb use the "rebuild table" method. Specifically, an offline DDL operation creates a temporary hidden table (which is invisible to users), and then migrates the data from the original table to the new table. After the data migration is completed, the temporary table is renamed to the original table name, and the original table is deleted. Therefore, after an offline DDL operation is completed, the table_id changes. During the execution of DDL operations, DML operations are not allowed.

Based on this principle, you can determine whether a DDL operation is an online DDL.

Method:

Run the following SQL statements before and after the DDL operation to check whether the table_id changes. If the table_id does not change, the DDL operation is an online DDL. If the table_id changes, the DDL operation is an offline DDL.

select distinct(table_id) from oceanbase.DBA_OB_TABLE_LOCATIONS where table_name='xxx';

Procedure:

Determine whether a DDL operation is an online DDL by following the procedure below.

  1. Create an empty table for verification:

    CREATE TABLE t10(a INT, b INT);
  2. View the current table_id:

    SELECT distinct(table_id)
    FROM oceanbase.DBA_OB_TABLE_LOCATIONS
    WHERE table_name='t10';
  3. Execute the expected DDL operation:

    ALTER TABLE t10 ADD c INT, ADD CONSTRAINT c_idx UNIQUE(c);
  4. View the table_id again:

    SELECT distinct(table_id)
    FROM oceanbase.DBA_OB_TABLE_LOCATIONS
    WHERE table_name='t10';
  5. If the table_id values returned in steps 2 and 4 are the same, the DDL operation is an online DDL. If the table_id values are different, the DDL operation is an offline DDL.

info

This method cannot be used for table operations or partition operations.