-
Notifications
You must be signed in to change notification settings - Fork 3.7k
branch-4.0: [fix](mtmv) Fix mv rewrite failed when mv is rewritten by LimitAggToTopNAgg but query is not #58974 #59061
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
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
…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
Contributor
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
Contributor
|
run buildall |
Contributor
FE UT Coverage ReportIncrement line coverage |
yiguolei
approved these changes
Dec 17, 2025
Contributor
Author
|
PR approved by at least one committer and no changes requested. |
Contributor
Author
|
PR approved by anyone and no changes requested. |
zddr
approved these changes
Dec 18, 2025
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.
Cherry-picked from #58974