-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
[opt](nereids) support partitionTopn for multi window exprs #38393
Conversation
Thank you for your contribution to Apache Doris. Since 2024-03-18, the Document has been moved to doris-website. |
run buildall |
1 similar comment
run buildall |
7e65c5a
to
29f6a0b
Compare
run buildall |
29f6a0b
to
04ff675
Compare
run buildall |
TPC-H: Total hot run time: 39375 ms
|
TPC-DS: Total hot run time: 172696 ms
|
ClickBench: Total hot run time: 30.74 s
|
run buildall |
TPC-H: Total hot run time: 39737 ms
|
TPC-DS: Total hot run time: 172790 ms
|
ClickBench: Total hot run time: 31.38 s
|
run buildall |
TPC-H: Total hot run time: 39385 ms
|
TPC-DS: Total hot run time: 173456 ms
|
ClickBench: Total hot run time: 30.41 s
|
...core/src/main/java/org/apache/doris/nereids/rules/rewrite/CreatePartitionTopNFromWindow.java
Outdated
Show resolved
Hide resolved
please add a sql example in "Proposed changes" section |
Done |
PR approved by at least one committer and no changes requested. |
PR approved by anyone and no changes requested. |
* pushPartitionLimitThroughWindow is used to push the partitionLimit through the window | ||
* and generate the partitionTopN. If the window can not meet the requirement, | ||
* it will return null. So when we use this function, we need check the null in the outside. | ||
* check and get valid window function and partition limit value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add comment to explain the input parameter and return value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
long chosenRowNumberPartitionLimit = Long.MAX_VALUE; | ||
boolean hasRowNumber = false; | ||
for (NamedExpression windowExpr : windowExpressions) { | ||
WindowExpression windowFunc = (WindowExpression) windowExpr.child(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check before cast?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Set<Expression> conjuncts = filter.getConjuncts(); | ||
Set<Expression> relatedConjuncts = extractRelatedConjuncts(conjuncts, windowExpr.getExprId()); | ||
for (Expression conjunct : relatedConjuncts) { | ||
Preconditions.checkArgument(conjunct instanceof BinaryOperator); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add error msg? log warning log and return null instead throw exception?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove the pre-condition checking since the former logic has been done.
Preconditions.checkArgument(leftChild instanceof SlotReference | ||
&& rightChild instanceof IntegerLikeLiteral); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add error msg? log warning log and return null instead throw exception?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove the pre-condition checking since the former logic has been done.
d053abc
to
95c8ad6
Compare
run buildall |
TPC-H: Total hot run time: 41944 ms
|
TPC-DS: Total hot run time: 168646 ms
|
ClickBench: Total hot run time: 30.61 s
|
PR approved by at least one committer and no changes requested. |
Support partitionTopn for multi window exprs. If row_number exists, choose row_number with the minimal limit value; if not, choose others with the minimal limit value. Example: ``` mysql> explain shape plan select * from (select row_number() over(partition by c1, c2 order by c3) as rn, rank() over(partition by c1 order by c3) as rk from push_down_multi_predicate_through_window_t) t where rn <= 1 and rk <= 1; +----------------------------------------------------------------------------------+ | Explain String(Nereids Planner) | +----------------------------------------------------------------------------------+ | PhysicalResultSink | | --PhysicalProject | | ----filter((rk <= 1) and (rn <= 1)) | | ------PhysicalWindow | | --------PhysicalQuickSort[LOCAL_SORT] | | ----------PhysicalDistribute[DistributionSpecHash] | | ------------PhysicalWindow | | --------------PhysicalQuickSort[LOCAL_SORT] | | ----------------PhysicalDistribute[DistributionSpecHash] | | ------------------PhysicalPartitionTopN | | --------------------PhysicalOlapScan[push_down_multi_predicate_through_window_t] | +----------------------------------------------------------------------------------+ ``` --------- Co-authored-by: zhongjian.xzj <zhongjian.xzj@zhongjianxzjdeMacBook-Pro.local>
intro by #38393 Fix the cases whose window function both contains row_number and other types but only the other types contains pushing down filter.
…e#39233) intro by apache#38393 Fix the cases whose window function both contains row_number and other types but only the other types contains pushing down filter.
Support partitionTopn for multi window exprs. If row_number exists, choose row_number with the minimal limit value; if not, choose others with the minimal limit value. Example: ``` mysql> explain shape plan select * from (select row_number() over(partition by c1, c2 order by c3) as rn, rank() over(partition by c1 order by c3) as rk from push_down_multi_predicate_through_window_t) t where rn <= 1 and rk <= 1; +----------------------------------------------------------------------------------+ | Explain String(Nereids Planner) | +----------------------------------------------------------------------------------+ | PhysicalResultSink | | --PhysicalProject | | ----filter((rk <= 1) and (rn <= 1)) | | ------PhysicalWindow | | --------PhysicalQuickSort[LOCAL_SORT] | | ----------PhysicalDistribute[DistributionSpecHash] | | ------------PhysicalWindow | | --------------PhysicalQuickSort[LOCAL_SORT] | | ----------------PhysicalDistribute[DistributionSpecHash] | | ------------------PhysicalPartitionTopN | | --------------------PhysicalOlapScan[push_down_multi_predicate_through_window_t] | +----------------------------------------------------------------------------------+ ``` --------- Co-authored-by: zhongjian.xzj <zhongjian.xzj@zhongjianxzjdeMacBook-Pro.local>
intro by #38393 Fix the cases whose window function both contains row_number and other types but only the other types contains pushing down filter.
## Proposed changes pick from #38393 Co-authored-by: xiongzhongjian <xiongzhongjian@selectdb.com>
Support partitionTopn for multi window exprs.
If row_number exists, choose row_number with the minimal limit value; if not, choose others with the minimal limit value.
Example: