TRUNCATE
On this page
The TRUNCATE command removes all rows from a table.
Syntax
TRUNCATE [TABLE] <table_name>Remarks
-
For rowstore tables,
TRUNCATEis the preferred method (vsDELETE). -
This command can be run on the master aggregator or a child aggregator (refer to Node Requirements for SingleStore Commands ).
-
Table memory can be freed when the
TRUNCATEcommand is run.For information on when/how much table memory is freed when this command is run, see Memory Management. -
The
TRUNCATEcommand does not support temporary tables. -
This command causes implicit commits.
Refer to COMMIT for more information. -
Refer to the Permissions Matrix for the required permissions.
Locking Behavior
SingleStore supports online TRUNCATE, which waits for DML queries that are already running on the target table to finish before it begins truncating the table.TRUNCATE command is run on the table.TRUNCATE acquires a database-level lock on the target table and then truncates the table.
Because TRUNCATE and ALTER TABLE share the database-level DDL operation lock, a concurrent ALTER TABLE or TRUNCATE on another table in the same database waits while the currently running operation holds the lock.TRUNCATE is waiting for DML on its target table.
TRUNCATE uses the same distributed DDL machinery as ALTER TABLE.ALTER TABLE or TRUNCATE operation can be in the two-phase commit (2PC) or commit path at a time.
Additionally, concurrent ALTER TABLE and TRUNCATE operations are not guaranteed to complete in the order in which they were issued.ALTER TABLE and TRUNCATE statements waiting for the database-level DDL operation lock.
For online ALTER TABLE, data-population that occurs after the 2PC commit can overlap with other operations after the database-level commit lock is released.TRUNCATE does not have a long-running data-population phase.
Delays and Timeout
If TRUNCATE statements are frequently run on a table that has a lot of long-running queries, then the workload may experience some additional delay because the TRUNCATE operation blocks other queries from starting while it waits for completion of long-running queries.
The TRUNCATE command throws a timeout error if there are long running DML queries in your workload which extend the blocking period to several minutes.
Refer to Query Errors for resolving query timeout errors due to long running queries in a workload.
Example
TRUNCATE TABLE testTable;
Related Topics
Last modified: