Updated on 2025-03-13 GMT+08:00

DELETE

  • [Rule] The DELETE statement must contain the WHERE clause to avoid full table scan.
  • [Rule] Do not use ORDER BY or GROUP BY in the DELETE statement to avoid unnecessary sorting.
  • [Rule] Use TRUNCATE instead of DELETE to clear a table.

    TRUNCATE creates a new physical file and physically deletes the original file when the transaction ends to clear the disk space. However, the DELETE statement marks data in the table and does not clear the disk space until the VACUUM FULL phase.

  • [Recommendation] If a DELETE statement is executed on a table that has a primary key or index, the WHERE condition must be used together with the primary key or index to improve execution efficiency.