Repository navigation
Fix PLACEHOLDER action exception for correlated columns in lambdas - #98285
Merged
Merged
Conversation
When a correlated column from an outer query is referenced inside a lambda (e.g., `arrayMap(x -> c0, [1])` in a correlated subquery), `visitCorrelatedColumn` was adding PLACEHOLDER nodes to all action scopes including lambda scopes. PLACEHOLDER nodes are not registered as DAG inputs, so `getRequiredColumnsNames` did not include them, and the lambda capture mechanism never captured the correlated column. The PLACEHOLDER survived into `ExpressionActions` and threw "Trying to execute PLACEHOLDER action" at runtime. Fix: add PLACEHOLDER only to the outermost scope (where it will be decorrelated), and add INPUT to inner lambda scopes so the standard lambda capture mechanism works correctly. Closes #85460 Co-Authored-By: Claude Opus 4.6 <[email protected]>
Contributor
|
Workflow [PR], commit [5e65dde] Summary: ❌
|
novikd
approved these changes
Feb 28, 2026
Member
|
Nice catch! |
alexey-milovidov
added a commit
that referenced
this pull request
Mar 1, 2026
Fix PLACEHOLDER action exception for correlated columns in lambdas
alexey-milovidov
pushed a commit
to SteveBalayanAKAMedian/ClickHouse
that referenced
this pull request
Aug 19, 2026
The last query in the test had no ORDER BY: SELECT (SELECT arrayMap(x -> c0 * x, [1, 2])) FROM (SELECT number AS c0 FROM numbers(3)); Its correlated scalar subquery is decorrelated into a JOIN, and the resulting pipeline is multi-stream (EXPLAIN PIPELINE shows ExpressionTransform x 192 over Resize x 2 192 -> 1), so the row order follows whichever stream finishes first. The test never pinned it, so the recorded reference order was luck rather than a guarantee, and Fast test began reporting "result differs with reference" with the same five values in a different order. The failures are pure permutations: two different orderings were produced by the same commit, which rules out a deterministic result change. On a build of master carrying none of the changes that exposed this, an interleaved 200-run A/B under max_block_size = 1 produced 4 distinct permutations without ORDER BY (20.5% of runs deviating) and 200/200 identical output with it. Appending ORDER BY c0 makes the order total, since c0 is unique across the three rows. The reference file needs no change, because the pinned order is the order it already records. This test guards the PLACEHOLDER fix for correlated columns in lambdas (ClickHouse#98285, closes ClickHouse#85460). Reverting visitCorrelatedColumn in PlannerActionsVisitor.cpp to its pre-ClickHouse#98285 form makes the ORDER BY'd test abort with no output, and restoring it makes the test pass, so the added ORDER BY does not hide that regression. Validated with 50 runs with randomization, 50 runs with --no-random-settings (the Fast test shape), and 25 clickhouse-test runs against the unchanged reference. The unfixed query under the same conditions fails 9 of 60 runs. Related: ClickHouse#114550 Co-Authored-By: Claude Fable 5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
arrayMap(x -> c0, [1])in a correlated subquery)visitCorrelatedColumnwas adding PLACEHOLDER nodes to all action scopes including lambda scopes, but PLACEHOLDER nodes are not DAG inputs, so the lambda capture mechanism never captured the correlated column — the PLACEHOLDER survived intoExpressionActionsand threw at runtimeCloses #85460
Test plan
04005_correlated_column_in_lambdastateless test with multiple correlated-column-in-lambda patternsSELECT (SELECT arrayMap(x -> c0, [1])) FROM t003808_correlated_subquery_with_totals)Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix LOGICAL_ERROR "Trying to execute PLACEHOLDER action" when correlated columns from outer queries are referenced inside lambda functions such as
arrayMap.🤖 Generated with Claude Code
Version info
26.3.1.155