← Lessons

quiz vs the machine

Gold1420

Databases

Materialized Views

Precomputing query results to trade storage for read speed.

5 min read · core · beat Gold to climb

View vs Materialized View

A regular view is just a saved query that runs every time you read it. A materialized view instead stores the precomputed result on disk. Reading it returns the cached rows instantly, which is ideal for expensive aggregations run often.

Keeping It Fresh

  • The stored result goes stale as base tables change.
  • A full refresh recomputes the whole view from scratch.
  • An incremental refresh applies only the changed rows, which is cheaper.
  • Refresh can run on a schedule or be triggered by writes.

When To Use One

  • Dashboards that rerun the same heavy aggregation many times.
  • Reports where slightly stale data is acceptable.
  • Avoid them when data must be perfectly up to the second.

Key idea

A materialized view stores precomputed query results for fast reads, trading extra storage and a refresh step against the cost of recomputing expensive queries every time.

Check yourself

Answer to earn rating on the learn ladder.

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

2. An incremental refresh is preferred because it: