morrySnow commented on code in PR #63379:
URL: https://github.com/apache/doris/pull/63379#discussion_r3420390237
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/EliminateOrderByKey.java:
##########
@@ -89,7 +92,23 @@ private static Plan eliminateWindow(LogicalWindow<Plan>
window) {
for (OrderExpression orderExpression : orderExpressions) {
orderKeys.add(orderExpression.getOrderKey());
}
- List<OrderKey> retainExpression = eliminate(dataTrait, orderKeys);
+ // an order key that repeats one of the window's own partition
keys is constant within each
+ // partition, so ordering by it is redundant and can be pruned (in
addition to the data-trait
+ // based elimination below).
+ Set<Expression> partitionKeyConstants =
ImmutableSet.copyOf(windowExpression.getPartitionKeys());
+ List<OrderKey> retainExpression = eliminate(dataTrait, orderKeys,
partitionKeyConstants);
+ // After CheckAndStandardizeWindowFunctionAndFrame every window
has a frame, and a frame requires
+ // a non-empty ORDER BY
(WindowFunctionChecker.checkWindowFrameBeforeFunc); a ROWS frame also
+ // depends on the physical row sequence that ORDER BY defines. So
pruning all order keys away
+ // would leave a framed window without an ORDER BY. Ranking
functions (row_number/rank/dense_rank)
+ // ignore the frame, so emptying their order keys is safe and is
exactly what lets partition topn
+ // drop the redundant partition key. Frame type cannot tell us
this: row_number()/ntile() are
+ // standardized to a default ROWS frame even without a
user-written one. For any non-ranking
+ // window function keep one (redundant) order key.
+ if (!orderKeys.isEmpty() && retainExpression.isEmpty()
+ && !isRankingFunction(windowExpression.getFunction())) {
+ retainExpression = ImmutableList.of(orderKeys.get(0));
+ }
Review Comment:
这个会导致be执行错误或者core吗?
--
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]