docs/content/product/caching/matching-pre-aggregations.mdx
When executing a query, Cube will try to match and fulfill it with the best available pre-aggregation.
Since pre-aggregations contain a condensed representation of the data from the upstream data source (rather than a copy of that data), Cube needs to ensure that fulfilling a query with a pre-aggregation is possible and doing so will produce correct results.
If there's no matching pre-aggregation, Cube will fall back to querying the upstream data source, unless the rollup-only mode is enabled.
<InfoBox>If you don't know why a query doesn't match a pre-aggregation, check common pitfalls first.
</InfoBox>Cube goes through the following steps to determine if there are any pre-aggregations matching a query:
rollup pre-aggregations are tested before original_sql
pre-aggregations.Cube goes through the following steps to determine whether a query matches a particular eligible pre-aggregation:
<Diagram src="https://ucarecdn.com/f986b0cb-a9ea-47b7-a743-ca9a4644c246/" />See the details for each step:
{sum} / {count}), then referenced leaf measures will be
checked for additivity.one_to_many
relationship between cubes in the query.There are extra considerations that apply to matching time dimensions.
hour and day is hour because both hour and day can be divided
by hour.month,
the values should be the start and end days of the month, i.e.,
['2020-01-01T00:00:00.000', '2020-01-31T23:59:59.999']; when the granularity
is day, the values should be the start and end hours of the day, i.e.,
['2020-01-01T00:00:00.000', '2020-01-01T23:59:59.999']. Date ranges are
inclusive, and the minimum granularity is second. By default, this is ensured
via the allow_non_strict_date_range_match
parameter of pre-aggregations: it allows to match non-strict date ranges and is
set to true by default.scheduled_refresh_time_zones
configuration option.If a query specifies a custom granularity for its time
dimension, then a matching pre-aggregation with the same custom granularity will
be used even if there is also an matching pre-aggregation with a default
granularity (e.g., day or month).
There are extra considerations that apply to matching ungrouped queries:
If you're not sure why a query does not match a pre-aggregation, try to identify the part of the query that prevents it from matching. You can do that by removing measures, dimensions, filters, etc. from your query until it matches. Then, refer to the matching algorithm and common pitfalls to understand why that part was an issue.
Most commonly, a query would not match a pre-aggregation because they contain non-additive measures.
<ReferenceBox>See this recipe for workarounds.
</ReferenceBox>If a query uses any time zone other than UTC, please check the section on
matching time dimensions and the
scheduled_refresh_time_zones
configuration option.