Repository navigation
Fix parallel_view_processing setting being ignored for MV fan-out - #109170
Conversation
Since 25.10 (#87280), `parallel_view_processing=0` had no effect — materialized views always ran in parallel regardless of the setting. The root cause was that `InsertDependenciesBuilder` builds a `CopyTransform` fan-out to all dependent MV branches, and the pipeline executor thread ceiling was set to `max_threads` unconditionally in three places: - `InsertDependenciesBuilder::createChainWithDependencies` - `InsertDependenciesBuilder::createChainWithDependenciesForAllStreams` (rebuilt squashing path) - `InterpreterInsertQuery::buildInsertPipeline` (decisive overwrite for `INSERT ... VALUES` — the builder is called with `max_insert_threads=1` but the pipeline was widened back to `max_threads` before execution) For `INSERT ... SELECT` the source side can raise `Pipe::max_parallel_streams` above 1, so a chain-level fix alone is insufficient; `limitMaxThreads` is needed after `setMaxThreads` in `addInsertToSelectPipeline`. Fix: introduce `InsertDependenciesBuilder::getViewProcessingNumThreads()` which returns `max_threads` when `parallel_view_processing=1` or no views are involved, and 1 otherwise. Use it in all four call sites. Closes: #106845 Co-Authored-By: Claude Sonnet 4.6 (1M context) <[email protected]>
|
Workflow [PR], commit [101a0c7] Summary: ❌
AI ReviewSummaryThis PR caps the MV insert pipeline when Missing context / blind spots
Findings❌ Blockers
Final VerdictChanges requested. |
InterpreterInsertQuery.cpp referenced Setting::parallel_view_processing without declaring it in its local namespace Setting block, which fails to compile since each translation unit must locally declare every Setting:: tag it uses.
| pipeline.setNumThreads(max_threads); | ||
| // max_threads is already memory-adjusted; use it for the parallel case to preserve that adjustment. | ||
| const bool serial_views = !settings[Setting::parallel_view_processing] && insert_dependencies->isViewsInvolved(); | ||
| pipeline.setNumThreads(serial_views ? 1 : max_threads); |
There was a problem hiding this comment.
parallel_view_processing = 0 is still ineffective when use_async_executor_for_materialized_views = 1. The new serial_views ? 1 : max_threads cap only throttles the outer insert pipeline, but createSelect can still build ExecutingInnerQueryFromViewTransform<PullingAsyncPipelineExecutor> for every view (InsertDependenciesBuilder.cpp:1382). On the first pull(), each branch starts its own ThreadFromGlobalPool (PullingAsyncPipelineExecutor.cpp:100-115), and ExceptionKeepingTransform leaves that processor in Generate without blocking the single outer worker. That means one outer thread can walk the other branches and start their async executors too, so the views still run concurrently despite the new cap.
clickhouse-test also randomizes use_async_executor_for_materialized_views, so the new regression test does not pin or cover this mode. To make the fix match the PR contract, serial view processing needs to force the synchronous MV executor (or otherwise serialize async-executor startup) and the test should exercise use_async_executor_for_materialized_views = 1.
| auto & chain = result_chains.emplace_back(std::move(processor_list)); | ||
| chain.attachResources(std::move(resources)); | ||
| chain.setNumThreads(init_context->getSettingsRef()[Setting::max_threads]); | ||
| chain.setNumThreads(getViewProcessingNumThreads()); |
There was a problem hiding this comment.
Why we need this?
Why we need to limit threads on the pipeline for insertion?
parallel_view_processing=0 eliminated the multiple branches for pipeline graph.
But we could execute even single chained pipeline with several threads. I would rather remove this setting than give it more impact.
There was a problem hiding this comment.
I agree with you, but it seems we broke an expected behavior from this setting.
I guess we can just change it to true by default?
|
But in general I'm OK with the changes. It indeed would be more clear if we now handle that setting in this way, and then do make memory accounting more adjustable without manual settings. |
…processing test The 200ms wall-clock duration threshold is unreliable under debug/ASan/MSan/TSan builds, where interpreter overhead alone can push even the genuinely-parallel case past the threshold (observed 5/5 failures in the flaky check for amd_asan_ubsan, amd_debug, amd_msan, amd_tsan). `peak_threads_usage` is an exact count of threads that attached to the query's thread group (`ThreadGroup::linkThread`), not a sampled or timed value, so it distinguishes serial from parallel view processing independent of build overhead. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=109170&sha=dd1d1cd26c4645b68617a12718d9e11e6530177a&name_0=PR&name_1=Stateless%20tests%20(amd_asan_ubsan,%20flaky%20check) Related: #109170
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 22/22 (100.00%) · Uncovered code |
|
Found via ClickGap automated review. Please close or comment if this is incorrect or needs adjustment. TL;DRFix parallel_view_processing setting being ignored for MV fan-out ClickGap verified: reproduced it with the script below on Reproduction-- Reproduces on a server (needs system.query_log). Insert into a table with several
-- dependent MVs and compare peak_threads_usage for parallel_view_processing 0 vs 1.
CREATE TABLE pvp_source (n UInt64) ENGINE=MergeTree ORDER BY tuple();
CREATE TABLE pvp_target (n UInt64, mv UInt8, s UInt8) ENGINE=MergeTree ORDER BY tuple();
-- create 8 MVs that each do real per-row work so the fan-out actually spins up threads
CREATE MATERIALIZED VIEW pvp_mv1 TO pvp_target AS SELECT n, 1 AS mv, sleepEachRow(0.03) AS s FROM pvp_source;
-- ... repeat for pvp_mv2 .. pvp_mv8 ...
-- setting IGNORED == bug: both inserts report the SAME (max) peak_threads_usage
INSERT INTO pvp_source SETTINGS parallel_view_processing=0, max_threads=16, max_insert_threads=16,
max_block_size=1, min_insert_block_size_rows=1, log_queries=1 SELECT number FROM numbers(16);
INSERT INTO pvp_source SETTINGS parallel_view_processing=1, max_threads=16, max_insert_threads=16,
max_block_size=1, min_insert_block_size_rows=1, log_queries=1 SELECT number+100 FROM numbers(16);
SYSTEM FLUSH LOGS query_log;
SELECT Settings['parallel_view_processing'] AS pvp, peak_threads_usage
FROM system.query_log WHERE type='QueryFinish' AND query_kind='Insert'
AND current_database=currentDatabase() ORDER BY event_time DESC LIMIT 2;
-- Observed on buggy build (<=26.5): pvp=0 -> 18 threads, pvp=1 -> 18 threads (setting ignored).
-- Expected/fixed: pvp=0 -> ~2 threads, pvp=1 -> 18 threads.Bisect
Affects
Suggested next stepThe fix has landed on master; the affected release branches above still need the backport. Component: cc fix PR author: @antonio2368 ClickGap · Finding: Triage metadata |
…ening the timeout Since ClickHouse#109170 fixed parallel_view_processing being ignored, MV fan-out is serialized by default (setting defaults to false). This genuinely slowed down `RabbitMQ`'s internal insert-to-views pipeline for the 5 materialized views in this test, which had been relying on the previously-buggy always-parallel behavior. ClickHouse#109892 masked the slowdown by making the test's no-progress deadline reset on progress instead of addressing the throughput regression, which is reverted here. Set `parallel_view_processing = 1` in the test's default profile, which is the only place this setting can be applied for RabbitMQ's internal insert context (it can't be set via `CREATE TABLE ... SETTINGS` or session `SET`, since `StorageRabbitMQ` captures the global context at construction). Verified with the CI msan binary: 188s (serial, default) vs 119s (parallel) for the underlying consumption; combined with the revert, the test now passes in ~124s against the original fixed 180s deadline.
|
Can we backport it? |
Backport #109170 to 26.6: Fix parallel_view_processing setting being ignored for MV fan-out
Cherry pick #109170 to 26.3: Fix parallel_view_processing setting being ignored for MV fan-out
…ignored for MV fan-out
Backport #109170 to 26.3: Fix parallel_view_processing setting being ignored for MV fan-out
…ing being ignored for MV fan-out
…processing test The 200ms wall-clock duration threshold is unreliable under debug/ASan/MSan/TSan builds, where interpreter overhead alone can push even the genuinely-parallel case past the threshold (observed 5/5 failures in the flaky check for amd_asan_ubsan, amd_debug, amd_msan, amd_tsan). `peak_threads_usage` is an exact count of threads that attached to the query's thread group (`ThreadGroup::linkThread`), not a sampled or timed value, so it distinguishes serial from parallel view processing independent of build overhead. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=109170&sha=dd1d1cd26c4645b68617a12718d9e11e6530177a&name_0=PR&name_1=Stateless%20tests%20(amd_asan_ubsan,%20flaky%20check) Related: ClickHouse#109170
…w-processing Fix parallel_view_processing setting being ignored for MV fan-out
…ening the timeout Since ClickHouse#109170 fixed parallel_view_processing being ignored, MV fan-out is serialized by default (setting defaults to false). This genuinely slowed down `RabbitMQ`'s internal insert-to-views pipeline for the 5 materialized views in this test, which had been relying on the previously-buggy always-parallel behavior. ClickHouse#109892 masked the slowdown by making the test's no-progress deadline reset on progress instead of addressing the throughput regression, which is reverted here. Set `parallel_view_processing = 1` in the test's default profile, which is the only place this setting can be applied for RabbitMQ's internal insert context (it can't be set via `CREATE TABLE ... SETTINGS` or session `SET`, since `StorageRabbitMQ` captures the global context at construction). Verified with the CI msan binary: 188s (serial, default) vs 119s (parallel) for the underlying consumption; combined with the revert, the test now passes in ~124s against the original fixed 180s deadline.
OTHER: parallel_view_processing=0 ignored -> behaviour. Effect in the production build a394e92: its upstream test(s) 04490_parallel_view_processing_values fail on it and pass on official 26.8.8.8, run on isolated servers (evidence/fix_ci_20260925/upstream_repro/server_triage_PROD263_vs_UP2688.tsv). Upstream patch unchanged, with its test(s): 04490_parallel_view_processing_values. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes: #106845
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
parallel_view_processingsetting being ignored when inserting into a table with materialized views — since 25.10, views always ran in parallel regardless of the setting.Documentation entry for user-facing changes
Version info
26.7.1.696(included in26.7and later)26.6.4.38,26.3.29.8