Problem Statement
What is a key difference between a view and a materialized view?
Explanation
A materialized view trades storage and refresh work for faster reads, which helps heavy, repeated analytics. A plain view is only a saved query definition.
Choose refresh timing based on freshness needs. Some engines support fast refresh with logs; others only full refresh.
Code Solution
SolutionRead Only
-- Postgres
CREATE MATERIALIZED VIEW mv_sales AS
SELECT date_trunc('day', created_at) d, SUM(total) s
FROM orders GROUP BY 1;Practice Sets
This question appears in the following practice sets:
