Repository navigation
Fix logical error 'visited_views == right->visited_views' on parallel materialized view squashing - #107027
Conversation
… MV squashing When two materialized views on the same source table write to the same target table, and a dependent view reads that target (e.g. via a scalar subquery), an INSERT could abort the server with a debug/sanitizer assertion: Logical error: 'this->visited_views == right->visited_views' DeduplicationInfo::mergeSelf (src/Interpreters/InsertDeduplication.cpp) Root cause: with insert deduplication disabled, the parallel-insert squashing optimization (materialized_views_squash_parallel_inserts, on by default) merges chunks produced by the different views. Those chunks carry DeduplicationInfo whose visited_views chains legitimately differ, because they originated from different views. mergeSelf asserted the chains were equal. That assertion is over-strict when deduplication is disabled. visited_views is only bookkeeping in that case: getDeduplicationHashes returns an empty set when disabled, and the deduplication retry path is unreachable. The two sibling visited_views checks in the same function are already guarded by !disabled; this brings the equality check in line with them. When deduplication is enabled, squash_parallel_inserts is forced off, so the convergence cannot happen and the assertion stays fully active to catch real bugs. This was observed by the experimental serverfuzz Stress test on master and in several Stress runs across unrelated PRs. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate
Session id: cron:clickhouse-worker-slot-2:20260610-150600 |
|
cc @CheSema @al13n321 could you review this? It relaxes the |
|
Workflow [PR], commit [c6039a1] Summary: ❌
AI ReviewSummaryThis PR relaxes the PR Metadata
### Changelog category (leave one):
- CI Fix or Improvement (changelog entry is not required)
### Changelog entry (a [user-readable short description](https://github.com/ClickHouse/ClickHouse/blob/master/docs/changelog_entry_guidelines.md) of the changes that goes into CHANGELOG.md):
...Missing context / blind spots
Findings
Final VerdictStatus: ✅ Approve No inline code findings. The metadata cleanup above is recommended before merge. |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 4/5 (80.00%) | Lost baseline coverage: none · Uncovered code |
|
@groeneai I do not see |
The test relied on an implicit precondition: parallel-insert squashing (materialized_views_squash_parallel_inserts) is force-disabled whenever deduplication for dependent materialized views is on, so the squashing path that triggers the assertion is only reachable when MV deduplication is off. The original INSERT did not set deduplicate_blocks_in_dependent_materialized_views; it happened to be effectively off because INSERT ... SELECT FROM numbers() is a non-stable INSERT SELECT and deduplicate_insert_select=enable_when_possible (default) auto-disables deduplication for it. That is subtle and easy to break under settings randomization, so set the setting explicitly to make the precondition unambiguous. Verified on a default-settings clickhouse-server: the test still aborts the server with 'this->visited_views == right->visited_views' on a binary without the fix, and passes with the fix. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
@CheSema good question, and you are right that the precondition was only implicit. I have now set it explicitly (pushed in c6039a1). How the failure was triggered without setting The INSERT is That is what unblocks the squashing path: With squashing on, chunks from I verified this on a default-settings On the |
|
CI summary on HEAD
No PR-caused failures on the current HEAD. Ready for review. |
f81e540
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a server crash (logical error
this->visited_views == right->visited_views) onINSERTwhen two materialized views on the same source table write to the same target table and a dependent view reads that target, withmaterialized_views_squash_parallel_insertsenabled.Description
When two materialized views on the same source table write to the same target table, and a dependent materialized view reads that target (for example via a scalar subquery), an
INSERTcould abort the server in debug and sanitizer builds:Root cause: with insert deduplication disabled, the parallel-insert squashing optimization (
materialized_views_squash_parallel_inserts, enabled by default) merges chunks produced by the different views. Those chunks carryDeduplicationInfowhosevisited_viewschains legitimately differ, because they originated from different views.mergeSelfasserted the chains were equal.The assertion is over-strict when deduplication is disabled. In that case
visited_viewsis only bookkeeping:getDeduplicationHashesreturns an empty set when disabled, and the deduplication retry path is unreachable. The two siblingvisited_viewschecks in the same function are already guarded by!disabled; this change brings the equality check in line with them. When deduplication is enabled,squash_parallel_insertsis forced off, so the convergence cannot happen and the assertion stays fully active to catch real bugs.Found by the experimental serverfuzz Stress test on master, and seen in several Stress runs across unrelated PRs. Added a regression test
04327_mv_squash_parallel_inserts_visited_views.Version info
26.6.1.645