Link Search Menu Expand Document

DELETE

Deletes rows from the specified table.

Syntax

DELETE FROM <table> WHERE <expression>

Parameters

Parameter Description
<table> The table to delete rows from.
<expression> A Boolean expression. Only rows for which this expression returns true will be deleted. Condition can have subqueries doing semijoin with other table(s).

The DELETE FROM <table> without <expression> will delete all rows from the table. It is equivalent to a TRUNCATE TABLE statement.

Remarks

Deleted rows are marked for deletion, but are not automatically cleaned up. You can monitor fragmentation in information_schema.tables to understand how many rows are marked for deletion out of total rows; fragmentation = (rows marked for deletion / total rows). Total row count in information_schema.tables includes the number of rows marked for deletion. Query performance is not materially impacted by delete marks.

To mitigate fragmentation, use the VACUUM command to manually clean up deleted rows.

Example

The following example deletes entries from the levels table where the level is equal to 0:

DELETE FROM levels WHERE level = 0

Table before:

nickname level
esimpson 8
sabrina21 4
kennthpark 0
rileyjon 2
aaronbutler 1
ywilson 0

Returns:

nickname level
esimpson 8
sabrina21 4
rileyjon 2
aaronbutler 1

Known limitations

Below are some known limitations of the DELETE command.

  • Only one DELETE will be executed against a table at once.

  • DELETE cannot be used on tables that have certain aggregating indexes. An attempt to issue a DELETE statement on a table with an aggregating index outside of the below defined will fail- these table level aggregating indexes need to be dropped first. DELETE can be used on tables that have aggregating indexes containing the following aggregating functions:
  • Queries against tables with deleted rows are supported and can be run. However, expect slower performance.

  • DELETE marks are always loaded during engine warm-up, regardless of engine policy. This can increase engine start time if there are significant number of deletions.