cli/manuals/materialized-views.md
Live materialized views in Turso are automatically updating database objects that maintain query results in real-time. Unlike traditional materialized views that require manual refresh, Turso's live materialized views use Incremental View Maintenance (IVM) to stay current with minimal overhead.
Materialized views are an experimental feature that must be explicitly enabled:
tursodb --experimental-views your_database.db
Traditional materialized views store a snapshot of query results that becomes stale as the underlying data changes. You must manually refresh them, which often means re-executing the entire query. That is a costly operation for large datasets.
Turso's materialized views are different. They automatically update themselves by tracking only the changes to the underlying tables. When you insert, update, or delete a row, the materialized view calculates just the incremental changes needed to stay current. This means:
Instead of re-computing the entire view when data changes, IVM tracks what has changed and updates only the affected portions of the materialized view. For example:
This approach is particularly powerful for aggregations. If you have a view that calculates the sum of millions of rows, adding one new row only requires adding that single value to the existing sum—not re-summing all million rows.
Because live materialized views are instantly updated, they are fully transactional. Views are updated inside the same transaction as the base table modifications, ensuring:
If a transaction rolls back, all changes—including those to materialized views—are rolled back together.
Create a materialized view using standard SQL syntax:
CREATE MATERIALIZED VIEW sales_summary AS
SELECT
product_id,
COUNT(*) as total_sales,
SUM(amount) as revenue,
AVG(amount) as avg_sale_amount
FROM sales
GROUP BY product_id;
Once created, you can query the materialized view like any table:
SELECT * FROM sales_summary WHERE revenue > 10000;
Materialized views excel in scenarios where:
As an experimental feature, materialized views in Turso currently have some limitations:
While materialized views provide excellent query performance, they do add overhead to write operations. Each insert, update, or delete must also update any dependent materialized views. Consider this trade-off when designing your schema: