ClickHouse DELETE in 26.11: lightweight DELETE is still a mutation by default
In ClickHouse 26.11 DELETE FROM is still a mutation by default: a count() over every part, then a _row_exists rewrite. One delete of 0 rows took 212 s.
In January 2024 a ClickHouse user ran a lightweight DELETE that matched no rows. It took 211.956 s. The same WHERE in a SELECT took 0.233 s (issue #59225, version 23.8.2). The table had about 55,000 parts per node, and that is the whole explanation. In ClickHouse, DELETE FROM is not a row operation. It is a mutation that visits parts, and its cost depends on how many parts there are and how they are stored, not on how many rows you delete.
Day 16 of this series was planned as “lightweight DELETE vs ALTER DELETE vs ReplacingMergeTree tombstones”. The surprise: nearly three years after that report, in ClickHouse 26.11, DELETE FROM is still a mutation by default. The cheap kind of delete, a patch part, is there, but you have to switch it on per table and per session. This post explains what each delete method writes, what it costs when you run it, and what it keeps costing afterwards.
Everything below comes from the source at tag v26.11.1.2942-stable, the 26.11 changelog, ClickHouse’s docs and blog, and numbers other people have published in GitHub issues. Nothing was benchmarked for this post.
The short answer
| Question | Answer (26.11) |
|---|---|
What does DELETE FROM t WHERE … run? |
ALTER TABLE t UPDATE _row_exists = 0 WHERE …, a mutation (lightweight_delete_mode = 'alter_update') |
| Does it wait? | Yes: lightweight_deletes_sync = 2, it waits for every replica. ALTER TABLE … DELETE doesn’t wait (mutations_sync = 0) |
| What does it write? | A new _row_exists column for each part with matching rows (Wide parts); Compact parts are rewritten whole |
What does ALTER TABLE … DELETE write? |
Every column of every part with matching rows |
| What does every delete do first? | A SELECT count() … WHERE on each part, to find the parts it touches |
| When is the row gone from disk? | At the next merge of that part, not before |
| Is there a delete that writes almost nothing? | Yes: a patch part, with lightweight_delete_mode = 'lightweight_update' and two table settings, both off by default |
ReplacingMergeTree is_deleted? |
An insert. Cheapest to write, but every read needs FINAL and the row never leaves the disk without an experimental cleanup |
Four ways to delete a row
Every MergeTree part is immutable. A delete can only do one of four things: rewrite the parts that hold the row, write a small “this row is gone” marker next to them, write a separate patch, or insert a newer row that says “deleted”. ClickHouse has one method for each.
The details, read from the 26.11 source:
ALTER TABLE t DELETE WHERE p is the classic mutation. In MutationsInterpreter.cpp a DELETE command becomes a stage that “affects all columns” with the filter isZeroOrNull(p), and it sets need_rebuild_projections and need_rebuild_indexes_for_update_delete. Every part that contains a matching row is read and written again, every column, plus its skip indexes and projections. It runs in the background: mutations_sync defaults to 0, so the statement returns before the work is done.
DELETE FROM t WHERE p is the “lightweight” delete. InterpreterDeleteQuery.cpp turns it into the text ALTER TABLE t UPDATE _row_exists = 0 WHERE p and runs that, with mutations_sync replaced by lightweight_deletes_sync. So it is a mutation too, of one column: the hidden _row_exists mask. On a Wide part (one file per column) only that column is written and the other files are hard-linked into the new part. On a Compact part (all columns in one file, the format for small parts) every column is rewritten (MutateTask.cpp, rewritesAllPartColumns).
DELETE FROM with lightweight_delete_mode = 'lightweight_update' takes a different branch of the same function. It runs UPDATE t SET _row_exists = 0 WHERE p, which is a lightweight update: ClickHouse writes a small patch part with the keys of the deleted rows and leaves the existing parts alone. Reads apply the patch on the fly. Merges fold it in later.
ReplacingMergeTree(ver, is_deleted) doesn’t delete at all. You insert the row again with a higher version and is_deleted = 1. Queries with FINAL skip it. Merges keep the newest row for each key, and by default that is the tombstone itself, so it stays on disk. Removing it needs OPTIMIZE … FINAL CLEANUP, behind the table setting allow_experimental_replacing_merge_with_cleanup (still experimental and off by default in 26.11). Day 11’s post on ReplacingMergeTree duplicates covers that engine in depth.
| Method | Writes | Visible to queries | Gone from disk | Default in 26.11 |
|---|---|---|---|---|
ALTER TABLE … DELETE |
all columns of touched parts | when the mutation finishes | when the mutation finishes | async (mutations_sync = 0) |
DELETE FROM (alter_update) |
_row_exists of touched Wide parts; all columns of Compact ones |
when the statement returns | at the next merge of the part | yes, waits for all replicas |
DELETE FROM (lightweight_update) |
one patch part | when the statement returns | when merges apply the patch | opt-in, needs 2 table settings |
ReplacingMergeTree is_deleted = 1 |
one inserted row | only with FINAL |
only with experimental CLEANUP |
n/a (engine choice) |
Why deleting zero rows can take minutes
Both mutation paths start the same way. Before touching a part, ClickHouse asks whether it needs to. isStorageTouchedByMutations builds SELECT count() FROM <part> WHERE p and runs it on each part (MutationsInterpreter.cpp, prepareQueryAffectedAST). A part whose count is 0 isn’t rewritten: it gets the new mutation version in its name and is cloned with hard links. That is cheap per part but not free, and it happens per part: with 55,000 parts, a delete that matches nothing still runs 55,000 small counts and renames 55,000 parts. That is issue #59225 in one sentence.
The count is a normal SELECT, so the primary key and skip indexes can prune inside each part. Partitions are a different matter. In 26.11 the only way to skip whole partitions without running the count is an explicit IN PARTITION: the code compares the partition ID first and returns “no rows” without a query. A list of partitions is accepted since 26.9. There is also optimize_mutations_with_partition_pruning (new in 26.9, on by default), which finds the partitions from the WHERE clause by itself, but its own description says it “currently applies only to replicated tables”. On a plain MergeTree you still write:
DELETE FROM events IN PARTITION '2026-11' WHERE user_id = 42;
The second cost is the read itself. Issue #68264 (2024) showed that a mutation reads one mark range at a time. On a 100-million-row table with index_granularity = 128, a one-row DELETE took 11.8 s, while the matching SELECT with one thread took about 2 s. With the default granularity of 8192 the same delete took about 1 s. The issue is still open. Day 9’s post on index_granularity explains why tiny granules cost more everywhere.
Then there’s waiting. lightweight_deletes_sync defaults to 2, so DELETE FROM returns only when every replica has finished. ALTER TABLE … DELETE returns at once. A 2023 forum test that found ALTER DELETE “faster” (164 ms against 2.49 s, discussion #49767) was timing a queued mutation against a finished one. And mutations queue up: at 500 unfinished mutations on a table ClickHouse starts delaying new ones (number_of_mutations_to_delay), and at 1,000 it refuses them with “Too many mutations” (number_of_mutations_to_throw, MergeTreeSettings.cpp). One help for many single-row deletes arrived recently: when several queued UPDATE _row_exists = 0 WHERE key IN (…) commands reach the same large Wide part, ClickHouse now merges them into one predicate, up to 256 keys (#122718, enable_row_mask_update_coalescing, on by default in 26.10 and backported to 26.8).
The delete that writes almost nothing: patch parts
Lightweight updates arrived in 25.7, were on by default as a beta from 25.8 (enable_lightweight_update = 1) and were promoted to production in October 2026 (#125719). DELETE FROM can use them, but only if all of these hold (MergeTreeData::supportsLightweightUpdate and InterpreterDeleteQuery, 26.11):
- the session sets
lightweight_delete_mode = 'lightweight_update'(defaultalter_update); - the table has
enable_block_number_column = 1andenable_block_offset_column = 1, both false by default: the patch needs them to find the rows again; - the engine is not Summing, Aggregating or GraphiteMergeTree, and the table has no
UNIQUE KEY.
If any condition fails, lightweight_update quietly falls back to the mutation. Use lightweight_update_force instead and the DELETE throws, which is the better choice when you rely on it.
ALTER TABLE events MODIFY SETTING enable_block_number_column = 1, enable_block_offset_column = 1;
SET lightweight_delete_mode = 'lightweight_update_force';
DELETE FROM events WHERE user_id = 42; -- writes one patch part
How fast is it? ClickHouse’s own benchmark (Tom Schreiber, “How we made ClickHouse UPDATEs 1,000× faster, Part 3”, ClickHouse 25.7, 600 million TPC-H rows in one part on an m6i.8xlarge) says plainly: “We didn’t benchmark DELETEs separately.” It argues that a delete is either a mutation of _row_exists or a patch of it, and so is represented by the update numbers. With that caveat, for a single-row change:
| Method (25.7, their benchmark) | Time to apply one single-row change | Worst-case cost on later reads (their summary table) |
|---|---|---|
| Classic mutation | 90–170 s | baseline |
| Lightweight update (patch part) | 0.04–0.07 s | +7–21% |
| ReplacingMergeTree insert | 0.03–0.04 s | +21–550% (FINAL) |
| On-the-fly mutation | ~0.03 s | +12–427% |
The read costs are measured with background merges switched off, the worst case: once a merge applies the patch, the overhead goes away. The Part 2 post adds a limit that matters for frequent deletes: patch parts are parts, and they count toward the TOO_MANY_PARTS limits like any insert.
What a delete keeps costing afterwards
A _row_exists delete is fast to read past: each read gets an extra filter step on the mask, like a PREWHERE (createLightweightDeleteStep in MergeTreeBlockReadUtils.cpp). The rows still use disk, and some shortcuts stop working until a merge removes them:
count()stops being free. Without deletes,SELECT count()reads the row count from part metadata. With a mask it has to read a column (#47930, open since 2023). From 25.12 to 26.10 it read the column with the smallest type, which could be “more than 1000 times larger” than the smallest column on disk. 26.11 goes back to the smallest column on disk (#131371).- The planner counts deleted rows. On a 26.11 pre-release build, a table whose 4 million rows had all been deleted was still estimated at 4 million rows, so join reordering built the hash table from the wrong side: 5.4–5.8 s instead of 0.28–1.85 s, 2.9× to 20.8× slower (#133496, opened 22 November 2026, still open).
- The query condition cache was switched off for the whole table by a single lightweight delete, until a fix in August 2026 (#112947).
- Projections block it.
lightweight_mutation_projection_modeis a table setting and defaults tothrow, soDELETE FROMfails on a table with projections until you choosedroporrebuild. 26.11 made the error message say so (#128701) and fixed rebuilt projections returning deleted rows (#111809). IN (SELECT …)deletes read the subquery’s table in full from 26.6 until 26.11 restoredPREWHEREthere (#125031).
When the bytes matter (privacy deletes, for example), you can force them out. ALTER TABLE t APPLY DELETED MASK rewrites the parts that carry a mask, and the docs suggest min_age_to_force_merge_seconds if rows must be gone by a deadline. ReplacingMergeTree tombstones have no such path outside the experimental CLEANUP.
Which one to use
- Delete whole partitions when you can.
ALTER TABLE … DROP PARTITIONor a TTL that drops parts removes files and runs no count at all. Design the partition key around how data leaves the table. - Occasional deletes of a few rows:
DELETE FROMwithIN PARTITION, keep the part count low, and leavelightweight_deletes_syncat its default when the next query has to see the result. - Frequent small deletes: turn on the two block columns and use
lightweight_delete_mode = 'lightweight_update_force'. Watch the part count, because every patch is a part. - Large deletes (a big share of a table):
ALTER TABLE … DELETE, run off-peak, and checksystem.mutationsuntil it’s done. You pay for one rewrite and the reads stay clean. - Rows that change and disappear all the time: a ReplacingMergeTree with
is_deletedis still the cheapest write, if you can affordFINALon every read. ClickHouse’s guide recommends it only while deletes stay under about 10% of the rows.
FAQ
Is DELETE FROM faster than ALTER TABLE DELETE?
For a few rows on Wide parts, yes: it writes one small column instead of every column. Both run the same per-part count() first, and DELETE FROM waits for the result while ALTER DELETE returns at once, so a stopwatch can mislead you.
Does lightweight DELETE free disk space?
No. It hides the rows. The space comes back when the part is merged, or after ALTER TABLE … APPLY DELETED MASK.
Why is my DELETE slow even though it matches nothing?
It visits every part to count matches. Many parts, many partitions or a small index_granularity make that slow. Add IN PARTITION so it skips partitions without counting.
Can I undo a lightweight delete?
Until a merge removes the rows, SET apply_deleted_mask = 0 makes queries see them again. The setting’s own description mentions debugging and “undelete”. After a merge they’re gone.
How do I make DELETE FROM use patch parts?
ALTER TABLE t MODIFY SETTING enable_block_number_column = 1, enable_block_offset_column = 1, then SET lightweight_delete_mode = 'lightweight_update_force'. It doesn’t work on Summing, Aggregating or Graphite MergeTree tables.
Tomorrow, Day 17: the JSON type vs Map vs String with JSONExtract. What each one stores, and what it costs to read.