A range deletion removes a contiguous set of rows within one partition by using comparison operators on an ordered clustering-key value. It is useful when the rows to remove are defined by a boundary, such as “before this time,” rather than by a list of exact row IDs. In CQL, use a normal DELETE statement, name the partition with = or IN, and add <, >, <=, or >= conditions for the clustering key. section 6.2.4
The partition key must still identify a known partition. A condition such as date_bucket < 1 is rejected because it could require checking an unknown number of partitions. Scylla can route a request for date_bucket = 0 by its partition key, then apply the range condition to rows ordered within that partition. section 6.2.4
Table 6.1 Scylla supports the typical comparison operators.
|
Operator
|
Meaning
|
Valid example
|
|---|---|---|
=
|
Equal to
|
1 = 1
|
>
|
Greater than
|
2 > 1
|
<
|
Less than
|
28 < 34
|
>=
|
Greater than or equal to
|
247 >= 12
|
<=
|
Less than or equal to
|
43 <= 66
|
Use comparison operators to express an open or closed deletion boundary: < and > exclude the boundary value, while <= and >= include it. section 6.2.4
Delete article summaries in a time range
In article_summaries_by_date, date_bucket identifies the partition and id is a TIMEUUID clustering value. This deletes summaries in bucket 0 whose IDs fall after 2023-09-14 and before 2023-09-17: DELETE FROM article_summaries_by_date WHERE date_bucket = 0 AND id < minTimeUuid('2023-09-17 00:00:00') AND id > maxTimeUuid('2023-09-14 00:00:00'); minTimeUuid and maxTimeUuid turn timestamps into TIMEUUID boundary values, allowing the deletion to follow the ordering of the id column. section 6.2.4 section 6.6
Choose the deletion form that matches the scope of the rows:
- Use DELETE with an exact clustering-key value for one row. section 6.2.4
- Use IN when several known clustering-key values should be deleted together; every target value must be enumerated. section 6.2.4
- Use comparison operators when the target rows form an ordered interval inside a specified partition. section 6.2.4
- Use TRUNCATE when every row in the table should be removed, rather than a range within one partition. section 6.2.4 section 6.6
Deletion is not immediately equivalent to erasing storage. Scylla records deleted data with tombstones, which remain until compaction can remove them after gc_grace_seconds. Repair must synchronize tombstones during that period to avoid data resurrection. section 6.6
