Aggregate awareness lets you optimize query performance by routing queries to pre-aggregated tables in your data warehouse. End users can access data at different levels of granularity, as Omni will pick the most efficient table based on the query’s structure.Documentation Index
Fetch the complete documentation index at: https://docs.omni.co/llms.txt
Use this file to discover all available pages before exploring further.
Requirements
To follow the steps in this guide, you’ll need Querier, Modeler, or Connection Admin permissions.How it works
You build pre-aggregated (or rollup) tables in your preferred transformation tool, such as dbt, and register them with amaterialized_query parameter on the aggregate’s view. This gives you full control over how the aggregation is defined and refreshed.
At query runtime, Omni inspects the requested fields and rewrites the SQL to use the aggregate table when it contains everything the query needs. Because the aggregate is smaller than the base table, the rewritten query runs faster and uses fewer warehouse resources. The rewrite is automatic, meaning end users don’t need to choose which table to query.
Omni uses the aggregate:
- For single-table queries — All queried dimensions and measures are mapped in the aggregate’s
materialized_query.fields. - For joined queries within a topic — All queried fields from the base view are mapped in the aggregate’s
materialized_query.fields, and the aggregate also includes the join keys to the other views. Omni then joins the aggregate to the dimension views instead of the base table.
Setting up aggregate awareness
Once you’ve identified the query you’d like to optimize:1
Build an aggregate or rollup table
Build an aggregate or rollup table within Omni or some other transformation layer such as dbt.If you do this outside of Omni and don’t see your table, refresh the schema to have Omni build it.To demonstrate, let’s say you have a table with the following definition and you want to optimize the performance of the daily aggregations:In your transformation layer, you defined the following materialized table, which has pre-aggregated daily metrics:
order_items table
Pre-aggregated table definition
2
Add a materialized_query parameter
In Omni’s model IDE, add a The
materialized_query parameter to the optimized view to enable Omni to match the aggregate table to the underlying base views:Pre-aggregated table daily_sales
fields parameter maps each field from the base view to the corresponding column name in the aggregate table. You can also use the array format, though the object format shown here is recommended for clarity.3
Verify the setup
Verify that aggregate awareness is working by inspecting the generated SQL using Omni’s SQL inspector. The inspector will show whether Omni is querying the aggregate table or the granular table.
Query rewritten to use the aggregate table
Troubleshooting
If you expect Omni to use the aggregated table but it’s not, consider the following:-
Missing fields: Ensure that all the fields being queried are present in the aggregated table and correctly mapped in the
materialized_queryparameter. - Missing join keys: If your query joins the base view to other tables in a topic, the materialized view must include the join keys to those tables. Without the join keys, Omni cannot optimize queries that involve joins.
-
Incompatible queries:
count_distinctover a different level of aggregation than the aggregate table cannot use aggregate awareness, because the count cannot be re-aggregated from the pre-aggregated values. -
Cache: If the query results are being retrieved from the cache, Omni may not need to rewrite the SQL.
- Try clearing the cache to test if aggregate awareness is working as expected.
- You can also test by setting the
cache_policyto0so that it never uses cache.
If a query cannot be answered entirely by the
materialized_query, aggregate awareness is not likely to be used on that query.Next steps
- Learn more about the
materialized_queryparameter - Define a
cache_policy - Bring Omni in sync with your database with schema refreshes
- Use the Workbook inspector to debug your queries