github-actions[bot] commented on code in PR #63379:
URL: https://github.com/apache/doris/pull/63379#discussion_r3412307152
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/EliminateOrderByKey.java:
##########
@@ -89,7 +89,11 @@ 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());
Review Comment:
This pruning can make `CreatePartitionTopNFromWindow` apply to a
`LogicalWindow` that still has another window expression with a different
partition key. `LogicalWindow#getPushDownWindowFuncAndLimit` only checks that
every window's order keys are empty or equal to the chosen window's order keys;
it does not check partition keys. After this rule, a query such as:
```sql
SELECT a, b, c, rn2
FROM (
SELECT a, b, c,
row_number() OVER (PARTITION BY a ORDER BY a, b) AS rn1,
row_number() OVER (PARTITION BY c ORDER BY b) AS rn2
FROM t
) s
WHERE rn1 <= 1;
```
changes from incompatible order lists (`[a,b]` vs `[b]`) to compatible order
lists (`[b]` vs `[b]`), so PartitionTopN is pushed below the whole window by
partition `a`. That removes rows before `rn2` over partition `c` is evaluated;
for example, with `(1,100,1),(1,101,1),(2,200,1),(2,201,1)`, the kept row
`(2,200,1)` should have `rn2 = 3` before the `rn1` filter, but after the
pushdown it is computed over only the top rows per `a` and becomes `2`.
Please make the PartitionTopN compatibility check require the same
partition-key set as the chosen window, matching
`LogicalWindowToPhysicalWindow` grouping semantics, before relying on the
pruned order keys, and add a test for this case.
--
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]