Skip to content

Conversation

@murphyatwork
Copy link
Contributor

@murphyatwork murphyatwork commented Dec 18, 2025

Why I'm doing:

What I'm doing:

Skew join hint should be able to support both left side and right side.

Fixes #66924

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
    • 4.0
    • 3.5
    • 3.4
    • 3.3

Note

Enables skew join hints to reference columns from either the left or right join side by fixing scope analysis and optimizer transformations, with new tests verifying right-side hints.

  • Analyzer:
    • analyzeJoinHints now receives leftScope/rightScope; skew column is analyzed against a combined join scope.
  • Optimizer (SkewJoinOptimizeRule):
    • Properly finds the counterpart column for the skew key regardless of which side it’s on.
    • Renames/rewires helpers (addSaltForSkewChild/addSaltForOtherChild) and applies salt to the correct child based on column lineage.
    • Tightens validation when hint is used but skew column counterpart isn’t found.
  • Transformer:
    • Translates join[skew|...] column using a builder that includes both left/right plans, enabling right-side column support.
  • Tests:
    • Add cases validating right-side skew hints in both v1 and v2 planner modes.

Written by Cursor Bugbot for commit 1bcfe9f. This will update automatically on new commits. Configure here.

Signed-off-by: Murphy <mofei@starrocks.com>
Signed-off-by: Murphy <mofei@starrocks.com>
Copilot AI review requested due to automatic review settings December 18, 2025 04:39
@murphyatwork murphyatwork requested review from a team as code owners December 18, 2025 04:39
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug where skew join hints would fail with a "column not found" error when referencing columns from the right side of a join. Previously, the skew join optimization only resolved columns against the left relation's scope, preventing users from specifying skew columns on the right table (e.g., join[skew|t1.v4(1,2)]). The fix enables bidirectional support by resolving skew columns against a combined scope of both join relations and dynamically determining which side contains the skew column during optimization.

Key changes:

  • Column resolution now checks both left and right relations to find the skew column
  • Optimization logic determines skew column side dynamically and applies salt operations accordingly
  • Variable renaming from side-specific (rightSkewColumn) to side-agnostic (otherSideSkewColumn) names

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
fe/fe-core/src/main/java/com/starrocks/sql/analyzer/QueryAnalyzer.java Modified analyzeJoinHints to accept both left and right scopes, creating a joined scope for skew column resolution
fe/fe-core/src/main/java/com/starrocks/sql/optimizer/transformer/RelationTransformer.java Updated skew column translation to pass both left and right OptExprBuilders for bidirectional column lookup
fe/fe-core/src/main/java/com/starrocks/sql/optimizer/rule/transformation/SkewJoinOptimizeRule.java Enhanced optimization rule to detect which side contains the skew column and renamed methods/variables to be side-agnostic
fe/fe-core/src/test/java/com/starrocks/sql/plan/SkewJoinV2Test.java Added test case verifying right-side skew column hints work correctly with V2 optimization
fe/fe-core/src/test/java/com/starrocks/sql/plan/SkewJoinTest.java Added test case verifying right-side skew column hints work correctly with standard optimization

@sonarqubecloud
Copy link

@alvin-celerdata
Copy link
Contributor

@cursor review

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no bugs!


Signed-off-by: Murphy <mofei@starrocks.com>
@github-actions
Copy link

[Java-Extensions Incremental Coverage Report]

pass : 0 / 0 (0%)

@github-actions
Copy link

[FE Incremental Coverage Report]

pass : 37 / 37 (100.00%)

file detail

path covered_line new_line coverage not_covered_line_detail
🔵 com/starrocks/sql/optimizer/transformer/RelationTransformer.java 1 1 100.00% []
🔵 com/starrocks/sql/optimizer/rule/transformation/SkewJoinOptimizeRule.java 32 32 100.00% []
🔵 com/starrocks/sql/analyzer/QueryAnalyzer.java 4 4 100.00% []

@github-actions
Copy link

[BE Incremental Coverage Report]

pass : 0 / 0 (0%)

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.

Specifying the column of right side in skew hint cause syntax error

2 participants