TRUNCATE

Removes all rows from the table.

TRUNCATE is equivalent to running a DELETE which removes all the rows from the table but without all the overhead of deleting one row at a time.

Syntax

TRUNCATE [TABLE] <table_name>;

Remarks

  • SingleStore supports online TRUNCATE, which means that you can read and write while the table is being truncated. For Rowstore tables, TRUNCATE is the preferred method (vs DELETE).

  • Blocking: Note that online TRUNCATE will not begin truncating the table, but it will wait until all DML queries that were already running on the table finish. This allows any in-progress queries to complete execution before truncating the table, and ensures consistency of results from queries on the table since the time of execution of TRUNCATE. New read or write queries are blocked until the in-progress queries are finished and TRUNCATE has begun truncating the table. This blocking period lasts until all in-progress reads and writes have completed. TRUNCATE blocks the table via a lock.

    If you are frequently running TRUNCATE statements on a table and have a lot of long-running queries on that table, then your normal workload may experience some periods of delay since the TRUNCATE operation blocks other queries from starting while it waits for completion of long-running queries.

    The TRUNCATE operation throws a timeout error if there are long running DML queries in your workload, which extends the blocking period to several minutes.

    Refer to ISSUE: Long Running Queries Blocking DDL Operations and Workload for resolving query timeout errors due to long running queries in a workload.

  • This command can be run on the master aggregator node, or a child aggregator node (see Node Requirements for SingleStore Commands ).

  • This command causes implicit commits. Refer to COMMIT for more information.

  • Table memory can be freed when the TRUNCATE command is run. For information on when/how much table memory is freed when this command is run, see Memory Management.

  • Refer to the Permission Matrix for the required permission.

Example

TRUNCATE TABLE table_name;

Last modified: January 9, 2023

Was this article helpful?

Verification instructions

Note: You must install cosign to verify the authenticity of the SingleStore file.

Use the following steps to verify the authenticity of singlestoredb-server, singlestoredb-toolbox, singlestoredb-studio, and singlestore-client SingleStore files that have been downloaded.

You may perform the following steps on any computer that can run cosign, such as the main deployment host of the cluster.

  1. (Optional) Run the following command to view the associated signature files.

    curl undefined
  2. Download the signature file from the SingleStore release server.

    • Option 1: Click the Download Signature button next to the SingleStore file.

    • Option 2: Copy and paste the following URL into the address bar of your browser and save the signature file.

    • Option 3: Run the following command to download the signature file.

      curl -O undefined
  3. After the signature file has been downloaded, run the following command to verify the authenticity of the SingleStore file.

    echo -n undefined |
    cosign verify-blob --certificate-oidc-issuer https://oidc.eks.us-east-1.amazonaws.com/id/CCDCDBA1379A5596AB5B2E46DCA385BC \
    --certificate-identity https://kubernetes.io/namespaces/freya-production/serviceaccounts/job-worker \
    --bundle undefined \
    --new-bundle-format -
    Verified OK