How we scaled raw GROUP BY to 100 B+ rows in under a second
ClickHouse Cloud's parallel replicas feature spreads a single GROUP BY query across every core of every node in a service, with no pre-aggregation or data reshuffling. In the benchmark, 100 billion rows were aggregated in 414 ms at about 1.45 TB/s, compared with 16.6 s on a single 89-core node. The speedup rests on ClickHouse's execution model. Each pipeline stream scans a non-overlapping set of part ranges and builds mergeable partial aggregation states in one of 30+ specialized hash table variants, so any core or node can process any subset of rows and the partial results merge correctly. The post also covers memory behaviour by aggregate function, the reproducible benchmark setup, and how runtime scales vertically (more cores per node) and horizontally (more nodes).
Related posts
- Introducing multi-stage distributed query execution in ClickHouse Cloud
ClickHouse hardMaster
ClickHouse Cloud adds multi-stage distributed query execution, splitting a query plan into stages connected by exchange operators (Gather, Shuffle, Broadcast, Scatter) so intermediate data can be repartitioned between nodes mid-query. Shuffling by join key means each worker builds only its share of the hash table instead of the full right side, and shuffling by GROUP BY key removes the single-coordinator final merge for high-cardinality aggregations. Exchanges stream blocks between workers over TCP by default, with a persisted mode writing to object storage for spilling and future fault recovery. Early TPC-H results show up to 3.4× speedups on join-heavy queries and 7.4× faster aggregation on 8 nodes versus 1.
- ClickHouse and The One Billion Row Challenge
ClickHouse mediumAdept
ClickHouse Local solves the One Billion Row Challenge (min/mean/max temperature per station from a 13GB text file) in about 20 seconds on an 8-core Hetzner VM, versus nearly 3 minutes for the Java baseline. Reading lines with LineAsString and splitting on ';' instead of using the CSV parser cut the time from 27.6s to 19.9s. Loading into a Memory table first, or precomputing aggregates with a Materialized View into an AggregatingMergeTree via a Null engine, makes later queries near-instant but costs 21–26s of load time, so neither beats the single-scan query end to end. ClickHouse SQL using randCanonical and a Box-Muller transform also generates the dataset 6.8x faster than the Java generator.
- Why ClickHouse Cloud wins at real-time analytics
ClickHouse mediumAdept
In the CostBench streaming benchmark (113.2 billion stock quotes ingested at about 1M rows/s while queries ran), ClickHouse Cloud scored 412× to 1,996× better end-to-end performance per dollar than Snowflake, Databricks, BigQuery and Redshift Serverless. Its lead comes from sorting data and computing incremental materialized-view pre-aggregations in memory at insert time, so summaries never lag behind raw data. Background part merges then keep combining the mergeable aggregation states. Ingestion and merging are parallelized across nodes, cores and SIMD lanes, and a 4-core ingest service prepared all the data for $28.69 with 14.4× compression, while the other systems needed separate asynchronous refresh stages that lagged and cost $79–$696.
- Join me if you can: ClickHouse vs. Databricks vs. Snowflake - Part 2
ClickHouse mediumAdept
Replacing fact-to-dimension joins with in-memory dictionaries in ClickHouse Cloud sped up a 17-query join benchmark over 1.4 billion rows by 1.9–3.5× in total runtime, up to 6.6× on individual queries, and cut cost by up to 60%. The Locations table becomes a complex_key_hashed dictionary for String-key lookups. The Products table becomes a range_hashed dictionary that resolves time-versioned rows with a hash map plus binary search over date ranges, provided the source has no overlapping ranges per key. Queries change only by swapping JOINs for dictGet calls, and the gains grew as the cluster scaled from 2 to 8 nodes.
- Parallelizing ClickHouse aggregation merge for fixed hash map
ClickHouse hardMaster
ClickHouse 25.11 parallelizes the merge phase for GROUP BY on 8- and 16-bit keys, which use an array-backed FixedHashMap. Before this, these aggregations could not use the bucket-wise parallel merge available to two-level hash tables, so a UInt16 key query ran in 62.8s versus 8.5s for the same query cast to UInt64. The fix has merge threads work in place on disjoint key subsets instead of converting to a two-level table. Along the way: contiguous range segmentation balanced poorly, a shared non-thread-safe Arena caused memory corruption and needed one Arena per thread, and a fixed 3ms regression on trivial aggregates was solved by computing the min/max populated index before the parallel merge.