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

Clear Tables and Partitions

TRUNCATE clears all data in a specified table or partition in one operation, retaining only the table structure and partition definition. It replaces the active partition data instead of writing row-level delete predicates. Use it when every row in the target table or partition should be removed.

Find a cleanup task​

Choose TRUNCATE​

TRUNCATE is suitable for scenarios that require clearing large amounts of data at once:

  • Test environment reset: Clear test data in preparation for re-importing.
  • Partition data rebuild: Clear specified partitions and then rewrite corrected data.
  • Large-scale data cleanup: Avoid evaluating a predicate for every row when clearing an entire target.
  • Cleanup after historical data archiving: Clear the original table or partition after archiving is complete.

Write a TRUNCATE statement​

Specify the target​

TRUNCATE TABLE [db.]tbl [PARTITION(p1, p2, ...)] [FORCE];

Set statement parameters​

ParameterRequiredDescription
db.NoDatabase name. The current database is used when omitted.
tblYesName of the table to be cleared.
PARTITION(..)NoSpecifies a list of partition names; only these partitions are cleared. When omitted, the entire table is cleared.
FORCENoBypasses recycle-bin recovery. Physical storage cleanup is asynchronous. Use with caution.

Run cleanup examples​

Clear an entire table​

Clear an entire table

Clear all data in the tbl table under example_db:

TRUNCATE TABLE example_db.tbl;

Clear specified partitions​

Clear specified partitions

Clear only the p1 and p2 partitions of the tbl table:

TRUNCATE TABLE tbl PARTITION(p1, p2);

Clear data without recovery​

Clear data without recovery

Clear example_db.tbl while bypassing recycle-bin recovery:

TRUNCATE TABLE example_db.tbl FORCE;

Warning:

After using FORCE, data cannot be recovered via RECOVER. Confirm before executing.

Check cleanup constraints​

Before executing TRUNCATE, confirm the following conditions:

  • Only data is cleared, structure is retained: The table structure and partition definitions are retained; only data is cleared.
  • Filter conditions are not supported: You can only clear the entire table or specified partitions. WHERE conditions cannot be appended.
  • Table state must be NORMAL: A table that is performing SCHEMA CHANGE cannot be truncated.
  • Affects ongoing imports: May cause running import tasks to fail. Execute during idle import periods.
  • Check recovery before clearing data: Without FORCE, old partitions enter the recycle bin. Recovery requires retained metadata, compatible schema, and no conflicting active partition. It is not an automatic undo of the table operation.

Recover retained partitions​

Without FORCE, TRUNCATE retains the old partitions in the recycle bin and creates empty replacements. RECOVER TABLE does not undo this operation because the table still exists.

For a partitioned table, recovery uses RECOVER PARTITION. First inspect SHOW CATALOG RECYCLE BIN and confirm the old partition ID and retention with an administrator. A replacement partition with the same name or overlapping values must be moved or removed before recovery. Stop writes and preserve any new data before changing that partition.

The following statement illustrates recovery after the conflicting active partition has been handled. Replace <old-partition-id> with the retained ID:

RECOVER PARTITION p1 <old-partition-id> FROM example_db.tbl;

Schema or index changes after truncation can prevent recovery. For an unpartitioned table, or if you cannot safely resolve the partition conflict, contact VeloDB Cloud support before attempting recovery. See RECOVER for syntax and permissions.

Warning:

Retention is service-managed in VeloDB Cloud. Recovery is unavailable after FORCE or after the retained metadata expires. Keep a separate backup or reloadable source for data you must restore.

Compare TRUNCATE with DELETE​

Both can be used to delete data, but their applicable scenarios differ significantly:

Comparison ItemTRUNCATEDELETE
Deletion granularityEntire table or entire partitionRow-level, with optional WHERE conditions
Filtering supportedNoYes
Execution workReplaces active partition metadataEvaluates predicates or writes delete markers, depending on the table model
Execution speedDepends on partition creation and metadata workRelated to the number of matched rows
Recoverable by defaultOld partitions may be recovered subject to retention and conflicts (non-FORCE)Not directly recoverable
Typical scenariosLarge-scale clearing, partition rebuildPrecise deletion of small amounts of data

Choose a cleanup method:

  • To clear an entire table or an entire partition, prefer TRUNCATE.
  • To delete part of the data based on conditions, use DELETE.

Resolve common questions​

Retain the table structure​

No. TRUNCATE only clears data. The table structure, partition definitions, indexes, and other metadata are all retained.

Check recovery eligibility​

  • Without FORCE: Old partitions are eligible for recovery within retention, subject to name/range and schema checks. See Recover retained partitions.
  • With FORCE: Recycle-bin recovery is unavailable. Physical cleanup runs asynchronously.

Wait for schema changes​

No. The table state must be NORMAL; otherwise, the command reports an error. Wait for SCHEMA CHANGE to complete before executing.

Coordinate running loads​

It may cause ongoing import tasks to fail. Execute during idle import periods, or pause related imports first.

Choose between TRUNCATE and DROP TABLE​

  • TRUNCATE: Retains the table structure and only clears data.
  • DROP TABLE: Deletes the table itself, including its structure and data.

Delete selected rows in a partition​

No. TRUNCATE can only clear an entire table or specified partitions; it does not support row-level filtering. To delete by condition, use DELETE.