← Lessons

quiz vs the machine

Gold1360

Databases

Materialized Views for Analytics

Precomputing aggregates so dashboards answer instantly.

5 min read · core · beat Gold to climb

Stored Results

A regular view is just a saved query that recomputes every time. A materialized view stores the computed result on disk. Dashboards that read a rollup such as daily revenue per region can read the small precomputed table instead of scanning the raw facts.

Keeping It Fresh

The stored result drifts as new data arrives. Engines refresh it either fully by recomputing or incrementally by applying only new rows to the existing aggregate. Incremental refresh is cheaper but only works for aggregations that combine cleanly, like sums and counts.

Why Use Them

  • Speed: read a tiny rollup instead of billions of facts.
  • Consistency: every dashboard uses the same definition.
  • Cost: heavy aggregation runs once, not per query.

Key idea

Materialized views store precomputed aggregates so analytics queries read a small rollup instead of scanning raw facts, traded against the cost of keeping the result fresh.

Check yourself

Answer to earn rating on the learn ladder.

1. How does a materialized view differ from a regular view?

2. Why is incremental refresh limited to some aggregations?