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

Wrong projection after optimize_projections rule #9109

Closed
jiacai2050 opened this issue Feb 2, 2024 · 6 comments
Closed

Wrong projection after optimize_projections rule #9109

jiacai2050 opened this issue Feb 2, 2024 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@jiacai2050
Copy link
Contributor

jiacai2050 commented Feb 2, 2024

Describe the bug

When upgrade latest datafusion from a old version, I found optimize_projections rule produce wrong projection. Eg:

create table t(x bigint, y bigint) as values (1,1), (2,2);

select x from t where y > 0;

Only x will be included in projection, y is missing from the plan.

To Reproduce

First apply following changes, the purpose is to push down all filters

@@ -884,6 +884,7 @@ impl OptimizerRule for PushDownFilter {
                 let results = scan
                     .source
                     .supports_filters_pushdown(filter_predicates.as_slice())?;
+                let results  = vec![TableProviderFilterPushDown::Exact; results.len()];
                 let zip = filter_predicates.iter().zip(results);

https://github.com/apache/arrow-datafusion/blob/f4fc2639f1d9d1f4dbc73d39990a83f6bf7a725f/datafusion/optimizer/src/push_down_filter.rs#L887

Then run datafusion-cli:

create table t(x bigint, y bigint) as values (1,1), (2,2);
explain verbose select x from t where y > 0;

Then we will get

| logical_plan after optimize_projections                    | Projection: t.x                                                                                                          |                                                                    
|                                                            |   TableScan: t projection=[x], unsupported_filters=[t.y > Int64(0)]                                                      |  

Expected behavior

The right projection should be [x, y].

Additional context

No response

@jiacai2050 jiacai2050 added the bug Something isn't working label Feb 2, 2024
@ozankabak
Copy link
Contributor

We will take a look and address next week. Thanks

@alamb
Copy link
Contributor

alamb commented Feb 2, 2024

Possibly related #9111

@alamb
Copy link
Contributor

alamb commented Feb 6, 2024

I think this is working as designed as explained in #9131 (review) , though perhaps we could improve the design.

@mustafasrepo
Copy link
Contributor

mustafasrepo commented Feb 6, 2024

When I run the queries as you described in the issue body. I got the following plan:

logical_plan 
TableScan: t projection=[x], unsupported_filters=[t.y > Int64(0)]
physical_plan 
MemoryExec: partitions=1, partition_sizes=[1]

Considering #9131 review. I don't think these plans are wrong or sub-optimal. @jiacai2050 Can you try your queries in the main branch (not in the latest release) if possible. Because, I couldn't reproduce the logical plan in the issue.

@jiacai2050
Copy link
Contributor Author

@mustafasrepo Sorry for my delayed response, I will re-check this using latest main branch this week.

jiacai2050 added a commit to apache/horaedb that referenced this issue Feb 23, 2024
## Rationale
Close #1461 

## Detailed Changes
Bump datafusion to
https://github.com/CeresDB/arrow-datafusion/commits/e21b03154, which is
version 33.

Some important breaking changes:
- apache/datafusion#7920
- apache/datafusion#9109

## Test Plan
CI

---------

Co-authored-by: jiacai2050 <dev@liujiacai.net>
@jiacai2050
Copy link
Contributor Author

Closed since this is expected, thanks everyone involved.

For other developers, if you have met this issue, you can check how I "workaround" this issue here

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

Successfully merging a pull request may close this issue.

4 participants