CREATE MATERIALIZED VIEW stores query results on disk and keeps them in sync with source tables.
Reduce query latency by pre-computing results. ClickHouse stores the output table on disk and refreshes it automatically when source data changes.
Use CREATE MATERIALIZED VIEW ... TO ... AS SELECT
. The TO
clause names the destination table. Include POPULATE
to backfill existing data.
Aggregate Orders
rows into a daily summary so dashboards read from a small lookup table instead of scanning every order.
Yes. ClickHouse updates the destination table whenever inserts hit the source table, using the SELECT logic you define.
Drop and recreate it, or truncate the destination table and run ALTER TABLE ... MATERIALIZE
for specific partitions.
Partition the destination table on the same key used in queries, keep SELECT deterministic, and avoid heavy joins that nullify performance gains.
Yes, but joins slow insert performance because each new row triggers the join operation. Prefer denormalized source tables or pre-join data upstream.
Yes. Use ALTER TABLE dest_table ADD COLUMN ...
followed by ALTER TABLE dest_table MATERIALIZE COLUMN ...
to fill historic partitions.
Delete or drop partitions in the destination table. The materialized view will add future data normally.