ClickHouse materialized view insert performance: since 26.7, one view puts your INSERT on one thread

Since 26.7, an INSERT into a ClickHouse table with any materialized view runs on one thread unless parallel_view_processing=1. One user saw 293 → 1,557 ms.

The question for day 15 of this series was “how many materialized views can a ClickHouse table have before inserts slow down?”. The published measurements give a plain answer: the count of views matters much less than how many rows they write and how many parts they create. A view that copies every row roughly doubles the write, and fifty views that each keep a fiftieth of the rows cost about as much as ten.

The part that has changed recently is threading. Since ClickHouse 26.7 (and the backports 26.6.4.38 and 26.3.29.8), a table with even one materialized view is written on one thread, unless you set parallel_view_processing = 1. For INSERT … SELECT the limit covers the whole pipeline, the SELECT included. From 25.10 to 26.6 the setting was silently ignored and views always ran in parallel, so an upgrade can make view-heavy ingestion several times slower without any change on your side. One user reported average insert time going from 293 ms on 26.3.12 to 1,557 ms on 26.8, with threads per insert dropping from 5.4 to 1 (issue #133571).

Everything below comes from the source at tag v26.11.1.2942-stable, the setting descriptions and history in Settings.cpp, ClickHouse issues and pull requests, and measurements other people have published. Nothing was benchmarked for this post. Derived numbers are marked as arithmetic.

The short answer

Question Answer (26.11)
What does one view add to an insert? Its SELECT on every inserted block, a second sort, and one more part per block (per partition)
How much slower with one SELECT * view? −36% inserts/s (1M-row batches) to −55% (100-row batches) on MergeTree
Where does the extra CPU go? ~77% re-sorting the copied rows for the target, ~23% writing and compressing
Are views run in parallel? No by default (parallel_view_processing = 0): one thread, views one after another
Does max_insert_threads help? Not on a table with views, unless parallel_view_processing = 1
Does min_insert_block_size_rows_for_materialized_views cut target parts? Not by default since 26.2: dedup in views switches the squashing off
Is source + views one atomic write? No: each table commits its own parts

What a materialized view does to one inserted block

An incremental materialized view is a trigger. ClickHouse’s docs describe it as “just a trigger that runs a query on blocks of data as they’re inserted”, with the source table in the view’s SELECT replaced by the block. In 26.11 the insert pipeline is built by InsertDependenciesBuilder. For every block written to the source table, each dependent view does this:

  1. runs its SELECT over the block (a filter, a projection, an aggregation, or a JOIN against other tables);
  2. sends the result to its target table’s sink, which sorts the rows by the target’s ORDER BY and splits them by partition;
  3. writes one new part per partition that the rows touch. A view whose SELECT returns no rows for that block writes nothing: splitBlockIntoParts returns no parts for an empty block.

The cost model follows directly. Each block the source writes produces 1 + v parts, where v is the number of views that return rows for it, multiplied by the partitions involved. Every view also sorts its rows a second time and runs its own query. A view on a view (a chain) does the same again one level down.

One inserted block, a table with three materialized views (not to scale)parallel_view_processing = 0 (default): one thread, one step after anothersource: run the SELECT on the block, sort, write a partsourceview 1: run the SELECT on the block, sort, write a partview 1view 2: run the SELECT on the block, sort, write a partview 2view 3: run the SELECT on the block, sort, write a partview 3INSERT returnsparallel_view_processing = 1 views run side by sidesource: run the SELECT on the block, sort, write a partsourceview 1: run the SELECT on the block, sort, write a partview 1view 2: run the SELECT on the block, sort, write a partview 2view 3: run the SELECT on the block, sort, write a partview 3INSERT returnstime →Each box: run the view's SELECT on the block, sort by the target's ORDER BY, write one part per partition.With 0, an INSERT … SELECT runs on one thread end to end (26.7+); with 1 it gets max_threads back.
Read from the 26.11 source: InsertDependenciesBuilder.cpp (getViewProcessingNumThreads returns 1 when views are involved and the setting is 0) and InterpreterInsertQuery.cpp. The docs' three-view example with sleep(1) per view takes 3.786 s sequential and 1.588 s parallel.

The INSERT does not return until every view has written its part. That is why a slow view SELECT shows up directly as insert latency. The docs’ own JOIN example is a clear case: loading 238.98 million votes took 29.359 s without the view and 111.964 s with a view that joins every block against another table, 3.8× slower.

How many views: the published numbers

The most complete public measurement is Altinity’s Performance impact of materialized views in ClickHouse by Stefan Kaeser (first published in 2022, updated in 2026). It used clickhouse-benchmark on a 6-core laptop with a consumer NVMe disk, with SELECT * views into identical MergeTree tables. The ClickHouse version is not given. Inserts per second into a MergeTree source:

Views on the source 0 1 5 10 50
100-row inserts, every view copies all rows 923.3 411.9 169.5 89.4 18.2
1M-row inserts, every view copies all rows 5.8 3.7 1.2 0.7 0.16
1M-row inserts, each view keeps 1/N of the rows 5.8 3.7 2.3 1.9 1.7
1M-row inserts, views chained one after another 5.8 3.7 1.3 0.7 0.15
1-million-row INSERTs per second into MergeTree, by number of viewsevery view copies all rowseach view keeps 1/N of the rows (WHERE iCol % N = X)02460 views: 5.8 inserts/s5.80 views1 views: 3.7 inserts/s3.71 views: 3.7 inserts/s3.71 view5 views: 1.2 inserts/s1.25 views: 2.3 inserts/s2.35 views10 views: 0.7 inserts/s0.710 views: 1.9 inserts/s1.910 views50 views: 0.16 inserts/s0.1650 views: 1.7 inserts/s1.750 viewsAll-rows views: rows written per second stays at 7.2–8.2 million (inserts/s × 1M × (1 + N)): the disk is the limit.Filtered views write the same rows whether N is 10 or 50, so 50 views cost about as much as 10.
Numbers from Altinity, Performance impact of materialized views in ClickHouse (Stefan Kaeser; 6-core laptop, consumer NVMe, clickhouse-benchmark, version not given), parallel views on one source table. Measured by the author, not here; the rows-written line is arithmetic.

Two things in this table explain almost everything else.

Rows written stay constant. Multiply each all-rows result by the rows it writes (1M into the source plus 1M per view). That gives 5.8, 7.4, 7.2, 7.7 and 8.2 million rows per second for 0, 1, 5, 10 and 50 views (arithmetic). The machine writes about 7 to 8 million rows a second however they are split, so each view that copies every row costs a full extra write. The filtered views write 2 million rows per insert in total whatever N is, which is why 50 of them (1.7 inserts/s) are almost as cheap as 10 (1.9).

Small inserts pay a fixed cost per view. With 100-row inserts, the time per insert is 1.08 ms with no view, 2.43 ms with one and 54.9 ms with fifty (arithmetic from the inserts/s). That is roughly 1 ms per view per insert, almost all of it creating one more tiny part. Altinity also ran each test against a Null table, which runs the views but writes nothing. There the same arithmetic gives about 0.3 to 0.4 ms per view, and with 1M-row inserts one view cost only 4% (32.1 → 30.8 inserts/s). The trigger itself is cheap. The parts and the rows written are what cost.

Altinity’s conclusion, and the fix they suggest for a user who had about a hundred views on one table, is to layer them. A first layer of views only cuts the data down, and the expensive logic runs on that subset.

Where the CPU goes: the target sorts again

A pull request from an outside contributor in July 2026 profiled the 1:1 case on a recent master build (PR #109535, Ryzen 3900X, 1M-row inserts of data not sorted by the key, 8 concurrent clients):

Views CPU per insert Throughput
none 326 ms 22.8 M rows/s
one SELECT * view, 50% of rows match 466 ms (+43%) 16.3 M rows/s (−29%)
one SELECT * view, 100% of rows match 591 ms (+81%) 13.1 M rows/s (−43%)

The author found that about 77% of the extra CPU is the view target’s sink sorting the rows by its primary key (stableGetPermutation plus the column permute in MergeTreeDataWriter::writeTempPart). The source sink has already done the same sort on the same rows. Writing and compressing accounted for only ~23%. The cost grows linearly with the share of rows the view passes on, about 2.7 ms per percent matched per 1M rows. The proposed fix was a presort_inserts_with_materialized_views setting, which in their test cut the overhead from +73% to +29%. The PR was closed without being merged, and the setting doesn’t exist in 26.11’s Settings.cpp. The diagnosis still holds: a copy view is a second full sort and write.

The setting that changed under everyone: parallel_view_processing

The docs say parallel_view_processing defaults to 0, meaning “Materialized Views are executed sequentially in uuid order”. Their example has three views that each sleep(1). It takes 3.786 s sequentially and 1.588 s with the setting on.

Through 2025 and 2026 the setting stopped doing what the docs say, and then started again. The version table below was put together by two users in issue #106845 with the docs example. The last rows come from the fix and the setting history:

Version parallel_view_processing = 0 (default) = 1
≤ 25.5 serial parallel
25.6 – 25.9 (#77309, “rework pushing to views”) INSERT … SELECT parallel, INSERT … VALUES serial same, ignored
25.10 – 26.6.3 (#87280, “squash matview concurrent inserts”) always parallel parallel
26.7+, 26.6.4.38+, 26.3.29.8+ (#109170) serial, one thread parallel
What a materialized view does to an INSERT, release by release≤ 25.5parallel_view_processing works as documenteddefault 0: views one after another25.6#77309 reworks pushing to viewsINSERT … SELECT always parallel, INSERT … VALUES always serial25.10#87280 (squash matview inserts)views always parallel, whatever the setting says26.1 / 26.2dedup in dependent views on by default (26.2)views stop re-squashing blocks: one target part per source block26.7#109170: the setting is honoured againdefault 0 = one thread (also 26.6.4.38 and 26.3.29.8)26.8max_insert_threads = cores by default…except into tables with views; stats built on insertUpgrading from 25.10–26.6 to 26.7+ can turn parallel view pushes back into a serial, single-thread INSERT.
Sources: version table in issue #106845, PR #109170, issue #112345, PR #109000 and the setting history in Settings.cpp.

The fix in #109170 is small, and it goes further than “run the views one after another”. It adds getViewProcessingNumThreads(), which returns max_threads when parallel_view_processing is on or the table has no views, and 1 otherwise. Two call sites use it:

  • addInsertToSelectPipeline calls pipeline.limitMaxThreads(...) on the whole INSERT … SELECT pipeline. The SELECT that reads the source data is part of that pipeline, so it is capped at one thread as well.
  • buildPushPipelineFromDependencies, used for plain INSERT … VALUES / FORMAT inserts, sets pipeline.setNumThreads(serial_views ? 1 : max_threads).

The regression test that came with it (04490_parallel_view_processing_values) checks peak_threads_usage in system.query_log: “serial” means at most two threads, “parallel” at least three.

The result is the opposite of what 26.8 promised. In 26.8 max_insert_threads changed its default from 1 to 0, meaning the number of cores (PR #109000 and the setting history). But the setting’s own description lists the exceptions, and one of them is a destination that “has dependent materialized views … (unless parallel_view_processing is enabled and the dependent view chains are free of deduplication hazards)”. In the source, sink_stream_size starts at 1 and is set to max_insert_threads only when parallel_view_processing || !isViewsInvolved(). So on 26.8+ a table without views gets a parallel insert, and adding its first view turns that off.

What it looked like in production

Issue #133571, opened on 2026-11-22, is from a deployment of 6 servers ingesting about 1 million rows a second per node through async inserts (wait_for_async_insert = 1) into tables with views. The reporter’s own system.query_log numbers:

Period Inserts Threads per insert Avg insert time Parts written per insert
26.3.12.3 3,836,165 5.4 293 ms 3.6
26.8.34.13, max_insert_threads auto 20,735 1 1,557 ms 4.8
26.8.34.13, max_insert_threads = 32 290 1 1,468 ms 4.4

Changing max_insert_threads did nothing, as the source predicts. A maintainer reproduced the drop and named two causes. The first is #109170: parallel_view_processing = 0 is honoured again, so the inserts run on one thread. The second is that since 26.8 column statistics are built on insert by default (materialize_statistics_on_insert = 1, auto_statistics_types = 'basic, uniq_v2', for tables under materialize_statistics_on_insert_max_table_size = 25 GiB). The maintainer estimates this adds roughly 30% per inserted part, for the source and for every view target. That 30% is their estimate, and I found no separate measurement of it. Their suggested fix is parallel_view_processing = 1 in the ingest user’s profile (they checked that it applies to async insert flushes), plus materialize_statistics_on_insert = 0 if you don’t use the statistics.

Note that 26.3.12.3, the reporter’s “good” version, is older than the 26.3.29.8 backport. Staying on the 26.3 LTS line doesn’t avoid the change: a later 26.3 patch release brings it in too.

Parts: why views stopped squashing in 26.2

min_insert_block_size_rows_for_materialized_views and its _bytes twin are meant to squash small blocks before they reach a view’s target, so a view produces fewer, bigger parts. In 26.11 the squashing step only exists when this holds:

squash_parallel_inserts =
    !deduplicate_blocks_in_dependent_materialized_views
    && settings[Setting::materialized_views_squash_parallel_inserts];

deduplicate_blocks_in_dependent_materialized_views became on by default in 26.2 (“Enable deduplication for dependent materialized views by default”). Since #89140 (26.1), that flag decides whether a view branch squashes at all, so on default settings each source block becomes its own part in every view target. A ClickHouse developer explained in issue #112345 that the two currently exclude each other: “Either deduplication in MV’s targets or squashing”. The reproduction in that issue inserts 10,000 rows as 10 blocks and gets 10 parts in the view target with dedup on and 1 part with it off. The reporter’s own query log for the same insert job, before and after upgrading from 25.12.9.61 to 26.6.2.81:

Parts written per day Rows written per day Rows per part (arithmetic)
25.12 (2026-07-20) 7,906 540,658,588 68,386
26.6 (2026-07-22) 33,320 518,717,579 15,568

That is 4.4× more parts for the same data. All of those parts have to be merged later, and every one of them counts toward “too many parts”.

Errors: source and views are not one write

Each table in the chain commits its own parts. If the server dies after the source part is committed and before a view’s part is, the source keeps the rows and the view target doesn’t. Issue #104661 reproduces both partial states (t_src = 500, t_1 = 0 and t_src = 500, t_1 = 500, t_2 = 0). The setting description for materialized_views_ignore_errors (default off) is explicit that it controls only error reporting and “does not roll back a write to the source table”. The documented path to exactly-once is to retry the failed INSERT with insert deduplication on. That is the reason deduplicate_blocks_in_dependent_materialized_views is now on by default, and the reason squashing gave way to it. parallel_view_processing doesn’t change any of this. It only changes which partial states are possible.

What to do on 26.7 and later

If you see Do this
Inserts into a table with views slower after upgrading to 26.7+ / 26.6.4.38+ / 26.3.29.8+ Check length(thread_ids) and peak_threads_usage in system.query_log. If they’re 1, set parallel_view_processing = 1 for the ingest user, provided the views are independent of each other
INSERT … SELECT backfill into a table with views is slow Same setting: with 0, the SELECT side is also limited to one thread
max_insert_threads has no effect Expected with views unless parallel_view_processing = 1. The per-insert fan-out also stays off when a view target is Distributed or Buffer, or with use_strict_insert_block_limits
Many small parts in view targets Bigger client batches (or async inserts) first. deduplicate_blocks_in_dependent_materialized_views = 0 brings back min_insert_block_size_rows_for_materialized_views, but retries can then duplicate rows in the views
Insert CPU up ~30% after 26.8, small tables materialize_statistics_on_insert = 0 if no query relies on the statistics
Dozens of views that each copy most rows Layer them: one filtering view, then the logic on its output. Each copy view is a full extra sort and write
Views that read the source back through a JOIN Keep parallel_view_processing = 0, or look at wait_for_part_commit_in_dependent_materialized_views (26.6+)

parallel_view_processing = 1 is not free. All views run at once, so peak CPU and memory per insert go up. The docs also warn that parallel runs give “no guarantees to the order at which rows arrive to the target table”. For views that depend on each other, keep it off.

FAQ

How many materialized views can a ClickHouse table have? There is no fixed limit. The cost scales with the rows the views write and the parts they create, not with the number of views. In Altinity’s test each SELECT * view cost about one full extra write, while fifty views that each kept 1/50 of the rows were about as cheap as ten.

Do ClickHouse materialized views slow down inserts? Yes. Each one runs its query on every inserted block, sorts the result again and writes one more part. Published numbers: −36% to −55% inserts per second for one copy view, and +81% CPU per insert for a 1:1 view in a 2026 profile. The INSERT returns only after every view is written.

Is parallel_view_processing on by default? No, the default is 0. From 25.10 until 26.6.3 it was ignored and views always ran in parallel. Since 26.7 (26.6.4.38, 26.3.29.8) it works again, and with 0 an insert into a table with views runs on one thread.

Why does max_insert_threads do nothing on my table? On a table with materialized views, the write fan-out happens only with parallel_view_processing = 1 and no deduplication hazard in the view chain. A Distributed or Buffer view target counts as a hazard, and so does use_strict_insert_block_limits combined with deduplication. Async inserts are always written as a single stream.

Are materialized view inserts atomic with the source table? No. Each table commits its own parts. A crash or error can leave rows in the source and not in a view. Retry with insert deduplication on (the default) to converge.

Tomorrow, day 16: deleting rows, comparing lightweight DELETE, ALTER … DELETE and ReplacingMergeTree tombstones.