morrySnow commented on code in PR #63379:
URL: https://github.com/apache/doris/pull/63379#discussion_r3379396278
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalWindow.java:
##########
@@ -349,9 +350,18 @@ && child(0).child(0) instanceof LogicalPartitionTopN)) {
*/
public Plan pushPartitionLimitThroughWindow(WindowExpression windowFunc,
long partitionLimit, boolean hasGlobalLimit) {
- LogicalWindow<?> window = (LogicalWindow<?>) withChildren(new
LogicalPartitionTopN<>(windowFunc, hasGlobalLimit,
- partitionLimit, child(0)));
- return window;
+ // Prune order keys that repeat a partition key from the generated
PartitionTopN: they are constant within
+ // each partition, so BE does not need to sort by them. The window
above is pruned independently by the
+ // EliminateOrderByKey rule (which also benefits windows that never
become a PartitionTopN); doing the
+ // PartitionTopN side here makes it robust to rewrite ordering (the
topn may be created before the window
+ // is pruned), and both ends up consistent on the partition-key
dimension.
+ List<OrderExpression> orderKeys = windowFunc.getOrderKeys().stream()
+ .filter(orderKey ->
!windowFunc.getPartitionKeys().contains(orderKey.getOrderKey().getExpr()))
+ .collect(ImmutableList.toImmutableList());
+ LogicalPartitionTopN<Plan> partitionTopN = new
LogicalPartitionTopN<>(windowFunc.getFunction(),
+ windowFunc.getPartitionKeys(), orderKeys, hasGlobalLimit,
partitionLimit,
+ Optional.empty(), Optional.empty(), child(0));
Review Comment:
if we have prune order key in `EliminateOrderKey`, do we still need to do
same thing here?
--
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]