Note
This feature is an experimental feature in the current version.
Fork is a data cloning capability provided by OceanBase AI Database. It allows users to quickly create an independent copy based on an existing table or database. Fork reuses existing data organization and storage structures as much as possible while meeting consistency requirements, avoiding a full data copy. Subsequent writes to the target object incur incremental storage overhead.
Methods of Fork
Fork can be applied to a single table or an entire database, corresponding to two scenarios: partial data isolation and complete environment replication:
- Fork Table: Creates an independent target table based on the data of the source table at a certain snapshot point. The target table contains the complete structure and data of the source table. After creation, it is completely independent of the source table and can be freely read from and written to. For details, see Fork Table.
- Fork Database: Creates an independent target database based on the full data of the source database at a certain snapshot point. Internally, Fork is executed sequentially on each user table in the source database, ensuring all tables share the same snapshot version and guaranteeing cross-table data consistency. For details, see Fork Database.
The comparison between Fork Table and Fork Database is as follows:
Dimension |
Fork Table |
Fork Database |
|---|---|---|
| Cloning granularity | Single table | The entire database (all user tables) |
| Application scenarios | Data isolation is required only for some tables | Requires complete isolation of the database environment |
| Cross-table consistency | Not involved | All tables in the database share the same snapshot version |
| Syntax | FORK TABLE ... TO ... |
FORK DATABASE ... TO ... |
Application scenarios and value
Data version and branch management
When a team advances multiple changes in parallel on the same baseline data, such as fixing dirty data, adjusting feature fields, or changing index strategies, directly modifying the original table is risky and difficult to roll back, while full copies are time-consuming and consume a large amount of storage.
Fork allows multiple independent branches to be derived quickly from the same baseline. Each branch operates independently of others, enabling parallel operation by multiple people. Each copy corresponds to a snapshot of the source object at a certain point in time, so the data source is clear. If changes do not work as expected, you can switch back to the original branch directly, enabling lightweight rollback.
A/B testing and sandbox validation
Many validation tasks are meaningful only when conducted using real production data. However, experimenting directly in the production environment carries unacceptable risks, while setting up independent test environments is costly and prone to data bias.
Fork can quickly create isolated copies of production data. Experiments are conducted within these copies, leaving online data unaffected. When horizontal comparison of multiple solutions is needed, you can create independent copy for each solution, validate them in their respective environments, and then evaluate them collectively.
Vibe coding and synthetic data iteration
When data development is driven by natural language, the generated results are uncertain and require repeated experimentation, but each trial should not pollute existing data.
A Forked copy serves as a workspace that can be freely modified and discarded at any time. Users can adjust table structures and data in the copy using natural language instructions, forming a "description → generation → validation" loop. If the result is unsatisfactory, you can Fork a new copy and continue iterating with no extra burden.
Data migration and backup verification
Disaster recovery drills, test environment setup, and integrity checks before data archiving all require a complete copy. However, database-level data replication typically takes hours and requires reserving equivalent storage, often leading to such verifications being simplified or skipped altogether.
Database-level Fork can quickly create a full-database copy for use in disaster recovery drills, test environment setup, or integrity verification before data archiving. The creation cost is extremely low, enabling verification steps that were previously omitted due to high cost to be integrated into routine processes.
Features
Note
Parallel fork and background parallel processing are supported starting from V4.6.2.1. The WITH READ LOCK clause is supported starting from V4.6.2 BP1 hotfix1.
Features |
Description |
|---|---|
| Efficient creation | Avoids full data replication when creating the target object, suitable for large tables and entire databases. |
| Online execution | The source table can continue to support DML read and write operations during the fork process. |
| Write barrier | When the WITH READ LOCK clause is specified, OceanBase AI Database establishes a short-term write barrier on the source table before selecting a snapshot, blocking DML writes to the source table. The write barrier is automatically released after the target table becomes visible. |
| Snapshot consistency | The data of the target object is consistent with that of the source object at the time of the fork snapshot. All tables in the forked database share the same snapshot version. |
| Read/write isolation | After a fork is completed, the source object and target object become independent of each other. Subsequent writes to either object will not affect the other. |
| Progressive availability | The target object becomes accessible after creation. The refinement of backend data organization does not affect the snapshot semantics or availability provided to external users. |
| Parallel fork | Multiple forks can be initiated concurrently for the same source object, and the creation of each target object does not block others. |
| Background parallel processing | Background data processing uses multi-threaded parallel execution to improve the overall completion efficiency of forks. |
Fork can also be used for version rollback. If branch verification fails, stop using and delete the branch to return to the original version; if verification passes, you can switch the branch to the default version according to business and O&M procedures.
Privilege requirements
To initiate a fork, you must have both the SELECT privilege on the source object and the CREATE privilege on the target object:
Action |
Source object privilege |
Target object privilege |
|---|---|---|
| Fork Table | SELECT on the source table |
CREATE on the target database |
| Fork Database | SELECT on the source database |
CREATE on the target database |
- For Fork Table, the source table's
SELECTprivilege can be granted at the global, database, or table level. - Fork Database requires the
SELECTprivilege at the database level on the source database. A global privilege or a database-level privilege on the source database satisfies this requirement, but table-levelSELECTprivileges on individual tables in the source database do not. - Fork can only be executed within user tenant and is not supported in the sys tenant.
Fork only replicates the schema and data, not the privileges on the source object, nor does it automatically grant additional privileges to the fork initiator. Privileges for the target object are determined as if it were a newly created object: if the initiator has only CREATE and no SELECT on the target object, the fork can succeed, but the target data cannot be queried.
General limitations and constraints
- Operation mutual exclusion: During a Fork Table operation, the source table and target table are mutually exclusive with related DDL operations. During a Fork Database operation, the source database and its tables are mutually exclusive with DDL operations (such as
DROP TABLE,DROP DATABASE). DML read/write on the source object can continue during the fork. - Target object already exists: If the target object already exists, or if the target table has the same name as a foreign key placeholder parent table (mock FK parent table), the system returns an error. You must first delete the existing target object or rename it.
- Recycled objects: You cannot fork a table or database that has entered the recycle bin.
- System or internal objects: You cannot fork internal tables, or system or internal databases.
- Storage overhead: Fork reduces initial overhead by reusing the storage structure of the source object. Subsequent modifications to the target table/database will incur incremental storage consumption.
- Cascade fork: You can perform a fork on the target table/database produced by another fork, but cascade forking is not supported before the background processing of the current fork operation is complete.
FAQ
Q: What is the relationship between the forked table/database and the source table/database?
A: They are completely independent. Fork merely uses a snapshot of the source data as the initial state; after creation, they do not affect each other.
Q: Does fork affect the read/write performance of the source table?
A: The fork operation itself has minimal impact on the performance of the source table/source database. After fork completion, the read/write of the source table/source database and the target table/database do not interfere with each other.
Q: Can the source object still be written to during the fork process?
A: Yes. DML read/write can continue during the fork process, but related DDL operations are mutually exclusive with the fork operation.
Q: Can a historical point in time be specified for fork?
A: The current version does not support user-specified points in time. The system automatically selects an appropriate snapshot moment.
Q: Why can the target object be used before the background processing is fully complete?
A: Fork first completes the creation of the target object and provides access capability, while subsequent data organization continues in the background. This process does not affect snapshot consistency or normal read/write.
Q: How does fork differ from traditional data replication?
A: Traditional replication typically requires full data copying. Fork uses incremental replication and storage reuse technology, creating faster and consuming fewer resources.
Q: After the source table is deleted, can the forked target table still be used?
A: The target table becomes independent after the fork is complete and does not depend on the subsequent state of the source table.
Q: Does Fork Database guarantee that all tables have the same data at the same moment?
A: Yes. Fork Database ensures that all tables in the database share the same snapshot version.
Q: What is the difference between Fork Database and executing Fork Table for each table individually?
A: Fork Database uses the same snapshot version for all tables in the database, which guarantees data consistency across multiple tables. When executing Fork Table for each table individually, the snapshot moments for each table may differ. Fork Database also creates a target database that inherits the database properties of the source database.
Q: Can the same source database be forked multiple times?
A: Yes, and multiple forks can be initiated simultaneously. Multiple forks to different target databases can be executed in parallel. The data in each target database is a snapshot from its respective fork moment and is independent of others.