Repository navigation
Conversation
…L filter resolvePlannerOnlyFilters rebuilds a FilterStep with remove_filter = true, using a surviving conjunct's result_name as the filter column name. Because collectFilterConjuncts unwraps aliases, that conjunct can be a column of the step's own output header: filter push-down wraps a pushed predicate in a __filter<name> alias so the removal cannot hit the same-named stream column (ActionsDAG.cpp:3768-3779), and the unwrap discards that protection. checkAndRemoveFilterColumn then erases the column, shrinking the step's output header. The pass replaces node.step outright, so no updateInputHeader reaches the parent JoinStepLogical, whose expression DAG still holds an input node for the erased column, and that node cannot be pruned because the column is also one of the join's outputs. chooseJoinOrder is the first consumer to notice: JoinExpressionActions requires the DAG's input count to equal the left plus right header widths, and aborts with "Input nodes size mismatch in dag". With the join reorder disabled the same inconsistent plan reaches execution and throws NOT_FOUND_COLUMN_IN_BLOCK instead, and a NATURAL JOIN variant, where both sides carry a column of that name, throws UNKNOWN_IDENTIFIER. Re-establish the alias at the rebuild site when the chosen filter node's name collides with the step's output header, which is the same operation, for the same reason, as the push-down site. A Nullable join key is needed to reproduce: it makes the join condition null-rejecting, which is what makes deriveNotNullFiltersFromJoin emit the planner-only marker. Related: ClickHouse#114817 Co-Authored-By: Claude Opus 5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 1 finding), plus my own cold review
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-10:20260909-211000 |
|
cc @KochetovNicolai @antaljanosbenjamin, could you review this? |
|
Workflow [PR], commit [f78b8ab] Summary: ✅
AI ReviewSummaryThis PR re-aliases a surviving planner-only filter conjunct before rebuilding the Findings❌ Blockers
Final Verdict❌ Changes requested. The fix direction is correct, but the rebuilt filter column name still needs a uniqueness guard before this path is safe. LLVM Coverage ReportMeasured on commit f78b8ab.
Changed lines: Changed C/C++ lines covered: 5/5 (100.00%) · Uncovered code |
| /// collectFilterConjuncts unwraps aliases, so the surviving conjunct can be a column of the output header. | ||
| /// The step removes its filter column by name, which would erase that column and break the parent step. | ||
| if (filter->getOutputHeader()->has(new_filter->result_name)) | ||
| new_filter = &new_actions_dag.addAlias(*new_filter, "__filter" + new_filter->result_name); |
There was a problem hiding this comment.
This still doesn't guarantee a distinct filter column name. If the step already has a pass-through column called __filter<name>, promoting the surviving conjunct to that hard-coded alias creates a duplicate name in ActionsDAG::updateHeader: the new filter output is inserted first, then the original pass-through column. Block::insert either throws on mismatched structure or, for matching types, lets erase(filter_column_name) drop the name index for the surviving column.
That means a query that already projects something like toUInt8(7) AS __filteris_active can still fail after this rewrite, even though the old step was valid because the alias only lived under the enclosing and(...) output before resolvePlannerOnlyFilters promoted it. Please generate a unique filter alias here (same idea as the _filter_<name>_<idx> loop in ActionsDAG::createActionsForConjunction) and add that case to the regression test.
There was a problem hiding this comment.
Measured this before answering, and I am not making the change: the precondition is not constructible.
__filter* never reaches a header. grep -rn '"__filter"' src/ has exactly two producers: ActionsDAG.cpp:3777 (the push-down site this guard is patterned on) and this line. At both, the name is the step's own filter column and the step is built with remove_filter=true, so checkAndRemoveFilterColumn erases it. Nothing of that spelling survives into a step output header, so there is no pass-through column of that name to collide with.
The alias is one analyzer qualifier out of reach. The guard fires only when the surviving conjunct is already a column of the output header, so its name is __tableN.<id> and the alias is __filter__tableN.<id>. Every header column at that position is itself __tableN.<id>.
Your example, run verbatim and in its fully-qualified form, with this line instrumented:
SELECT is_active, name, label, `__filter__table1.is_active`
FROM (SELECT 'alpha' AS name, toNullable('k1') AS join_key, 1 AS is_active,
toUInt8(7) AS `__filter__table1.is_active`) AS left_side
INNER JOIN (SELECT 'k1' AS join_key, 'beta' AS label) AS right_side
ON left_side.join_key = right_side.join_key
WHERE is_active AND (label != name);
-- 1 alpha beta 7
fires=1 surviving=[__table1.is_active] alias=[__filter__table1.is_active]
dag_out_same_name=0 dag_node_same_name=0 out_hdr_has_alias=0
out_hdr=[__table1.name, __table1.is_active, __table1.`__filter__table1.is_active`, __table1.join_key]
The projected column lands as __table1.`__filter__table1.is_active` , one qualifier away from the alias, so it cannot spell it.
Breadth: 325 invocations of this pass over the join|not_null|filter_push_down|prewhere|push_down suites (1344 tests), 0 with any same-named DAG node, DAG output or header entry, and 0 cases where the step output header changed in names or order. All 62 distinct header column names observed match ^__table[0-9]+\..
On the cited model: createActionsForConjunction uniquifies against a concrete required_inputs set and gates the loop on has_input_name_collision, so there the collision is reachable. ActionsDAG.cpp:3774-3779 has the same purpose, the same prefix and the same header.has(...) test, and does not uniquify; matching it keeps the two sites consistent.
Not adding the test either: with the precondition unreachable it passes against unpatched master, so it would assert nothing.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units10 translation units recompiled, 79 s compile time in total, 10 of them have a recent master baseline. |
|
A revert of #114817 was opened today as #119275. The pass this patch touches, |
|
Nothing outstanding from my side: I diffed the folded commit ( Two things worth having for the reland. 1. The family reports under two STIDs, and they are one defect. Recomputing the id from the raw CIDB dumps with the CI parser's own 2. Baseline while the pass was in master: 23 CIDB rows over 21 carrier PRs plus one true-master Scope of what I verified, so it is not read as more than it is: the regression test pins the DAG fingerprint that 7 of those 23 rows carry (it was minimised from one of the fuzzer dumps). The other 16 share the abort site but I did not reproduce them individually, so I would not assume this one commit closes the whole family. I am tracking the signature in CIDB and will open a separate PR if it comes back after the reland. Also, the bot review on that commit (hard-coded |
|
Closing the loop here, since three CI answers of mine point at this PR as the owner of Measured today:
That is consistent with what I said on the reland thread ("I am not opening a separate PR: with the |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Not for changelog: this fixes a master-only regression that was never part of a release.
Description
Related: #114817 (an unreleased regression from it).
resolvePlannerOnlyFiltersrebuilds aFilterStepwithremove_filter = true, using a survivingconjunct's
result_nameas the filter column.collectFilterConjunctsunwraps aliases, so thatconjunct can be a column of the step's own output header: push-down had wrapped that predicate in a
__filter<name>alias so the removal could not hit the stream column (ActionsDAG.cpp:3768-3779),and the unwrap discards that protection.
FilterTransformthen erases the column, and since the passreplaces
node.step, noupdateInputHeaderreaches the parentJoinStepLogical, whoseexpressions still hold an input node for it. Nor can it be pruned, being a join output.
I re-establish the alias at the rebuild site when the chosen filter node's name collides with the
output header, the same idiom and reason as
ActionsDAG.cpp:3774-3779.Reproducer, on defaults:
A debug build aborts with
Input nodes size mismatch in dag(JoinExpressionActions.cpp:138, fromchooseJoinOrder). With the join reorder off the query is instead rejected withNOT_FOUND_COLUMN_IN_BLOCK, and aNATURAL JOINvariant withUNKNOWN_IDENTIFIER, so release buildsare affected too. All three return the correct rows after the change. A Nullable join key is required:
it makes the join condition null-rejecting, which produces the marker.
Validation: the new test reddens without the change and passes with it (two scenarios, each with the
join reorder on and off, asserting result rows), plus 50 runs on default randomization and 50 with a
forced join-order seed. Eight of the nine stateless tests #114817 touched pass with no reference
change; the ninth sets
query_plan_derive_not_null_filters_from_joins = 0, so it returns before thechanged branch.
Where it shows up in CI
Example report:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=118979&sha=ef26353f73160ecf71c7681c5d618d448637f813&name_0=PR
#114817 merged at 08:08 UTC on 2026-09-09. Five rows followed the same day, on five check flavours and
two architectures, every one on an unrelated PR. The two August rows share only the message text, whose
hash forms the failure id; that older shape was fixed by #110227. The query behind the 14:21:59 row was
captured and reproduces this mechanism locally.
This does not touch
src/Interpreters/JoinExpressionActions.cpp, so it does not overlap my open #108787.Workflow [PR]
Sync PR [sync-upstream/pr/119106]