Skip to content

fix: don't unifies projection if expr is non-trival #8454

New issue

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

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

Already on GitHub? # to your account

Merged
merged 2 commits into from
Dec 8, 2023

Conversation

haohuaijin
Copy link
Contributor

Which issue does this PR close?

Closes #8453

Rationale for this change

What changes are included in this PR?

don't unifies projection if the expression in non-trival. see discussion in #8296

Are these changes tested?

Are there any user-facing changes?

add physical plan check in .slt test

@github-actions github-actions bot added core Core DataFusion crate sqllogictest SQL Logic Tests (.slt) labels Dec 7, 2023
@alamb alamb requested a review from mustafasrepo December 7, 2023 22:28
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thank you for the contribution @haohuaijin . This change makes sense to me

cc @mustafasrepo and @Dandandan

let mut column_ref_map: HashMap<Column, usize> = HashMap::new();

// Collect the column references usage in the outer projection.
projection.expr().iter().for_each(|(expr, _)| {
Copy link
Contributor

Choose a reason for hiding this comment

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

I may be mistaken and it may not matter, but I think this will prevent pushing down exprs that refer to the same column more than once

Projection exprs=[b as c, b as d]
  Projection exprs = [a as b]

Into

Projection exprs=[a as c, a as d]

Copy link
Contributor Author

@haohuaijin haohuaijin Dec 8, 2023

Choose a reason for hiding this comment

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

We don't prevent Column and Literal push_down. We prevent other express push_down, used to prevent multiple evaluation of the same expression.

    if column_ref_map.iter().any(|(column, count)| {
        *count > 1 && !is_expr_trivial(&child.expr()[column.index()].0.clone())
    }) {
        return Ok(None);
    }

Copy link
Contributor

@mustafasrepo mustafasrepo left a comment

Choose a reason for hiding this comment

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

Thanks @haohuaijin for this PR. It is LGTM!.

Co-authored-by: Alex Huang <huangweijun1001@gmail.com>
@alamb alamb merged commit d771f26 into apache:main Dec 8, 2023
@alamb
Copy link
Contributor

alamb commented Dec 8, 2023

Thank you @haohuaijin,. @Weijun-H and @mustafasrepo

@haohuaijin haohuaijin deleted the fix_projection branch December 8, 2023 12:08
appletreeisyellow pushed a commit to appletreeisyellow/datafusion that referenced this pull request Dec 15, 2023
* fix: don't unifies projection if expr is non-trival

* Update datafusion/core/src/physical_optimizer/projection_pushdown.rs

Co-authored-by: Alex Huang <huangweijun1001@gmail.com>

---------

Co-authored-by: Alex Huang <huangweijun1001@gmail.com>
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
core Core DataFusion crate sqllogictest SQL Logic Tests (.slt)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Physical optimizer rule projection_pushdown undo the logical rule common_subexpr_eliminate
4 participants