Hi
first name,
Incremental and refreshable materialized views are commonly used features within ClickHouse that allow you to query pre-computed results based on a SELECT statement.
Incremental materialized views achieve this by precomputing results at insert time, speeding up your queries by preventing calculations from having to be evaluated every time you run a query for common access patterns.
Creating a materialized view is easy. Simply use the CREATE MATERIALIZED VIEW command like so:
CREATE MATERIALIZED VIEW analytics.monthly_aggregated_data_mv
TO analytics.monthly_aggregated_data
AS
SELECT
toDate(toStartOfMonth(event_time)) AS month,
domain_name,
sumState(count_views) AS sumCountViews
FROM analytics.hourly_data
GROUP BY
domain_name,
monthThis query will store your precomputed query results into a target table called `monthly_aggregated_data`, from which you can query your data quickly without any expensive calculations.
Refreshable materialized views conversely run a query periodically, sending the results to a target table where the rows are atomically updated. This can be great for scheduling tasks, such as exports, or periodically computing the results for intensive queries involving JOINs. See examples here.
Here's a helpful video on the differences between incremental and refreshable materialized views.
To learn more about how to use materialized views, please see our docs or watch our on-demand course on materialized views.
-- Thom O'Connor Support at ClickHouse
ClickHouse Inc., 650 Castro St. Ste. 120 Unit 92426, Mountain View, CA 94041, USA. If you'd like to no longer receive emails like these, you can unsubscribe here.