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

feat(condition): add column_self_eq_eliminate for condition simplification #15901

Merged
merged 12 commits into from
Mar 28, 2024

Conversation

xzhseh
Copy link
Contributor

@xzhseh xzhseh commented Mar 25, 2024

I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.

What's changed and what's your intention?

close #12931.

Checklist

  • I have written necessary rustdoc comments
  • I have added necessary unit tests and integration tests
  • I have added test labels as necessary. See details.
  • I have added fuzzing tests or opened an issue to track them. (Optional, recommended for new SQL features Sqlsmith: Sql feature generation #7934).
  • My PR contains breaking changes. (If it deprecates some features, please create a tracking issue to remove them in the future).
  • All checks passed in ./risedev check (or alias, ./risedev c)
  • My PR changes performance-critical code. (Please run macro/micro-benchmarks and show the results.)
  • My PR contains critical fixes that are necessary to be merged into the latest release. (Please check out the details)

Documentation

  • My PR needs documentation updates. (Please use the Release note section below to summarize the impact on users)

Release note

If this PR includes changes that directly affect users or other significant modifications relevant to the community, kindly draft a release note to provide a concise summary of these changes. Please prioritize highlighting the impact these changes will have on users.

@xzhseh xzhseh requested review from chenzl25 and st1page March 25, 2024 20:33
@xzhseh xzhseh self-assigned this Mar 25, 2024
@@ -849,6 +849,7 @@ impl Condition {
.into_iter()
.map(push_down_not)
.map(fold_boolean_constant)
.map(column_self_eq_eliminate)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the reason I put this optimization here is because it's hard to catch new variants of predicate(s) after each predicate_pushdown in logical_optimization, and the predicate in ch_benchmark can't be optimized though I've tried to insert as many LOGICAL_FILTER_EXPRESSION_SIMPLIFY as possible.

thus it's better to solve this problem from the root - from my perspective.

@xzhseh xzhseh requested a review from xiangjinwu March 25, 2024 20:41
|| func_type == ExprType::IsNotFalse
}

pub fn rewrite(expr: ExprImpl) -> ExprImpl {
Copy link
Contributor Author

@xzhseh xzhseh Mar 25, 2024

Choose a reason for hiding this comment

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

and why bother to separate the logic from ExpressionSimplifyRewriter in logical_filter_expression_simplify_rule?

  1. the former mainly aims to optimize pattern like, e.g., (e) [or / and] not(e).
  2. it's hard to maintain the module with two different logic interleaving. (and presumably more in the future)
  3. this one is especially to simplify Condition at constructing time, while the former will be used during logical_optimization.

Copy link
Contributor

@chenzl25 chenzl25 left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -612,6 +612,7 @@ impl LogicalOptimizer {
// Must push down predicates again after split over window so that OverWindow can be
// optimized to TopN.
plan = Self::predicate_pushdown(plan, explain_trace, &ctx);
plan = plan.optimize_by_rules(&LOGICAL_FILTER_EXPRESSION_SIMPLIFY);
Copy link
Contributor

Choose a reason for hiding this comment

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

.map(column_self_eq_eliminate)

If we have added column_self_eq_eliminate to the filter simplify method, do we need to add this rule here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I forget to delete it 🤣

@xzhseh xzhseh enabled auto-merge March 26, 2024 19:29
@xzhseh xzhseh added this pull request to the merge queue Mar 27, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to a conflict with the base branch Mar 27, 2024
@xzhseh xzhseh enabled auto-merge March 27, 2024 13:46
@xzhseh xzhseh added this pull request to the merge queue Mar 28, 2024
Merged via the queue into main with commit 2e197e1 Mar 28, 2024
26 of 27 checks passed
@xzhseh xzhseh deleted the xzhseh/self-equal-optimize branch March 28, 2024 02:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

optimizer: bool expression folding "self equal" as always true
2 participants