Skip to content

Cherry pick #111930 to 26.7: Fix Block structure mismatch when the split filter column name clashes with an input - #114292

Merged
robot-ch-test-poll4 merged 5 commits into
backport/26.7/111930from
cherrypick/26.7/111930
Aug 11, 2026
Merged

robot-ch-test-poll4 merged 5 commits into
backport/26.7/111930from
cherrypick/26.7/111930

Conversation

@robot-clickhouse-ci-2

Copy link
Copy Markdown
Contributor

Original pull-request #111930

Do not merge this PR manually

This pull-request is a first step of an automated backporting.
It contains changes similar to calling git cherry-pick locally.
If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.

The check results does not matter at this step - you can safely ignore them.

Troubleshooting

If the conflicts were resolved in a wrong way

If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

groeneai and others added 4 commits July 26, 2026 03:05
…an input

The AST fuzzer hit a logical error during query plan optimization:

  Block structure mismatch in IntersectOrExceptStep stream: different number
  of columns: ... __split_filter Nullable(Nothing) ... / (sibling has 3 cols)

trySplitFilter hand-rolled a workaround for the case where the filter column
name is also an input name. It called splitActionsForFilter without
avoid_duplicate_inputs, so the first DAG half ended up with two same-named
outputs (the pass-through input and the promoted computed filter node), and
then renamed the first match to the literal "__split_filter". Given the append
order, that first match is the pass-through, not the computed node. The rename
also reused remove_filter, a flag computed for the ORIGINAL name in the OTHER
half, as the removal flag for the synthetic name; when it is false the inner
FilterStep keeps the column. The outer ExpressionStep cannot drop it either,
because split.second's inputs still carry the original name and
ActionsDAG::updateHeader passes through unmatched header columns. So
__split_filter reached the branch output header, and the parent-header refresh
loop in optimizeTreeFirstPass pushed the wider header into
IntersectOrExceptStep::checkHeaders against the sibling branch.

ActionsDAG::split already solves this collision properly when
avoid_duplicate_inputs is set: it renames the promoted computed node in the
first half and repairs the second half by adding an input under the new name
while rewriting the old node into an ALIAS onto it, so second-half references
to the original name still resolve. Delete the hand-rolled workaround, set both
flags inside splitActionsForFilter (it has a single caller, so its signature
and ActionsDAG.h are untouched), and read the filter name from
split_nodes_mapping, the same idiom as splitSingleAndFilter in FilterStep.cpp.
The rename only fires on a genuine collision, so plans without one are
unchanged. __split_filter no longer exists in the source.

The leak also aborts with UNION ALL and EXCEPT, since they share the same
checkHeaders shape, so the test covers all three. It asserts the branch output
header column count rather than the absence of a literal name, so a stray
internal column would be caught under any name, and it asserts the '[split]'
step marker so the file cannot pass without the optimization running. A second
query keeps the clashing name live downstream and pins its result values, which
proves the renamed column still resolves in the second half.

Found by AST fuzzer (amd_msan) on an unrelated PR, STID 0993-315b. Same family
as #108142 and #108210.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Co-Authored-By: Claude Fable 5 <[email protected]>
…ader-leak

Fix Block structure mismatch when the split filter column name clashes with an input
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default labels Aug 11, 2026
Resolve conflict in src/Processors/QueryPlan/Optimizations/splitFilter.cpp
by taking the change from #111930: the old filter_name_clashes_with_input
workaround is replaced by the split_nodes_mapping-based rename.

Co-Authored-By: Claude Fable 5 <[email protected]>
@robot-ch-test-poll4
robot-ch-test-poll4 merged commit 61c4dd3 into backport/26.7/111930 Aug 11, 2026
1 check passed
@robot-ch-test-poll4
robot-ch-test-poll4 deleted the cherrypick/26.7/111930 branch August 11, 2026 22:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants