Repository navigation
Fix Block structure mismatch in UnionStep on a Sparse-vs-full divergent branch - #107041
Conversation
Pre-PR validation gate
Session id: cron:clickhouse-worker-slot-2:20260610-160200 |
|
cc @KochetovNicolai @davenger — could you review this? It fixes the #106956 |
|
Workflow [PR], commit [556f169] Summary: ✅
AI ReviewSummaryThis PR narrows to the sparse-only fix for #107273: Final VerdictStatus: ✅ Approve |
b79cdfa to
d2dc86c
Compare
|
Force-pushed a reworked fix (
The reworked fix addresses the root cause at the single enforcement point instead. The execution-time path ( Pre-PR validation gate
Session id: cron:clickhouse-worker-slot-25:20260610-203600 |
|
cc @KochetovNicolai @davenger — the approach changed since the first review request: instead of materializing constants during plan optimization, the fix now relaxes the plan-time header check in |
CI status — Option-C fix verified, all failures triaged (commit d2dc86c)CI has fully finished on the Option-C HEAD. The three earlier The one remaining red functional check is not caused by this PR:
All other checks green; Finish Workflow / Mergeable succeeded. Ready for review. |
Pre-PR validation gate (sparse follow-up commit
|
| # | Question | Answer |
|---|---|---|
| a | Deterministic repro? | Yes. The #107273 fiddle repro (INSERT INTO src SELECT id, _cdc_is_deleted FROM t_sp pushing through mv) aborts 100% on debug master f1fc3319 with the exact _cdc_is_deleted Bool UInt8(size = 0) vs Sparse(...) signature at UnionStep.cpp:28. |
| b | Root cause explained? | One branch reads _cdc_is_deleted Sparse (mostly-default Bool), the sibling full. Two strict plan-time header checks reject this benign serialization divergence that execution reconciles via makeConvertingActions: site 1 UnionStep::updateOutputHeader at plan construction (the release Code: 49, already relaxed by the first commit), and site 2 the debug-only checkHeaders in optimizeTree.cpp run after each pass. liftUpUnion forces every union-branch input header to the full expression output while a branch child still reads Sparse, so site 2 aborts. |
| c | Fix matches root cause? | Yes. Site 2 now uses assertCompatibleHeader instead of assertBlocksHaveEqualStructure, matching the contract UnionStep::updatePipeline already enforces post-makeConvertingActions (it asserts assertCompatibleHeader under the same debug guard). Not a band-aid: divergent Sparse/full serialization is a legitimate state; the debug check was simply stricter than the runtime contract. |
| d | Test intent preserved / new tests added? | assertCompatibleHeader still catches name/type/count/constant-value mismatches (real plan bugs). New regression test 04328_union_branch_sparse_header_mismatch added (sparse branch pushed to a materialized view). Existing tests, including 04327, unchanged. |
| e | Both directions demonstrated? | 04328 aborts (exit 134) on pristine master f1fc3319 and on the const-fold-only binary (site 2 still present); passes on the fully-fixed binary. Both 04328 and 04327 pass 20/20 via clickhouse-test with randomization; 01556/02381/02516 (the plan tests that were the earlier const-fold pivot's Fast-test failures) all pass. |
| f | Fix is general, not a narrow patch? | The relaxation is at the single shared debug-validation site that covers every set-operation step after every optimization, not just liftUpUnion. Site 1 is already symmetric for UnionStep and IntersectOrExceptStep from the first commit. |
Session id: cron:clickhouse-worker-slot-3:20260611-215000
|
Follow-up commit @KochetovNicolai @davenger could you take another look when you have a moment? |
|
CI fully finished on HEAD CI ledger (covered SHA 7e27bb3):
All failures explained, none PR-caused. Ready for review. cc @KochetovNicolai @davenger (comp-query-planner; UnionStep/IntersectOrExceptStep divergent-serialization fix — const-fold #106956 + sparse #107273). Session: cron:our-pr-ci-monitor:20260612-023000 |
|
CI finished on
All other checks pass. |
KochetovNicolai
left a comment
There was a problem hiding this comment.
This is too complex fix.
A sparse column should be able to be compared with a non-sparse column. They already have the same type. The current invariant that every place can process sparse properly. Let's weaken assertBlocksHaveEqualStructure.
7e27bb3 to
122561a
Compare
|
Done for the sparse case (#107273): weakened the shared One open question on the const-fold case (#106956), which is the other half this PR closes. Const cannot collapse the same way as Sparse: it carries a value, so unwrapping-and-equating in the primitive would drop the existing const-value equality check, and the divergent branch still needs a full output header (not Const) so the declared header matches what execution produces. So I kept the targeted Do you want this PR to keep both (sparse via the primitive + const-fold via the targeted widening), or should I split the const-fold half into a separate PR and scope this one to sparse only? |
Per review (KochetovNicolai): a Sparse column is structurally equal to the full column of the same type it wraps, and every consumer can process sparse, so it must compare equal to a non-sparse column even in the strict structure check. Unwrap ColumnSparse on both sides in the shared checkColumnStructure primitive (used by assertBlocksHaveEqualStructure / blocksHaveEqualStructure) even when allow_materialize is false. Const and Replicated stay strict unless allow_materialize. This fixes the ClickHouse#107273 sparse-vs-full `Block structure mismatch in UnionStep stream` (one branch reads a mostly-default Bool column Sparse, the sibling full, under a materialized view's UNION) at both check sites through the primitive: the plan-construction check in UnionStep::updateOutputHeader and the debug-only checkHeaders after liftUpUnion in optimizeTree.cpp, with no step-specific code. Closes ClickHouse#107273 Co-Authored-By: Claude Opus 4.8 <[email protected]>
122561a to
556f169
Compare
|
@KochetovNicolai done, split as you asked. This PR is now sparse-only (#107273): just the |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 8/8 (100.00%) | Lost baseline coverage: none · Uncovered code |
Cherry pick #107041 to 26.3: Fix Block structure mismatch in UnionStep on a Sparse-vs-full divergent branch
…n a Sparse-vs-full divergent branch
Cherry pick #107041 to 26.4: Fix Block structure mismatch in UnionStep on a Sparse-vs-full divergent branch
…n a Sparse-vs-full divergent branch
Cherry pick #107041 to 26.5: Fix Block structure mismatch in UnionStep on a Sparse-vs-full divergent branch
…n a Sparse-vs-full divergent branch
Backport #107041 to 26.4: Fix Block structure mismatch in UnionStep on a Sparse-vs-full divergent branch
Backport #107041 to 26.3: Fix Block structure mismatch in UnionStep on a Sparse-vs-full divergent branch
Backport #107041 to 26.5: Fix Block structure mismatch in UnionStep on a Sparse-vs-full divergent branch
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a
Block structure mismatch in UnionStep streamlogical error (server abort on debug/sanitizer builds,Code: 49on release builds) that occurred when one branch of aUNION/INTERSECT/EXCEPTread aSparse-serialized column while the sibling branch read the same column as a full one (for example when pushing to a materialized view).Description
Reported in #107273.
A
Boolcolumn with mostly-default values serializesSparse. AUNIONnested under a materialized view'sFROMsubquery can have one branch present that columnSparsewhile the sibling is full:A
Sparsecolumn is structurally the same column as the full column of the same type it wraps, and every consumer can already process sparse, so it should compare equal to a non-sparse column even in the strict structure check (per review). The fix unwrapsColumnSparseon both sides in the sharedcheckColumnStructureprimitive (used byassertBlocksHaveEqualStructure/blocksHaveEqualStructure) even whenallow_materializeis false.ConstandReplicatedstay strict unlessallow_materialize.This fixes the mismatch at both check sites through the one primitive: the plan-construction check in
UnionStep::updateOutputHeaderand the debug-onlycheckHeadersafterliftUpUnioninoptimizeTree.cpp, with no step-specific code. Genuine plan bugs (mismatched names, types, count, or constant values) are still caught.Added regression test
04328_union_branch_sparse_header_mismatch(sparse branch pushed to a materialized view).Version info
26.6.1.952(included in26.6and later)26.5.5.12,26.4.5.65,26.3.16.5