Challenge - 5 Problems
Materialized View Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Output of a simple materialized view query
Given the table sales with columns
Then running:
id, amount, and region, what is the output of the following query after creating the materialized view?CREATE MATERIALIZED VIEW regional_sales AS SELECT region, SUM(amount) AS total FROM sales GROUP BY region;Then running:
SELECT * FROM regional_sales ORDER BY region;PostgreSQL
CREATE MATERIALIZED VIEW regional_sales AS SELECT region, SUM(amount) AS total FROM sales GROUP BY region; SELECT * FROM regional_sales ORDER BY region;
Attempts:
2 left
💡 Hint
Materialized views store the result of the query at creation time.
✗ Incorrect
The materialized view stores the sum of amounts grouped by region at creation. Querying it returns the precomputed totals.
📝 Syntax
intermediate2:00remaining
Identify the syntax error in materialized view creation
Which option contains a syntax error when creating a materialized view in PostgreSQL?
Attempts:
2 left
💡 Hint
Check for missing keywords in the statement.
✗ Incorrect
Option A is missing the keyword 'AS' before the SELECT statement, which is required syntax.
❓ optimization
advanced2:00remaining
Best use of materialized view refresh
You have a materialized view that summarizes daily sales. Which option correctly refreshes the materialized view without locking reads during the refresh?
Attempts:
2 left
💡 Hint
Look for the option that allows concurrent reads during refresh.
✗ Incorrect
REFRESH MATERIALIZED VIEW CONCURRENTLY allows the view to be refreshed without blocking reads.
🔧 Debug
advanced2:00remaining
Why does this materialized view query fail?
You created a materialized view with:
Later, you run:
But you get outdated results after updating the sales table. Why?
CREATE MATERIALIZED VIEW mv AS SELECT id, amount FROM sales;Later, you run:
SELECT * FROM mv WHERE amount > 100;But you get outdated results after updating the sales table. Why?
Attempts:
2 left
💡 Hint
Think about how materialized views store data.
✗ Incorrect
Materialized views store a snapshot of data at creation or last refresh. They do not update automatically when base tables change.
🧠 Conceptual
expert2:00remaining
Materialized view storage and performance trade-off
Which statement best describes the main trade-off when using materialized views in PostgreSQL?
Attempts:
2 left
💡 Hint
Consider how materialized views store data and update it.
✗ Incorrect
Materialized views store query results physically, speeding up reads but need manual refresh which can be resource intensive.