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

[BugFix] fix agg in order by not being analyzed correctly #30108

Merged
merged 6 commits into from
Aug 31, 2023

Conversation

packy92
Copy link
Contributor

@packy92 packy92 commented Aug 29, 2023

Fixes #issue
For sql like

select min(v1) v1 from t0 group by v3 order by round(count(v2) / min(v1)), min(v1), abs(v1);

The statement had been transformed to a wrong plan fragment like:

LogicalProjectOperator {projection=[3: v3, 5: count, 6: min, min(1: v1)]}
            ->  LogicalAggregation {type=GLOBAL ,aggregations={4: min=min(1: v1), 5: count=count(2: v2), 6: min=min(1: v1)} ,groupKeys=[3: v3]}

This reason is the scope for analyzing order by is combined querySource scope and output scope. For the order by elements in the sql, its scope is like output scope: v1(tblName null), source scope: v1(tblName t0), v2(tblName t0), v3(tblName t0). When analyze min(v1), the v1 matched with v1(tblName null) firstly, while it should be v1(tblName t0). Even the old code would analyze the aggregations using source scope in the later step, the fisrt analyzed process has put the slotRef in a map. The second analyzed process may change the slotRef already in the map, leading to unexpect behavior when get obejct from the map.
So, the better way is to distinguish the aggregation func from the normal func in the analyze orderby stage, and use the corresponding scope to process them respectively.

What type of PR is this:

  • BugFix
  • Feature
  • Enhancement
  • Refactor
  • UT
  • Doc
  • Tool

Does this PR entail a change in behavior?

  • Yes, this PR will result in a change in behavior.
  • No, this PR will not result in a change in behavior.

If yes, please specify the type of change:

  • Interface/UI changes: syntax, type conversion, expression evaluation, display information
  • Parameter changes: default values, similar parameters but with different default values
  • Policy changes: use new policy to replace old one, functionality automatically enabled
  • Feature removed
  • Miscellaneous: upgrade & downgrade compatibility, etc.

Checklist:

  • I have added test cases for my bug fix or my new feature
  • This pr needs user documentation (for new or modified features or behaviors)
    • I have added documentation for my new feature or new function

Bugfix cherry-pick branch check:

  • I have checked the version labels which the pr will be auto-backported to the target branch
    • 3.1
    • 3.0
    • 2.5
    • 2.4

kangkaisen
kangkaisen previously approved these changes Aug 29, 2023
Signed-off-by: packy <[email protected]>
@sonarqubecloud
Copy link

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell B 4 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

warning The version of Java (11.0.20.1) you have used to run this analysis is deprecated and we will stop accepting it soon. Please update to at least Java 17.
Read more here

idea Catch issues before they fail your Quality Gate with our IDE extension sonarlint SonarLint

@wanpengfei-git
Copy link
Collaborator

[BE Incremental Coverage Report]

😍 pass : 0 / 0 (0%)

@wanpengfei-git
Copy link
Collaborator

[FE Incremental Coverage Report]

😍 pass : 10 / 10 (100.00%)

file detail

path covered_line new_line coverage not_covered_line_detail
🔵 com/starrocks/sql/analyzer/SelectAnalyzer.java 5 5 100.00% []
🔵 com/starrocks/sql/analyzer/AggregationAnalyzer.java 1 1 100.00% []
🔵 com/starrocks/sql/analyzer/ExpressionAnalyzer.java 4 4 100.00% []

@Seaven Seaven merged commit eea93ef into StarRocks:main Aug 31, 2023
@wanpengfei-git
Copy link
Collaborator

@Mergifyio backport branch-3.1

@github-actions github-actions bot removed the 3.1 label Aug 31, 2023
@wanpengfei-git
Copy link
Collaborator

@Mergifyio backport branch-3.0

@mergify
Copy link
Contributor

mergify bot commented Aug 31, 2023

backport branch-3.1

✅ Backports have been created

@github-actions github-actions bot removed the 3.0 label Aug 31, 2023
@mergify
Copy link
Contributor

mergify bot commented Aug 31, 2023

backport branch-3.0

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Aug 31, 2023
---------

Signed-off-by: packy92 <[email protected]>
Signed-off-by: packy <[email protected]>
(cherry picked from commit eea93ef)
mergify bot pushed a commit that referenced this pull request Aug 31, 2023
---------

Signed-off-by: packy92 <[email protected]>
Signed-off-by: packy <[email protected]>
(cherry picked from commit eea93ef)

# Conflicts:
#	fe/fe-core/src/main/java/com/starrocks/sql/analyzer/AggregationAnalyzer.java
#	fe/fe-core/src/main/java/com/starrocks/sql/analyzer/SelectAnalyzer.java
#	fe/fe-core/src/test/java/com/starrocks/sql/analyzer/AnalyzeAggregateTest.java
packy92 added a commit to packy92/starrocks that referenced this pull request Sep 1, 2023
packy92 added a commit to packy92/starrocks that referenced this pull request Sep 1, 2023
packy92 added a commit to packy92/starrocks that referenced this pull request Sep 1, 2023
Jay-ju pushed a commit to Jay-ju/starrocks that referenced this pull request Sep 7, 2023
packy92 added a commit that referenced this pull request Sep 13, 2023
packy92 added a commit that referenced this pull request Sep 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants