Skip to content

Don't add filters to projection in TableScan - #7670

Merged
Dandandan merged 1 commit into
apache:mainfrom
Dandandan:dont_add_filters_to_projection
Sep 28, 2023
Merged

Don't add filters to projection in TableScan#7670
Dandandan merged 1 commit into
apache:mainfrom
Dandandan:dont_add_filters_to_projection

Conversation

@Dandandan

@DandandanDandandan commented Sep 27, 2023

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Closes#7683

Rationale for this change

We don't want to scan columns not needed by the rest of the plan.

What changes are included in this PR?

We change the scan implementations to apply the filters before the projection.
This way we don't need to add the filters to the projection in to make the plan correct.

Are these changes tested?

Existing tests + new test.

Are there any user-facing changes?

@DandandanDandandan changed the title WIP Don't add filters to used columnsWIP Don't add filters to used columns in TableScanSep 27, 2023
@github-actionsgithub-actionsBot added logical-expr Logical plan and expressions optimizer Optimizer rules core Core DataFusion crate labels Sep 27, 2023
@Dandandan
Dandandan marked this pull request as draft September 28, 2023 07:24

let expected = "\
Projection: Int32(1) AS a\
\n TableScan: test projection=[a], full_filters=[b = Int32(1)]";

@DandandanDandandanSep 28, 2023

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the important fix - before this would add b to the projection (even if it was not needed in the plan above). This would lead to unnecessary scanning columns supported by the filter.

@Dandandan
Dandandan marked this pull request as ready for review September 28, 2023 09:43
@DandandanDandandan changed the title WIP Don't add filters to used columns in TableScanDon't add filters to used columns in TableScanSep 28, 2023
@DandandanDandandan changed the title Don't add filters to used columns in TableScanDon't add filters to projection in TableScanSep 28, 2023
if !scan.projected_schema.fields().is_empty() =>
{
let mut used_columns: HashSet<Column> = HashSet::new();
// filter expr may not exist in expr in projection.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This added filters to the projection since #5188

FYI @jackwener

Add test
WIP fix
Fix filter after scan
Totally reemove filter to column extraction
Fix test
Update tests 1
Update tests 2
Update tests 3
@Dandandan
Dandandanforce-pushed the dont_add_filters_to_projection branch from b283946 to 27069f0CompareSeptember 28, 2023 11:43
@Dandandan

Copy link
Copy Markdown
ContributorAuthor

FYI @alamb this might help with enabling parquet filter pushdown as well by default

@thinkharderdevthinkharderdev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@alambalamb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great @Dandandan -- thank you so much ❤️

\n Projection: test1.a, test1.b\
\n Filter: test1.b > UInt32(1)\
\n TableScan: test1\
\n TableScan: test1, full_filters=[test1.b > UInt32(1)]\

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is great to see the filters pushed into the scans as part of this test

@Dandandan
Dandandan merged commit 4b2b7dc into apache:mainSep 28, 2023
Ted-Jiang pushed a commit to Ted-Jiang/arrow-datafusion that referenced this pull request Oct 7, 2023
Add test
WIP fix
Fix filter after scan
Totally reemove filter to column extraction
Fix test
Update tests 1
Update tests 2
Update tests 3
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

coreCore DataFusion cratelogical-exprLogical plan and expressionsoptimizerOptimizer rules

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Filters of TableScan are added to projection when not needed

3 participants

@Dandandan@alamb@thinkharderdev