Delete Data
VeloDB Cloud provides multiple deletion methods, covering typical scenarios such as conditional deletion, partition-level deletion, full-table truncation, batch primary key deletion, and atomic overwrite. Starting from user scenarios, this article helps you quickly choose the most suitable deletion approach.
Choose a deletion method
Choose the corresponding deletion method based on your scenario:
| Use Case | Recommended Method | Applicable Model | Characteristics |
|---|---|---|---|
| Delete part of the data by condition | DELETE statement | All table models | General-purpose, flexible |
| Clear expired partition data while retaining definitions | Clear partitions (TRUNCATE) | Partitioned tables | Removes a whole partition from active data |
| Empty an entire table while keeping the schema | Full-table deletion (TRUNCATE) | All table models | Quickly resets data |
| Bulk delete a large number of primary keys (CDC sync, etc.) | Delete Sign | Unique Key model | Implements bulk deletion through updates |
| Rewrite partition data without interrupting queries | Atomic replacement with temporary partitions | Partitioned tables | Atomic overwrite, avoids query gaps |
Apply a deletion method
Delete rows by condition
Suitable for the general scenario of deleting part of the data by condition, and supports all table models.
Write the statement
DELETE FROM table_name WHERE condition;
Check applicability
- Meets most day-to-day deletion needs
- For whole-table or whole-partition cleanup, compare
TRUNCATEbefore issuing many row deletes.
For detailed usage, see Delete operation.
Clear or remove expired partitions
Use date partitions to manage retention. TRUNCATE ... PARTITION clears the data while keeping the partition definition. To remove an expired partition and its definition, use ALTER TABLE ... DROP PARTITION instead.
Write the statement
TRUNCATE TABLE tbl PARTITION(p1, p2);
Evaluate the operation
- Modifies only the partition metadata, no data scan required
- Retains empty partition definitions for reuse. To remove them, use
ALTER TABLE tbl DROP PARTITION p1.
For detailed usage, see Truncate operation.
Clear an entire table
Suitable for scenarios where you need to quickly empty an entire table while keeping its schema, such as redoing data in offline analysis.
Write the statement
TRUNCATE TABLE table_name;
For detailed usage, see Truncate operation.
Delete keys through loading
Data deletion can be viewed as a special form of data update. On a primary key model with update capability (Unique Key), you can use a delete sign to perform deletion through update writes.
Handle CDC delete events
- CDC (Change Data Capture) data sync: tag the binlog of a DELETE operation with a delete sign and write it into VeloDB Cloud to delete the data with the corresponding primary key.
Check benefits and constraints
- Batches primary-key deletions with other writes in the same load
- An advanced feature, with relatively higher usage complexity
For detailed usage, see Batch delete.
Replace partition data atomically
When you need to rewrite the data of a partition, directly using the "delete first, then load" approach leaves a window during which the data cannot be queried. Atomic replacement with temporary partitions avoids this issue.
Replace the partition
- Create a temporary partition that corresponds to the target partition
- Load the new data into the temporary partition
- Atomically replace the original partition through a replace operation
For detailed usage, see Temporary partition. If you need to atomically replace an entire table, see Atomic table replacement.
Compare deletion methods
| Method | Statement or interface | Granularity | Work performed | Table models |
|---|---|---|---|---|
| Conditional delete | DELETE FROM | Matching rows | Predicate deletion or row lookup and delete-marker writes | All three internal table models, with different predicate constraints |
| Clear a partition | TRUNCATE TABLE ... PARTITION | Entire partition | Replace partition metadata while retaining the definition | Partitioned tables |
| Clear a table | TRUNCATE TABLE | Entire table | Replace active partition data while retaining the table | All three internal table models |
| Load delete markers | __DORIS_DELETE_SIGN__ / merge_type | Keys in a batch | Load delete markers together | Unique Key |
| Replace a partition | REPLACE PARTITION | Entire partition | Load replacement data first, then switch metadata | Partitioned tables |
Plan cleanup and workload impact
- Impact on the number of versions: Repeated row deletes and loads can increase data-version and cleanup work.
TRUNCATEand partition replacement switch active metadata instead of adding row-level delete predicates. - Storage release delay: Logical deletion and physical storage reclamation are separate. Compaction, recycle-bin retention, and background cleanup can delay storage release, depending on the operation.
- Table model restrictions: Delete sign applies only to the Unique Key primary key model. Partition-related deletion applies only to partitioned tables.
Resolve common questions
Choose between DELETE and TRUNCATE
The DELETE statement deletes data by a WHERE condition and can be used on any table. TRUNCATE directly deletes an entire table or an entire partition by modifying only the metadata, with coarser granularity and no per-row predicate evaluation.
Allow background storage cleanup
Row deletes rely on background compaction and cleanup. Whole-partition and table operations can also retain data in the recycle bin. Neither operation guarantees immediate storage reclamation.
Batch CDC delete events
The Unique Key primary key model combined with the delete sign approach is recommended. It can process a large number of primary key deletions in bulk, while avoiding one SQL request per event. Throughput depends on batch size, keys, and the warehouse workload.
Switch partition data atomically
Use atomic replacement with temporary partitions: write the new data into a temporary partition first, then switch partitions through an atomic replacement operation. New queries see the formal partitions before or after the metadata switch.