number_of_mutations_to_throw unfinished ones (1000 by default). After that, every ALTER TABLE ... UPDATE, ALTER TABLE ... DELETE, DELETE FROM and other mutating ALTER fails with TOO_MANY_MUTATIONS (code 692). Mutations are applied in the order they were created, so usually one mutation that can never finish is at the head of the queue and everything else waits behind it. Find that mutation in system.mutations, remove it with KILL MUTATION, and the rest of the queue is processed.
Example
To keep the example short, the limit is lowered to 5 for this table:String to UInt32 rewrites the column with a mutation. The mutation fails on the value 'n/a', and the ALTER reports it (shortened here):
UInt32, and the mutation stays in the queue and is retried again and again. With alter_sync = 0 the ALTER does not wait for the mutation and returns without any error, which makes the problem harder to notice.
Reading the column now fails, because the stored strings are converted on the fly:
DELETE FROM readings WHERE id = 105, and so is an ALTER TABLE readings MODIFY COLUMN value String that tries to undo the type change.
Find the mutation that blocks the queue
Look at the oldest unfinished mutation that has a failure reason:latest_fail_reason, because a part has to pass the earlier mutation first. The oldest one is the cause.
If no unfinished mutation has a failure reason, the queue is not blocked by an error: mutations are submitted faster than the table applies them. See Other causes.
Fix it
Kill the blocking mutation only:KILL MUTATION removes the mutation from the queue, but it does not undo a schema change. After a failed MODIFY COLUMN, the table definition still has the new type and SELECT still fails, so change the column back to the type that the data has:
DELETE WHERE id = 100 has been applied:
UPDATE or DELETE with an expression that fails, killing it is enough: there is no schema change to undo.
KILL MUTATION WHERE database = ... AND table = ... without a mutation_id kills all unfinished mutations of the table. Use it only if you are ready to submit the other mutations again.
To do the type change properly, first make the data convertible, then change the type:
Other causes
- Many small mutations. An application that sends one
ALTER TABLE ... UPDATEorDELETEper row or per event can fill the queue even though each mutation succeeds. Combine the changes into fewer statements. See How do I view the number of active or queued mutations? to watch the queue. Nullableto non-Nullable. Before ClickHouse 25.12,MODIFY COLUMNfrom aNullabletype to a non-Nullabletype got stuck in the same way when the column containedNULL. Since 25.12 such anALTERis rejected unless it has aDEFAULTexpression, andNULLvalues are replaced with that default, for exampleALTER TABLE t MODIFY COLUMN c String DEFAULT ''.
About the limits
number_of_mutations_to_throw(default 1000) is the number of unfinished mutations at which new ones are rejected.number_of_mutations_to_delay(default 500) is the number at which each new mutation is delayed for a short time before it is accepted.
MergeTree settings that you can change for a table with ALTER TABLE ... MODIFY SETTING. Raising them does not make the queue shorter: it only postpones the error, so fix the cause first.
For other ways to find failing mutations, see How to find failed merges and mutations.