Skip to main content
The ALTER does not go through because earlier mutations of the same table have not finished. A common cause is a mutation that fails on every attempt: everything submitted after it queues up behind it. Find that mutation in system.mutations, read its latest_fail_reason, and either wait for it or remove it with KILL MUTATION.

The error

In ClickHouse Cloud, an ALTER such as DROP PROJECTION can be rejected with a message of this form:
The message names the oldest and the newest unfinished mutation of the table, and it suggests a retry. A retry can only help if these mutations make progress. If one of the unfinished mutations fails on every attempt, deal with it first. A self-managed MergeTree table in the same situation reports it differently, as the example below shows. The diagnosis and the fix are the same.

Example

Create a table and a mutation that cannot succeed:
The UPDATE returns without an error, because mutations run asynchronously by default. A later ALTER then fails:
On this self-managed table, the ALTER is not undone. SHOW CREATE TABLE page_views no longer lists the projection, and DROP PROJECTION by_user is queued as mutation_3.txt behind the failing mutation. Failed mutations are retried with growing delays, so depending on the timing the statement can also wait for a long time before it returns this error.

Find the mutation that blocks the queue

The long latest_fail_reason values are shortened here. Read the result like this:
  • A failure is recorded for every mutation that was applied to the part in the same attempt, so all rows can show the same latest_fail_reason. The position of a row does not tell which mutation fails: a valid mutation that was submitted before the failing one, but was not applied yet, reports the same reason.
  • Find the failing mutation by its command. The full text of the reason names the expression that failed after while executing, here toUInt32(duration_text), and only mutation_2.txt contains it. If the reason does not make it clear, test the expression of every unfinished command with a SELECT.
  • An empty latest_fail_reason and a parts_to_do value that goes down between two runs of the query mean that the mutation is working. Wait for it, then run the ALTER again.
  • The same latest_fail_reason in every run means that the mutation will not finish on its own.
In ClickHouse Cloud, system.mutations on every node shows all mutations. In a self-managed cluster, query all replicas with clusterAllReplicas.

Remove the stuck mutation

The mutation that was queued behind it now completes:
Keep in mind:
  • KILL MUTATION does not roll back the parts that the mutation has already rewritten.
  • In ClickHouse Cloud, a killed mutation can stay at is_killed = 1 and is_done = 0 for a while if another long-running mutation is ahead of it.
  • Before you repeat the ALTER that failed, check SHOW CREATE TABLE and system.mutations. It may be applied or queued already, as in this example.
Then fix the cause and submit the mutation again. Here the cause is a function that throws an exception for one row:
An ALTER that drops or renames a column used by an unfinished mutation is rejected right away, with the same remedy:

How to avoid it

  • Test the expression of an UPDATE or DELETE with a SELECT before you submit the mutation. In the example, SELECT count() FROM page_views WHERE toUInt32OrNull(duration_text) IS NULL returns 1, the row that makes toUInt32 fail.
  • Do not send many ALTER statements to one table at the same time. Combine them into one statement, or run them one after another and wait for each, as described in Concurrent ALTER assignment on one table.
  • Watch the number of unfinished mutations, see How do I view the number of active or queued mutations?.