Repository navigation
Fix a planning hang when a filter over repeated subexpressions is checked against a JOIN - #125117
Conversation
The walk used node_to_column as its only visited marker, but a node whose
arguments are not all known got no entry when allow_unknown_function_arguments
is false. Every parent then re-walked its whole subtree, so a chain like
a_k = a_{k-1} + a_{k-1} cost O(2^depth) visits.
filterResultForMatchedRows (ANY to SEMI/ANTI join conversion) and the
always-false check that tryPushDownOverJoinStep runs on every filter
push-down over a join both call it with no known inputs and the default
parameters. A filter over a doubled alias chain therefore never finished
planning and did not react to max_execution_time or KILL QUERY (seen as
"Hung check failed" in Stress test (amd_tsan) on ClickHouse#116577).
Record such a node as unknown (null column) so it is visited once. Parents
already materialise a missing child as the same {nullptr, type, name} and
treat a null column as unknown, so the results do not change.
Co-Authored-By: Claude Opus 5.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 review (2 nits).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20261010-232300 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-7:20261010-215100 |
|
Workflow [PR], commit [e012146] Summary: ✅
AI ReviewSummaryPR #125117, head Final Verdict✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 17 s compile time in total, 7 of them have a recent master baseline. |
The client AST fuzzer takes its seeds only from *.sql files. In the targeted fuzzer run on this PR it turned the LEFT JOIN of this chain into an INNER JOIN, so the filter is pushed into the right side of the join, and splitActionsForJOINFilterPushDown then builds names that grow as 2^depth (issue ClickHouse#123724): the server grew to 46 GB and was OOM-killed. The same query does that on builds without this fix too (26.10.1.286, 26.9.7.6); on master it hangs in evaluatePartialResult before it gets there. Build the same two queries in a .sh test, like 05317_exponential_null_propagation.sh, so the chain is not a fuzzer seed, here or in the master fuzzer corpus. Co-Authored-By: Claude Opus 5.5 <[email protected]>
CI finish ledger - 0965a79Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
All 164 other check runs completed and Session id: cron:our-pr-ci-monitor:20261011-073009 |
Since ClickHouse#116781, `FilterStep::serialize` hashes the filter with `ActionsDAG::Node::updateHash` when it builds the hash table statistics key of the join (`calculateHashTableCacheKeys`). That hash walks the children of every node again, so on this chain it runs once per path, and the first query hangs in the second optimization pass on current master even with the fix. The merge queue run on 8d3778b (master 3389afa + this branch) timed out on it in Fast test and in the flaky check. That walk is a different defect from the one fixed here, so the test turns the statistics off and checks only the push-down probe. Measured on master 3389afa + this branch: the test passes 50/50 with random settings and 20/20 without (at most 0.9 s); without the new setting it times out at 60 s. On master 2cb89c8 (no fix) the test still times out at 60 s, stuck in `filterResultForNotMatchedRows`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
The merge queue run timed out on On master 3389afa + this PR the test now passes 50/50 in under 1 s. On master without the fix it still times out, stuck in |
Backport #125117 to 26.10: Fix a planning hang when a filter over repeated subexpressions is checked against a `JOIN`
…eated subexpressions is checked against a `JOIN`
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a query that never finished planning, ignoring
max_execution_timeandKILL QUERY, when a filter over expressions that reuse the same subexpression (such asx + xacross nested subqueries) is pushed down to aJOINor checked for theANYtoSEMI/ANTIjoin conversion.Description
On 26.3.33.24 LTS, as on every release line since 25.12, a
WHEREover a chain ofx + xaliases above anANY LEFT JOINnever finishes planning and ignoresmax_execution_timeandKILL QUERY. Since #123829 (in 26.8.21.10 and 26.9.13.15) the same happens for such a filter pushed down to a plainLEFT JOIN. That is the hung query inStress test (amd_tsan)on #116577 (report, stuck for 2037 s inActionsDAG::evaluatePartialResult<-filterResultForNotMatchedRows<-tryPushDownOverJoinStep).Root cause:
evaluatePartialResultmarks a node as visited only by giving it an entry innode_to_column. A node whose arguments are unknown got no entry unlessallow_unknown_function_argumentsis set, so every parent walked its subtree again: O(2^depth) fora_k = a_{k-1} + a_{k-1}. The ANY-to-SEMI probe (filterResultForMatchedRows) and the always-false probe that #123829 added to filter push-down over a join both call it with no known inputs and default parameters.Change: record such a node with a null column, which the walk already treats as unknown, so each node is visited once. Results are unchanged: a parent already received exactly that
{nullptr, type, name}for a missing child.Validation: the new test times out (60 s) on master and on this tree with the two lines reverted, and passes in 0.2 s with the fix; 50/50 randomized runs; 369 of 370 related join and filter push-down tests pass. The test pins
join_use_nulls = 0,compile_expressions = 0andcollect_hash_table_stats_during_joins = 0: otherwise planning still walks the expression once per path elsewhere (#123724, the expression JIT, and since #116781 the join statistics key inActionsDAG::Node::updateHash), which this PR does not change. It is a.shtest so that the AST fuzzer does not mutate it: anINNER JOINin place of itsLEFT JOINreaches #123724 too.Workflow [PR]
Sync PR [sync-upstream/pr/125117]
Version info
26.11.1.47-master(included in26.11and later)