KILL Statements

There are two kinds of kill statements: to kill a query and to kill a mutation

KILL QUERY

  1. KILL QUERY [ON CLUSTER cluster]
  2. WHERE <where expression to SELECT FROM system.processes query>
  3. [SYNC|ASYNC|TEST]
  4. [FORMAT format]

Attempts to forcibly terminate the currently running queries.
The queries to terminate are selected from the system.processes table using the criteria defined in the WHERE clause of the KILL query.

Examples:

  1. -- Forcibly terminates all queries with the specified query_id:
  2. KILL QUERY WHERE query_id='2-857d-4a57-9ee0-327da5d60a90'
  3. -- Synchronously terminates all queries run by 'username':
  4. KILL QUERY WHERE user='username' SYNC

Read-only users can only stop their own queries.

By default, the asynchronous version of queries is used (ASYNC), which doesn’t wait for confirmation that queries have stopped.

The synchronous version (SYNC) waits for all queries to stop and displays information about each process as it stops.
The response contains the kill_status column, which can take the following values:

  1. finished – The query was terminated successfully.
  2. waiting – Waiting for the query to end after sending it a signal to terminate.
  3. The other values ​​explain why the query can’t be stopped.

A test query (TEST) only checks the user’s rights and displays a list of queries to stop.

KILL MUTATION

  1. KILL MUTATION [ON CLUSTER cluster]
  2. WHERE <where expression to SELECT FROM system.mutations query>
  3. [TEST]
  4. [FORMAT format]

Tries to cancel and remove mutations that are currently executing. Mutations to cancel are selected from the system.mutations table using the filter specified by the WHERE clause of the KILL query.

A test query (TEST) only checks the user’s rights and displays a list of mutations to stop.

Examples:

  1. -- Cancel and remove all mutations of the single table:
  2. KILL MUTATION WHERE database = 'default' AND table = 'table'
  3. -- Cancel the specific mutation:
  4. KILL MUTATION WHERE database = 'default' AND table = 'table' AND mutation_id = 'mutation_3.txt'

The query is useful when a mutation is stuck and cannot finish (e.g. if some function in the mutation query throws an exception when applied to the data contained in the table).

Changes already made by the mutation are not rolled back.