Mohammad Gufran Jahangir August 30, 2025 0

TopicViewMaterialized View
What it isA stored query; results are computed each time you query itA precomputed table of the query’s results, stored on disk
PerformanceSame as running the underlying SELECT every timeFast to read (results already computed)
FreshnessAlways current (reads base tables live)Can be stale until it’s refreshed (on a schedule or on demand)
Storage cost~None (just metadata)Consumes storage (it’s physically materialized)
MaintenanceNo refresh neededNeeds refresh/maintenance; refresh costs compute
Good forConvenience, security (row/column masking via views), reuse of logicDashboards/BI and heavy aggregates that repeat often
Failure surfaceSame as base queryAdds refresh jobs, dependencies, and staleness management

Databricks-specific notes (Unity Catalog / DBSQL)

  • A materialized view (MV) is stored as a Delta table and maintained by Databricks; you can schedule it or refresh manually.
  • Typical syntax: -- Logical view CREATE OR REPLACE VIEW prod.dw.v_sales AS SELECT d.date_key, SUM(amount) AS revenue FROM prod.dw.fact_sales f JOIN prod.dw.dim_date d USING(date_key) GROUP BY d.date_key; -- Materialized view (precompute + keep it fresh) CREATE OR REPLACE MATERIALIZED VIEW prod.dw.mv_daily_sales SCHEDULE EVERY 15 MINUTES AS SELECT date_key, SUM(amount) AS revenue FROM prod.dw.fact_sales GROUP BY date_key; -- On-demand refresh (if needed) REFRESH MATERIALIZED VIEW prod.dw.mv_daily_sales;
  • Privileges: readers need SELECT on the view/MV; to rebuild an MV you also need the REFRESH privilege (and of course USE CATALOG/SCHEMA on the container).
  • Trade-off: MVs buy latency at the cost of storage + refresh compute and possible staleness. Views are always up-to-date but can be slower.

Quick “when to use which”

  • Use a view when you want a reusable, secure, always-fresh SQL abstraction.
  • Use a materialized view when many users hit the same heavy query (e.g., daily revenue by product) and you want sub-second BI with predictable cost.

Category: 
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments