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 concat expr with multiple args nullsFraction #52683

Merged
merged 1 commit into from
Nov 7, 2024

Conversation

stephen-shelby
Copy link
Contributor

@stephen-shelby stephen-shelby commented Nov 6, 2024

Why I'm doing:

The current nullsFraction method for concat calculation is incorrect and may be negative. This will cause the cardinality of the join node to be 1.

  8:HASH JOIN
  |  join op: LEFT OUTER JOIN (BROADCAST)
  |  equal join conjunct: [44: xxx, LARGEINT, true] = [127: ccc, LARGEINT, true]
  |  other predicates: concat[(cast([9: CLAIM_STATUS_CD, BIGINT, true] as VARCHAR), ' - ', [126: LOOKUP_DETAIL, VARCHAR, true]); args: VARCHAR; result: VARCHAR; args nullable: true; result nullable: true] = '3 - CLEARED'
  |  output columns: 3, 8, 9, 43, 54, 126
  |  can local shuffle: false
  |  cardinality: 1
  |  column statistics: 
  |  * aaa-->[4.446678308E9, 1.8487815906E10, 0.0, 8.0, 1.0] ESTIMATE
  |  * vvv-->[-Infinity, Infinity, 0.0, 1.0000000994337923, 1.0] ESTIMATE
  |  * ccc-->[1.0, 42.0, 0.0, 8.0, 1.0] ESTIMATE
  |  * www-->[-1.3145022026298428E38, 1.2734555494779917E38, 0.0, 16.0, 1.0] ESTIMATE
  |  * qqqq-->[-1.5620653915393402E38, 1.2734555494779917E38, 0.0, 16.0, 1.0] ESTIMATE
  |  * rrr-->[-1.7007341574472433E38, 1.7003487503261273E38, 0.0, 16.0, 1.0] ESTIMATE
  |  * ccaa-->[-Infinity, Infinity, 0.0, 7.076923076923077, 1.0] ESTIMATE
  |  * aafff-->[-1.5620653915393402E38, 1.2734555494779917E38, 0.0, 16.0, 1.0] ESTIMATE
  |  
  |----7:EXCHANGE
  |       distribution type: BROADCAST
  |       cardinality: 13
  |    
  5:OlapScanNode
     table: table, rollup: table
     preAggregation: on
     partitionsRatio=1/1, tabletsRatio=814/814
     tabletList=30250908,30250912,30250916,30250920,30250924,30250928,30250932,30250936,30250940,30250944 ...
     actualRows=643644364, avgRowSize=65.0
     cardinality: 643644364
     column statistics: 
     * afffa-->[4.446678308E9, 1.8487815906E10, 0.0, 8.0, 6.4845024E8] ESTIMATE
     * dsdf-->[-Infinity, Infinity, 0.0, 1.0000000994337923, 7.0] ESTIMATE
     * ccc-->[1.0, 42.0, 0.0, 8.0, 10.0] ESTIMATE
     * fff-->[-1.3145022026298428E38, 1.2734555494779917E38, 0.0, 16.0, 7.0] ESTIMATE
     * aaaa-->[-1.5620653915393402E38, 1.2734555494779917E38, 0.0, 16.0, 10.0] ESTIMATE
     * wwww-->[-1.7007341574472433E38, 1.7003487503261273E38, 0.0, 16.0, 9105.0] ESTIMATE

What I'm doing:

Reference binaryExpressionCalculate nullsFraction algorithm is 1 - ((1 - left.getNullsFraction ()) * ( 1 - right.getNullsFraction ())). Fix multiaryExpressionCalculate

Fixes #issue

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
  • This is a backport pr

Bugfix cherry-pick branch check:

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

@stephen-shelby stephen-shelby requested a review from a team as a code owner November 6, 2024 14:37
@stephen-shelby stephen-shelby changed the title [BugFix] fix concat nullsFractionc [BugFix] fix concat expr with multiple args nullsFraction Nov 7, 2024
nullsFraction = 1 - childColumnStatisticList.stream().mapToDouble(ColumnStatistic::getAverageRowSize)
.reduce(1, (a, b) -> (1 - a) * (1 - b));
nullsFraction = 1 - childColumnStatisticList.stream().mapToDouble(ColumnStatistic::getNullsFraction)
.reduce(1.0, (a, b) -> a * (1 - b));
Copy link
Contributor

Choose a reason for hiding this comment

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

why no (1-a) * (1-b) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if nullsFraction are [a, b, c], isn't our expectation 1 - ((1 - a) * (1 - b) * (1- c)) ?

Copy link
Contributor

@Seaven Seaven Nov 7, 2024

Choose a reason for hiding this comment

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

let's rename the parameters ? not a/b

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link

sonarcloud bot commented Nov 7, 2024

Copy link

github-actions bot commented Nov 7, 2024

[Java-Extensions Incremental Coverage Report]

pass : 0 / 0 (0%)

Copy link

github-actions bot commented Nov 7, 2024

[FE Incremental Coverage Report]

pass : 2 / 2 (100.00%)

file detail

path covered_line new_line coverage not_covered_line_detail
🔵 com/starrocks/sql/optimizer/statistics/ExpressionStatisticCalculator.java 2 2 100.00% []

Copy link

github-actions bot commented Nov 7, 2024

[BE Incremental Coverage Report]

pass : 0 / 0 (0%)

@Seaven Seaven enabled auto-merge (squash) November 7, 2024 07:56
@Seaven Seaven merged commit 3b8e683 into StarRocks:main Nov 7, 2024
50 checks passed
Copy link

github-actions bot commented Nov 7, 2024

@Mergifyio backport branch-3.3

@github-actions github-actions bot removed the 3.3 label Nov 7, 2024
Copy link

github-actions bot commented Nov 7, 2024

@Mergifyio backport branch-3.2

@github-actions github-actions bot removed the 3.2 label Nov 7, 2024
Copy link

github-actions bot commented Nov 7, 2024

@Mergifyio backport branch-3.1

@github-actions github-actions bot removed the 3.1 label Nov 7, 2024
Copy link
Contributor

mergify bot commented Nov 7, 2024

backport branch-3.3

✅ Backports have been created

Copy link
Contributor

mergify bot commented Nov 7, 2024

backport branch-3.2

✅ Backports have been created

Copy link
Contributor

mergify bot commented Nov 7, 2024

backport branch-3.1

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Nov 7, 2024
mergify bot pushed a commit that referenced this pull request Nov 7, 2024
Signed-off-by: stephen <[email protected]>
(cherry picked from commit 3b8e683)

# Conflicts:
#	fe/fe-core/src/main/java/com/starrocks/sql/optimizer/statistics/ExpressionStatisticCalculator.java
mergify bot pushed a commit that referenced this pull request Nov 7, 2024
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.

3 participants