Why automatic parallel replicas
In ClickHouse Cloud every replica of a service can read all of its data, but by default a query runs on the one replica that received it. Parallel replicas let one query use all replicas at once: each replica reads a share of the data, processes it, and sends its partial result to the replica that received the query, which combines them. Whether that pays off depends on the query:- A query that reads a lot of data and reduces it to a small result, such as a query with very selective filters or a low-cardinality aggregation, can run several times faster with parallel replicas.
- A query that reads little data, or whose replicas have to send back almost as much as they read,
such as a
GROUP BYover a very high-cardinality column, usually gets slower: the extra network transfer and the final merge cost more than the parallel reading saves.
enable_parallel_replicas = 1, for a user, a profile, or the whole service, is
all-or-nothing: the setting applies to every query, the ones that get faster and the ones that get slower.
Automatic parallel replicas make the choice per query instead.
What it does
When automatic parallel replicas are enabled:- The first time a query runs, it runs on one replica as usual. While it runs, ClickHouse collects certain execution statistics and remembers them in an in-memory cache.
- The next time the same query runs, ClickHouse compares two estimates, one replica against all replicas, and picks the faster one.
- When in doubt, the query runs on one replica, exactly as without the feature. A query is never moved to parallel replicas unless the model predicts that it pays off.

Enabling automatic parallel replicas
Automatic parallel replicas build on the regular parallel replicas setup, plus one setting:cluster_for_parallel_replicas is default. max_parallel_replicas is the largest
number of replicas a query may use; values above the number of replicas in the service are capped to it.
To enable it for every query of a user, put the settings into a
settings profile:
Modes
enable_parallel_replicas = 2 forces parallel replicas for a query and turns the automatic decision off.
Use it to ensure that the query will use parallel replicas regardless of the automatic decision.
To enforce the opposite (execution on a single replica), use SETTINGS enable_parallel_replicas = 0.
SETTINGS automatic_parallel_replicas_mode = 0 is not the same: it turns the automatic decision off, and with
enable_parallel_replicas = 1 the query then uses parallel replicas whenever it supports them.
Examples
The examples below come from ClickBench and TPC-H runs on ClickHouse Cloud services. Times are the fastest of several runs. With parallel replicas forced on, two ClickBench queries that read about as much data move in opposite directions. The difference is how much the replicas have to send back:
A query that switches
GROUP BY reduce that to about 0.5 MB of partial results.
On a service with three replicas, splitting the reading three ways saves far more than sending 0.5 MB
costs, so ClickHouse switches to parallel replicas: the query goes from ~200 ms on one replica to ~100 ms.
A query that stays on one replica
(WatchID, ClientIP) pair is unique, so the partial results
the replicas would send back are ~2 GB, more than they read. ClickHouse keeps the query on one replica:
it takes ~500 ms, the same as without automatic parallel replicas. Forcing parallel replicas on this query
makes it 2.8 times slower, ~1,400 ms.
A query that reads the same data on every replica
For some queries parallel replicas split the reading of only one table between the replicas. Every other table in the same query is read in full by each replica. The time estimate alone may say parallel replicas would be faster, but the lion’s share of the reading would be duplicated on every replica. In such cases, ClickHouse also keeps the query on one replica.How it works
Every time a query is planned, ClickHouse goes through these steps:- Size check. ClickHouse estimates how much the query will read. Under N MiB per replica
(
automatic_parallel_replicas_min_bytes_per_replica, 1 MiB by default), parallel replicas can’t pay off, and the query runs on one replica without further work. - Statistics. If there are no statistics for this query yet, it runs on one replica and ClickHouse records two numbers: the compressed bytes it reads, and the compressed bytes replicas would have to send back.
- Decision. If there are statistics, ClickHouse compares the time to read everything on one replica with the time to read a share on each replica plus sending the results back, and picks the faster one. A query that was estimated to be faster with parallel replicas, but that would also read most of its data on every replica in full, stays on one replica.

Related settings and tuning
The defaults suit most workloads.
The regular parallel replicas settings apply as well:
max_parallel_replicas,
cluster_for_parallel_replicas, and
parallel_replicas_local_plan,
which must stay enabled (the default). parallel_replicas_min_number_of_rows_per_replica is ignored when
the automatic mode is on.
Observability
Each query records what automatic parallel replicas did in theProfileEvents column of
system.query_log. This query shows the latest queries with their
events:
For more detail, the decisions are logged at
Trace level by the AutoParallelReplicas logger, including
the reason a query was skipped and the numbers the decision was based on. Run a query with
SETTINGS send_logs_level = 'trace', or search system.text_log for
logger_name = 'AutoParallelReplicas'.
Limitations
- The first run doesn’t benefit. A query is decided on its second run on a replica. Queries that run only once always run on one replica.
- Statistics are per replica and in memory. If your queries go to different replicas, each replica collects its own statistics first. The storage is an in-memory SLRU cache that can keep up to 1 million entries. The cache is lost when a replica restarts.
- Only queries that parallel replicas support. For example, queries with
FINALalways run on one replica. See the parallel replicas limitations. - Some query shapes stay on one replica. Queries with some steps, such as
UNION,DISTINCTorARRAY JOIN, or withGLOBAL INandGLOBAL JOIN, are not considered by automatic parallel replicas yet. Support for more shapes will be added in new releases. - Compute-heavy queries can be missed. The decision is based on bytes read and sent back, not on
processing time. A query that does heavy processing on little data can stay on one replica although it
would be faster with parallel replicas. Setting
enable_parallel_replicas = 2forces parallel replicas for such a query.
What’s next
Automatic parallel replicas are generally available, and we continue to improve them. The next steps address the limitations above:- Count processing time, not only bytes. ClickHouse will also measure how much CPU time each part of a query takes, so that compute-heavy queries can be moved to parallel replicas too.
- Support more query shapes. Queries with
UNION, aggregations that spill to disk, and other shapes that stay on one replica today.
Troubleshooting
A query never uses parallel replicas
Run the query a few times, then look at its events with the query above and messages logged by theAutoParallelReplicas logger:
AutoParallelReplicasSkippedDueToSettings: check the setup in Enabling automatic parallel replicas.AutoParallelReplicasNoStatisticson every run: the runs land on different replicas, or the query changes from run to run, for example due to a filter on a non-deterministic function.AutoParallelReplicasSkippedEarlyorAutoParallelReplicasRejectedByThreshold: the query is too small for parallel replicas.AutoParallelReplicasRejectedByCostModelorAutoParallelReplicasRejectedByDuplicatedReads: ClickHouse estimated that one replica is faster. To check, run the query withSETTINGS enable_parallel_replicas = 2and compare the time.AutoParallelReplicasSkippedDueToQueryorAutoParallelReplicasPlansNotComparable: the query has a shape that isn’t supported. See Limitations.
A query got slower after switching to parallel replicas
Confirm withAutoParallelReplicasApplied that the query switched, then compare with the query on one
replica by adding SETTINGS enable_parallel_replicas = 0. If one replica is faster, keep that
setting for the query and report the case on GitHub
with the comp-parallel-replicas label.
The same query is fast sometimes and slow other times
The first run of a query on each replica collects statistics and runs on one replica, so it can be slower than the following runs. The same happens again when the amount of data the query reads changes a lot and the statistics are collected again.Small queries got a little slower
Deciding costs some planning time. CheckAutoParallelReplicasOptimizationMicroseconds and
AutoParallelReplicasPlanBuildMicroseconds. If small queries on your service are affected, raise
automatic_parallel_replicas_min_bytes_per_replica so that more of them skip the decision.