Skip to content

[BugFix] Preserve null fractions for outer join columns#70144

Open
OliLay wants to merge 4 commits intoStarRocks:mainfrom
OliLay:layer/fix-join-outer-null-fractions
Open

[BugFix] Preserve null fractions for outer join columns#70144
OliLay wants to merge 4 commits intoStarRocks:mainfrom
OliLay:layer/fix-join-outer-null-fractions

Conversation

@OliLay
Copy link
Contributor

@OliLay OliLay commented Mar 11, 2026

Why I'm doing:

Consider the following query:

explain costs
select
    *
from
    TABLE1 t1
    LEFT JOIN TABLE2 t2 ON t1.NULLABLE = t2.NULLABLE
    LEFT JOIN TABLE3 t3 ON t1.NULLABLE = t3.NULLABLE;

At the moment, even though t1.NULLABLE has proper null fractions (e.g. 0.8), the second join assumes that t1.NULLABLE has 0.0 null fractions. This is because for equality predicates, we reset the null fractions to 0 since NULLs are not preserved. In the context of the predicate (and inner joins) this is right, but outer joins should not reset null fractions. Subsequent joins should re-use the original column null fractions instead.

See the following EXPLAIN where the in the topmost join (7) 4: NULLABLE has 0 null fractions, while for the joins prior to that join the correct null fractions are shown. The fixed EXPLAIN contains the proper null fractions for 4: NULLABLE

Wrong null fractions lead to the join not being rewritten, e.g. by the join skew rule.

What I'm doing:

For outer joins, do not reset the null fractions of columns used in join predicates.

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 pr needs auto generate documentation
  • 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
    • 4.1
    • 4.0
    • 3.5
    • 3.4

@OliLay OliLay requested a review from a team as a code owner March 11, 2026 10:45
@mergify mergify bot assigned OliLay Mar 11, 2026
@CelerData-Reviewer
Copy link

@codex review

OliLay added 2 commits March 11, 2026 11:47
Signed-off-by: Oliver Layer <o.layer@celonis.com>
Signed-off-by: Oliver Layer <o.layer@celonis.com>
@OliLay OliLay force-pushed the layer/fix-join-outer-null-fractions branch from 486f5e0 to 4bacfb4 Compare March 11, 2026 10:47
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 486f5e06f8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

OliLay added 2 commits March 11, 2026 15:17
Signed-off-by: Oliver Layer <o.layer@celonis.com>
Signed-off-by: Oliver Layer <o.layer@celonis.com>
@github-actions
Copy link
Contributor

[Java-Extensions Incremental Coverage Report]

pass : 0 / 0 (0%)

@github-actions
Copy link
Contributor

[FE Incremental Coverage Report]

pass : 15 / 15 (100.00%)

file detail

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

@github-actions
Copy link
Contributor

[BE Incremental Coverage Report]

pass : 0 / 0 (0%)

@sonarqubecloud
Copy link

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.

2 participants