Skip to content

materializeBlock: instantiate type-only header columns before materializing - #122128

Merged
vdimir merged 4 commits into
ClickHouse:masterfrom
iliasabk:fix/join-materialize-typeonly-column
Oct 15, 2026
Merged

vdimir merged 4 commits into
ClickHouse:masterfrom
iliasabk:fix/join-materialize-typeonly-column

Conversation

@iliasabk

@iliasabk iliasabk commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Closes: #121906

Changelog category (leave one):

  • Critical Bug Fix (crash, data loss, RBAC)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fix a server crash when a RIGHT JOIN/FULL JOIN is planned for parallel replicas (parallel_replicas_plan_based=1) and the join output header declares a column by type only — e.g. the residual column of a constant NULL conjunct in the ON clause. Type-only header columns are now materialized as an empty column of the declared type instead of being dereferenced as null.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Motivation / issue

Fixes #121906 — a RIGHT JOIN whose ON clause carries a constant NULL conjunct (AND CAST(NULL AS Nullable(UInt8))) segfaults under parallel_replicas_plan_based=1 while the join step builds its output header. Reproduced 3/3 by the reporter on 26.10.1.552; INNER/LEFT/FULL and untyped-NULL/toNullable(1) variants are unaffected.

JoinStep::updateOutputHeader -> JoiningTransform::transformHeader -> ConcurrentHashJoin::initialize -> HashJoin::materializeColumnsFromLeftBlock calls materializeBlockInplace on the left header (required for RIGHT/FULL joins so non-joined rows get correct defaults). Under plan-based parallel replicas that header can declare a column by type only (column == nullptr) — e.g. the residual column for the constant NULL conjunct — and materializeBlockInplace (src/Core/Block.cpp) dereferenced it unconditionally, giving the SIGSEGV at Block.cpp element.column->convertToFullColumnIfConst().

Fix

materializeBlock and materializeBlockInplace now instantiate an empty column of the declared type (element.type->createColumn()) for type-only entries before materializing — the same convention JoinStepLogical::updateOutputHeader already uses for null header columns from ActionsDAG::getResultColumns(). This covers every caller that can receive a type-only header column (join initialization, post-join header materialization in transformHeader, and the parallel-replicas header reconciliation in PlannerJoinTree).

Regression test

tests/queries/0_stateless/04768_parallel_replicas_right_join_null_conjunct.sql runs the issue's RIGHT JOIN ... AND CAST(NULL AS Nullable(UInt8)) under the plan-based parallel-replicas settings (test_cluster_one_shard_three_replicas_localhost, max_parallel_replicas=3, parallel_replicas_for_non_replicated_merge_tree=1), checks the same path for FULL JOIN, and a matching RIGHT JOIN control.

Verification

Not built locally — the change instantiates a declared-type column for type-only header entries plus the stateless test; the diff was reviewed against master and relies on CI for compilation and test execution.


Workflow [PR]
Sync PR [sync-upstream/pr/122128]

Version info

  • Merged into: 26.10.1.2505-master (included in 26.10 and later)
  • Backported to: 26.10.8.22, 26.9.20.21, 26.8.29.8

…lizing

A RIGHT/FULL JOIN under plan-based parallel replicas can receive a left
header whose columns are declared by type only (column == nullptr), e.g.
the residual column from a constant NULL conjunct in the ON clause.
HashJoin::materializeColumnsFromLeftBlock calls materializeBlockInplace
on that header, which dereferenced the missing column -> SIGSEGV in
JoiningTransform::transformHeader -> JoinStep::updateOutputHeader.

Instantiate an empty column of the declared type for type-only entries,
matching the existing convention in JoinStepLogical::updateOutputHeader.

Fixes ClickHouse#121906
@clickhouse-gh clickhouse-gh Bot added comp-joins JOINs end-to-end (planning hooks + runtime join operators/algorithms). Single bucket to avoid pla... external Author is not a member of the ClickHouse organization labels Sep 25, 2026
@yariks5s yariks5s added the can be tested Allows running workflows for external contributors label Sep 28, 2026
@yariks5s

Copy link
Copy Markdown
Member

Please make a PR comment in accordance with the template

@clickhouse-gh

clickhouse-gh Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [cf34c8d]

Summary: ✅


AI Review

Summary

This PR fixes the materializeBlock / materializeBlockInplace null dereference when a plan-derived header carries a type-only column, and adds a stateless regression test for the RIGHT JOIN / FULL JOIN parallel-replicas path. I did not find any remaining correctness or safety issues in the current diff; the earlier test-vacuity concern about automatic_parallel_replicas_mode is fixed, and the current Praktika report for the PR is all green.

Final Verdict

✅ No actionable findings in the current revision.

LLVM Coverage Report

Measured on commit cf34c8d.

Metric Baseline Current Δ
Lines 88.20% 88.30% +0.10%
Functions 92.10% 92.10% +0.00%
Branches 79.70% 79.70% +0.00%

Changed lines: Changed C/C++ lines covered: 9/9 (100.00%) · Uncovered code

Full report · Diff report

@iliasabk

Copy link
Copy Markdown
Contributor Author

Done — the Closes: link is now visible text below the template comment block instead of inside it. Thanks for the heads-up.

@vdimir vdimir self-assigned this Sep 29, 2026
@clickhouse-gh clickhouse-gh Bot added pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! labels Sep 29, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Commit cf34c8d05b11c3e086f99444454db9c0bb76b1b7 was not compared: the CI logs cluster did not answer (every POST attempt failed with an exception).

See the job log for details.

@clickhouse-gh

clickhouse-gh Bot commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 32 queries analysed

no significant changes detected. K_source=6 K_base=30 flagged=0/65

clickbench

🟢 No significant changes

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: 0d574d07-7957-400a-b6d7-a2bced06af06
  • MIRAI run: 2c66f2b7-1978-4830-8756-cea3e0d2b2b0
  • PR check IDs:
    • clickbench_3235312_1791145830
    • clickbench_3235318_1791145831
    • clickbench_3235329_1791145831
    • tpch_adapted_1_official_3235347_1791145831
    • tpch_adapted_1_official_3235369_1791145831
    • tpch_adapted_1_official_3235383_1791145831

…test

Without this, the harness-randomized automatic mode can pick a
single-replica plan for the small test tables, so the test never
exercises the plan-based parallel-replicas header-building path and
passes vacuously even if the original segfault regresses.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@iliasabk

iliasabk commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

Fixed — pinned automatic_parallel_replicas_mode = 0 before the parallel-replicas settings in the new regression test (matching the convention in neighboring tests like 04041_materialized_cte_parallel_replicas.sql), so it always exercises the plan-based parallel-replicas header-building path instead of possibly passing vacuously under the harness-randomized automatic mode.

@CLAassistant

CLAassistant commented Oct 6, 2026 •

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
2 out of 3 committers have signed the CLA.

✅ iliasabk
✅ alexey-milovidov
❌ Ilias Aberkane


Ilias Aberkane seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

clickhouse-gh Bot added a commit that referenced this pull request Oct 15, 2026
Backport #122128 to 26.9: materializeBlock: instantiate type-only header columns before materializing
clickhouse-gh Bot added a commit that referenced this pull request Oct 15, 2026
Backport #122128 to 26.8: materializeBlock: instantiate type-only header columns before materializing
strtgbb pushed a commit to Altinity/ClickHouse that referenced this pull request Oct 21, 2026
…e-only header columns before materializing
@fm4v fm4v added v26.10-must-backport and removed pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore labels Nov 19, 2026
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Nov 19, 2026
clickhouse-gh Bot added a commit that referenced this pull request Nov 19, 2026
Backport #122128 to 26.10: materializeBlock: instantiate type-only header columns before materializing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-joins JOINs end-to-end (planning hooks + runtime join operators/algorithms). Single bucket to avoid pla... external Author is not a member of the ClickHouse organization pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v26.10-must-backport

Projects

None yet

9 participants