Repository navigation
Fix deduplication token attribution for materialized-view targets of partitioned tables - #112649
Conversation
…ialized-view targets filterToPartition attributed each token to partitions by walking its source-row range over a partition selector sized to the sink block. When a materialized view changes the row count before a partitioned deduplicating target, the tokens describe the source rows while the selector describes the smaller view-output block, so the walk read out of bounds (a crash in release builds; a NOT_IMPLEMENTED rejection after #111103's guard). Per-partition attribution is only valid at the direct insert destination; for any materialized-view target (level == VIEW) keep every token in every partition instead. Related: #111100 Related: #111103 Caused by: #111049
|
Workflow [PR], commit [47f7654] Summary: ❌
AI ReviewSummaryThis PR fixes the out-of-bounds read in Findings❌ Blockers
Tests
Final VerdictChanges requested. |
| /// count in its inner query, so there is no mapping from the tokens' source rows to the | ||
| /// view-output selector: keep every token in every partition instead. A repeated token may | ||
| /// still be deduplicated per partition through the cached data hashes. | ||
| if (level == Level::VIEW) |
There was a problem hiding this comment.
level == Level::VIEW is too broad here. setViewID flips that bit for every dependent materialized view, including a trivial TO dst AS SELECT * FROM src where row_to_partition.size() == getRows() and the per-partition attribution is still valid. In those row-preserving cases, returning cloneSelf() feeds the full token list into deduplicateSelf for every partition, so async/user-token duplicates from another partition now participate in the current partition's self-dedup. Because async hashes normalize SOURCE_NUMBER, a single async insert split into multiple source blocks under one insert_deduplication_token can drop the later partition entirely behind a pass-through MV: filterSelf keeps the first duplicate token globally, even if that token wrote no rows to this partition. This fallback needs to key off the mapping actually being lost, not just VIEW.
There was a problem hiding this comment.
After MV's select we could not think that we still have the mapping which row from what insert and which row belongs to what token. The matching rows count does not grant us to make such assumption either.
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 5/5 (100.00%) · Uncovered code |
|
Backport labels have been automatically added based on https://github.com/clickhouse/clickhouse-core-incidents/issues/2006 Labels added:
These labels ensure backport PRs are properly created for each affected release version. The release automation will create backport PRs as needed based on these labels. |
|
Backport labels have been automatically added based on https://github.com/clickhouse/clickhouse-core-incidents/issues/2006 Labels added:
These labels ensure backport PRs are properly created for each affected release version. The release automation will create backport PRs as needed based on these labels. |
…erialized-view targets of partitioned tables
Backport #112649 to 26.7: Fix deduplication token attribution for materialized-view targets of partitioned tables
|
The current release of 26.7 does not contain this bug-fix, and we really need it. Is it possible to cut a new patch release of 26.7 that includes this PR? |
|
@EmeraldShift I'm so sorry, we are currently improving the patch release process, and it might take us up to 1 week to release it. |
|
@EmeraldShift new release v26.7.3.19-stable |
|
Thank you for the quick turnaround! |
Backport #112649 to 26.5: Fix deduplication token attribution for materialized-view targets of partitioned tables
Backport #112649 to 26.6: Fix deduplication token attribution for materialized-view targets of partitioned tables
|
Backport labels have been automatically added based on https://github.com/clickhouse/clickhouse-core-incidents/issues/2006 Labels added:
These labels ensure backport PRs are properly created for each affected release version. The release automation will create backport PRs as needed based on these labels. |
…on for materialized-view targets of partitioned tables
…on for materialized-view targets of partitioned tables
|
Would it be backported to 26.3? It looks it is present there since 26.3.17.65 and auto-backport failed in linked PR. |
Cherry pick #112649 to 26.3: Fix deduplication token attribution for materialized-view targets of partitioned tables
…erialized-view targets of partitioned tables
Backport #112649 to 26.3: Fix deduplication token attribution for materialized-view targets of partitioned tables
|
It seems that this PR is not backported to 26.4. |
Linked issues
Related: #111100
Related: #111103
Caused by: #111049
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix an out-of-bounds read (a crash in release builds) in insert deduplication when an
INSERTflows through a materialized view whose inner query changes the number of rows and the deduplicating target table is partitioned.DeduplicationInfo::filterToPartitionattributed each deduplication token to partitions by walking the token's source-row range over a partition selector sized to the (smaller) view-output block, reading past its bounds. It now keeps every token in every partition for any materialized-view target — where the source-row-to-partition mapping no longer exists after the row count changed — instead of the out-of-bounds walk (and instead of theNOT_IMPLEMENTEDthat a later guard raised for the same insert).filterToPartitionwas introduced by #111049 to fix an async-insert deduplication-token bleed across partitions (#111031): for a multi-token insert split across partitions it drops, from each partition's part, the tokens whose rows did not land there. That attribution walks each token's source-row range over the partition scatter selector, which is only correct at the direct insert destination, where the deduplication info'soffsetsstill describe exactly the block being split.A materialized-view target can have changed the row count in its inner query (e.g.
GROUP BY), so the tokens describe the source rows while the selector describes the smaller view-output block — there is no source-row-to-partition mapping. #111103 turned the resulting out-of-bounds walk into a fail-loudNOT_IMPLEMENTED, which rejects a legitimate insert. This PR instead keys off the token's own view provenance (level == Level::VIEW, set whenever the data passes through a view) and keeps every token in every partition for any view target. This cannot cause cross-partition false deduplication because the deduplication block id is prefixed with thepartition_id.Tests:
04658_deduplication_mv_row_drift_partitioned— a plain materialized view (noAliasengine) with a row-count-changingGROUP BYinto a partitioned deduplicating target, single-token and two-token; the insert deduplicates instead of crashing or being rejected.04621_deduplication_alias_hop_partitioned_target— the two-token case now deduplicates instead of being rejected withNOT_IMPLEMENTED.Version info
26.8.1.734-master(included in26.8and later)26.7.3.9,26.3.39.4