Cloudflare

Announcing support for GROUP BY, SUM, and other aggregation queries in R2 SQL

Dec 18, 2025Jérôme Schneider, Nikita Lapkov, Marc Selwan
Announcing support for GROUP BY, SUM, and other aggregation queries in R2 SQL
SummaryAI, from the source post

This post introduces support for aggregation queries (GROUP BY, SUM, COUNT, AVG, etc.) in R2 SQL. It details the implementation of 'scatter-gather aggregations' for queries without HAVING/ORDER BY clauses, which compute pre-aggregates on worker nodes and merge them on the coordinator. For queries with HAVING/ORDER BY, it introduces 'shuffling aggregations' that use deterministic hash partitioning to colocate data for specific groups before final aggregation, followed by a synchronization barrier and local finalization on workers, and a k-way merge on the coordinator. This significantly enhances R2 SQL's analytical capabilities for large datasets.

More from the Data Infrastructure & Analytics trail