Repository navigation
Make cascading materialized views see the row being inserted - #105943
Conversation
A materialized view whose inner SELECT reads the source storage via `INNER JOIN` back to the source can miss the row currently being inserted: `MergeTreeSink::consume` and `ReplicatedMergeTreeSink::consume` defer the part commit via the `delayed_chunk` pattern, but the MV cascade acquires its `StorageSnapshot` before that deferred commit runs. The new setting `wait_for_part_commit_in_dependent_materialized_views` (default `false`) makes the sink finish the delayed chunk inside `consume` whenever the destination has at least one dependent view, committing the part before yielding to the cascade. When disabled, the existing parallel-write overlap is preserved.
|
Workflow [PR], commit [121b7f9] Summary: ✅
AI ReviewSummaryThis PR adds Missing context / blind spots
Tests
Final VerdictStatus: Minimum required action: add focused non-replicated |
| finishDelayedChunk(); | ||
| delayed_chunk = std::make_unique<MergeTreeDelayedChunk>(); | ||
| delayed_chunk->partitions = std::move(partitions); | ||
| if (synchronously_commit_part_for_dependent_views) |
There was a problem hiding this comment.
The fix updates both MergeTreeSink::consume and ReplicatedMergeTreeSink::consume, but the new regression test covers only ReplicatedMergeTree.
Can you add a focused MergeTree variant of this cascade (INNER JOIN back to the source with wait_for_part_commit_in_dependent_materialized_views = 1) to prove the non-replicated path is protected too? Right now we have no test evidence for this branch.
| { | ||
| delayed_chunk = std::make_unique<MergeTreeDelayedChunk>(); | ||
| delayed_chunk->partitions = std::move(partitions); | ||
| finishDelayedChunk(); | ||
| } | ||
| else | ||
| { | ||
| finishDelayedChunk(); | ||
| delayed_chunk = std::make_unique<MergeTreeDelayedChunk>(); | ||
| delayed_chunk->partitions = std::move(partitions); | ||
| } |
There was a problem hiding this comment.
What happens if materialized_views_ignore_errors = 0, wait_for_part_commit_in_dependent_materialized_views = 1. Wouldn't the data be committed to the table in case an exception is thrown in the depedant view? I think we should think about what is the correct way to handle this.
There was a problem hiding this comment.
What about just documenting the behavior properly and let the user to decide to enable the setting since it's disabled by default?
There was a problem hiding this comment.
materialized_views_ignore_errors=0 -- ignores the errors in MV's processors (select and sinks)
The data might either be commited in the dest table in that case or not. We do not provide guarantee here. We encourage users do reties, they will commit missed data.
wait_for_part_commit_in_dependent_materialized_views=1 adds prefix guarantees indeed.
I do not see the issue here. Or I do not understand the case.
There was a problem hiding this comment.
No still wait_for_part_commit_in_dependent_materialized_views=1 won't provide prefix commit guarantees.
If your insert several blocks they are handled by different instances of sync processors which work in parallel. Each parallel branch would have its own prefix. All together they would not have it.
prefix commit guarantees is only reachable here when insert works in one thread.
There was a problem hiding this comment.
No still
wait_for_part_commit_in_dependent_materialized_views=1won't provide prefix commit guarantees. If you inserts several blocks they are handled by different instances of sync processors in parallel. Each branch would have its own prefix. prefix commit guarantees is only reachable here when insert works in one thread.
what solution would you recommend? Should we force to a single thread insert when the setting is enabled or just document the limitation?
There was a problem hiding this comment.
The data might either be commited in the dest table in that case or not.
Based on our docs (which might be misunderstood by me) if we have an insert chain insert -> table -> mv -> mv_table and materialized_views_ignore_errors = 0, then if the insertion into mv_table fails, the block won't be inserted into table neither. With this change I think this behavior is changed.
There was a problem hiding this comment.
That ineresting that you have such impression from the doc.
Could you please point to the exact part there?
I see there
Allows to ignore errors for MATERIALIZED VIEW, and deliver original block to the table regardless of MVs
And it says nothing about what would be inserted in target table in case of an error in MV part.
There was a problem hiding this comment.
"Allows" suggests that without that it is "prohibited", so that makes the impression for me that if ignore_errors = 0 the original block won't be delivered.
If it would "ensure" that the block is delivered, then I would say it doesn't say anything about what happens if the errors are not ignored.
There was a problem hiding this comment.
I see, we better to alter that description then.
There was a problem hiding this comment.
More symboles in the description than it was, but it describes it with complete context.
| , context(context_) | ||
| , storage_snapshot(storage.getStorageSnapshotWithoutData(metadata_snapshot, context_)) | ||
| , deduplicate((*storage.getSettings())[MergeTreeSetting::non_replicated_deduplication_window] > 0 && storage.getDeduplicationLog() != nullptr) | ||
| , synchronously_commit_part_for_dependent_views( |
There was a problem hiding this comment.
The same changes needs to be done in private for SMT, right?
There was a problem hiding this comment.
yes, this public PR is fork of https://github.com/ClickHouse/clickhouse-private/pull/58692
There was a problem hiding this comment.
It make sense to make private part of that changes in the sync PR. I usually do it in that way.
The previous one-line description ("Allows to ignore errors for MATERIALIZED
VIEW, and deliver original block to the table regardless of MVs") was read
as implying that with the setting disabled the original block is not
delivered to the source table when a dependent view throws. That is not
what the setting does: it controls only how MV pipeline errors are reported
and provides no atomicity guarantee against the source table either way.
Discussed in ClickHouse#105943 (comment)
CheSema
left a comment
There was a problem hiding this comment.
OK from me, but I do not see the private part in sync PR
it should be done now. |
|
📊 Cloud Performance Report ✅ AI verdict: This PR adds a new opt-in setting (wait_for_part_commit_in_dependent_materialized_views, default off) that only changes INSERT behavior for tables with dependent materialized views; it touches sink-side part-commit plumbing, not the query-execution path. The two flagged ClickBench improvements (Q4 -12.2%, Q15 -16.7%) are read-only SELECTs that exercise none of this code, and with the setting disabled by default the new branch never runs. Both apparent gains are run-to-run variance rather than a real effect of this change, so both have been downgraded to not-sure. No action needed on these queries. clickbenchFlagged queries (2 of 43)
q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_official🟢 No significant changes Debug info
|
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 51/58 (87.93%) | Lost baseline coverage (was covered on master, now uncovered in this PR): 1 line(s) · Uncovered code |
Cherry pick #105943 to 26.3: Make cascading materialized views see the row being inserted
Cherry pick #105943 to 26.4: Make cascading materialized views see the row being inserted
Cherry pick #105943 to 26.5: Make cascading materialized views see the row being inserted
… see the row being inserted
… see the row being inserted
… see the row being inserted
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
A materialized view whose inner SELECT reads the source storage via
INNER JOINback to the source can miss the row currently being inserted:MergeTreeSink::consumeandReplicatedMergeTreeSink::consumedefer the part commit via thedelayed_chunkpattern, but the MV cascade acquires itsStorageSnapshotbefore that deferred commit runs.The new setting
wait_for_part_commit_in_dependent_materialized_views(defaultfalse) makes the sink finish the delayed chunk insideconsumewhenever the destination has at least one dependent view, committing the part before yielding to the cascade. When disabled, the existing parallel-write overlap is preserved.Version info
26.6.1.518