Repository navigation
Conversation
…xpanded_ast_elements Option B of the three alternatives requested in ClickHouse#123724. The analyzer bounds an expression's size written out as a tree (`max_expanded_ast_elements`), but nested subqueries evade it because each level is small. Filter push-down then composes the levels into one conjunct with O(depth) nodes and 2^depth paths. At a JOIN, `splitActionsForJOINFilterPushDown` rebuilds it through `buildFilterActionsDAGImpl`, which spells the names out per path, and the disjunction push-down (`extractPartialPredicate` -> `onlyDependsOnAvailableColumns`) walks it per path without memo. On 26.9.9.28 the non-equi JOIN query from ClickHouse#123724 is OOM-killed during planning; without the disjunction check the same query hangs instead. A memoized `isExpandedSizeAbove` (on `computeForNodes`) moves a conjunct over the limit from the pushed lists to `rejected`, so it is evaluated by the filter above the JOIN, as master does for any conjunct it cannot push; the other conjuncts are still pushed. `tryToExtractPartialPredicate` returns nothing when the whole filter is over the limit. The gate applies only when every read below the JOIN ends without its filter (`canLeaveConjunctsOutOfFilter`: MergeTree and bounded `numbers(N)`); any other leaf, e.g. unbounded `system.numbers` or a remote read, keeps master behaviour, because it may need the pushed bound to end. The read side is not gated: a read uses its filter as the complete condition for exact LIMIT push-down (`numbers`) and the exact-count projection (MergeTree), so leaving a conjunct out of a read's filter returns wrong results. A composed filter that reaches a read without crossing a JOIN is therefore not fixed here. An `indexHint` counts with the condition it holds. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Remove three comments that narrate the new code (the settings field, the fail-closed leaf check, the gate call site). 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; 3 rounds, 5 findings, none in the last round) plus my own review (rows 1, 3, 4 and 7).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-9:20261124-050300 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-40:20261124-043600 |
|
Workflow [PR], commit [2c428ac] Summary: ❌
AI ReviewSummaryThe PR uses Findings❌ Blockers
Tests
Final VerdictStatus: ❌ Block Bound the remaining shared |
| { | ||
| std::erase_if(conjunctions.allowed, [&](const Node * conjunct) | ||
| { | ||
| if (!isExpandedSizeAbove(conjunct, max_expanded_conjunct_size)) |
There was a problem hiding this comment.
[Blocker] The size gate still leaves an exponential traversal inside splitActionsForJOINFilterPushDown: the unconditional extractConjunctionAtoms(predicate) below (line 4215) walks shared and nodes once per path, without a visited set.
For example, adapt the new test's bounded numbers join to project val < 4 AS c0, then nest SELECT id, c0 AND c0 AS c1, SELECT id, c1 AND c1 AS c2, and so on, finishing with WHERE c36 AND id < 10. After expression merging and removeAliasesForFilter, getConjunctionNodes finds only the small leaf predicates, so every check here passes. Atom collection then attempts to materialize 2^36 copies of the same leaf in a plain std::vector (512 GiB of pointers alone), despite the default max_expanded_ast_elements. This leaves the same server OOM risk on a bounded-source JOIN.
Make atom collection operate on distinct DAG nodes while preserving predicate order, and add a regression for an AND doubling chain. If the solution instead retains the whole chain above the join, also account for the per-path walk in trySplitSingleAndFilter in FilterStep.cpp; keeping it above the join alone does not make that consumer bounded.
There was a problem hiding this comment.
Measured on this head and on master alike (depth 36 is memcg-OOM-killed after about 30 s; the first walk to blow up is the per-atom loop in filterResultForNotMatchedRows), this is extractConjunctionAtoms enumerating a shared and once per path, a separate defect from the conjunct size this PR gates that none of the three #123724 alternatives targets. I'll fix it in its own PR, so the fix applies whichever alternative is merged.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units1020 translation units recompiled, 6129 s compile time in total, 1020 of them have a recent master baseline. |
CI finish ledger - 2c428acEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20261124-090025 |
|
Fixing PR for the AsynchronousMetrics UBSan abort that killed the node in |
Related: #123724
Related: #100173
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed an out-of-memory kill while planning a query whose filter or
JOIN ONcondition reuses a column across nested subqueries above aJOIN, e.g.SELECT b + b AS c FROM (SELECT a + a AS b FROM ...)repeated 36 times. A filter conjunct that would exceedmax_expanded_ast_elementswritten out as a tree is now evaluated above theJOINinstead of being pushed below it, when every table read below theJOINis a MergeTree table or a boundednumbers,numbers_mtorgenerate_seriestable function.Description
Option B of the three alternatives requested in #123724 (option A: #134010). Found by Stress test (amd_msan): https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=100173&sha=b00d774e18fa8a5be47f1f2c8fcc26290d8fc13a&name_0=PR&name_1=Stress%20test%20%28amd_msan%29
On 26.9.9.28, a query with a non-equi
JOIN ONconjunct over such a chain is OOM-killed during planning despitemax_server_memory_usage.Each level passes
max_expanded_ast_elements; filter push-down composes them into one conjunct with 2^depth paths. At aJOIN,splitActionsForJOINFilterPushDownrebuilds it with names spelled out per path, and the disjunction push-down walks it per path.A memoized
isExpandedSizeAbove(counting anindexHint's own condition) keeps such a conjunct in the filter above theJOIN, like any unpushable conjunct; the others are still pushed. The disjunction push-down skips a whole filter over the limit. Only if every read below theJOINends without its filter (MergeTree, boundednumbers; notsystem.numbers).Master vs this PR (debug, 12 GiB cap, 36 doublings):
JOIN ONconjunct: defaults, runtime filters off, push-down offa36 >= id AND id >= 5above aJOIN(impliedindexHint)join_use_nulls = 1) and the fuzzed one from the reportWHEREovernumbers()or MergeTree, noJOINNot fixed: a composed filter reaching a read without crossing a
JOIN. A read uses its filter as the complete condition (exactLIMITpush-down, exactcount()), so leaving a conjunct out there gives wrong results (measured).Price: such a conjunct no longer narrows the read below the
JOIN(primary key,numbersranges), also at sizes master still plans. Below the limit plans are unchanged (251 related tests match master); planning time is within noise.Workflow [PR]
Sync PR [sync-upstream/pr/134034]