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

Summary
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
- Introducing Cloudflare Basin: an open, serverless data platform, now generally available
- Introducing the Billable Usage API: programmatic cost visibility for Cloudflare
- Announcing the Monetization Gateway: charge for any resource behind Cloudflare via x402
- How we built Cloudflare's data platform and an AI agent on top of it
- Iran's Internet is partially restored, Cloudflare Radar data shows