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

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


The following commit(s) were added to refs/heads/branch-3.0 by this push:
     new 936d21fc1b0 branch-3.0: [fix](nereids) fix join condition with 
AddMinMax rule hung #47772 (#47807)
936d21fc1b0 is described below

commit 936d21fc1b066c81d65485df0d26b0bafee38ff3
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Sat Feb 22 14:20:11 2025 +0800

    branch-3.0: [fix](nereids) fix join condition with AddMinMax rule hung 
#47772 (#47807)
    
    Cherry-picked from #47772
    
    Co-authored-by: 924060929 <lanhuaj...@selectdb.com>
---
 .../rules/expression/ExpressionRewrite.java        |  13 +++-
 .../data/nereids_syntax_p0/join_condition.out      | Bin 0 -> 31842 bytes
 .../suites/nereids_syntax_p0/join_condition.groovy |  67 +++++++++++++++++++++
 3 files changed, 78 insertions(+), 2 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/ExpressionRewrite.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/ExpressionRewrite.java
index 277f1e6f2d8..e69f93bf845 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/ExpressionRewrite.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/ExpressionRewrite.java
@@ -40,6 +40,7 @@ import 
org.apache.doris.nereids.trees.plans.logical.LogicalProject;
 import org.apache.doris.nereids.trees.plans.logical.LogicalRepeat;
 import org.apache.doris.nereids.trees.plans.logical.LogicalSort;
 import org.apache.doris.nereids.util.ExpressionUtils;
+import org.apache.doris.nereids.util.Utils;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
@@ -204,7 +205,14 @@ public class ExpressionRewrite implements 
RewriteRuleFactory {
         private Pair<Boolean, List<Expression>> 
rewriteConjuncts(List<Expression> conjuncts,
                 ExpressionRewriteContext context) {
             boolean isChanged = false;
-            ImmutableList.Builder<Expression> rewrittenConjuncts = new 
ImmutableList.Builder<>();
+            // some rules will append new conjunct, we need to distinct it
+            // for example:
+            //   pk = 2 or pk < 0
+            // after AddMinMax rule:
+            //   (pk = 2 or pk < 0) and pk <= 2
+            //
+            // if not distinct it, the pk <= 2 will generate repeat forever
+            ImmutableSet.Builder<Expression> rewrittenConjuncts = new 
ImmutableSet.Builder<>();
             for (Expression expr : conjuncts) {
                 Expression newExpr = rewriter.rewrite(expr, context);
                 newExpr = newExpr.isNullLiteral() && expr instanceof 
EqualPredicate
@@ -214,7 +222,8 @@ public class ExpressionRewrite implements 
RewriteRuleFactory {
                 isChanged = isChanged || !newExpr.equals(expr);
                 
rewrittenConjuncts.addAll(ExpressionUtils.extractConjunction(newExpr));
             }
-            return Pair.of(isChanged, rewrittenConjuncts.build());
+            ImmutableList<Expression> newConjuncts = 
Utils.fastToImmutableList(rewrittenConjuncts.build());
+            return Pair.of(isChanged && !newConjuncts.equals(conjuncts), 
newConjuncts);
         }
     }
 
diff --git a/regression-test/data/nereids_syntax_p0/join_condition.out 
b/regression-test/data/nereids_syntax_p0/join_condition.out
new file mode 100644
index 00000000000..c0d89f66c4f
Binary files /dev/null and 
b/regression-test/data/nereids_syntax_p0/join_condition.out differ
diff --git a/regression-test/suites/nereids_syntax_p0/join_condition.groovy 
b/regression-test/suites/nereids_syntax_p0/join_condition.groovy
new file mode 100644
index 00000000000..5a8d20d820a
--- /dev/null
+++ b/regression-test/suites/nereids_syntax_p0/join_condition.groovy
@@ -0,0 +1,67 @@
+// 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("join_condition") {
+    multi_sql """
+        drop table if exists 
table_9_undef_partitions2_keys3_properties4_distributed_by5;
+        create table 
table_9_undef_partitions2_keys3_properties4_distributed_by5 (
+        col_int_undef_signed int/*agg_type_placeholder*/   ,
+        col_varchar_10__undef_signed varchar(10)/*agg_type_placeholder*/   ,
+        pk int/*agg_type_placeholder*/
+        ) engine=olap
+        distributed by hash(pk) buckets 10
+        properties("replication_num" = "1");
+        insert into 
table_9_undef_partitions2_keys3_properties4_distributed_by5(pk,col_int_undef_signed,col_varchar_10__undef_signed)
 values 
(0,0,null),(1,6,null),(2,9,null),(3,2,''),(4,null,'here'),(5,null,'i'),(6,null,'now'),(7,5,'c'),(8,null,'t');
+
+        drop table if exists 
table_100_undef_partitions2_keys3_properties4_distributed_by5;
+        create table 
table_100_undef_partitions2_keys3_properties4_distributed_by5 (
+        col_int_undef_signed int/*agg_type_placeholder*/   ,
+        col_varchar_10__undef_signed varchar(10)/*agg_type_placeholder*/   ,
+        pk int/*agg_type_placeholder*/
+        ) engine=olap
+        distributed by hash(pk) buckets 10
+        properties("replication_num" = "1");
+        insert into 
table_100_undef_partitions2_keys3_properties4_distributed_by5(pk,col_int_undef_signed,col_varchar_10__undef_signed)
 values 
(0,null,''),(1,null,''),(2,null,''),(3,0,null),(4,7,null),(5,9,'d'),(6,9,null),(7,null,null),(8,null,null),(9,null,''),(10,null,'are'),(11,null,'were'),(12,2,''),(13,null,'one'),(14,null,'ok'),(15,null,'your'),(16,null,''),(17,null,null),(18,4,''),(19,null,null),(20,null,null),(21,null,null),(22,3,''),(23,null,null),(24,8,''),(25,2,'I''m'),(26,nul
 [...]
+
+        drop table if exists 
table_20_undef_partitions2_keys3_properties4_distributed_by5;
+        create table 
table_20_undef_partitions2_keys3_properties4_distributed_by5 (
+        col_int_undef_signed int/*agg_type_placeholder*/   ,
+        col_varchar_10__undef_signed varchar(10)/*agg_type_placeholder*/   ,
+        pk int/*agg_type_placeholder*/
+        ) engine=olap
+        distributed by hash(pk) buckets 10
+        properties("replication_num" = "1");
+        insert into 
table_20_undef_partitions2_keys3_properties4_distributed_by5(pk,col_int_undef_signed,col_varchar_10__undef_signed)
 values 
(0,null,'my'),(1,null,'a'),(2,5,''),(3,0,'that'),(4,0,'want'),(5,null,'g'),(6,null,null),(7,null,''),(8,null,null),(9,3,'b'),(10,null,'her'),(11,6,''),(12,null,'k'),(13,null,'then'),(14,2,null),(15,null,''),(16,null,'g'),(17,null,'x'),(18,null,'d'),(19,null,null);
+
+        drop table if exists 
table_8_undef_partitions2_keys3_properties4_distributed_by5;
+        create table 
table_8_undef_partitions2_keys3_properties4_distributed_by5 (
+        col_int_undef_signed int/*agg_type_placeholder*/   ,
+        col_varchar_10__undef_signed varchar(10)/*agg_type_placeholder*/   ,
+        pk int/*agg_type_placeholder*/
+        ) engine=olap
+        distributed by hash(pk) buckets 10
+        properties("replication_num" = "1");
+        insert into 
table_8_undef_partitions2_keys3_properties4_distributed_by5(pk,col_int_undef_signed,col_varchar_10__undef_signed)
 values 
(0,3,'s'),(1,8,''),(2,null,null),(3,7,'k'),(4,null,'x'),(5,null,''),(6,null,'will'),(7,null,'so');
+        """
+
+    order_qt_join_with_add_min_max_rule """SELECT *  FROM 
table_9_undef_partitions2_keys3_properties4_distributed_by5 AS t1
+            LEFT ANTI JOIN 
table_100_undef_partitions2_keys3_properties4_distributed_by5 AS t2 ON t2 . 
`pk` = 2 OR t2 . `pk` < 0
+            RIGHT ANTI JOIN 
table_9_undef_partitions2_keys3_properties4_distributed_by5 AS alias1 ON alias1 
. `pk` >= 3
+            CROSS JOIN 
table_20_undef_partitions2_keys3_properties4_distributed_by5 AS alias2
+            INNER JOIN 
table_8_undef_partitions2_keys3_properties4_distributed_by5 AS alias3 ;
+            """
+}
\ 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