Repository navigation
Description
Describe what's wrong
- Planning a join on keys built as nested
x + xaliases allocates column names that grow exponentially with nesting depth. - Trigger: default
enable_join_runtime_filters = 1,join_use_nulls = 1, and an innerLEFT JOINconverted toINNERby the transitive pass. - Names should stay linear in depth; at depth 24 planning takes 6.1 s and 9.4 GB.
- At depth 36 the server was OOM-killed, and
max_memory_usagedoes not stop the plan-time growth.
Root cause: buildFilterActionsDAGImpl (ActionsDAG.cpp:4438) rebuilds every FUNCTION node with an empty result_name, so addFunctionImpl (ActionsDAG.cpp:662) concatenates child names. On a DAG with shared nodes like plus(X, X) the name length grows with the number of paths, not nodes.
Analysis details (evidence, affected locations, impact)
Why we believe this is a bug: When the transitive pass turns the inner LEFT JOIN into INNER, the runtime filter RF1(a6_6) for the outer join gets pushed through the merged x + x expression and the converted join to the right stream. tryAddJoinRuntimeFilter re-runs filter push-down regardless of settings. The rebuilt filter DAG gets fresh names. buildFilterActionsDAGImpl (ActionsDAG.cpp:4438) calls addFunction with an empty result_name, and addFunctionImpl (ActionsDAG.cpp:655-664) builds the name by concatenating the child names. So plus(X, X) doubles the name at every level: the DAG stays linear in size, but its name strings grow as 2^depth. EXPLAIN shows the result: the pushed-down filter column is RF1(plus(plus(...toNullable(val)...))) expanded down to the leaves.
Affected locations:
src/Interpreters/ActionsDAG.cpp:4438— buildFilterActionsDAGImpl rebuilds FUNCTION nodes with an empty result_namesrc/Interpreters/ActionsDAG.cpp:662— addFunctionImpl builds the name by concatenating child result namessrc/Interpreters/ActionsDAG.cpp:4105— splitActionsForJOINFilterPushDown: replace_equivalent_columns_in_filter calls buildFilterActionsDAGImpltests/queries/0_stateless/05317_exponential_null_propagation.sh:29— PR test pins --enable_join_runtime_filters 0
Impact: One read-only SELECT at default settings allocates name strings that grow exponentially with alias-nesting depth during planning. On master this needs join_use_nulls = 1 and the inner LEFT JOIN from #123509 (where this was found; not confirmed as the cause)'s test; the user-written INNER JOIN form needs no setting and also hits 26.8. max_memory_usage does not stop the plan-time string growth. At depth 36 the kernel OOM killer killed the server process.
Does it reproduce on most recent release?
Confirmed on master (501d978d7b9d); not checked on a release.
How to reproduce
The scaling script allocates tens of GB, so run it in a sandbox; the user-written INNER JOIN form needs no setting at all.
-- Test: a runtime filter pushed through a join on a key built as `x + x` over nested subqueries keeps column names linear in depth.
SET enable_analyzer = 1;
SET join_use_nulls = 1;
SET enable_join_runtime_filters = 1;
SET query_plan_convert_outer_join_to_inner_join = 1;
SET query_plan_convert_outer_join_to_inner_join_transitively = 1;
SET query_plan_join_swap_table = 0;
SET enable_parallel_replicas = 0;
SELECT count() > 0, max(length(explain)) < 5000
FROM
(
EXPLAIN actions = 1
SELECT count()
FROM
(
SELECT a1_6 + a1_6 AS a2_1, a2_1 + a2_1 AS a2_2, a2_2 + a2_2 AS a2_3, a2_3 + a2_3 AS a2_4, a2_4 + a2_4 AS a2_5, a2_5 + a2_5 AS a2_6
FROM
(
SELECT r.val + r.val AS a1_1, a1_1 + a1_1 AS a1_2, a1_2 + a1_2 AS a1_3, a1_3 + a1_3 AS a1_4, a1_4 + a1_4 AS a1_5, a1_5 + a1_5 AS a1_6
FROM (SELECT number AS id FROM numbers(2)) AS l
LEFT JOIN (SELECT number AS id, number - 1 AS val FROM numbers(1, 1)) AS r ON l.id = r.id
)
) AS g
INNER JOIN (SELECT 0 AS val) AS k ON g.a2_6 = k.val
)
WHERE explain LIKE '%Filter column: RF%';Verified: this block reproduces on current master (501d978d7b9d) when pasted as is.
Expected behavior
The pushed-down runtime filter column name stays short and planning memory stays linear in nesting depth.
Expected output of the reproducer above:
1 1
Error message and/or stacktrace
The runtime filter column name expands the whole expression tree, reaching 376,866 chars in EXPLAIN, and memory grows to tens of GB.
Actual output of the reproducer above on master (501d978d7b9d):
1 0
Suggested fix
In buildFilterActionsDAGImpl, keep node->result_name for nodes with no replaced input in their subtree. For the remaining nodes, generate a bounded name, e.g. a per-node unique suffix, instead of concatenating the child names. Trade-off: those rebuilt nodes stop spelling out their expression in EXPLAIN.
Additional context
Same pattern as #122613 (found by: vector, fix_path; same version: 26.8), #123432 (found by: lexical, vector, fix_path; vector: cosine distance 0.15 (agrees with the lexical leg)).
Open risks:
buildFilterActionsDAG(ActionsDAG.cpp:4504) is also reached fromSourceStepWithFilter,ReadFromMergeTreeandpropagatePredicateAcrossEquiJoin, so any filter pushed onto a source over such a DAG gets the same names. Not tested here apart from the join path.EXPLAIN actions = 1also prints the merged join condition with exponential length: theJoin conditions:line is 110,643 chars at depth 12, with or without runtime filters. This only affectsEXPLAIN.
Found during automated review of PR #123509; the bug predates that PR (it reproduces on the master build just before it merged), so the introducing change is not identified yet. Severity P1 · Finding h_pr123509_001
Activity
groeneai commentedon Oct 4, 2026
@KochetovNicolai, a design question before I send a fix.
This is wider than the join path. A plain
WHEREover such a chain, with no join at all, is OOM-killed at default settings on master (3ade111) and on 26.9.9.28:Written as one
SELECT, the same expression is rejected bymax_expanded_ast_elements(Query tree is too big. Maximum: 500000). The nested form passes the analyzer, and the plan then composes the levels into one DAG with 36plusnodes but 2^36 paths. Each consumer that walks it per path blows up:buildFilterActionsDAGImplconcatenates names: reached fromSourceStepWithFilter::applyFilters(the query above) and fromsplitActionsForJOINFilterPushDown(this issue).query_plan_filter_push_down = 0does not avoid it.query_plan_merge_expressions = 0the query instead fails incloneDAGWithInversionPushDown(KeyCondition, only INPUT nodes are memoized), called fromReadFromSystemNumbersStep::makePipe: Code 241 after 18 s.onlyDependsOnAvailableColumns(partial JOIN push-down) andappendColumnNameWithoutAlias(RPNBuilder) recurse per path too.So keeping
result_nameinbuildFilterActionsDAGImpl, as suggested above, would move the OOM into index analysis. I see three options:tryMergeExpressions,composeinoptimizePrimaryKeyConditionAndLimit) skip the merge when the result's expanded size exceedsmax_expanded_ast_elements.applyFilters, PREWHERE) skip a conjunct whose expanded size exceedsmax_expanded_ast_elements, via one memoized helper. The filter is still evaluated where it is.buildFilterActionsDAGImpl, memoizecloneDAGWithInversionPushDown, and stopRPNBuilderfrom building a key name that can never match a key.I would do B: it changes only the code that walks per path, and it reuses the limit the analyzer already applies. Which do you prefer: A, B or C?
groeneai commentedon Oct 6, 2026
The stress test fuzzer now reaches this in CI:
Stress test (amd_msan)on #100173 (unrelated to that PR) was killed by the kernel OOM killer on a fuzzed05317_exponential_null_propagationquery whose join condition becameON g.a6_6 > k.val. The memory limit did not stop it.On master (44b568f, debug build) with
join_use_nulls = 1andenable_join_runtime_filters = 0, the same query is OOM-killed in a 16 GiB cgroup after 13 s despitemax_server_memory_usage = 12G. Withquery_plan_filter_push_down = 0it returns0in 1 s.Query
The fix is waiting on the choice between A, B and C above.
rschu1ze commentedon Oct 7, 2026
@zlareb1 @groeneai @clickgapai Is this fixed by #123509?
clickgapai commentedon Oct 7, 2026
No. #123509 is already in master (the latest commit, merged Oct 2), and this still reproduces on the latest commit.
convertOuterJoinToInnerJoinTransitively.cpp. The growth is inbuildFilterActionsDAGImpl, which Fix exponential planning in transitive outer-to-inner JOIN conversion #123509 doesn't change:FUNCTIONnode exceptindexHintwith an empty name (ActionsDAG.cpp:4398).addFunctionImplthen builds the name by joining the child names (:661), so eachx + xlevel doubles its length.05317_exponential_null_propagationpasses because it sets--enable_join_runtime_filters 0(line 29). With the default value1, the same query still blows up:Filter column: RF…line inEXPLAIN actions = 1: 94,242 / 376,866 / 1,507,362 chars at depth 12 / 14 / 16.clickhouse local: 1.08 GB at depth 20 and 2.78 GB at depth 22. With runtime filters off it stays flat at about 275 MB.WHEREcase from groeneai's comment above also still grows on this build: 1.69 GB and 2.58 s at depth 20.Repro: run 05317's query with
--enable_join_runtime_filters 1.groeneai commentedon Oct 7, 2026
No. Both reproductions above ran on master builds that already contain #123509 (3ade111 and 44b568f, both after its merge commit bdfd200). I re-checked just now on 44b568f: the join-free
WHEREexample from my first comment is still OOM-killed in a 16 GiB cgroup after 10 s despitemax_server_memory_usage = 12G, also withquery_plan_filter_push_down = 0.The fix is waiting on the choice between A, B and C in #123724 (comment).
Build the 05359 queries in a shell test
rschu1ze commentedon Nov 23, 2026
@groeneai Send three PRs for A, B and C each. We need to see the code.
groeneai commentedon Nov 23, 2026
Acknowledged. I'm preparing three separate PRs, one per option (A, B and C), and I'll link all three here once they are open.
groeneai commentedon Nov 24, 2026
Option A: #134010. It fixes every measured shape (the join-free
WHEREchain overnumbers()and MergeTree, the JOIN shapes and the fuzzed 05317 query); the price is that a filter whose condition would exceedmax_expanded_ast_elementsis not pushed down or used for index or projection analysis.groeneai commentedon Nov 24, 2026
Option B: #134034. It fixes the shapes where the composed conjunct is pushed below a
JOIN(the non-equiJOIN ONquery, the same over MergeTree, the fuzzed 05317 query), but not the join-freeWHEREchain overnumbers()or MergeTree, where leaving a conjunct out of the read's own filter gives wrong results (details in the PR).groeneai commentedon Nov 24, 2026
Option C: #134059. It fixes every measured shape and keeps every optimization (the filter is still pushed down and used for index analysis); the price is nine changed places in 13 files, and the consumers no repro reaches (skip-index name lookups, text-index direct read and a few more) stay unfixed and are listed in the PR.