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

Move inlist rule to expr_simplifier #9692

Merged
merged 2 commits into from
Mar 19, 2024
Merged

Conversation

jayzhan211
Copy link
Contributor

@jayzhan211 jayzhan211 commented Mar 19, 2024

Which issue does this PR close?

Closes #9140.

I think short inlist simplifier should be an independent simplifier that can't be moved to simplifier, so that it will only be run once after all the other inlist simplification. Therefore, close the issue.

Rationale for this change

What changes are included in this PR?

Are these changes tested?

Are there any user-facing changes?

Signed-off-by: jayzhan211 <jayzhan211@gmail.com>
@github-actions github-actions bot added the optimizer Optimizer rules label Mar 19, 2024
) =>
{
match (*left, *right) {
(Expr::InList(l1), Expr::InList(l2)) => {

This comment was marked as outdated.

Signed-off-by: jayzhan211 <jayzhan211@gmail.com>
@github-actions github-actions bot added the sqllogictest SQL Logic Tests (.slt) label Mar 19, 2024
@jayzhan211 jayzhan211 marked this pull request as ready for review March 19, 2024 15:06
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 @jayzhan211 -- this is a nice cleanup and removes a copy (for node in the expression tree).

I am also running the planning benchmark to see if this PR provides an improvement

// 6. `a in (1,2,3,4) AND a not in (1,2,3,4,5) -> a in (), which is false`
// 7. `a not in (1,2,3,4) AND a in (1,2,3,4,5) -> a = 5`
// 8. `a in (1,2,3,4) AND a not in (5,6,7,8) -> a in (1,2,3,4)`
if let Expr::BinaryExpr(BinaryExpr { left, op, right }) = expr.clone() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Removing this expr.clone() is 👍

Transformed::yes(Expr::InList(merged_inlist))
}

// Simplify expressions that is guaranteed to be true or false to a literal boolean expression
Copy link
Contributor

Choose a reason for hiding this comment

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

👨‍🍳 👌 -- very nice

@@ -1482,6 +1590,22 @@ impl<'a, S: SimplifyInfo> TreeNodeRewriter for Simplifier<'a, S> {
}
}

// TODO: We might not need this after defer pattern for Box is stabilized. https://github.com/rust-lang/rust/issues/87121
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@alamb
Copy link
Contributor

alamb commented Mar 19, 2024

Testing with

git checkout inlist-rule2
cargo bench --bench sql_planner -- all

#alamb@aal-dev:~/arrow-datafusion4$ git merge-base HEAD apache/main
#b0b329ba39403b9e87156d6f9b8c5464dc6d2480

git checkout b0b329ba39403b9e87156d6f9b8c5464dc6d2480
cargo bench --bench sql_planner -- all

@alamb
Copy link
Contributor

alamb commented Mar 19, 2024

I did not measure any significant difference in performance on the sql_planner benchmarks unfortunately

@alamb alamb merged commit 7fab5ac into apache:main Mar 19, 2024
23 checks passed
@jayzhan211
Copy link
Contributor Author

I did not measure any significant difference in performance on the sql_planner benchmarks unfortunately

I doubt if even the rule is included.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
optimizer Optimizer rules sqllogictest SQL Logic Tests (.slt)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

consolidate all the InList rewrites into a single pass
2 participants