Materialized views: trading storage and refresh for query savings
A materialized view precomputes an expensive query and stores the result, so reads are fast and cheap, at the cost of storage and refresh compute. For frequently-run expensive queries, the trade pays off. Here is the cost math.
Quick answer
A materialized view precomputes and stores the result of an expensive query, so subsequent reads are fast and cheap instead of re-running the computation. The cost is storage for the result and refresh compute to keep it current. It pays off when an expensive query is read far more often than the underlying data changes, so the query savings exceed the storage and refresh cost.
An expensive query, a large aggregation, a multi-table join, a complex analytical computation, costs the same every time it runs. A materialized view runs it once, stores the result, and serves that stored result to readers, turning a repeated expensive computation into a cheap lookup. The tradeoff is the storage and the refresh, and whether they beat the query cost depends on the read-versus-change ratio.
What you pay and what you save
| Cost | Saving | |
|---|---|---|
| Storage | Storing the precomputed result | |
| Refresh compute | Recomputing to stay current | |
| Query | Cheap reads instead of re-running the expensive query |
You pay to store the result and to refresh it (fully or incrementally) as the underlying data changes. You save the cost of re-running the expensive query on every read. On a per-scan or per-compute-priced warehouse like Athena or BigQuery, where each query is billed, this saving is direct and can be large.
The read-versus-change ratio
The trade pays off when the expensive query is read far more often than the underlying data changes. If a costly aggregation is queried hundreds of times a day but the data updates a few times, a materialized view refreshed on those few updates serves hundreds of cheap reads for a few refreshes, clearly worth it. If the data changes constantly and is read rarely, the refresh cost can exceed the query savings, and a plain query is cheaper.
Using materialized views well
Create materialized views for expensive, frequently-read queries over relatively stable data, use incremental refresh where the engine supports it (recompute only what changed, not the whole view), and avoid them for rarely-read or rapidly-changing data where refresh cost dominates. Done right, they are a targeted way to cut query cost and latency together for hot analytical queries, the precompute counterpart to caching.
FAQ
How do materialized views save money?
By precomputing and storing the result of an expensive query, so subsequent reads serve the cheap stored result instead of re-running the costly computation. On per-scan or per-compute-priced warehouses where each query is billed, this turns many expensive queries into one refresh plus cheap reads, a direct saving.
What does a materialized view cost?
Storage for the precomputed result and refresh compute to keep it current as the underlying data changes (full or incremental recomputation). The trade pays off when these are less than the cost of re-running the expensive query on every read, which depends on the read-versus-change ratio.
When is a materialized view worth it?
When an expensive query is read far more often than the underlying data changes, so a few refreshes serve many cheap reads. A costly aggregation queried hundreds of times a day over data that updates a few times is a clear win. Rapidly-changing, rarely-read data is not, since refresh cost dominates.
When should I not use a materialized view?
When the underlying data changes constantly and the view is read rarely, because the refresh cost to keep it current can exceed the query savings. In that case a plain query on demand is cheaper. Materialized views suit stable data with expensive, frequently-run queries, not volatile, rarely-read data.
What is incremental refresh in materialized views?
A refresh mode that recomputes only the part of the view affected by changed underlying data, rather than recomputing the entire view. Where the engine supports it, incremental refresh sharply reduces refresh compute cost, making materialized views economical even for larger or more frequently-updated data.
Does C3X estimate materialized view cost?
Materialized view cost is storage plus refresh compute, and the saving is reduced query cost, all usage-driven. C3X prices the surrounding data infrastructure, and you model query frequency, data change rate, and refresh cost to evaluate whether a materialized view saves money for a given query.
What to do next
Estimate the infrastructure around your analytics before you build it. C3X reads your Terraform and prices your resources against a live catalog. Start with the quickstart.
Share this post
Try C3X on your own Terraform
Free and open source. No API key required. One command to install, one command to estimate.