Skip to main content
Allows to execute multiple statements in parallel.

Syntax

Executes statements statement1, statement2, statement3, … in parallel with each other. Only statements that neither return a result set nor expect input data can be combined, see Restrictions. Executing statements in parallel may be faster than just a sequence of the same statements in many cases. For example, statement1 PARALLEL WITH statement2 PARALLEL WITH statement3 is likely to be faster than statement1; statement2; statement3.

Examples

Creates two tables in parallel:
Drops two tables in parallel:

Restrictions

A statement that returns a result set, such as SELECT, or expects input data is rejected with the INCORRECT_QUERY error. DDL executed ON CLUSTER or through the DDL log of a Replicated database returns a status table, so it is rejected too, but only after it has been sent to the hosts, which still execute it. It can be combined if distributed_ddl_output_mode is none or none_only_active:

Settings

Setting max_threads controls how many threads are spawned.

Comparison with UNION

The PARALLEL WITH clause is a bit similar to UNION, which also executes its operands in parallel. However there are some differences:
  • PARALLEL WITH doesn’t return any results from executing its operands, it can only rethrow an exception from them if any;
  • PARALLEL WITH combines statements that neither return a result set nor expect input data, while UNION combines SELECT queries.