Lakehouse Table Cloning and Fast Backup Guide
Overview
In data warehouse operations, you often need to quickly create table copies for testing, backup, or data recovery. Singdata Lakehouse provides the CREATE TABLE ... CLONE syntax, supporting zero-copy cloning that instantly creates table replicas without copying the actual data. This guide categorizes by business scenario to help you quickly master efficient table cloning methods.
Quick Navigation
- Full Table Clone -- Clone table structure and all data
- Point-in-time Clone -- Clone the table state at a specific point in time
- Clone Structure Only -- Clone structure without data using LIKE
- Post-clone Verification -- Confirm clone results match the source table
- Clone and Independent Modification -- Verify cloned table independence
SQL Commands Covered
| Command | Purpose | Use Case |
|---|---|---|
CREATE TABLE ... CLONE | Zero-copy table cloning | Fast backup, test environment setup |
CREATE TABLE ... CLONE ... AT | Point-in-time clone | Restore to a historical state |
CREATE TABLE ... LIKE | Clone table structure only | Create an empty table for data loading |
Prerequisites
The following examples use a simulated orders table orders_clone:
Full Table Clone
Use CREATE TABLE ... CLONE to instantly create a replica of the table. The cloned table shares underlying data files with the source, consuming no additional storage space (until you perform write operations on the cloned table).
Result Verification:
| order_id | customer_id | amount | order_date |
|---|---|---|---|
| 1 | 101 | 500 | 2024-06-01 |
| 2 | 102 | 300 | 2024-06-02 |
| 3 | 103 | 800 | 2024-06-03 |
Point-in-time Clone
Use the AT clause to clone the table state at a specific point in time, commonly used to restore to a historical version.
Use Cases:
- Restore to a previous state after erroneous operations
- Audit historical data
- Compare data changes
Clone Structure Only
Use the LIKE syntax to clone the table structure without copying data, suitable for creating empty tables for subsequent data loading.
Result Verification:
| COUNT(*) |
|---|
| 0 |
Post-clone Verification
After cloning, it is recommended to verify consistency between the cloned table and the source table.
Result Explanation:
| source_count | clone_count |
|---|---|
| 3 | 3 |
Clone and Independent Modification
Once created, the cloned table is independent -- modifications to the cloned table will not affect the source table.
Result Explanation:
| tbl | cnt |
|---|---|
| source | 3 |
| clone | 4 |
Clean Up Test Data
After completing clone verification, it is recommended to clean up test tables:
Notes
- Zero-copy Property: Cloned tables share data files with the source, consuming no additional storage space (until new data is written).
- Time Travel Dependency: Point-in-time cloning depends on Time Travel functionality and must be within the retention period.
- Permission Inheritance: Cloned tables do not automatically inherit source table permissions; separate configuration is required.
- Dynamic Table Cloning: Dynamic Tables can also be cloned, but the clone becomes a regular table and no longer auto-refreshes.
- Materialized View Cloning: Materialized views also become regular tables after cloning.
