From 651cd5f0491827da65b660bd41e9641186cec920 Mon Sep 17 00:00:00 2001 From: "zhongjian.xzj" Date: Mon, 12 Aug 2024 16:15:48 +0800 Subject: [PATCH] [fix](nereids) fix partitionTopN choosing under multi winexprs --- .../nereids/trees/plans/logical/LogicalWindow.java | 2 +- .../push_down_multi_filter_through_window.groovy | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalWindow.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalWindow.java index 560be6e8420f1c..6cd8389349a007 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalWindow.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalWindow.java @@ -285,8 +285,8 @@ && child(0).child(0) instanceof LogicalPartitionTopN)) { if (curPartitionLimit < chosenRowNumberPartitionLimit) { chosenRowNumberPartitionLimit = curPartitionLimit; chosenWindowFunc = windowFunc; + hasRowNumber = true; } - hasRowNumber = true; } else if (!hasRowNumber) { // if no row_number, choose the one with minimal limit value if (curPartitionLimit < chosenPartitionLimit) { diff --git a/regression-test/suites/nereids_rules_p0/push_down_filter_through_window/push_down_multi_filter_through_window.groovy b/regression-test/suites/nereids_rules_p0/push_down_filter_through_window/push_down_multi_filter_through_window.groovy index 39b70e76f52b3a..d808d30f8ebdfe 100644 --- a/regression-test/suites/nereids_rules_p0/push_down_filter_through_window/push_down_multi_filter_through_window.groovy +++ b/regression-test/suites/nereids_rules_p0/push_down_filter_through_window/push_down_multi_filter_through_window.groovy @@ -62,6 +62,20 @@ suite("push_down_multi_filter_through_window") { contains "partition limit: 10" } + explain { + sql ("select * from (select rank() over(partition by c1 order by c3) as rk, row_number() over(partition by c1, c2 order by c3) as rn from push_down_multi_predicate_through_window_t) t where rk <= 1;") + contains "VPartitionTopN" + contains "functions: rank" + contains "partition limit: 1" + } + + explain { + sql ("select * from (select rank() over(partition by c1 order by c3) as rk, row_number() over(partition by c1, c2 order by c3) as rn from push_down_multi_predicate_through_window_t) t where rn <= 10;") + contains "VPartitionTopN" + contains "functions: row_number" + contains "partition limit: 10" + } + explain { sql ("select * from (select rank() over(partition by c1 order by c3) as rk, rank() over(partition by c1, c2 order by c3) as rn from push_down_multi_predicate_through_window_t) t where rn <= 1 and rk <= 10;") contains "VPartitionTopN"