Aggregate Projections for Dashboard Query Acceleration
Pre-computed rollups can cut dashboard scans, if grain, matching, and write cost line up.

Aggregate projections make dashboards faster by storing pre-computed GROUP BY results inside MergeTree parts, reducing query reads from billions of raw events to thousands of rolled-up rows. Their value depends on more than creating a summary. The grain must fit the dashboard, the optimizer must choose it, and the write path must keep it up to date without overloading ingestion.
Why dashboard queries fight columnar engines by default
A MergeTree table has one ORDER BY, which can be a tuple of several columns. That gives the table one physical ordering shared by all dashboard questions. Queries whose filters and grouping cannot use that ordering must scan raw data. Columnar storage makes it efficient to read the columns a query needs, but there is still a gap between storing events one by one and asking for quarterly totals.
Dashboard refreshes turn that gap into repeated work. A tile asking for “total revenue by region for the last quarter” can scan billions of rows, then repeat the aggregation hundreds or thousands of times per day. Separate tables with different sort keys give queries other access paths, but they copy the data and make writes more complex without covering every query shape. The cost reaches the user on every refresh. Fast dashboards invite use, while dashboards that keep spinning get abandoned.
What an aggregate projection actually is inside a MergeTree part
An aggregate projection is a pre-materialized GROUP BY result stored as a hidden structure inside the same MergeTree parts as the underlying data. It is not a separate table or view. When a query matches, the engine can answer it from that embedded summary. The application or analyst does not need to redirect the query to another table.
The distinction from a normal projection is important. A normal projection stores a full second copy of the data under a different sort key, which can roughly double storage. An aggregating projection instead stores rolled-up rows in AggregateFunction state columns that hold sums, counts, distinct counts, and similar measures. It is usually much smaller because many events contribute to each stored group.
Those states also support more than simple totals. Probabilistic structures for approximate distinct counts and t-digest for quantile estimation can be merged across time windows. Because the projection lives inside the parts, it follows the data through merges, TTL operations, and replication. No separate maintenance job is needed to keep the structure aligned with its table.
How to choose the right grain and dimensions for a projection
For a telemetry table that has event_time, region, and revenue, a daily projection grouped by region may fit a dashboard that shows daily revenue totals. But can it answer an hourly question? Once events have been rolled into daily groups, that finer detail is unavailable. Conversely, retaining unnecessarily fine time buckets leaves more rows to scan.
Check whether dashboards request hourly, daily, or weekly buckets, and which dimensions users filter or group by. For the telemetry example, region must remain available if users select a region as well as compare regions. Estimate the projected row count by multiplying the dimension cardinalities, including the time buckets. High-cardinality dimensions such as session ID or user ID can leave nearly as many rows as the raw table.
Measures need the same scrutiny as dimensions. Revenue totals are additive, while distinct counts and quantiles need suitable aggregate states. Daily or hourly buckets serve most dashboard queries. Sub-minute buckets usually keep too much detail to be worth their write overhead, so finer grain needs a query that calls for it.
The match conditions the query optimizer enforces before using a projection
The optimizer must establish that the projection contains every column referenced in SELECT, WHERE, GROUP BY, and HAVING, and that its grouping keys cover the query’s GROUP BY structure. A missing filter column can therefore disqualify a projection even when the displayed measures and dimensions look right. Almost matching is not enough to use it.
A projection storing uniqState requires uniqMerge rather than count(distinct), so the query must consume the matching merge function. Transparent selection means the optimizer chooses the matching structure without the application naming a different table.
What happens when the match fails? There is no error announcing that the intended acceleration has disappeared. The query runs against the main table, so a mismatch in the design slows it down without warning. Engineers should therefore test actual dashboard queries with EXPLAIN, including their filters and HAVING clauses, and confirm that the plan selects the projection.
The write-side cost and how aggregating projections keep it manageable
Every insert must write into each projection on the table, so projection count adds to write I/O. A table with five projections makes five more write operations for each insert batch. Rolled-up rows keep aggregating projections smaller than full copies, but they do not make those writes free.
Adding a projection for every new query shape can turn an acceptable cost for one or two useful summaries into an ingestion bottleneck. The practical response is to prioritize the highest-frequency queries and measure write throughput with and without each projection. A slightly coarser grain that serves several query shapes is preferable to a fine-grained design useful for only one, provided it still answers those queries.
Existing data creates a separate, one-time expense. Backfilling a projection requires a full scan to materialize its rows, which can consume substantial resources on a large table. That work should be planned for off-peak hours. That cost lasts only as long as the backfill, while ongoing write amplification can prevent the write path from keeping up over time.
Where projections end and materialized views begin
Projections suit repeated aggregation over a single table when the definition needs neither a JOIN nor a WHERE filter. Their simplicity comes from staying within that boundary. They offer co-location with parts and transparent selection without a separate ingestion pipeline. However, they cannot provide independent TTL policies or chained transformation pipelines.
An enriched summary requiring a JOIN, a pre-filter, or several transformation steps belongs there rather than in an increasingly elaborate projection design. These tools work in layers. A production system can use projections for its recurring dashboard GROUP BY queries and materialized views for summaries that need enrichment.
Skip indexes address a different access pattern again. They let the engine skip granules for selective lookups and narrow range scans. That helps less when a broad aggregation needs to read most granules anyway. The practical split is therefore projections for core dashboard aggregations, materialized views for joined or transformed summaries, and skip indexes for selective filter columns.

Keeping projections current as data arrives: ingestion and CDC patterns
For append-only streams such as telemetry, inserts extend the projection through the MergeTree insert pipeline. There is no separate refresh job to schedule. Yet how fresh the data is still depends on when events reach the table, while how efficiently it is written depends on how they arrive.
For operational data with inserts, updates, and deletes, log-based CDC supplies the stream of changes. Debezium connected to Kafka captures structured change events in near-real-time without polling, while a Flink or Spark consumer merges them into a queryable mirror of the operational state. The projection depends on that maintained table.
A disciplined pipeline uses a durable log such as Kafka or Redpanda, stateful processing, and contract-enforced schemas through Protobuf plus Schema Registry. Schema drift can otherwise break projection matches silently. In a medallion model, Bronze holds raw CDC events, Silver holds tables that have been cleaned and upserted, and Gold holds aggregates ready for analytics where the query grain stays the same. Batch size also deserves attention. Very small inserts create many small parts and frequent projection writes, so async inserts or ingestion-layer batching can reduce write amplification without changing the projection itself.
How compute-storage separation changes what aggregate projections can do at scale
A projection reduces scan work, but it cannot reserve CPU for a dashboard. On a shared cluster, ingestion and backfills compete with reads for compute resources. Even a well-matched projection can be slowed by that contention.
Compute-storage separation allows workload classes to scale independently. Dashboard reads can use dedicated virtual compute with a hot cache, while ETL uses separate compute for writes. That isolation keeps dashboard p99 latency bounded when end-of-quarter ETL volumes spike, because the workloads draw from separate compute pools.
Replica-based scaling has a different cost profile. It duplicates the full dataset, including projections, and takes minutes to hours to provision. That means paying for more storage even when only compute capacity needs to grow. Separating compute from storage lets serving capacity grow without copying the data, so projections can benefit from resources beyond those of a single shared cluster.
What aggregate projections mean for AI agent query workloads
AI agents can issue repetitive analytical queries without the pauses that naturally occur between human dashboard interactions. That makes repeated raw scans especially expensive. Projections cut the work for each query, but an agent loop can still keep shared compute under load. Isolation remains necessary for the design.
Why focus on p99? Agents do not back off under stress, and queries chained within a reasoning step turn individual delays into cumulative waiting. A tail-latency spike can therefore cascade through the loop. Projection reads that return in milliseconds instead of seconds keep that accumulated delay manageable, while averages can conceal the slow requests that disrupt the sequence.
One agent session may spawn dozens of sub-queries, multiplying raw scan load even when each query’s latency looks acceptable. Isolated read-only compute prevents agent activity from competing with production ingestion and human dashboards. Accountability also requires full query logging down to the column. A serving architecture should record which projection was selected, which columns were read, and which agent session issued the query, so autonomous access remains auditable.
A design checklist for projections that stay fast and maintainable over time
Before building, profile the real dashboard queries with EXPLAIN and identify the highest-frequency GROUP BY shapes. Estimate cardinality for each candidate dimension to assess how small a summary will be. Confirm that each measure is additive or expressible as an AggregateFunction state. Then choose the coarsest grain that still serves the target queries. The workload should guide the design.
At design time, include the columns needed by SELECT, WHERE, GROUP BY, and HAVING without adding unrelated dimensions. Use states such as uniqState and quantileState for non-additive measures, and name projections for their grain and dimensions so drift is visible in DDL. After creation, test every target query with EXPLAIN. Measure write throughput before and after each addition, and schedule existing-table backfills off-peak.
To keep projections in check over time, set a low limit on how many each table can have and check actual query logs quarterly. Retire projections whose query patterns have drifted. Growing ingestion volume, lost optimizer matches, or pressure to add a summary for every dashboard are signals to revisit the design. Requirements for JOINs, definition-time filters, independent TTLs, or chained transformations should lead to materialized views instead. Where compute and storage are separated, assign dashboard reads to isolated compute with a hot cache, keeping ingestion contention from undoing the latency gains.


