Skip to content

decorrelate_where_in reports error when optimizing limit subquery #5808

@HaoYang670

Description

@HaoYang670

Describe the bug

decorrelate_where_in currently only support Predicate as the top level plan in the sub-queries, otherwise it will return an error:
https://github.com/apache/arrow-datafusion/blob/667f19ebad216b7592af5a91b70a24fb21c3bb64/datafusion/optimizer/src/decorrelate_where_in.rs#L151-L152

However, for limit subquery, the top level plan might be Limit which let decorrelate_where_in fail.

To Reproduce

Set skip_failed_rules to false and run the test support_limit_subquery, you will fail on the test with the error message

Error: Context("decorrelate_where_in", Internal("Optimizer rule 'decorrelate_where_in' failed due to unexpected error: a projection is required at datafusion/optimizer/src/decorrelate_where_in.rs:152\ncaused by\nError during planning: Could not coerce into Projection! at datafusion/expr/src/logical_plan/plan.rs:1293"))
test sql::subqueries::support_limit_subquery ... FAILED

Expected behavior

No error should be generated. At least, we can let decorrelate_where_in return Ok(None)

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions