[fix](mtmv) Fix mv rewrite failed when mv is rewritten by LimitAggToTopNAgg but query is not#58974
Merged
starocean999 merged 3 commits intoapache:masterfrom Dec 16, 2025
Conversation
…opNAgg but query is not
Contributor
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
Member
Author
|
run buildall |
TPC-H: Total hot run time: 35773 ms |
TPC-DS: Total hot run time: 180941 ms |
ClickBench: Total hot run time: 27.47 s |
Contributor
FE Regression Coverage ReportIncrement line coverage |
1 similar comment
Contributor
FE Regression Coverage ReportIncrement line coverage |
Member
Author
|
run buildall |
TPC-H: Total hot run time: 35125 ms |
TPC-DS: Total hot run time: 179247 ms |
ClickBench: Total hot run time: 27.48 s |
Contributor
FE UT Coverage ReportIncrement line coverage |
Member
Author
|
run buildall |
TPC-H: Total hot run time: 36039 ms |
TPC-DS: Total hot run time: 177746 ms |
ClickBench: Total hot run time: 27.59 s |
morrySnow
approved these changes
Dec 12, 2025
Contributor
|
PR approved by at least one committer and no changes requested. |
Contributor
|
PR approved by anyone and no changes requested. |
Contributor
FE Regression Coverage ReportIncrement line coverage |
1 similar comment
Contributor
FE Regression Coverage ReportIncrement line coverage |
englefly
approved these changes
Dec 15, 2025
github-actions Bot
pushed a commit
that referenced
this pull request
Dec 16, 2025
…opNAgg but query is not (#58974) Fix mv rewrite failed when mv is rewritten by LimitAggToTopNAgg but query is not such as query and mv def sql is as fllowing: ```sql SELECT c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice, sum(l_quantity) FROM customer, orders, lineitem WHERE o_orderkey IN ( SELECT l_orderkey FROM lineitem GROUP BY l_orderkey HAVING sum(l_quantity) > 300 ) AND c_custkey = o_custkey AND o_orderkey = l_orderkey GROUP BY c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice ORDER BY o_totalprice DESC, o_orderdate LIMIT 100 ``` if query plan is rewrtten by rule `LimitAggToTopNAgg`, plan would be like as following, tonN contains all goup by key ```sql LogicalResultSink[812] ( outputExprs=[c_name#1, c_custkey#0, o_orderkey#8, o_orderdate#12, o_totalprice#11, __sum_5#50] ) **| +--LogicalTopN ( limit=100, offset=0, orderKeys=[o_totalprice#11 desc, o_orderdate#12 asc null first, c_name#1 asc, c_custkey#0 asc, o_orderkey#8 asc] )** ``` if mv plan is not rewrtten by rule `LimitAggToTopNAgg`, plan would be like as following, tonN not contain all goup by key ```sql LogicalResultSink[801] ( outputExprs=[c_name#1, c_custkey#0, o_orderkey#8, o_orderdate#12, o_totalprice#11, __sum_5#50] ) **+--LogicalTopN ( limit=100, offset=0, orderKeys=[o_totalprice#11 desc, o_orderdate#12 asc null first] )** ``` this would cause `doris/regression-test/suites/nereids_rules_p0/mv/tpch/mv_tpch_test.groovy` mv18 rewrite fail, the pr fix this
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What problem does this PR solve?
Fix mv rewrite failed when mv is rewritten by LimitAggToTopNAgg but query is not
such as query and mv def sql is as fllowing:
if query plan is rewrtten by rule
LimitAggToTopNAgg, plan would be like as following, tonN contains all goup by keyif mv plan is not rewrtten by rule
LimitAggToTopNAgg, plan would be like as following, tonN not contain all goup by keythis would cause
doris/regression-test/suites/nereids_rules_p0/mv/tpch/mv_tpch_test.groovymv18 rewrite fail, the pr fix thisIssue Number: close #xxx
Related PR: #xxx
Problem Summary:
Release note
None
Check List (For Author)
Test
Behavior changed:
Does this need documentation?
Check List (For Reviewer who merge this PR)