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

morrysnow 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 83acdc14f47 [fix](Nereids) should push project through limit after 
eliminate union node (#39640) (#39755)
83acdc14f47 is described below

commit 83acdc14f47a63c2bf7934f7859be75d79030d8b
Author: morrySnow <101034200+morrys...@users.noreply.github.com>
AuthorDate: Thu Aug 22 13:57:39 2024 +0800

    [fix](Nereids) should push project through limit after eliminate union node 
(#39640) (#39755)
    
    pick from master #39640
    
    otherwise:
    
    push limit through union could generate plan:
    
    limit
    +-- union
        |-- limit
        |   +-- empty relation
        +-- limit
            +-- project
    
    and then eliminate union will generate plan:
    
    +-- limit
        +-  project
            +-- limit
                +-- project
    
    it could not be processed by tranlator correctly
---
 .../doris/nereids/jobs/executor/Rewriter.java       | 13 ++++++++++++-
 .../union/push_limit_with_eliminate_union.groovy    | 21 +++++++++++++++++++++
 2 files changed, 33 insertions(+), 1 deletion(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/executor/Rewriter.java 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/executor/Rewriter.java
index 9df26fce31f..413a410ac59 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/executor/Rewriter.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/executor/Rewriter.java
@@ -114,6 +114,7 @@ import 
org.apache.doris.nereids.rules.rewrite.PushDownFilterThroughProject;
 import org.apache.doris.nereids.rules.rewrite.PushDownLimit;
 import org.apache.doris.nereids.rules.rewrite.PushDownLimitDistinctThroughJoin;
 import 
org.apache.doris.nereids.rules.rewrite.PushDownLimitDistinctThroughUnion;
+import org.apache.doris.nereids.rules.rewrite.PushDownProjectThroughLimit;
 import org.apache.doris.nereids.rules.rewrite.PushDownTopNDistinctThroughJoin;
 import org.apache.doris.nereids.rules.rewrite.PushDownTopNDistinctThroughUnion;
 import org.apache.doris.nereids.rules.rewrite.PushDownTopNThroughJoin;
@@ -416,7 +417,17 @@ public class Rewriter extends AbstractBatchJobExecutor {
                 topic("eliminate",
                         // SORT_PRUNING should be applied after mergeLimit
                         custom(RuleType.ELIMINATE_SORT, EliminateSort::new),
-                        bottomUp(new EliminateEmptyRelation())
+                        bottomUp(
+                                new EliminateEmptyRelation(),
+                                // after eliminate empty relation under union, 
we could get
+                                // limit
+                                // +-- project
+                                //     +-- limit
+                                //         + project
+                                // so, we need push project through limit to 
satisfy translator's assumptions
+                                new PushDownFilterThroughProject(),
+                                new PushDownProjectThroughLimit(),
+                                new MergeProjects())
                 ),
                 topic("agg rewrite",
                     // these rules should be put after mv optimization to 
avoid mv matching fail
diff --git 
a/regression-test/suites/nereids_p0/union/push_limit_with_eliminate_union.groovy
 
b/regression-test/suites/nereids_p0/union/push_limit_with_eliminate_union.groovy
new file mode 100644
index 00000000000..1c9604a5ad6
--- /dev/null
+++ 
b/regression-test/suites/nereids_p0/union/push_limit_with_eliminate_union.groovy
@@ -0,0 +1,21 @@
+// 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("push_limit_with_eliminate_union") {
+    // this should not failed for [INTERNAL_ERROR]VSlotRef  have invalid slot 
id
+    sql """(select 1 limit 0 union all select count() + 1) limit 1;"""
+}


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

Reply via email to