Optimizing BigQuery Aggregations with Materialized Views
You have a table that contains millions of rows of sales data, partitioned by date. Various applications and users query this data many times a minute. The query requires aggregating values by using AVG, MAX, and SUM, and does not require joining to other tables. The required aggregations are only computed over the past year of data, though you need to retain full historical data in the base tables. You want to ensure that the query results always include the latest data from the tables, while also reducing computation cost, maintenance overhead, and duration. What should you do?
Community Votes
100% of anonymous learners picked answer A. Votes are pick records left by other test-takers — they are not the verified answer.
Community Insight
The exam tests the ability to select materialized views for performance optimization, specifically recognizing that a filter within the materialized view limits the scope of pre-computation without affecting the underlying base table's data retention.
For optimizing frequent aggregation queries on large partitioned tables while preserving full historical data, creating a materialized view with a filter for the relevant date range is the best solution. This approach ensures results are always fresh while significantly reducing computation costs and query latency.
A common error is selecting Option B, which incorrectly applies a partition expiration to the base table, thereby deleting historical data that the question explicitly requires to be kept.
Community Discussion (9 comments)
- Materialized View: Materialized views in BigQuery are precomputed views that periodically cache the result of a query for increased performance and efficiency. They are especially beneficial for heavy and repetitive aggregation queries. - Filter for Recent Data: Including a clause to focus on the last year of partitions ensures that the materialized view is only storing and updating the relevant data, optimizing storage and refresh time. - Always Up-to-date: Materialized views are maintained by BigQuery and automatically updated at regular intervals, ensuring they include the latest data up to a certain freshness point.
Comments & Corrections
No comments yet — spotted an error or have a note? Share it below.
Expert Analysis
Why the Answer Is Correct
Option A is the correct choice because BigQuery materialized views pre-compute and cache the results of the aggregation query, drastically reducing computation cost and duration. By including a filter clause for the last year, the materialized view only stores and updates the relevant recent data, optimizing maintenance. Crucially, this filter is applied only to the view definition, ensuring the base table retains its full historical data while the view automatically refreshes to include the latest changes.Why the Other Options Are Wrong
Option B is incorrect because configuring partition expiration on the base table deletes data older than one year, which violates the requirement to retain full historical data. Option C is incorrect because a standard view does not pre-compute results; it merely runs the underlying query every time, failing to reduce computation cost or duration. Option D is suboptimal because managing a scheduled query creates high maintenance overhead and results in stale data (up to an hour old), whereas materialized views are managed services that provide fresher data automatically.Community Comment Notes
Comment [1] accurately highlights that materialized views are designed for heavy, repetitive aggregation queries and that filtering ensures the view only maintains relevant data. Comment [6] reinforces why Option B is wrong, noting that partition expiration would delete necessary historical data. Comment [2] correctly points out that while Option C provides fresh data, it lacks the performance benefits of pre-computation required by the scenario.Official Reference
Exam Strategy
When a question requires reducing computation cost and maintenance overhead while ensuring the latest data is available, look for Materialized Views as the primary solution. Always double-check that options involving partitioning or expiration do not conflict with data retention requirements specified in the prompt.