Online DDL
- Definition: During online DDL operations, users can still access the database, including performing read and write operations.
- Advantages: It has minimal impact on business operations and allows DDL operations to be executed while the system is running. It is typically used in scenarios with high availability requirements.
- Characteristics: Online DDL operations usually support concurrent access and require fewer locks, thereby reducing downtime.
Offline DDL
- Definition: During offline DDL operations, the relevant tables are locked, preventing users from accessing the database's related data.
- Advantages: It is simple to implement and suitable for situations where the impact on business operations is minimal.
- Characteristics: Offline DDL operations can cause downtime, affecting normal query and transaction processing.
Transactional Consistency
- Transaction: A transaction is a set of operations that either all succeed or all fail, and it ensures data consistency during its execution.
- Online DDL and offline DDL operations are typically independent. In some database management systems, DDL operations themselves may not be supported by transactions (especially offline DDL).
Transaction wait strategy
- Online DDL: Typically, you do not need to wait for the current transaction to end. It can be executed concurrently.
- Offline DDL: Typically, you need to wait for the current transaction to end. This is because the related tables are locked during the execution.
The following table lists the Online DDL operations supported in the MySQL mode of OceanBase Database V4.x.
| Category | Operation | Time consumption | Remarks | DDL support after creating a materialized view log (mlog) |
|---|---|---|---|---|
| Index operations | Add index | Depends on the amount of data. Data reorganization is required. | Mainly involves global and local indexes, global indexes with partitions, and spatial indexes (supported in V4.1.0 and later). | 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 amount of data. Index data completion is required. | For example, ALTER TABLE t1 ADD INDEX i4(c1), DROP INDEX i2, RENAME INDEX i1 TO i1x. |
Supported |
| Column operations | Add/change/delete Skip Index type | Only table schema modification is required. | Not supported yet | Not supported |
| Column operations | Add a column at the end | Only metadata modification is required. | For example, adding a LOB (TEXT) column, ALTER TABLE tbl1 ADD c3 LOB. |
Supported
NoticeFor OceanBase Database V4.3.5, column addition in the base table of a materialized view log is supported starting from V4.3.5 BP1. |
| Column operations | Add a column in the middle (BEFORE/AFTER/FIRST) |
Depends on the amount of data. Data reorganization is required (i.e., the original data must be rewritten). | Not supported in Oracle mode. | Supported
NoticeFor OceanBase Database V4.3.5, column addition in the base table of a materialized view log is supported starting from V4.3.5 BP1. |
| Column operations | Add a VIRTUAL column |
Only metadata modification is required. | Not supported yet | Not supported |
| Column operations | Change a column to NOT NULL |
Depends on the amount of data. Data query is required. | Not supported yet | Not supported |
| Column operations | Change a column to NULL |
Only metadata modification is required. | Not supported yet | Not supported |
| Column operations | Set a default value for a column | Only metadata modification is required. | Not supported yet | Not supported |
| Column operations | Remove the default value of a column | Only metadata modification is required. | Not supported yet | Not supported |
| Column operations | Modify the value of an auto-increment column | Only metadata modification is required. | Not supported yet | Not supported |
| Column operations | Rename a column | Only metadata modification is required. | Not supported yet | Not supported |
| Column operations | Increase the length or precision of a column type | Only metadata modification is required. | For example, increasing the length of an INT column, increasing the length of a VARCHAR column, or converting a NUMBER column. |
Not supported |
| Column operations | Mixed column operations | Depends on the longest operation. | Individual column operations are Online, and most mixed column operations are Online. To confirm whether an operation is Online DDL, refer to How to determine whether a DDL operation is Online DDL. | Not supported |
| Foreign key constraint operations | Add a foreign key, CHECK, or NOT NULL constraint |
Depends on the amount of data. Data query is required. | Not supported yet | Supported for adding a foreign key constraint, but not for adding CHECK or NOT NULL constraints |
| Foreign key constraint operations | Drop a foreign key, CHECK, or NOT NULL constraint |
Depends on the amount of data. Data query is required. | Not supported yet | Supported for dropping a foreign key constraint, but not for dropping CHECK or NOT NULL constraints |
| Table operations | Rename a table | Only metadata modification is required. | Not supported yet | Not supported |
| Table operations | Change the row format | Only metadata modification is required. | Not supported yet | Not supported |
| Table operations | Change the block size | Only metadata modification is required. | Not supported yet | Not supported |
| Table operations | Change the compression algorithm | Only metadata modification is required. | Not supported yet | Not supported |
| Table operations | Optimize the tablespace | Only metadata modification is required. | Not supported yet | Not supported |
| Table operations | Convert a rowstore table to a columnstore table
NoticeWhen you execute |
Only table schema modification is required. | Not supported yet | Not supported |
| Table operations | Convert a rowstore table to a hybrid row-columnstore table
NoticeWhen you execute |
Only table schema modification is required. | Not supported yet | Not supported |
| Partition operations | Add a partition | Only metadata modification is required. | Not supported yet | Not supported |
| Partition operations | Change the automatic partitioning attributes | Only metadata modification is required. | For example:
|
Not supported |
The following table lists the Offline DDL operations supported in the MySQL mode of OceanBase Database V4.x.
Notice
- The DDL support after creating a full-text index, multivalued index, or vector index in the table applies to OceanBase Database V4.3.5 BP2 and later.
- Offline DDL is not supported for full-text, multivalued, or vector indexes in shared storage mode.
| Category | Operation | Time | Remarks | DDL support after creating a materialized log | DDL support after creating a full-text, multivalued, or vector index |
|---|---|---|---|---|---|
| Column operations | Reordering columns (BEFORE/AFTER/FIRST) |
Data volume related, requires data reorganization | Not supported in Oracle mode | Not supported | Supported |
| Column operations | Adding an auto-increment column | Data volume related, requires data reorganization | Not available | Not supported | Supported |
| Column operations | Modifying a column to an auto-increment column | Data volume related, requires data query | Not available | Not supported | Supported |
| Column operations | Modifying column type | Data volume related, requires data reorganization | Not supported in Oracle mode | Not supported | Supported |
| Column operations | Modifying a column to a primary key | Data volume related, requires data reorganization | Not available | Not supported | Supported |
| Column operations | Adding or dropping a STORED generated column |
Data volume related, requires data reorganization | Not available | Not supported | Supported |
| Column operations | Dropping a column | Data volume related, requires data reorganization | Not available | Not supported | Supported |
| Column operations | Dropping a VIRTUAL column |
Data volume related, requires data reorganization | Not available | Not supported | Supported |
| Column operations | Mixed column operations | If there are offline column operations, it will be upgraded to offline DDL. | Not available | Not supported | Supported |
| Primary key operations | Adding or dropping a primary key | Data volume related, requires data reorganization | Not available | Not supported | Supported |
| Table operations | TRUNCATE table |
Related to active transactions | Not available | Not supported | Supported |
| Table operations | Changing the character set | Data volume related, requires data reorganization | Not supported in Oracle mode | Not supported | Supported |
| Table operations | Dropping a table | Related to active transactions | Not available | Not supported | Supported |
| Table operations | Converting from rowstore to columnstore
NoticeWhen you execute |
Data volume related, requires data reorganization | Not available | Not supported | Supported |
| Table operations | Converting from rowstore to row-column hybrid storage
NoticeWhen you execute |
Data volume related, requires data reorganization | Not available | Not supported | Supported |
| Table operations | Converting from columnstore to rowstore | Data volume related, requires data reorganization | Not available | Not supported | Supported |
| Table operations | Converting from columnstore to row-column hybrid storage | Data volume related, requires data reorganization | Not available | Not supported | Supported |
| Table operations | Converting from row-column hybrid storage to columnstore | Data volume related, requires data reorganization | Not available | Not supported | Supported |
| Table operations | Converting from row-column hybrid storage to rowstore | Data volume related, requires data reorganization | Not available | Not supported | Supported |
| Partition operations | Modifying the partitioning rule | Data volume related, requires data reorganization | Not available | Not supported | Supported |
| Partition operations | Dropping a partition | Related to active transactions | Adds a table lock at the partition level. | Not supported | Supported |
| Partition operations | TRUNCATE partition |
Related to active transactions | Adds a table lock at the partition level. | Not supported | Supported |
| Partition operations | Partition exchange | Related to active transactions | Adds a table lock at the partition level. | Not supported | Not supported |
| Partition operations | Manually splitting a partition | Data volume related, requires data reorganization | Not available | Not supported | Not supported |
| Partition operations | Modifying automatic partitioning attributes and partitioning rules | Data volume related | For example: ALTER TABLE t1 PARTITION BY RANGE(xxx) SIZE('xxx') (PARTITION...); |
Not supported | Supported |
How to determine whether a DDL operation is online
In OceanBase Database, 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 online and provides the operation steps and considerations. For operations such as column type changes or mixed DDL operations, it is recommended to verify whether the operation is online before execution.
How to determine whether a DDL operation is online
For some operations, it is difficult to determine whether the operation is online or offline. Therefore, it is recommended to verify whether the operation is online in the case of mixed DDL operations.
Principle of offline DDL:
Offline DDL operations in OceanBase Database use the "rebuild table" method. Specifically, an offline DDL operation creates a temporary hidden table (which is invisible to users), migrates data from the original table to the new table, and then renames the temporary table to the original table name while deleting the original table. Therefore, the table_id changes after an offline DDL operation, 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 the table_id does not change, the DDL operation is online. If the table_id changes, the DDL operation is offline.
select distinct(table_id) from oceanbase.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);View the current
table_id:SELECT distinct(table_id) FROM oceanbase.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);View the
table_idagain:SELECT distinct(table_id) FROM oceanbase.DBA_OB_TABLE_LOCATIONS WHERE table_name='t10';If the
table_idreturned in step 2 and step 4 is the same, the DDL operation is online. If thetable_idchanges, the DDL operation is offline.
Note
This method does not apply to table operations and partition operations.
