Skip to content

Commit 3628b32

Browse files
Add pre-aggregate best practices and semantic layer note (#527)
* Add pre-aggregate best practices: granularity, sizing, and semantic layer coverage Generated-By: mintlify-agent * Link AI agents and API reference in pre-aggregates overview Generated-By: mintlify-agent --------- Co-authored-by: mintlify[bot] <109931778+mintlify[bot]@users.noreply.github.com>
1 parent 372179e commit 3628b32

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

references/pre-aggregates/getting-started.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ Pre-aggregates are defined under the `pre_aggregates` key in your model configur
7878

7979
## Multiple pre-aggregates per model
8080

81-
You can define multiple pre-aggregates on the same model, each targeting different query patterns. For example, you might want a fine-grained daily pre-aggregate for detailed dashboards and a coarser monthly one for summary views:
81+
You can define multiple pre-aggregates on the same model, each targeting different query patterns. It is better to have **multiple small, focused pre-aggregates** rather than a single one containing all metrics and dimensions. Including too many dimensions increases the number of unique combinations, which generates large materialization files — this defeats the purpose of pre-aggregates, since they are meant to be smaller and faster than querying the warehouse directly.
82+
83+
For example, you might want a fine-grained daily pre-aggregate for detailed dashboards and a coarser monthly one for summary views:
8284

8385
```yaml
8486
models:

references/pre-aggregates/overview.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Pre-aggregates let you define materialized summaries of your data directly in yo
1212

1313
This is especially useful for dashboards with high traffic or expensive aggregations that don't need real-time data.
1414

15+
Any query that goes through the Lightdash semantic layer can hit a pre-aggregate — this includes the Lightdash app, the [API](/api-reference/v1/introduction), [MCP](/references/integrations/lightdash-mcp), [AI agents](/guides/ai-agents), the [Embed SDK](/references/embedding), and the [React SDK](/references/react-sdk).
16+
1517
<CardGroup cols={2}>
1618
<Card title="Getting started" icon="rocket" horizontal href="/references/pre-aggregates/getting-started">
1719
Define pre-aggregates in your dbt project and configure scheduling.
@@ -74,6 +76,10 @@ When a user runs a query, Lightdash automatically checks if a pre-aggregate can
7476
- The query does not contain custom dimensions, custom metrics, or table calculations
7577
- If the query uses a time dimension, the requested granularity is **equal to or coarser** than the pre-aggregate's granularity (for example, a `day` pre-aggregate can serve `day`, `week`, `month`, or `year` queries, but not `hour`)
7678

79+
<Tip>
80+
If you pre-aggregate at **day** granularity, the cache hits for `day`, `week`, `month`, `quarter`, and `year` queries. If you pre-aggregate at **month** granularity, the cache hits for `month`, `quarter`, and `year` — but **not** for `day` or `week`, since those require finer-grained data.
81+
</Tip>
82+
7783
When multiple pre-aggregates match a query, Lightdash picks the smallest one (fewest dimensions, then fewest metrics as tiebreaker).
7884

7985
### Dimensions from joined tables

0 commit comments

Comments
 (0)