Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expression column_refs does not return outer referenced columns in subqueries #15046

Open
helgikrs opened this issue Mar 6, 2025 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@helgikrs
Copy link

helgikrs commented Mar 6, 2025

Describe the bug

Calling column_refs() on a subquery expression returns no column references, even if the subquery contains outer references.

PushDownFilter optimization uses the column_refs() to compare against the columns returned from prevent_predicate_push_down_columns() on an extension node. The effect of this is that a subquery in a filter may get pushed below an extension node when it shouldn't.

To Reproduce

    let outer_ref = Expr::OuterReferenceColumn(DataType::Int64, Column::new(None::<String>, "a"));
    let plan = LogicalPlanBuilder::empty(true)
        .project(vec![outer_ref.clone()])
        .unwrap()
        .build()
        .unwrap();

    let subq = Subquery {
        subquery: Arc::new(plan),
        outer_ref_columns: vec![outer_ref],
    };

    let expr = Expr::Exists(Exists::new(subq, false));

    println!("{:?}", expr.column_refs());

Expected behavior

column_refs() should return the outer columns used by the subquery expression.

Additional context

The relevant code is here. It just collects Expr::Columns within self.

@jatin510
Copy link
Contributor

jatin510 commented Mar 6, 2025

take

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants