🗄️ Database Design / Normalization
Intermediate
What is a materialized view?
Answer
A materialized view stores the result of a complex query physically on disk, unlike regular views which execute the query each time. Reading a materialized view is as fast as reading a regular table. The trade-off: the stored data can become stale — it must be refreshed periodically (REFRESH MATERIALIZED VIEW view_name in PostgreSQL). Refresh strategies: on-demand, on a schedule, or automatically on base table change (some RDBMS). Use cases: expensive aggregations for dashboards, pre-joined data for reporting, and reducing load on OLTP tables by pre-computing analytics. PostgreSQL and Oracle support materialized views natively.
More Database Design / Normalization Questions
View all →- Intermediate What are database anomalies and how does normalization prevent them?
- Intermediate What is denormalization and when is it used?
- Intermediate What are isolation levels in database transactions?
- Intermediate What are dirty reads, non-repeatable reads, and phantom reads?
- Intermediate What is query optimization and what is a query execution plan?