Skip to content

fix: SQL follow Postgres scope strictness - #28937

Merged
ritchie46 merged 1 commit into
mainfrom
sql-scope-resolution
Aug 24, 2026
Merged

ritchie46 merged 1 commit into
mainfrom
sql-scope-resolution

Conversation

@ritchie46

Copy link
Copy Markdown
Member

made with opus 5

A qualified column resolved its qualifier against every registered table, not
just the relations the current `FROM` declares. Inside a subquery, where the
enclosing query's tables are still registered, an outer qualifier therefore
bound to a table of that name instead of correlating: `x.a < t1.a` over
`FROM t1 AS x` compared the inner relation against itself and quietly answered
the wrong question. Shapes the subquery lowerings do not claim, such as a
subquery carrying `LIMIT` or `GROUP BY`, still reach that path, so the same
wrong answer was reachable for them.

Record the relations each `FROM` declares and let a qualifier name only those.
An alias replaces the table name, as it does in Postgres, so `t1.a` over
`FROM t1 AS f` is now refused rather than resolved. A nested join is flattened
rather than bound to its alias, so its own relations stay declared.

Queries whose subquery shape has no lowering now fail rather than return a
wrong answer; correlated `IN`, `EXISTS` and the quantified comparisons are
unaffected, as they are lowered before this path is reached.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012PeS5DzwijVsijK68XXPsw
@github-actions github-actions Bot added A-sql Area: Polars SQL functionality fix Bug fix python Related to Python Polars rust Related to Rust Polars labels Aug 24, 2026
@github-actions

Copy link
Copy Markdown
Contributor

The uncompressed lib size after this PR is 60.9148 MB.

@ritchie46
ritchie46 merged commit 56c6644 into main Aug 24, 2026
30 of 33 checks passed
@ritchie46
ritchie46 deleted the sql-scope-resolution branch August 24, 2026 10:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-sql Area: Polars SQL functionality fix Bug fix python Related to Python Polars rust Related to Rust Polars

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant