Skip to content

Fix PLACEHOLDER action exception for correlated columns in lambdas - #98285

Merged
alexey-milovidov merged 1 commit into
masterfrom
fix-placeholder-in-lambda
Feb 28, 2026
Merged

alexey-milovidov merged 1 commit into
masterfrom
fix-placeholder-in-lambda

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Feb 28, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Fix LOGICAL_ERROR "Trying to execute PLACEHOLDER action" when correlated columns from outer queries are referenced inside lambda functions (e.g., arrayMap(x -> c0, [1]) in a correlated subquery)
  • visitCorrelatedColumn was 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 into ExpressionActions and threw at runtime
  • Fix: add PLACEHOLDER only to the outermost scope (decorrelated later), and INPUT to inner lambda scopes so the standard capture mechanism works

Closes #85460

Test plan

  • Added 04005_correlated_column_in_lambda stateless test with multiple correlated-column-in-lambda patterns
  • Verified the minimal reproducer from the issue: SELECT (SELECT arrayMap(x -> c0, [1])) FROM t0
  • Verified nested lambdas, arithmetic in lambdas, and multi-row tables all work correctly
  • Verified existing correlated subquery tests still pass (e.g., 03808_correlated_subquery_with_totals)

Changelog category (leave one):

  • Bug Fix

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

  • Merged into: 26.3.1.155

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]>
@clickhouse-gh

clickhouse-gh Bot commented Feb 28, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [5e65dde]

Summary: ❌

job_name test_name status info comment
AST fuzzer (amd_debug) failure
Logical error: Replica A decided to read in B mode, not in C. This is a bug (STID: 7334-66bb) FAIL cidb

@clickhouse-gh clickhouse-gh Bot added pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! labels Feb 28, 2026
@alexey-milovidov alexey-milovidov added pr-bugfix Pull request with bugfix, not backported by default and removed pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-critical-bugfix labels Feb 28, 2026
@novikd novikd self-assigned this Feb 28, 2026
@novikd

novikd commented Feb 28, 2026

Copy link
Copy Markdown
Member

Nice catch!

@alexey-milovidov
alexey-milovidov merged commit fadacf2 into master Feb 28, 2026
143 of 144 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-placeholder-in-lambda branch February 28, 2026 20:13
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Feb 28, 2026
alexey-milovidov added a commit that referenced this pull request Mar 1, 2026
Fix PLACEHOLDER action exception for correlated columns in lambdas
@robot-clickhouse robot-clickhouse added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Jun 29, 2026
@robot-ch-test-poll robot-ch-test-poll added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Jun 29, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v25.12-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CI crash] [LOGICAL_ERROR] Trying to execute PLACEHOLDER action

6 participants