This is an automated email from the ASF dual-hosted git repository.

yiguolei pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-2.1 by this push:
     new 6c2107788c5 [fix](nereids) support one phase DeferMaterializeTopN 
#45693-branch-2.1 (#45845)
6c2107788c5 is described below

commit 6c2107788c501cc13687f086038f6c211ba94917
Author: minghong <zhoumingh...@selectdb.com>
AuthorDate: Wed Dec 25 12:00:58 2024 +0800

    [fix](nereids) support one phase DeferMaterializeTopN #45693-branch-2.1 
(#45845)
---
 ...erializeTopNToPhysicalDeferMaterializeTopN.java |  9 +++-
 .../defer_materialize_topn/one_phase.out           |  7 +++
 .../cte/test_cte_name_reuse.groovy                 |  2 +-
 .../defer_materialize_topn/one_phase.groovy        | 50 ++++++++++++++++++++++
 4 files changed, 65 insertions(+), 3 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/implementation/LogicalDeferMaterializeTopNToPhysicalDeferMaterializeTopN.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/implementation/LogicalDeferMaterializeTopNToPhysicalDeferMaterializeTopN.java
index 9ad6b73d1c8..2799ca30147 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/implementation/LogicalDeferMaterializeTopNToPhysicalDeferMaterializeTopN.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/implementation/LogicalDeferMaterializeTopNToPhysicalDeferMaterializeTopN.java
@@ -20,6 +20,7 @@ package org.apache.doris.nereids.rules.implementation;
 import org.apache.doris.nereids.rules.Rule;
 import org.apache.doris.nereids.rules.RuleType;
 import org.apache.doris.nereids.trees.plans.Plan;
+import org.apache.doris.nereids.trees.plans.SortPhase;
 import 
org.apache.doris.nereids.trees.plans.logical.LogicalDeferMaterializeTopN;
 import 
org.apache.doris.nereids.trees.plans.physical.PhysicalDeferMaterializeTopN;
 import org.apache.doris.nereids.trees.plans.physical.PhysicalTopN;
@@ -38,8 +39,12 @@ public class 
LogicalDeferMaterializeTopNToPhysicalDeferMaterializeTopN extends O
                     .build()
                     .transform(topN.getLogicalTopN(), ctx.cascadesContext)
                     .get(0);
-            return wrap(physicalTopN, topN, wrap((PhysicalTopN<? extends 
Plan>) physicalTopN.child(), topN,
-                    ((PhysicalTopN<?>) physicalTopN.child()).child()));
+            if (physicalTopN.getSortPhase() == SortPhase.MERGE_SORT) {
+                return wrap(physicalTopN, topN, wrap((PhysicalTopN<? extends 
Plan>) physicalTopN.child(), topN,
+                        ((PhysicalTopN<?>) physicalTopN.child()).child()));
+            } else {
+                return wrap(physicalTopN, topN, physicalTopN.child());
+            }
 
         
}).toRule(RuleType.LOGICAL_DEFER_MATERIALIZE_TOP_N_TO_PHYSICAL_DEFER_MATERIALIZE_TOP_N_RULE);
     }
diff --git 
a/regression-test/data/nereids_rules_p0/defer_materialize_topn/one_phase.out 
b/regression-test/data/nereids_rules_p0/defer_materialize_topn/one_phase.out
new file mode 100644
index 00000000000..cb3f8c9b7cc
--- /dev/null
+++ b/regression-test/data/nereids_rules_p0/defer_materialize_topn/one_phase.out
@@ -0,0 +1,7 @@
+-- This file is automatically generated. You should know what you did if you 
want to edit this
+-- !1 --
+11113
+
+-- !2 --
+11113
+
diff --git 
a/regression-test/suites/nereids_rules_p0/cte/test_cte_name_reuse.groovy 
b/regression-test/suites/nereids_rules_p0/cte/test_cte_name_reuse.groovy
index 5d472716f00..0f943db5b31 100644
--- a/regression-test/suites/nereids_rules_p0/cte/test_cte_name_reuse.groovy
+++ b/regression-test/suites/nereids_rules_p0/cte/test_cte_name_reuse.groovy
@@ -14,7 +14,7 @@
 // KIND, either express or implied.  See the License for the
 // specific language governing permissions and limitations
 // under the License.
-suite("test_cte_name_reuse)") {
+suite("test_cte_name_reuse") {
     sql "SET enable_nereids_planner=true"
     sql "SET enable_pipeline_engine=true"
     sql "SET enable_fallback_to_original_planner=false"
diff --git 
a/regression-test/suites/nereids_rules_p0/defer_materialize_topn/one_phase.groovy
 
b/regression-test/suites/nereids_rules_p0/defer_materialize_topn/one_phase.groovy
new file mode 100644
index 00000000000..c7b106eff2a
--- /dev/null
+++ 
b/regression-test/suites/nereids_rules_p0/defer_materialize_topn/one_phase.groovy
@@ -0,0 +1,50 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+suite("one_phase") {
+    sql """
+    drop table if exists users;
+    
+    CREATE TABLE `users` (
+        `UserID` bigint NULL
+    ) ENGINE=OLAP
+    DUPLICATE KEY(`UserID`)
+    DISTRIBUTED BY HASH(`UserID`) BUCKETS 48
+    PROPERTIES (
+    "replication_allocation" = "tag.location.default: 1",
+    "min_load_replica_num" = "-1",
+    "is_being_synced" = "false",
+    "storage_medium" = "hdd",
+    "storage_format" = "V2",
+    "inverted_index_storage_format" = "V2",
+    "light_schema_change" = "true",
+    "disable_auto_compaction" = "false",
+    "enable_single_replica_compaction" = "false",
+    "group_commit_interval_ms" = "10000",
+    "group_commit_data_bytes" = "134217728"
+    ); 
+    
+    insert into users values (11111),(11112),(11113);
+ 
+    """
+    
+    sql "set sort_phase_num=1;"
+    qt_1 "select userid from users order by userid limit 2, 109000000;"
+
+    sql "set sort_phase_num=2;"
+    qt_2 "select userid from users order by userid limit 2, 109000000;"
+
+}
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to