Online DDL
- Definition: Online DDL allows users to access the database, including reading and writing, during DDL operations.
- Advantages: It has minimal impact on business operations and can be executed while the system is running, making it suitable for high-availability scenarios.
- Characteristics: It typically supports concurrent access and less locking, reducing downtime.
Offline DDL
- Definition: Offline DDL locks the relevant tables during operations, preventing users from accessing the database's related data.
- Advantages: It is simple to implement and suitable for scenarios where the impact on business operations is minimal.
- Characteristics: It can cause downtime during DDL operations, affecting normal queries and transaction processing.
Transactional DDL
- Transaction: A transaction is a set of operations that either all succeed or all fail, ensuring data consistency during execution.
- Online DDL and offline DDL operations are typically separate. In some database management systems, DDL operations themselves may not be supported by transactions (especially offline DDL).
Transaction wait strategy
- Online DDL: Usually does not require waiting for the current transaction to complete and can be executed concurrently.
- Offline DDL: Usually requires waiting for the current transaction to complete, as the relevant tables are locked during execution.
The following table lists the Online DDL operations supported in Oracle mode of OceanBase Database V4.x.
| Category | Operation | Time | Remarks | DDL support after creating a materialized view log (mlog) |
|---|---|---|---|---|
| Index operations | Add index | Depends on the data volume, and data reorganization is required | Mainly involves global/index, global index with partitions, and spatial indexes (supported in V4.1.0 and later versions). | Supported |
| Index operations | Drop index | Depends on whether there are active transactions | Not supported yet. | Supported |
| Index operations | Rename index | Only metadata modification is required | Not supported yet. | Supported |
| Index operations | Mixed index operations | Depends on the longest operation | For example, the ALTER TABLE t1 ADD INDEX i4(c1), DROP INDEX i2, RENAME INDEX i1 TO i1x syntax is not supported in Oracle mode. |
Not supported |
| Column operations | Add/modify/delete Skip Index type | Only table schema modification is required | Not supported yet. | Not supported |
| Column operations | Add column at the end | Only metadata modification is required | For example, adding a LOB (TEXT) column with the ALTER TABLE tbl1 ADD c3 LOB statement. |
Supported
NoticeFor OceanBase Database V4.3.5, the addition of columns to the base table of a materialized view log is supported starting from V4.3.5 BP1. |
| Column operations | Add VIRTUAL column |
Only metadata modification is required | Not supported yet. | Not supported |
| Column operations | Drop column
NoteFor OceanBase Database V4.3.5, the |
Only metadata modification is required | Not supported yet. | Not supported |
| Column operations | Modify column to NOT NULL |
Depends on the data volume, and data query is required | Not supported yet. | Not supported |
| Column operations | Modify column to NULL |
Only metadata modification is required | Not supported yet. | Not supported |
| Column operations | Set column default value | Only metadata modification is required | Not supported yet. | Not supported |
| Column operations | Drop column default value | Only metadata modification is required | Not supported yet. | Not supported |
| Column operations | Modify auto-increment column value | Only metadata modification is required | Not supported yet. | Not supported |
| Column operations | Rename column | Only metadata modification is required | Not supported yet. | Not supported |
| Column operations | Increase column type length or precision | Only metadata modification is required | For example, increasing the length of an INT column, extending a VARCHAR column, or converting a NUMBER column. |
Not supported |
| Column operations | Mixed column operations | Depends on the longest operation | Single column operations are Online, while mixed column operations are mostly Online. To confirm whether a DDL operation is Online, refer to the section How to determine whether a DDL operation is Online (Online DDL). | Not supported |
| Foreign key constraint operations | Add foreign key, CHECK/NOT NULL constraints |
Depends on the data volume, and data query is required. | Not supported yet. | Supported for adding foreign keys and CHECK constraints, but not for NOT NULL constraints |
| Foreign key constraint operations | Drop foreign key, CHECK/NOT NULL constraints |
Depends on the data volume, and data query is required. | Not supported yet. | Supported for dropping foreign key constraints, but not for CHECK/NOT NULL constraints |
| Table operations | Rename table | Only metadata modification is required | Not supported yet. | Not supported |
| Table operations | Modify row format | Only metadata modification is required | Not supported yet. | Not supported |
| Table operations | Modify block size | Only metadata modification is required | Not supported yet. | Not supported |
| Table operations | Modify compression algorithm | Only metadata modification is required | Not supported yet. | Not supported |
| Table operations | Optimize tablespace | Only metadata modification is required | Not supported yet. | Not supported |
| Table operations | Convert rowstore to columnstore
NoticeWhen you execute the |
Only table schema modification is required | Not supported yet. | Not supported |
| Table operations | Convert rowstore to row-column hybrid storage
NoticeWhen you execute the |
Only table schema modification is required | Not supported yet. | Not supported |
| Partition operations | Add partition | Only metadata modification is required | Not supported yet. | Not supported |
| Partition operations | Modify automatic partitioning attributes only | Only metadata modification is required | For example:
|
Not supported |
The following table lists the Offline DDL operations supported in Oracle mode of OceanBase Database V4.x.
| Category | Operation | Time | Remarks | DDL Support After Creating a Materialized Log (MLOG) |
|---|---|---|---|---|
| Column Operations | Add an auto-increment column | Depends on the data volume and requires data reorganization (i.e., rewriting all existing data) | N/A | Not supported |
| Column Operations | Modify a column to be a primary key | Depends on the data volume and requires data reorganization | N/A | Not supported |
| Column Operations | Add or drop a STORED generated column |
Depends on the data volume and requires data reorganization | N/A | Not supported |
| Column Operations | Drop a column | Depends on the data volume and requires data reorganization | N/A | Not supported |
| Column Operations | Drop a VIRTUAL column |
Depends on the data volume and requires data reorganization | N/A | Not supported |
| Column Operations | Clear obsolete columns | Depends on the data volume and requires data reorganization | N/A | Not supported |
| Column Operations | Perform mixed column operations | If offline column operations are involved, it will be upgraded to offline DDL. | N/A | Not supported |
| Primary Key Operations | Add or drop a primary key | Depends on the data volume and requires data reorganization | N/A | Not supported |
| Table Operations | TRUNCATE a table |
Depends on whether there are active transactions | N/A | Not supported |
| Table Operations | Drop a table | Depends on whether there are active transactions | N/A | Not supported |
| Table Operations | Convert a rowstore table to a columnstore table
NoticeIf you do not add the |
Depends on the data volume and requires data reorganization | N/A | Not supported |
| Table Operations | Convert a rowstore table to a row-column hybrid table
NoticeIf you do not add the |
Depends on the data volume and requires data reorganization | N/A | Not supported |
| Table Operations | Convert a columnstore table to a rowstore table | Depends on the data volume and requires data reorganization | N/A | Not supported |
| Table Operations | Convert a columnstore table to a row-column hybrid table | Depends on the data volume and requires data reorganization | N/A | Not supported |
| Table Operations | Convert a row-column hybrid table to a columnstore table | Depends on the data volume and requires data reorganization | N/A | Not supported |
| Table Operations | Convert a row-column hybrid table to a rowstore table | Depends on the data volume and requires data reorganization | N/A | Not supported |
| Partition Operations | Modify the partitioning rule | Depends on the data volume and requires data reorganization | N/A | Not supported |
| Partition Operations | Drop a partition | Depends on whether there are active transactions | A table lock is placed at the partition level on the partition. | Not supported |
| Partition Operations | TRUNCATE a partition |
Depends on whether there are active transactions | A table lock is placed at the partition level on the partition. | Not supported |
| Partition Operations | Swap partitions | Depends on whether there are active transactions | A table lock is placed at the partition level on the partition. | Not supported |
| Partition Operations | Manually split a partition | Depends on the data volume and requires data reorganization | N/A | Not supported |
| Partition Operations | Modify the automatic partitioning attributes and partitioning rule | Depends on the data volume | For example: ALTER TABLE t1 PARTITION BY RANGE(xxx) SIZE('xxx') (PARTITION...); |
Not supported |
How to determine whether a DDL operation is online
In OceanBase Database, whether a DDL operation is online or offline significantly impacts business operations. This topic describes how to determine whether a DDL operation is online and provides specific steps and considerations. For operations such as column type changes or mixed DDL operations, it is recommended to verify whether they are online before execution.
Methods to determine whether a DDL operation is online
Some DDL operations cover a wide range of operations and cannot be fully listed as online or offline. Therefore, it is recommended to verify whether the operation is online when mixed DDL operations are involved.
Principle of offline DDL operations:
Offline DDL operations in OceanBase Database use the "rebuild table" method. Specifically, an offline DDL operation creates a temporary hidden table (invisible to users), migrates data from the original table to the new table, renames the temporary table to the original table name, and deletes the original table. Therefore, after an offline DDL operation, the table_id changes, and no DML operations are allowed during the DDL operation.
Based on this principle, you can determine whether a DDL operation is online.
Method:
Execute the following SQL statements before and after the DDL operation to check whether the table_id changes. If it does not change, the DDL operation is online; if it changes, the DDL operation is offline.
select distinct(table_id) from DBA_OB_TABLE_LOCATIONS where table_name='xxx';
Steps:
Follow the steps below to determine whether a DDL operation is online.
Create an empty table for verification:
CREATE TABLE t10(a INT, b INT);Check the current
table_id:SELECT distinct(table_id) FROM DBA_OB_TABLE_LOCATIONS WHERE table_name='t10';Execute the expected DDL operation:
ALTER TABLE t10 ADD c INT, ADD CONSTRAINT c_idx UNIQUE(c);Check the
table_idagain:SELECT distinct(table_id) FROM DBA_OB_TABLE_LOCATIONS WHERE table_name='t10';If the
table_idvalues returned in steps 2 and 4 are the same, the DDL operation is online; if thetable_idchanges, the DDL operation is offline.
Note
This method does not apply to table and partition operations.
