Repository navigation
Conversation
… subqueries `mergeExpressions` folds nested projections such as `a2 = a1 + a1`, `a3 = a2 + a2`, ... into one `ActionsDAG` whose `plus` nodes have the same child twice: the DAG has O(depth) nodes but 2^depth root-to-leaf paths. When such an expression becomes a JOIN key, several plan-time walks visited it per path instead of per node, so planning doubled with every nesting level and never finished at depth 36 (the AST-fuzzer variant of 05317_exponential_null_propagation hung a stress check for 3937 s, ignoring `max_execution_time` and `KILL QUERY`; planning has no cancellation points). - `ActionsDAG::Node::updateHash` recursed into every child without a memo, and `ActionsDAG::updateHash` walked every path and called it at each node. Both now compute a Merkle digest (own fields + the 128-bit digests of the children), each node hashed once per call. The contract is unchanged (a structural hash; equal expressions hash equal; the runtime-filter id value is still skipped); only the values change. All consumers (hash-table statistics keys, join output keys, the query condition cache, automatic parallel replicas) are per-process and in-memory, so they only start cold after an upgrade. Reached from `deriveCacheKeysForNewJoin` during join reordering, the stack of the stress-check hang. - `strictOnRelations` (null-rejection analysis under `join_use_nulls = 1`) recursed through every null-propagating function per path; it is now an iterative walk with a visited set, and `predicateNullRejectingRelations` caches its per-node results, as ClickHouse#123509 did for `collectNullPropagatingInputs` / `collectNullRejectedInputs`. - The consumed-inputs walk in `buildPhysicalJoinImpl` pushed every child of every node; it now skips visited nodes. Without it the stress-check query still hangs there after the hash fix. Each change was checked by reverting it alone: the matching query hangs again. With the default `enable_join_runtime_filters = 1` such a join next runs out of memory in predicate push-down (ClickHouse#123724); that family is reached without a join too and is not changed here, so the new test's `INNER JOIN` arms pin `enable_join_runtime_filters = 0` like 05317, and the test turns off the server-side AST fuzzer (`ast_fuzzer_runs = 0`), whose variants of these queries reach it. Related: ClickHouse#123509 Related: ClickHouse#123432 Related: ClickHouse#123724 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; 2 findings over 3 rounds, the last round clean) plus my own review over 3 rounds.
Severity: ❌ blocker / |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-41:20261003-225500 |
|
Workflow [PR], commit [02a8b79] Summary: ❌
AI ReviewSummaryThis PR replaces the path-exploding join-planning walks over shared Final Verdict
LLVM Coverage Report |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units1234 translation units recompiled, 8901 s compile time in total, 1234 of them have a recent master baseline. |
CI finish ledger - 652dbd4Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
None of these touches join planning, and Session id: cron:our-pr-ci-monitor:20261004-063241 |
…n-planning-shared-subexpression Picks up ClickHouse#123738 (amd_fuzzers relocation overflow fix). Co-Authored-By: Claude Opus 5.5 <[email protected]>
CI finish ledger - 02a8b79Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20261004-120236 |
|
Same as #123509 |
|
I don't think #123509 covers this. It was merged on 2026-10-03, before I opened this PR, and changes only the walk in On master 516006f (26.10.1.1758, includes #123509), release build:
The Stress hung check has hit it 5 times since #123509 merged, every time inside Would you reopen it, or would you prefer a different shape? |
Related: #123509
Related: #123432
Related: #123724
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed join planning that never finished, and ignored
max_execution_timeandKILL QUERY, for a join on an expression built by nested subqueries that reuse a column (for examplex + xat every level).Description
On 26.8 and 26.9, a
LEFT JOINwhose key is built by nested subqueries that each use the previous column twice never finishes planning and ignoresmax_execution_timeandKILL QUERY; anINNER JOINdoes the same withenable_join_runtime_filters = 0. CI: a stress-test variant of05317_exponential_null_propagationhung for 3937 s (Stress test (arm_release)).Root cause:
mergeExpressionsfolds such projections into oneActionsDAGwith O(depth) nodes but 2^depth paths, and three planning walks visited it once per path:ActionsDAG::Node::updateHash/ActionsDAG::updateHash(join statistics keys during join reordering);strictOnRelations/predicateNullRejectingRelations(null rejection withjoin_use_nulls = 1);buildPhysicalJoinImpl.Change: the hash is a Merkle digest computed once per node, and the two walks keep a visited set or a per-node cache. Hash values change, but every consumer is an in-memory per-process cache key.
Validation: reverting each change alone makes its query hang again. With
enable_join_runtime_filters = 0, at depth 24/25/26/27 master plans in 3.9/7.2/14.0/27.8 s and the fix in about 0.6 s. The new test times out on master and passes 50/50 with random settings. TheLEFT JOINarm runs with the default settings.Not fixed here: with the default
enable_join_runtime_filters = 1, the runtime filter on such a key is pushed down through the expression, and predicate push-down and index analysis then build names or walk it once per path too (#123724), so anINNER JOINof this shape runs out of memory; master gets there after the hang. It is reached without a join too, so it needs its own fix; the test'sINNER JOINarms pinenable_join_runtime_filters = 0, as 05317 does.Workflow [PR]
Sync PR [sync-upstream/pr/123793]