Online DDL
- Definition: During an online DDL operation, users can continue to access the database, including reading and writing data.
- Advantages: Online DDL operations have minimal impact on business operations and can be performed while the system is running, making them ideal for high-availability scenarios.
- Characteristics: They usually support concurrent access and involve fewer locks, thereby reducing downtime.
Offline DDL
- Definition: During an offline DDL operation, the related tables are locked, preventing users from accessing the corresponding data in the database.
- Advantages: Simple and easy to implement, suitable for scenarios with minimal impact on business operations.
- Characteristics: Offline DDL operations cause some downtime, affecting normal queries and transaction processing.
Transaction correlation
- Transaction: A transaction is a group of operations that must either all succeed or all fail, ensuring data consistency during execution.
- Online and offline DDL operations are usually performed separately. In some database management systems, DDL operations may not be controlled by transactions (especially offline DDL).
Transaction wait strategies
- Online DDL: Typically does not need to wait for the current transaction to end and can be executed concurrently.
- Offline DDL: Usually needs to wait for the current transaction to end since the related table is locked during execution.
The following table describes the online DDL operations supported by OceanBase Database V4.x in MySQL mode.
| Type | Operation | Time spent | Remarks | DDL support after mlog creation |
|---|---|---|---|---|
| Index operation | Add an index | Related to the data volume, because data is reorganized (or rewritten) | This operation mainly involves global indexes, local indexes, global indexes with specified partitions, and spatial indexes (supported in OceanBase Database V4.1.0 and later). | Supported |
| Index operation | Drop an index | Related to whether active transactions exist | N/A | Supported |
| Index operation | Rename an index | Only for metadata modification | N/A | Supported |
| Index operation | Hybrid index operations | Related to the data amount, because index data needs to be supplemented | For example, ALTER TABLE t1 ADD INDEX i4(c1), DROP INDEX i2, RENAME INDEX i1 TO i1x involves hybrid index operations. |
Supported |
| Column operation | Add, change, or delete the skip index type | Only for table schema modification | N/A | Not supported |
| Column operation | Add a column to the end of a table | Only for metadata modification | For example, add a LOB (TEXT) column by executing a statement such as ALTER TABLE tbl1 ADD c3 LOB. |
Supported
NoteFor OceanBase Database V4.3.5, support for adding columns to the base table of materialized view logs is available starting from V4.3.5 BP1. |
| Column operations | Add a column in the middle (BEFORE, AFTER, or FIRST) |
Data volume related. Data needs to be reorganized (that is, the original data needs to be rewritten). | Not supported in Oracle mode. | Supported
NoteFor OceanBase Database V4.3.5, support for adding columns to the base table of materialized view logs is available starting from V4.3.5 BP1. |
| Column operation | Add a virtual column | Only for metadata modification | N/A | Not supported |
| Column operation | Set a NOT NULL constraint on a column |
Related to the data volume, because data is queried | N/A | Not supported |
| Column operation | Set a NULL constraint on a column |
Only for metadata modification | N/A | Not supported |
| Column operation | Set a default value for a column | Only for metadata modification | N/A | Not supported |
| Column operation | Drop the default value of a column | Only for metadata modification | N/A | Not supported |
| Column operation | Change the value of an auto-increment column | Only for metadata modification | N/A | Not supported |
| Column operation | Rename a column | Only for metadata modification | N/A | Not supported |
| Column operation | Increase the length or precision of the data type for a column | Only for metadata modification | For example, increase the length of the INT type, increase the length of the VARCHAR type, or convert the NUMBER type. |
Not supported |
| Column operation | Hybrid column operations | Related to the operation with the longest execution time | All single-column operations and most hybrid column operations are online DDL operations. For information about how to determine whether a DDL operation is an online operation, see the Determine whether a DDL operation is an online operation section in this topic. | Not supported |
| FOREIGN KEY constraint operation | Add a FOREIGN KEY, CHECK, or NOT NULL constraint | Related to the data volume, because data is queried | N/A | You can add a FOREIGN KEY constraint but not a CHECK or NOT NULL constraint. |
| FOREIGN KEY constraint operation | Drop a FOREIGN KEY, CHECK, or NOT NULL constraint | Related to the data volume, because data is queried | N/A | You can drop a FOREIGN KEY constraint but not a CHECK or NOT NULL constraint. |
| Table operation | Rename a table | Only for metadata modification | N/A | Not supported |
| Table operation | Change the row format | Only for metadata modification | N/A | Not supported |
| Table operation | Change the block size | Only for metadata modification | N/A | Not supported |
| Table operation | Change the compression algorithm | Only for metadata modification | N/A | Not supported |
| Table operation | Optimize a tablespace | Only for metadata modification | N/A | Not supported |
| Table operations | Convert row-based storage to columnar storage
NoticeWhen you execute |
Only the table schema needs to be modified. | N/A | Not supported |
| Table operations | Convert row-based storage to hybrid row-column-based storage
NoticeWhen you execute |
Only the table schema needs to be modified. | N/A | Not supported |
| Partition operation | Add a partition | Only for metadata modification | N/A | Not supported |
| Partition operations | Modify only the auto-partitioning attributes | Only metadata needs to be modified. | For example:
|
Not supported |
The following table describes the offline DDL operations supported by OceanBase Database V4.x in MySQL mode.
Notice
- The DDL support information for creating full-text, multi-valued, and vector indexes applies only to V4.3.5 BP2 and later versions.
- Offline DDL is not supported for full-text, multi-valued, or vector indexes in shared storage mode.
| Type | Operation | Time spent | Remarks | DDL support after mlog creation | DDL support after creating full-text, multi-valued, or vector indexes |
|---|---|---|---|---|---|
| Column operation | Reorder columns (BEFORE/AFTER/FIRST) |
Related to the data volume, because data is reorganized (or rewritten) | This operation is not supported in Oracle mode. | Not supported | Supported |
| Column operation | Add an auto-increment column | Related to the data volume, because data is reorganized (or rewritten) | N/A | Not supported | Supported |
| Column operation | Change a column to an auto-increment column | Related to the data volume, because data is queried | N/A | Not supported | Supported |
| Column operation | Change the type of a column | Related to the data volume, because data is reorganized (or rewritten) | This operation is not supported in Oracle mode. | Not supported | Supported |
| Column operation | Set a column as the primary key | Related to the data volume, because data is reorganized (or rewritten) | N/A | Not supported | Supported |
| Column operation | Add or drop a STORED generated column |
Related to the data volume, because data is reorganized (or rewritten) | N/A | Not supported | Supported |
| Column operation | Drop a column | Related to the data volume, because data is reorganized (or rewritten) | N/A | Not supported | Supported |
| Column operations | Drop a VIRTUAL column |
Data volume related. Data needs to be reorganized. | N/A | Not supported | Supported |
| Column operation | Hybrid column operations | If an offline column operation is involved, the operation is upgraded to an offline DDL operation. | N/A | Not supported | Supported |
| Primary key operation | Add or drop a primary key | Related to the data volume, because data is reorganized (or rewritten) | N/A | Not supported | Supported |
| Table operation | Truncate a table | Related to whether active transactions exist | N/A | Not supported | Supported |
| Table operation | Change the character set | Related to the data volume, because data is reorganized (or rewritten) | This operation is not supported in Oracle mode. | Not supported | Supported |
| Table operation | Drop a table | Related to whether active transactions exist | N/A | Not supported | Supported |
| Table operations | Convert row-based storage to columnar storage
NoticeWhen you execute |
Data volume related. Data needs to be reorganized. | N/A | Not supported | Supported |
| Table operations | Convert row-based storage to hybrid row-column-based storage
NoticeWhen you execute |
Data volume related. Data needs to be reorganized. | N/A | Not supported | Supported |
| Table operation | Convert a columnstore table into a rowstore table | Related to the data volume, because data is reorganized (or rewritten) | N/A | Not supported | Supported |
| Table operation | Convert a columnstore table into a hybrid rowstore-columnstore table | Related to the data volume, because data is reorganized (or rewritten) | N/A | Not supported | Supported |
| Table operation | Convert a hybrid rowstore-columnstore table into a columnstore table | Related to the data volume, because data is reorganized (or rewritten) | N/A | Not supported | Supported |
| Table operation | Convert a hybrid rowstore-columnstore table into a rowstore table | Related to the data volume, because data is reorganized (or rewritten) | N/A | Not supported | Supported |
| Partition operation | Modify partitioning rules | Related to the data volume, because data is reorganized (or rewritten) | N/A | Not supported | Supported |
| Partition operation | Drop a partition | Related to whether active transactions exist | A partition-level table lock is added to the partition. | Not supported | Supported |
| Partition operation | Truncate a partition | Related to whether active transactions exist | A partition-level table lock is added to the partition. | Not supported | Supported |
| Partition operation | Exchange a partition | Related to whether active transactions exist | A partition-level table lock is added to the partition. | Not supported | Not supported |
| Partition operations | Manual partition split | Data volume related. Data needs to be reorganized. | N/A | Not supported | Not supported |
| Partition operations | Modify the auto-partitioning attributes and the partitioning rule | Data volume related. | For example: ALTER TABLE t1 PARTITION BY RANGE(xxx) SIZE('xxx') (PARTITION...); |
Not supported | Supported |
Determine whether a DDL operation is an online operation
In OceanBase Database, the online/offline attribute of a DDL operation has significant impact on business. This section describes how to determine whether a DDL operation is an online operation. For some DDL operations, such as changing the type of a column or a hybrid DDL operation, we recommend that you first determine whether the operation is an online DDL operation.
Method for determining whether a DDL operation is an online operation
It is impossible to list all online and offline operations. Before you perform a hybrid DDL operation, we recommend that you first determine whether the hybrid DDL operation is an online operation.
Technical mechanism of offline DDL operations:
Offline DDL operations in OceanBase Database adopt the "table rebuild" method. Specifically, an offline DDL operation creates a temporary hidden table (invisible to users) and migrates data from the original table to the new table. After the data migration is completed, the temporary table is renamed to the name of the original table, and the old table is deleted. Therefore, after an offline DDL operation is completed, the table_id changes. You must not perform DML operations on the table during the DDL operation.
You can use this principle to determine whether a DDL operation is online DDL.
Method:
Execute the following SQL statement before and after a DDL operation is performed. If the table ID does not change, the DDL operation is an online operation. If the table ID changes, the DDL operation is an offline operation.
select distinct(table_id) from oceanbase.DBA_OB_TABLE_LOCATIONS where table_name='xxx';
Procedure:
Perform the following steps to determine whether a DDL operation is an online operation:
Create an empty table for verification.
CREATE TABLE t10(a INT, b INT);Query the current table ID.
SELECT distinct(table_id) FROM oceanbase.DBA_OB_TABLE_LOCATIONS WHERE table_name='t10';Perform a DDL operation.
ALTER TABLE t10 ADD c INT, ADD CONSTRAINT c_idx UNIQUE(c);Query the table ID again.
SELECT distinct(table_id) FROM oceanbase.DBA_OB_TABLE_LOCATIONS WHERE table_name='t10';If the table IDs returned in Step 2 and Step 4 are the same, the DDL operation is an online operation. If they are different, the DDL operation is an offline operation.
Note
You cannot use this method to determine whether a table or partition operation is an online DDL operation.