Syntax
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:Restrictions
A statement that returns a result set, such asSELECT, 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
ThePARALLEL WITH clause is a bit similar to UNION, which also executes its operands in parallel. However there are some differences:
PARALLEL WITHdoesn’t return any results from executing its operands, it can only rethrow an exception from them if any;PARALLEL WITHcombines statements that neither return a result set nor expect input data, whileUNIONcombinesSELECTqueries.