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): LogicalAgg::prune_col with duplicate group_keys #3632

Merged
merged 3 commits into from
Jul 5, 2022

Conversation

xiangjinwu
Copy link
Contributor

@xiangjinwu xiangjinwu commented Jul 4, 2022

I hereby agree to the terms of the Singularity Data, Inc. Contributor License Agreement.

What's changed and what's your intention?

For the following test case:

create table t(v1 int, v2 int, v3 int) with ('appendonly' = false);
insert into t values (1, 2, 3);
select v2, min(v1) as min_v1, v3, max(v1) as max_v1 from t group by v3, v2, v2;

The proj exprs should be [$1, $3, $0, $4] but is actually [$1, $2, $0, $3]. The output is also wrong:

 v2 | min_v1 | v3 | max_v1 
----+--------+----+--------
  2 |      2 |  3 |      1
(1 row)

This even panics:

explain select v2, sum(v1) from t group by v3, v2, v2;

Originally posted by @xiangjinwu in #3533 (comment)

Limitations:

  • I have kept this PR to only contain the most necessary fix. Some helper utilities are no longer needed and can be cleaned up, but I do not want to distract the PR reader with them. A cleanup PR that keep logic equivalent will come later.
  • Better plan can dedup group_keys as well, and support re-ordering of group_keys to avoid project completely in the following query: select v2, v3 from t group by v3, v2

Checklist

  • I have written necessary docs and comments
  • I have added necessary unit tests and integration tests
  • All checks passed in ./risedev check (or alias, ./risedev c)

Refer to a related PR or issue link (optional)

@github-actions github-actions bot added the type/fix Bug fix label Jul 4, 2022
@codecov
Copy link

codecov bot commented Jul 4, 2022

Codecov Report

Merging #3632 (cccf08e) into main (be7830e) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #3632      +/-   ##
==========================================
- Coverage   74.36%   74.35%   -0.01%     
==========================================
  Files         776      776              
  Lines      110213   110210       -3     
==========================================
- Hits        81959    81946      -13     
- Misses      28254    28264      +10     
Flag Coverage Δ
rust 74.35% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...rc/frontend/src/optimizer/plan_node/logical_agg.rs 95.05% <100.00%> (-0.40%) ⬇️
src/frontend/src/utils/column_index_mapping.rs 75.22% <0.00%> (-4.43%) ⬇️
src/common/src/error.rs 65.92% <0.00%> (+1.11%) ⬆️

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

Copy link
Contributor

@likg227 likg227 left a comment

Choose a reason for hiding this comment

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

LGTM

@xiangjinwu xiangjinwu added the mergify/can-merge Indicates that the PR can be added to the merge queue label Jul 5, 2022
@mergify mergify bot merged commit c71493a into main Jul 5, 2022
@mergify mergify bot deleted the fix-3533-logical-agg-builder branch July 5, 2022 03:15
nasnoisaac pushed a commit to nasnoisaac/risingwave that referenced this pull request Aug 9, 2022
…ngwavelabs#3632)

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mergify/can-merge Indicates that the PR can be added to the merge queue type/fix Bug fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants