Skip to content

Wrong projection after optimize_projections rule #9109

@jiacai2050

Description

@jiacai2050

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

Metadata

Metadata

Assignees

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