Your retail analytics team created the following materialized view to speed up regional sales dashboards:
CREATE MATERIALIZED VIEW analytics.mv_sales_by_region
AS
SELECT
region,
SUM(sales_amount) AS total_sales
FROM analytics.fact_sales
GROUP BY region;
Business-intelligence tools continue to run SQL directly against the base table analytics.fact_sales. Which of the following ad-hoc queries can BigQuery's optimizer transparently rewrite to read only from analytics.mv_sales_by_region, avoiding a full scan of fact_sales without you changing any dashboard code?
SELECT region, SUM(sales_amount) FROM analytics.fact_sales WHERE order_channel = 'ONLINE' GROUP BY region;
SELECT region, SUM(sales_amount) FROM analytics.fact_sales GROUP BY region;
SELECT region, AVG(sales_amount) AS avg_sales FROM analytics.fact_sales GROUP BY region;
SELECT region, COUNT(*) AS order_count, SUM(sales_amount) FROM analytics.fact_sales GROUP BY region;
BigQuery can substitute an aggregate materialized view only when the query's SELECT list contains only columns that exist in the view and the query's GROUP BY keys and aggregate functions are each a subset of those defined in the view. The statement that selects region and SUM(sales_amount)-exactly the columns and aggregation materialized-and groups solely by region satisfies these rules, so the optimizer can rewrite it to use the view. The query that adds another aggregate (COUNT), changes the aggregate (AVG), or introduces a filter on a column that is not part of the view's GROUP BY keys all violate the rewrite conditions, forcing BigQuery to access the underlying table.
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 query rewriting work with materialized views?
Open an interactive chat with Bash
Why can't filters or additional aggregations be added for materialized view optimization?
Open an interactive chat with Bash
What is a materialized view in BigQuery?
Open an interactive chat with Bash
How does BigQuery's query rewrite work?
Open an interactive chat with Bash
Why can't filters or additional aggregates in SQL statements use 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
$19.99/mo
Billed monthly, Cancel any time.
3 Month Pass
$44.99
$14.99/mo
One time purchase of $44.99, Does not auto-renew.
MOST POPULAR
Annual Pass
$119.99
$9.99/mo
One time purchase of $119.99, Does not auto-renew.
BEST DEAL
Lifetime Pass
$189.99
One time purchase, Good for life.
What You Get
All IT & Cybersecurity Package plans include the following perks and exams .