DELETE
On this page
DELETE
is a DML statement that deletes rows in a table.
Syntax
DELETE FROM tbl_name
[WHERE expr]
[LIMIT row_count]
DELETE tbl_name FROM table_references
[WHERE expr]
[LIMIT row_count]
Arguments
table_
One or more tables to reference during the delete operation.table_
.
tbl_
Table from which rows will be deleted.
where_
One or more expression that evaluates to true for each row to be deleted.
row_
The maximum number of rows that can be deleted.
Remarks
-
The
DELETE
statement deletes rows fromtbl_
and returns the number of deleted rows.name -
Although
DELETE
supports referencing multiple tables using either joins or subqueries, SingleStore Helios only supports deleting from one table in aDELETE
statement. -
If the
maximum_
limit has been reached,table_ memory DELETE
queries can still be executed to remove data from the table, but largeDELETE
queries may fail if themaximum_
limit has been reached.memory -
Caution should be taken as
DELETE
queries allocate extra memory to mark rows as deleted.For rowstore tables, this equates to roughly 40 + 8*number_ of_ indexes bytes per deleted row. For columnstore tables, the memory usage will be lower because of how rows are marked to be deleted (roughly num_ rows_ in_ table/8 bytes if you delete a row in every segment file in the table). -
If the table is narrow, such as containing a small number of int columns,
DELETE
queries will show up as a relatively large spike in memory usage compared to the size of the table. -
The memory for a deleted row is reclaimed after the transaction commits and the memory is freed asynchronously by the garbage collector.
-
If you need to delete all records from a large table, use
TRUNCATE
instead.TRUNCATE
does not incur the memory penalty ofDELETE
; however, if you do need to runDELETE
over a large number of rows in a rowstore table, performDELETE
s in smaller batches usingLIMIT
to minimize the additional memory usage. -
Writing to multiple databases in a transaction is not supported.
-
For performance limitations refer to UPDATE
-
Refer to the Permission Matrix for the required permission.
Example
DELETE FROM mytbl WHERE seq = 1;DELETE FROM mytable LIMIT 100000;DELETE FROM mytblWHERE id IN (SELECT id FROM myother) LIMIT 10;DELETE t_rec FROM t_rec JOIN t_invalidWHERE t_rec.id = t_invalid.id;DELETE t_rec FROM t_rec JOIN(SELECT id FROM t_rec ORDER BY score LIMIT 10)tempWHERE t_rec.id=temp.id;DELETE b FROM a, b, cWHERE a.name = b.name OR b.name = c.name;DELETE x FROM looooooooooongName as x, yWHERE x.id = y.id;
Last modified: July 23, 2024