Loading Depth Study
Preparing your workspace
Views provide reusable query definitions, while materialized views store the query result for faster repeated reads until refreshed.
A regular view behaves like a virtual table based on its underlying query and always reflects current data when queried. A materialized view stores the result physically and can make expensive analytical queries much faster when real-time data is not required. Materialized views need to be refreshed to reflect changes. They can be valuable for dashboards and reporting systems with expensive calculations.
An admin analytics dashboard may use a materialized view for daily course statistics that do not need to update every second.
CREATE MATERIALIZED VIEW course_stats AS SELECT course_id, COUNT(*) AS enrollment_count, AVG(score) AS average_score FROM enrollments GROUP BY course_id; REFRESH MATERIALIZED VIEW course_stats;
A materialized view stores course statistics and can be refreshed when updated data is needed.