DELETE
Name
DELETE
Description
This statement is used to conditionally delete data in the specified table (base index) partition.
This operation will also delete the data of the rollup index related to this base index.
Syntax:
DELETE FROM table_name [PARTITION partition_name | PARTITIONS (p1, p2)]
WHERE
column_name1 op { value | value_list } [ AND column_name2 op { value | value_list } ...];
Note:
- The optional types of op include: =, >, <, >=, <=, !=, in, not in
- Only conditions on the key column can be specified when using AGGREGATE (UNIQUE) model.
- When the selected key column does not exist in a rollup, delete cannot be performed.
- Conditions can only have an "and" relationship. If you want to achieve an "or" relationship, you need to write the conditions in two DELETE statements.
- If it is a partitioned table, you can specify a partition. If not specified, Doris will infer partition from the given conditions. In two cases, Doris cannot infer the partition from conditions: 1) the conditions do not contain partition columns; 2) The operator of the partition column is not in. When a partition table does not specify the partition, or the partition cannot be inferred from the conditions, the session variable delete_without_partition needs to be true to make delete statement be applied to all partitions.
Please also note that:
- This statement may reduce query efficiency for a period of time after execution.
- The degree of impact depends on the number of delete conditions specified in the statement.
- The more conditions you specify, the greater the impact.
Example
-
Delete the data row whose k1 column value is 3 in my_table partition p1
DELETE FROM my_table PARTITION p1 WHERE k1 = 3;
-
Delete the data rows where the value of column k1 is greater than or equal to 3 and the value of column k2 is "abc" in my_table partition p1
DELETE FROM my_table PARTITION p1 WHERE k1 >= 3 AND k2 = "abc";
-
Delete the data rows where the value of column k1 is greater than or equal to 3 and the value of column k2 is "abc" in my_table partition p1, p2
DELETE FROM my_table PARTITIONS (p1, p2) WHERE k1 >= 3 AND k2 = "abc";
Keywords
DELETE