Availability: Pre-aggregates are an Early Access feature available on Enterprise plans only.
Getting started
Define pre-aggregates in your dbt project and configure scheduling.
Monitoring and debugging
Track materialization status, debug query matching, and view hit/miss stats.
How it works
Pre-aggregates follow a four-step cycle:- Define β You add a
pre_aggregatesblock to your dbt model YAML, specifying which dimensions and metrics to include. - Materialize β Lightdash runs the aggregation query against your warehouse and stores the results. This happens automatically on compile, on a cron schedule you define, or when you trigger it manually.
- Match β When a user runs a query, Lightdash checks if every requested dimension, metric, and filter is covered by a pre-aggregate.
- Serve β If a match is found, the query is served from the materialized data instead of hitting your warehouse.
Query matching
When a user runs a query, Lightdash automatically checks if a pre-aggregate can serve the results. A pre-aggregate matches when all of the following are true:- Every dimension in the query is included in the pre-aggregate
- Every metric in the query is included in the pre-aggregate
- Every dimension used in filters is included in the pre-aggregate
- All metrics use supported metric types
- The query does not contain custom dimensions, custom metrics, or table calculations
- If the query uses a time dimension, the requested granularity is equal to or coarser than the pre-aggregateβs granularity (for example, a
daypre-aggregate can serveday,week,month, oryearqueries β but nothour)
Dimensions from joined tables
Pre-aggregates support dimensions from joined tables. Reference them by their full name (for example,customers.first_name) in the dimensions list.
Supported metric types
Pre-aggregates support metrics that can be re-aggregated from pre-computed results:sumcountminmaxaverage
Unsupported metric types
Queries that include any of the following metric types will not match a pre-aggregate and will query the warehouse directly:count_distinct,sum_distinct,average_distinctmedian,percentilepercent_of_total,percent_of_previousrunning_totalnumber,string,date,timestamp,boolean- Metrics with custom SQL expressions