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

fix(optimizer): can't apply pull_up_correlated_predicate_agg_rule with non-null-propagating expr #20012

Merged
merged 6 commits into from
Jan 3, 2025

Conversation

xxchan
Copy link
Member

@xxchan xxchan commented Jan 3, 2025

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

What's changed and what's your intention?

fix #19835

Previously we check whether the Agg is count to decide whether the rule can be applied, but there are some other cases not considered, e.g., coalesce. We should check whether the agg/expr is "null-propagating".

The rule:

       Filter
         |
    LogicalApply
   /            \
 LHS          Project
                |
               Agg [group by nothing]
                |
              Project
                |
              Filter [correlated_input_ref(yyy) = xxx]

After:

       Filter
         |
    LogicalJoin [yyy = xxx]
   /            \
 LHS          Project
                |
               Agg [group by xxx]
                |
              Project
                |
              Filter

Checklist

  • I have written necessary rustdoc comments.
  • I have added necessary unit tests and integration tests.
  • I have added test labels as necessary.
  • I have added fuzzing tests or opened an issue to track them.
  • My PR contains breaking changes.
  • My PR changes performance-critical code, so I will run (micro) benchmarks and present the results.
  • My PR contains critical fixes that are necessary to be merged into the latest release.

Documentation

  • My PR needs documentation updates.
Release note

@xxchan xxchan requested review from chenzl25 and xiangjinwu January 3, 2025 06:28
@github-actions github-actions bot added the type/fix Bug fix label Jan 3, 2025
@xxchan xxchan requested a review from st1page January 3, 2025 06:30
Signed-off-by: xxchan <[email protected]>
Signed-off-by: xxchan <[email protected]>
@xxchan xxchan requested a review from chenzl25 January 3, 2025 08:51
.predicate()
.conjunctions
.iter()
.any(|expr| !Strong::is_null(expr, top_proj_null_bitset.clone()))
{
.all(|expr| Strong::is_null(expr, top_proj_null_bitset.clone()));
Copy link
Contributor

Choose a reason for hiding this comment

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

It should be any.

Suggested change
.all(|expr| Strong::is_null(expr, top_proj_null_bitset.clone()));
.any(|expr| Strong::is_null(expr, top_proj_null_bitset.clone()));

let mut top_proj_null_bitset =
FixedBitSet::with_capacity(top_project.base.schema().len() + apply_left_schema);
for (i, expr) in top_proj_exprs.iter().enumerate() {
if Strong::is_null(expr, agg_null_bitset.clone()) {
top_proj_null_bitset.insert(i + apply_left_schema);
} else {
top_proj_all_null = false;
Copy link
Contributor

@chenzl25 chenzl25 Jan 3, 2025

Choose a reason for hiding this comment

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

When Strong::is_null return false, it means we can't get any useful information, so we shouldn't allow apply rule based on it.

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.

Rest LGTM! Thanks

xxchan added 3 commits January 3, 2025 17:35
Signed-off-by: xxchan <[email protected]>
Signed-off-by: xxchan <[email protected]>
@xxchan xxchan enabled auto-merge January 3, 2025 09:38
@xxchan xxchan added this pull request to the merge queue Jan 3, 2025
Merged via the queue into main with commit 6248415 Jan 3, 2025
28 of 29 checks passed
@xxchan xxchan deleted the xxchan/productive-takin branch January 3, 2025 10:59
@maingoh
Copy link

maingoh commented Jan 29, 2025

@xxchan I don't see this commit in the latest tags 2.0.6 or 2.1.2 or v2.2.0-rc.1. I am wondering if will be tagged or if it has been forgotten ? Thank you !

@xxchan
Copy link
Member Author

xxchan commented Jan 30, 2025

I think it can be cherry-picked into 2.2 which hasn't been released yet

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.

PullUpCorrelatedPredicateAggRule is wrong for non-null-propagating expression
3 participants