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

Simplify associative expressions with references #11733

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tinfoil-knight
Copy link
Contributor

@tinfoil-knight tinfoil-knight commented Jul 30, 2024

Which issue does this PR close?

Draft for #11594

Rationale for this change

What changes are included in this PR?

Are these changes tested?

Tests have been added.

Are there any user-facing changes?

Would be a breaking change for users relying on exact match of the optimized plan. Documentation doesn't need an update.

@github-actions github-actions bot added the optimizer Optimizer rules label Jul 30, 2024
@tinfoil-knight
Copy link
Contributor Author

For an expression like i + 1 + 2 which gets evaluated like (i + 1) + 2, we just need to re-arrange the grouping in Simplifier, so that the expression changes to i + (1 + 2).

In the subsequent run of the simplify, ConstEvaluator will resolve the arithmetic expression which only has literals now.

BinaryExpr(BinaryExpr { left: BinaryExpr(BinaryExpr { left: Column(Column { relation: None, name: "c3" }), op: Plus, right: Literal(Int32(1)) }), op: Plus, right: Literal(Int32(2)) })


BinaryExpr(BinaryExpr { left: Column(Column { relation: None, name: "c3" }), op: Plus, right: BinaryExpr(BinaryExpr { left: Literal(Int32(1)), op: Plus, right: Literal(Int32(2)) }) })
BinaryExpr(BinaryExpr { left: Column(Column { relation: None, name: "c3" }), op: Plus, right: Literal(Int32(3)) })

@tinfoil-knight tinfoil-knight changed the title simplify associative expressions with literals Simplify associative expressions with references Jul 30, 2024
Copy link
Contributor Author

@tinfoil-knight tinfoil-knight Jul 30, 2024

Choose a reason for hiding this comment

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

Doesn't handle all possible positions currently for an associative expression.

Eg:

(i + 1) + 2; i + 1 + 2 will resolve to i + 3

But something like these won't
(1 + i) + 2
2 + (i + 1)
2 + (1 + i)
1 + 2 + i

Copy link

Thank you for your contribution. Unfortunately, this pull request is stale because it has been open 60 days with no activity. Please remove the stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale PR has not had any activity for some time label Sep 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
optimizer Optimizer rules Stale PR has not had any activity for some time
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant