Skip to main content
VeloDB Cloud 26.x is based on Apache Doris 4.x. See Version Mapping.

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 CaseRecommended MethodApplicable ModelCharacteristics
Delete part of the data by conditionDELETE statementAll table modelsGeneral-purpose, flexible
Clear expired partition data while retaining definitionsClear partitions (TRUNCATE)Partitioned tablesRemoves a whole partition from active data
Empty an entire table while keeping the schemaFull-table deletion (TRUNCATE)All table modelsQuickly resets data
Bulk delete a large number of primary keys (CDC sync, etc.)Delete SignUnique Key modelImplements bulk deletion through updates
Rewrite partition data without interrupting queriesAtomic replacement with temporary partitionsPartitioned tablesAtomic 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 TRUNCATE before 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

  1. Create a temporary partition that corresponds to the target partition
  2. Load the new data into the temporary partition
  3. 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​

MethodStatement or interfaceGranularityWork performedTable models
Conditional deleteDELETE FROMMatching rowsPredicate deletion or row lookup and delete-marker writesAll three internal table models, with different predicate constraints
Clear a partitionTRUNCATE TABLE ... PARTITIONEntire partitionReplace partition metadata while retaining the definitionPartitioned tables
Clear a tableTRUNCATE TABLEEntire tableReplace active partition data while retaining the tableAll three internal table models
Load delete markers__DORIS_DELETE_SIGN__ / merge_typeKeys in a batchLoad delete markers togetherUnique Key
Replace a partitionREPLACE PARTITIONEntire partitionLoad replacement data first, then switch metadataPartitioned tables

Plan cleanup and workload impact​

  • Impact on the number of versions: Repeated row deletes and loads can increase data-version and cleanup work. TRUNCATE and 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.