Skip to content

[feat](fe) Push limit through full outer join#63333

Closed
CalvinKirs wants to merge 1 commit into
apache:masterfrom
CalvinKirs:ck_foj
Closed

[feat](fe) Push limit through full outer join#63333
CalvinKirs wants to merge 1 commit into
apache:masterfrom
CalvinKirs:ck_foj

Conversation

@CalvinKirs
Copy link
Copy Markdown
Member

@CalvinKirs CalvinKirs commented May 18, 2026

What problem does this PR solve?

Issue Number: None

Related PR: None

Problem Summary: PushDownLimit skipped full outer joins, so LIMIT could not be pushed to either preserved input even though unordered LIMIT can be applied to both sides before the full outer join.

before:
mysql>   EXPLAIN SHAPE PLAN
    ->   SELECT [foj_t1.id](http://foj_t1.id/)
    ->   FROM foj_t1
    ->   FULL OUTER JOIN foj_t2
    ->   ON [foj_t1.id](http://foj_t1.id/) = [foj_t2.id](http://foj_t2.id/)
    ->   LIMIT 3;
+-------------------------------------------------------------------------------------------+
| Explain String(Nereids Planner)                                                           |
+-------------------------------------------------------------------------------------------+
| PhysicalResultSink                                                                        |
| --PhysicalLimit[GLOBAL]                                                                   |
| ----PhysicalLimit[LOCAL]                                                                  |
| ------hashJoin[FULL_OUTER_JOIN] hashCondition=(([foj_t1.id](http://foj_t1.id/) = [foj_t2.id](http://foj_t2.id/))) otherCondition=() |
| --------PhysicalOlapScan[foj_t1]                                                          |
| --------PhysicalOlapScan[foj_t2]                                                          |
+-------------------------------------------------------------------------------------------+
mysql> 
after:
mysql>   EXPLAIN SHAPE PLAN
    ->   SELECT [foj_t1.id](http://foj_t1.id/)
    ->   FROM foj_t1
    ->   FULL OUTER JOIN foj_t2
    ->   ON [foj_t1.id](http://foj_t1.id/) = [foj_t2.id](http://foj_t2.id/)
    ->   LIMIT 3;
+-------------------------------------------------------------------------------------------+
| Explain String(Nereids Planner)                                                           |
+-------------------------------------------------------------------------------------------+
| PhysicalResultSink                                                                        |
| --PhysicalLimit[GLOBAL]                                                                   |
| ----PhysicalLimit[LOCAL]                                                                  |
| ------hashJoin[FULL_OUTER_JOIN] hashCondition=(([foj_t1.id](http://foj_t1.id/) = [foj_t2.id](http://foj_t2.id/))) otherCondition=() |
| --------PhysicalLimit[LOCAL]                                                              |
| ----------PhysicalOlapScan[foj_t1]                                                        |
| --------PhysicalLimit[LOCAL]                                                              |
| ----------PhysicalOlapScan[foj_t2]                                                        |
+-------------------------------------------------------------------------------------------+
8 rows in set (0.01 sec)

Release note

None

Check List (For Author)

  • Test: Unit Test
    • ./run-fe-ut.sh --run org.apache.doris.nereids.rules.rewrite.PushDownLimitTest#testPushLimitThroughFullOuterJoin
    • ./run-fe-ut.sh --run org.apache.doris.nereids.rules.rewrite.PushDownLimitTest
  • Behavior changed: Yes (optimizer now pushes local LIMIT to both sides of full outer joins)
  • Does this need documentation: No

What problem does this PR solve?

Issue Number: close #xxx

Related PR: #xxx

Problem Summary:

Release note

None

Check List (For Author)

  • Test

    • Regression test
    • Unit Test
    • Manual test (add detailed scripts or steps below)
    • No need to test or manual test. Explain why:
      • This is a refactor/code format and no logic has been changed.
      • Previous test can cover this change.
      • No code files have been changed.
      • Other reason
  • Behavior changed:

    • No.
    • Yes.
  • Does this need documentation?

    • No.
    • Yes.

Check List (For Reviewer who merge this PR)

  • Confirm the release note
  • Confirm test cases
  • Confirm document
  • Add branch pick label

### What problem does this PR solve?

Issue Number: None

Related PR: None

Problem Summary: PushDownLimit skipped full outer joins, so LIMIT could not be pushed to either preserved input even though unordered LIMIT can be applied to both sides before the full outer join.

### Release note

None

### Check List (For Author)

- Test: Unit Test
    - ./run-fe-ut.sh --run org.apache.doris.nereids.rules.rewrite.PushDownLimitTest#testPushLimitThroughFullOuterJoin
    - ./run-fe-ut.sh --run org.apache.doris.nereids.rules.rewrite.PushDownLimitTest
- Behavior changed: Yes (optimizer now pushes local LIMIT to both sides of full outer joins)
- Does this need documentation: No
@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?

@CalvinKirs
Copy link
Copy Markdown
Member Author

run buildall

@CalvinKirs CalvinKirs closed this May 18, 2026
@CalvinKirs CalvinKirs deleted the ck_foj branch May 18, 2026 03:09
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.

2 participants