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

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


The following commit(s) were added to refs/heads/branch-2.0 by this push:
     new 3befbe20b62 [fix](Nereids) should push project through limit after 
eliminate union node (#39640) (#39761)
3befbe20b62 is described below

commit 3befbe20b62e7eeab49d87645ad0f18e9b4680dd
Author: morrySnow <101034200+morrys...@users.noreply.github.com>
AuthorDate: Thu Aug 22 13:57:10 2024 +0800

    [fix](Nereids) should push project through limit after eliminate union node 
(#39640) (#39761)
    
    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 8c378102811..bf98b8bb61b 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
@@ -98,6 +98,7 @@ import 
org.apache.doris.nereids.rules.rewrite.PushdownFilterThroughAggregation;
 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.PushdownProjectThroughLimit;
 import org.apache.doris.nereids.rules.rewrite.PushdownTopNThroughJoin;
 import org.apache.doris.nereids.rules.rewrite.PushdownTopNThroughWindow;
 import org.apache.doris.nereids.rules.rewrite.ReorderJoin;
@@ -362,7 +363,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())
             ),
             // this rule batch must keep at the end of rewrite to do some plan 
check
             topic("Final rewrite and check",
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