Your analytics team has built a materialized view named mv_sales that pre-aggregates SUM(revenue) grouped by sale_date and region_id from the retail.sales_fact table. A Looker Studio dashboard issues the following SQL:
SELECT region_id, SUM(revenue) AS revenue
FROM `retail.sales_fact`
WHERE sale_date BETWEEN '2024-01-01' AND '2024-01-31'
GROUP BY region_id;
Under which condition will BigQuery automatically rewrite this query to read from mv_sales even though the dashboard does not mention the view?
Only if the dashboard explicitly replaces retail.sales_fact with mv_sales in the FROM clause.
Only if mv_sales is stored in the same dataset as sales_fact and both tables are clustered on sale_date and region_id.
When the session parameter ENABLE_MATERIALIZED_VIEW_REWRITE is set to TRUE; otherwise BigQuery never rewrites queries automatically.
When the materialized view holds the same aggregate functions and a superset of the query's GROUP BY columns, and the query's filters are compatible with those used to build the view.
BigQuery's optimizer rewrites a query to use a materialized view when it can prove that the view's result completely satisfies the query. Because mv_sales contains the same aggregate function (SUM(revenue)) and a superset of the grouping columns (sale_date, region_id), the optimizer can derive the requested result by further aggregating the materialized view (dropping sale_date) and applying the narrower date filter. No explicit reference to the view, special session flag, or identical clustering is required. The rewrite fails if the query requests columns or aggregates that are not present in the view, or if the query explicitly disables materialized-view usage.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What is a materialized view in BigQuery?
Open an interactive chat with Bash
How does BigQuery’s optimizer decide to rewrite queries to use materialized views?
Open an interactive chat with Bash
Are there any specific settings required to enable materialized view query rewrites in BigQuery?
Open an interactive chat with Bash
How does BigQuery's optimizer rewrite queries to use materialized views?
Open an interactive chat with Bash
What makes a query filter compatible with a materialized view filter in BigQuery?
Open an interactive chat with Bash
What happens if the query requests columns or aggregates not present in the materialized view?
Open an interactive chat with Bash
GCP Professional Data Engineer
Preparing and using data for analysis
Your Score:
Report Issue
Bash, the Crucial Exams Chat Bot
AI Bot
Loading...
Loading...
Loading...
Pass with Confidence.
IT & Cybersecurity Package
You have hit the limits of our free tier, become a Premium Member today for unlimited access.
Military, Healthcare worker, Gov. employee or Teacher? See if you qualify for a Community Discount.
Monthly
$19.99 $11.99
$11.99/mo
Billed monthly, Cancel any time.
$19.99 after promotion ends
3 Month Pass
$44.99 $26.99
$8.99/mo
One time purchase of $26.99, Does not auto-renew.
$44.99 after promotion ends
Save $18!
MOST POPULAR
Annual Pass
$119.99 $71.99
$5.99/mo
One time purchase of $71.99, Does not auto-renew.
$119.99 after promotion ends
Save $48!
BEST DEAL
Lifetime Pass
$189.99 $113.99
One time purchase, Good for life.
Save $76!
What You Get
All IT & Cybersecurity Package plans include the following perks and exams .