Optimization

Materialized Views: Pre-Computed Results

Senior Data Analyst
March 20, 2026
5 min read

The Problem

My daily summary query takes 5 minutes. The data only changes once a day. Why recalculate it every time?

The Solution: Materialized View

A Materialized View stores the result of a query physically. Reads are instant.

CREATE MATERIALIZED VIEW daily_summary AS

SELECT date, SUM(amount) AS total_revenue FROM orders GROUP BY date;

-- Refresh when the data changes

REFRESH MATERIALIZED VIEW daily_summary;

Pro Tip

Schedule the `REFRESH` as a nightly cron job. Users get instant results during the day.

*Day 80: Project: Dashboard Performance Tuning.*

Ready to put your knowledge into practice?

Join SQL Mastery and learn through interactive exercises.