Skip to content

Fix exception in checkCorrelatedColumn for INTERPOLATE expression arguments - #98346

Merged
alexey-milovidov merged 3 commits into
masterfrom
fix-interpolate-correlated-column-scope
Mar 1, 2026
Merged

alexey-milovidov merged 3 commits into
masterfrom
fix-interpolate-correlated-column-scope

Conversation

@alexey-milovidov

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

Copy link
Copy Markdown
Member

Summary

  • Fix LOGICAL_ERROR exception "Cannot find the original scope of the column" when using INTERPOLATE with alias chains (e.g., SELECT 1 AS a, a AS b ORDER BY 1 WITH FILL STALENESS 1 INTERPOLATE (a AS b))
  • INTERPOLATE creates fake ColumnNodes with InterpolateNode as source; checkCorrelatedColumn didn't handle this node type, causing it to walk up the entire scope chain and throw
  • Also improved CorrelatedColumnsCollector to handle UNION nodes and skip subqueries missing from the scope map

Found by BuzzHouse fuzzer: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=98299&sha=09fdc20b9f0ecf42b37644a57de91f5ccbf68e42&name_0=PR&name_1=BuzzHouse%20%28arm_asan%29
#98299

Changelog category (leave one):

  • CI Fix or Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fix LOGICAL_ERROR exception "Cannot find the original scope of the column" when using INTERPOLATE with alias chains in ORDER BY ... WITH FILL.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

🤖 Generated with Claude Code

Version info

  • Merged into: 26.3.1.216

… arguments

`INTERPOLATE (a AS b)` creates a fake `ColumnNode` with an `InterpolateNode`
as its source. When resolving alias chains from a parent scope,
`CorrelatedColumnsCollector` would visit this fake column and
`checkCorrelatedColumn` would fail because `InterpolateNode` is never
registered in any scope's `registered_table_expression_nodes`.

The fix adds `INTERPOLATE` to the early-return check alongside `LAMBDA`,
since both represent expression arguments rather than table expressions.

Also improved `CorrelatedColumnsCollector` to handle `UNION` nodes (not
just `QUERY`) and to skip subqueries missing from the scope map rather
than falling through with the wrong scope context.

https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=98299&sha=09fdc20b9f0ecf42b37644a57de91f5ccbf68e42&name_0=PR&name_1=BuzzHouse%20%28arm_asan%29

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 [b8ca28a]

Summary: ✅

@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-ci and removed pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-critical-bugfix labels Feb 28, 2026
-- that are not in the scope map (e.g. inside INTERPOLATE expressions).
-- Previously this caused "Cannot find the original scope of the column" exception.

SELECT 1 AS a, a AS b ORDER BY 1 WITH FILL STALENESS 1 INTERPOLATE (a AS b);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test reproduces the issue.

alexey-milovidov and others added 2 commits March 1, 2026 01:03
The old analyzer has a pre-existing bug that crashes with
`INTERPOLATE` + `WITH FILL` queries ("Invalid number of rows in Chunk").
Since the fix targets the new analyzer's `CorrelatedColumnsCollector`,
force `allow_experimental_analyzer = 1` in the test.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the previous one for lambdas.

@alexey-milovidov alexey-milovidov self-assigned this Mar 1, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Mar 1, 2026
Merged via the queue into master with commit 39197ac Mar 1, 2026
144 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-interpolate-correlated-column-scope branch March 1, 2026 17:49
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Mar 1, 2026
alexey-milovidov added a commit that referenced this pull request Mar 1, 2026
…column-scope

Fix exception in checkCorrelatedColumn for INTERPOLATE expression arguments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-ci pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants