Skip to content

fix: requalify LATERAL filters through derived-table aliases - #26044

Open
canyang25 wants to merge 2 commits into
apache:mainfrom
canyang25:fix/25837-lateral-derived-alias
Open

canyang25 wants to merge 2 commits into
apache:mainfrom
canyang25:fix/25837-lateral-derived-alias

Conversation

@canyang25

Copy link
Copy Markdown

Which issue does this PR close?

Rationale for this change

A LATERAL subquery whose correlated filter goes through a derived-table alias failed to plan. When the filter was pulled up through the SubqueryAlias, it kept the inner table's qualifier. If the alias differed from the table name, the resulting join condition referenced a column the rewritten subquery no longer exposed, so the query errored instead of returning rows.

What changes are included in this PR?

When decorrelation pulls a correlated filter up through a SubqueryAlias, the filter's column references are requalified to the alias, so the join condition matches the subquery's output schema.

What is the testing strategy for this PR?

New cases in lateral_join.slt cover a correlated LATERAL filter through a derived-table alias that differs from the table name. They fail on main and pass with this change. Existing optimizer tests pass, and cargo fmt and cargo clippy are clean.

Are there any user-facing changes?

Queries of this shape now plan and return results instead of erroring. No public API changes.

This change was made with help from Cursor (Grok). I reviewed and tested it.

A correlated filter pulled through a SubqueryAlias kept the inner
table qualifier. When that alias differed from the table name, the
join condition named a column the rewritten subquery no longer had.

Fixes apache#25837

Assisted by Cursor (Grok).
@github-actions github-actions Bot added optimizer Optimizer rules sqllogictest SQL Logic Tests (.slt) labels Oct 5, 2026
@kumarUjjawal
kumarUjjawal self-requested a review October 5, 2026 06:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

optimizer Optimizer rules sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LATERAL subquery fails with a schema error when a derived table alias differs from the table name

1 participant