Skip to content

Unparsing of filter on subquery generates invalid SQL #25545

Description

@nuno-faria

Describe the bug

When unparsing a plan with a SubqueryAlias + FilterExec, the resulting SQL can be invalid, since the alias will be applied to the base table while the filter still refers to the previous table name.

To Reproduce

This query

select *
from (
    select a
    from t
) t2
where a = 1

is optimized to a plan like this

SubqueryAlias: t2
  Filter: t.a = Int32(1)
    TableScan: t projection=[a]

which is unparsed to

SELECT * FROM t AS t2 WHERE (t.a = 1) -- t.a is invalid

Expected behavior

No response

Additional context

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions