Why it matters

Repeated expensive queries are a huge waste in typical analytical clusters. Materialized views turn them into cheap lookups against pre-computed results. Getting them right can cut query costs by 10x for common dashboards.

Advertisement

The architecture

Regular views are metadata only. When queried, the view's underlying SQL is substituted into the outer query and executed fresh. This means views compose but every execution redoes all work.

Materialized views store query results as physical tables. On refresh, the query is re-executed and results are stored. Queries against the underlying tables can be automatically rewritten to hit the materialized view when compatible.

View types in HiveRegular viewlogical, freshMaterialized viewphysical, cachedQuery rewriteauto-redirect if matchMaterialized views need refresh; regular views always current
Two view types with different trade-offs.
Advertisement

How it works end to end

Materialized view refresh can be full (rebuild everything) or incremental (apply changes since last refresh). Incremental requires ACID tables and specific SQL patterns.

Query rewriting is optional. The optimizer inspects incoming queries and rewrites them to hit materialized views when it can prove semantic equivalence.

Storage cost is real. A materialized view over a large fact table can double storage. Prune aggressively.