Truncate is a powerful statement in Data Definition Language (DDL) that allows users to quickly and efficiently delete all rows from a table. It is treated as a DDL statement, meaning it does not retain undo information like DML statements. This makes it incredibly fast and efficient, allowing users to quickly reset the highest watermark in a table. Logically, Truncate is similar to a DELETE statement that deletes all rows, or to a sequence of DROP TABLE and CREATE TABLE statements.
When used with partitioned tables, Truncate preserves the partition; data and index files are removed and recreated, while partition definitions remain intact. This is an important aspect of the Sch-M lock, as while Truncate is in progress, a table cannot be modified in any way. Additionally, Truncate is treated for binary registration and replication purposes as DDL instead of DML. In computer applications, truncation error is the discrepancy that arises when executing a finite number of steps to approach an infinite process. In numerical analysis and scientific computing, the truncation error is the error caused by the approximation of a mathematical process.
To have Truncate create the tablespace in its current location, add the directory to the innodb_directories configuration before running Truncate. Truncate is incredibly useful for quickly resetting a table without having to manually delete each row. It can also be used to recreate a table if its data or index files have been corrupted. This makes it an invaluable tool for database administrators who need to quickly reset tables or recreate them from scratch. Overall, Truncate is an incredibly useful tool for database administrators who need to quickly reset tables or recreate them from scratch. It allows users to quickly and efficiently delete all rows from a table without having to manually delete each row.
Additionally, it can be used with partitioned tables to preserve the partition while deleting data and index files.