Skip to content

SEMI JOIN should not duplicate a singleton left row - #5241

Draft
bvolpato wants to merge 1 commit into
apache:mainfrom
bvolpato:bvolpato/fix-singleton-semi-join
Draft

bvolpato wants to merge 1 commit into
apache:mainfrom
bvolpato:bvolpato/fix-singleton-semi-join

Conversation

@bvolpato

@bvolpato bvolpato commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Jira Link

Pending issue creation and linkage. This PR is a draft.

Changes Proposed

A SEMI JOIN with a singleton left input currently becomes a filter and projection over the right input. If several right rows match, the rewrite returns the left row once per match instead of once overall.

Exclude SEMI joins from the left-singleton simplification, including the Project-over-Values variant. Add regressions for both shapes. Right-singleton SEMI joins retain their existing optimization.

Reproduction

Join left VALUES (1) to right VALUES (1), (1) with a SEMI equality join. The original join returns one row; the affected rewrite returns two.

./gradlew :core:test --tests 'org.apache.calcite.test.RelOptRulesTest.testSemiJoinWithConstantRowOnLeft' --tests 'org.apache.calcite.test.RelOptRulesTest.testSemiJoinWithProjectOnConstantRowOnLeft'

Validation

  • A compiled-source HepPlanner/Interpreter reproduction returns two rows before the fix and one after, for both left-side rule variants.
  • Both right-side rule variants still optimize and preserve their results.
  • Both exact planner regression methods pass against the checked-in XML snapshots and fail against the baseline rule.
  • ./gradlew autostyleApply and git diff --check pass.
  • Focused runs used freshly compiled changed classes with cached supporting artifacts. Native Gradle test-class compilation on pristine main was blocked by java.io.IOException: No space left on device; the full Gradle build has not been validated locally.

Downsides

This disables the invalid simplification for left-singleton SEMI joins. A separate existence-preserving rewrite could recover that optimization later.

@sonarqubecloud

sonarqubecloud Bot commented Sep 3, 2026

Copy link
Copy Markdown

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.

1 participant