Sobes.tech
Senior

What is a Materialized View in ClickHouse?

sobes.tech AI

Answer from AI

A Materialized View in ClickHouse is a database object that automatically maintains aggregated or transformed data based on the source table. When data is inserted into the base table, the Materialized View is instantly updated, recording the result in another table, which speeds up queries that use precomputed data.

Example of creating a Materialized View:

CREATE MATERIALIZED VIEW mv_example TO target_table AS
SELECT key, count() AS cnt
FROM source_table
GROUP BY key;

Here, when data is added to source_table, the aggregate count() by key is automatically updated in target_table through the Materialized View.