seawinde opened a new pull request, #67172:
URL: https://github.com/apache/doris/pull/67172

   ### What problem does this PR solve?
   
   Issue Number: N/A (Jira: DORIS-26137)
   
   Related PR: N/A
   
   Problem Summary: Queries using ORDER BY ... LIMIT can return incorrect 
results after partition compensation rewrites a materialized-view query. The 
compensation path unions the rewritten MV branch with the base-table branch, 
but previously placed the global TopN/Limit inside the branches or dropped it, 
so the final ordering and row bound were not applied globally.
   
   Root cause: The partition compensation path in 
`AbstractMaterializedViewRule` built a raw UNION directly from the rewritten 
and base-table plans without preserving the query's global LogicalTopN or 
GLOBAL LogicalLimit.
   
   Change Summary:
   
   | File | Change Description |
   |------|-------------------|
   | `AbstractMaterializedViewRule.java` | Preserve the query global TopN/Limit 
above the compensation UNION; apply limit plus offset as branch bounds and 
reject incompatible plan shapes or adjusted offsets. |
   | `MvExplorationSuiteTest.java` | Add FE coverage for global TopN, global 
Limit, offsets, nested Projects, and rejected shapes. |
   | `partition_curd_union_rewrite.groovy` | Add a stale-partition MV rewrite 
regression case with ORDER BY ... LIMIT and before/after result comparison. |
   
   ### Release note
   
   Fixed incorrect results for materialized-view transparent rewrites of 
partition-compensated queries with ORDER BY ... LIMIT.
   
   ### Check List (For Author)
   
   - Test
       - [x] Regression test
       - [x] 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:
       - [x] No.
       - [ ] Yes.
   
   - Does this need documentation?
       - [x] No.
       - [ ] Yes.
   
   ### Check List (For Reviewer who merge this PR)
   
   - [ ] Confirm the release note
   - [ ] Confirm test cases
   - [ ] Confirm document
   - [ ] Add branch pick label


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to