Skip to content

branch:4.2: [fix](fe) Move SemiJoinCommute to rewrite phase #66182 - #68288

Merged
yiguolei merged 9 commits into
apache:branch-4.2from
morrySnow:pick-66182-to-branch-4.2
Sep 21, 2026
Merged

yiguolei merged 9 commits into
apache:branch-4.2from
morrySnow:pick-66182-to-branch-4.2

Conversation

@morrySnow

Copy link
Copy Markdown
Contributor

picked from #66182

### What problem does this PR solve?

Issue Number: None

Related PR: None

Problem Summary: SemiJoinCommute structurally normalizes RIGHT OUTER, RIGHT SEMI, and RIGHT ANTI joins. Running it during analysis made analyzed plan shapes depend on join-reorder state, so consumers that identify analyzed plans could observe inconsistent signatures for the same query. Move the rule to both regular and CTE rewrite pipelines before the semi-join transpose rules, keeping analysis stable while preserving rewrite assumptions.

### Release note

None

### Check List (For Author)

- Test: Unit Test
    - ReorderJoinTest
    - SaltJoinTest
- Behavior changed: Yes. Analyze preserves RIGHT JOIN shape and Rewrite performs the existing normalization.
- Does this need documentation: No
### What problem does this PR solve?

Issue Number: None

Related PR: None

Problem Summary: SemiJoinCommute now runs in rewrite pipelines instead of analysis. Add coverage for the disable_join_reorder boundary, the materialized-view pre-rewrite pipeline, and the ordering between SemiJoinCommute and semi-join transpose rules.

### Release note

None

### Check List (For Author)

- Test: Unit Test
    - ReorderJoinTest
    - SaltJoinTest
- Behavior changed: No
- Does this need documentation: No
Issue Number: None

Related PR: apache#66182

Problem Summary: Moving SemiJoinCommute out of analysis exposed that CollectJoinConstraint assumed right outer, semi, and anti joins had already been normalized to left joins. A preserved-side ON predicate could then be treated as a single-table filter and pushed below the join, changing query results. Canonicalize right-join constraint metadata to the existing left-join model and update unit-test expectations for the equivalent child order produced by the new rewrite stage.

Fix incorrect LEADING query results for right outer, semi, and anti joins.

- Test: Regression test / Unit Test
    - InferTest, ReorderJoinTest, SaltJoinTest
    - query_p0/hint/fix_leading
    - query_p0/hint/test_leading
- Behavior changed: Yes, LEADING no longer pushes preserved-side right join ON predicates below the join.
- Does this need documentation: No
### What problem does this PR solve?

Issue Number: None

Related PR: apache#66182

Problem Summary: Moving SemiJoinCommute out of analysis exposes a pre-existing LEADING dependency on Analyzer normalizing right joins to left joins. The attempted hint fix is independent of the rewrite-stage migration and needs dedicated coverage for right outer, semi, and anti joins. Remove that hint implementation from this PR and temporarily disable only the failing select4_2 regression case until the follow-up fix is ready.

### Release note

None

### Check List (For Author)

- Test: Regression test / Unit Test
    - ./run-fe-ut.sh --run org.apache.doris.nereids.sqltest.InferTest,org.apache.doris.nereids.rules.rewrite.ReorderJoinTest,org.apache.doris.nereids.rules.rewrite.SaltJoinTest
    - ./run-regression-test.sh --run -d query_p0 -s fix_leading
- Behavior changed: Yes, defer LEADING handling for original right joins to a follow-up PR and temporarily skip its failing regression case.
- Does this need documentation: No
### What problem does this PR solve?

Issue Number: None

Related PR: apache#66182

Problem Summary: Moving SemiJoinCommute out of analysis exposes a pre-existing LEADING dependency on Analyzer normalizing right joins. Temporarily disable the corresponding select4_3 shape assertion alongside select4_2 until the independent LEADING fix is ready.

### Release note

None

### Check List (For Author)

- Test: Regression test
    - Verified the P0 failure is isolated to select4_3; select2_2 and select2_5 complete before it
- Behavior changed: No
- Does this need documentation: No
### What problem does this PR solve?

Issue Number: None

Related PR: apache#66182

Problem Summary: Moving SemiJoinCommute out of analysis exposes that LEADING constraint collection assumes right joins have already been normalized to left joins. RIGHT OUTER and RIGHT ANTI preserved-side predicates can then be pushed below their scans, while a RIGHT SEMI join can consume its condition before the complete non-output side is built and duplicate output rows. Canonicalize right-join constraint metadata to the equivalent left-join model without changing the analyzed plan, and restore or add focused regression coverage.

### Release note

Fix incorrect LEADING query results for right outer, semi, and anti joins.

### Check List (For Author)

- Test: Unit Test
    - ./run-fe-ut.sh --run org.apache.doris.nereids.rules.rewrite.ReorderJoinTest,org.apache.doris.nereids.sqltest.SqlPlanSuiteTest (34 tests passed)
    - Regression test not run yet; waiting for FE to be built and restarted with this commit
- Behavior changed: Yes. LEADING preserves right-join boundaries and ON predicate semantics.
- Does this need documentation: No
### What problem does this PR solve?

Issue Number: None

Related PR: apache#66182

Problem Summary: Refresh the fix_leading expected output after restoring right outer join coverage and adding focused right semi and right anti join cases. The generated results verify correct row counts and preserve the complete non-output side of the right semi join.

### Release note

None

### Check List (For Author)

- Test: Regression test
    - ./run-regression-test.sh --run -d query_p0 -s fix_leading -forceGenOut
    - ./run-regression-test.sh --run -d query_p0 -s fix_leading
- Behavior changed: No
- Does this need documentation: No
### What problem does this PR solve?

Issue Number: None

Related PR: apache#66182

Problem Summary: The right semi join regression test compared a complete physical plan shape even though equivalent CROSS JOIN children may be reordered by cost and statistics. Remove the unstable shape assertion while retaining result checks that reproduce the incorrect right semi and right anti join behavior.

### Release note

None

### Check List (For Author)

- Test: Regression test
    - ./run-regression-test.sh --run -d query_p0 -s fix_leading -forceGenOut
    - ./run-regression-test.sh --run -d query_p0 -s fix_leading
- Behavior changed: No
- Does this need documentation: No
@morrySnow
morrySnow requested a review from yiguolei as a code owner September 20, 2026 18:07
@hello-stephen

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@morrySnow

Copy link
Copy Markdown
Contributor Author

run buildall

@morrySnow morrySnow changed the title branch:4.1: [fix](fe) Move SemiJoinCommute to rewrite phase #66182 branch:4.2: [fix](fe) Move SemiJoinCommute to rewrite phase #66182 Sep 20, 2026
@morrySnow

Copy link
Copy Markdown
Contributor Author

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 100.00% (15/15) 🎉
Increment coverage report
Complete coverage report

@yiguolei
yiguolei merged commit 1faeee8 into apache:branch-4.2 Sep 21, 2026
26 of 28 checks passed
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