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

kxiao 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 c997fbea637 [fix](nereids)partition prune should consider <=> operator 
#32965 (#33032)
c997fbea637 is described below

commit c997fbea637d7fda251100bf7bc8c46c80858864
Author: starocean999 <[email protected]>
AuthorDate: Tue Apr 2 10:21:57 2024 +0800

    [fix](nereids)partition prune should consider <=> operator #32965 (#33032)
---
 .../rules/OneRangePartitionEvaluator.java          | 23 +++++++++
 .../partition_prune/test_nullsafe_eq_prune.out     |  4 ++
 .../partition_prune/test_nullsafe_eq_prune.groovy  | 56 ++++++++++++++++++++++
 3 files changed, 83 insertions(+)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/OneRangePartitionEvaluator.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/OneRangePartitionEvaluator.java
index d63dea78e0e..896517eabcc 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/OneRangePartitionEvaluator.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/OneRangePartitionEvaluator.java
@@ -39,6 +39,7 @@ import org.apache.doris.nereids.trees.expressions.IsNull;
 import org.apache.doris.nereids.trees.expressions.LessThan;
 import org.apache.doris.nereids.trees.expressions.LessThanEqual;
 import org.apache.doris.nereids.trees.expressions.Not;
+import org.apache.doris.nereids.trees.expressions.NullSafeEqual;
 import org.apache.doris.nereids.trees.expressions.Or;
 import org.apache.doris.nereids.trees.expressions.Slot;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.Date;
@@ -48,6 +49,7 @@ import 
org.apache.doris.nereids.trees.expressions.literal.NullLiteral;
 import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
 import org.apache.doris.nereids.types.BooleanType;
 import org.apache.doris.nereids.types.DataType;
+import org.apache.doris.nereids.util.ExpressionUtils;
 import org.apache.doris.nereids.util.Utils;
 
 import com.google.common.collect.BoundType;
@@ -386,6 +388,27 @@ public class OneRangePartitionEvaluator
         return result;
     }
 
+    @Override
+    public EvaluateRangeResult visitNullSafeEqual(NullSafeEqual nullSafeEqual, 
EvaluateRangeInput context) {
+        EvaluateRangeResult result = evaluateChildrenThenThis(nullSafeEqual, 
context);
+        if (!(result.result instanceof NullSafeEqual)) {
+            return result;
+        }
+        // "A <=> null" has been convert to "A is null" or false by 
NullSafeEqualToEqual rule
+        // so we don't consider "A <=> null" here
+        if (nullSafeEqual.left() instanceof Slot && nullSafeEqual.right() 
instanceof Literal) {
+            // A <=> literal -> A = literal and A is not null
+            return visit(ExpressionUtils.and(new EqualTo(nullSafeEqual.left(), 
nullSafeEqual.right()),
+                    new Not(new IsNull(nullSafeEqual.left()))), context);
+        } else if (nullSafeEqual.left() instanceof Literal && 
nullSafeEqual.right() instanceof Slot) {
+            // literal <=> A -> literal = A and A is not null
+            return visit(ExpressionUtils.and(new EqualTo(nullSafeEqual.left(), 
nullSafeEqual.right()),
+                    new Not(new IsNull(nullSafeEqual.right()))), context);
+        } else {
+            return result.withRejectNot(false);
+        }
+    }
+
     @Override
     public EvaluateRangeResult visitInPredicate(InPredicate inPredicate, 
EvaluateRangeInput context) {
         EvaluateRangeResult result = evaluateChildrenThenThis(inPredicate, 
context);
diff --git 
a/regression-test/data/nereids_rules_p0/partition_prune/test_nullsafe_eq_prune.out
 
b/regression-test/data/nereids_rules_p0/partition_prune/test_nullsafe_eq_prune.out
new file mode 100644
index 00000000000..20f6445a2b8
--- /dev/null
+++ 
b/regression-test/data/nereids_rules_p0/partition_prune/test_nullsafe_eq_prune.out
@@ -0,0 +1,4 @@
+-- This file is automatically generated. You should know what you did if you 
want to edit this
+-- !select --
+481
+
diff --git 
a/regression-test/suites/nereids_rules_p0/partition_prune/test_nullsafe_eq_prune.groovy
 
b/regression-test/suites/nereids_rules_p0/partition_prune/test_nullsafe_eq_prune.groovy
new file mode 100644
index 00000000000..9c6913e9e36
--- /dev/null
+++ 
b/regression-test/suites/nereids_rules_p0/partition_prune/test_nullsafe_eq_prune.groovy
@@ -0,0 +1,56 @@
+/*
+ * 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("test_nullsafe_eq_prune") {
+    sql "SET enable_nereids_planner=true"
+    sql "SET enable_fallback_to_original_planner=false"
+    sql "DROP TABLE IF EXISTS 
table_500_undef_partitions2_keys3_properties4_distributed_by56;"
+    sql """
+        create table 
table_500_undef_partitions2_keys3_properties4_distributed_by56 (
+                col_int_undef_signed int   ,
+                col_date_undef_signed date   ,
+                pk int,
+                col_int_undef_signed2 int   ,
+                col_date_undef_signed2 date   ,
+                col_varchar_10__undef_signed varchar(10)   ,
+                col_varchar_1024__undef_signed varchar(1024)   
+                ) engine=olap
+                DUPLICATE KEY(col_int_undef_signed, col_date_undef_signed, pk)
+                PARTITION BY             RANGE(col_int_undef_signed, 
col_date_undef_signed) (
+                                PARTITION p0 VALUES LESS THAN ('4', 
'2023-12-11'),
+                                PARTITION p1 VALUES LESS THAN ('6', 
'2023-12-15'),
+                                PARTITION p2 VALUES LESS THAN ('7', 
'2023-12-16'),
+                                PARTITION p3 VALUES LESS THAN ('8', 
'2023-12-25'),
+                                PARTITION p4 VALUES LESS THAN ('8', 
'2024-01-18'),
+                                PARTITION p5 VALUES LESS THAN ('10', 
'2024-02-18'),
+                                PARTITION p6 VALUES LESS THAN ('1147483647', 
'2056-12-31'),
+                                PARTITION p100 VALUES LESS THAN ('2147483647', 
'9999-12-31')
+                            )
+                distributed by hash(pk) buckets 10
+                properties("replication_num" = "1");
+    """
+    sql """
+        insert into 
table_500_undef_partitions2_keys3_properties4_distributed_by56(pk,col_int_undef_signed,col_int_undef_signed2,col_date_undef_signed,col_date_undef_signed2,col_varchar_10__undef_signed,col_varchar_1024__undef_signed)
 values 
(0,3,null,'2024-01-17','2024-01-31','e',null),(1,2,8,'2023-12-16','2023-12-15','e','u'),(2,5,4,'2024-01-31','2025-02-18','a','e'),(3,5,6,'2025-06-18','2026-01-18',null,'y'),(4,1,1,'2024-01-17','2025-02-18','j','g'),(5,1,7,'2024-01-19','2024-02-18','y
 [...]
+        
(219,1,4,'2024-02-18','2026-01-18','l','l'),(220,9,null,'2027-01-16','2023-12-13','y','a'),(221,null,8,'2023-12-13','2024-02-18','k','p'),(222,1,2,'2023-12-19','2026-01-18',null,'p'),(223,null,2,'2023-12-15','2024-01-09','r','z'),(224,9,5,'2025-06-18','2023-12-20','t','t'),(225,0,5,'2023-12-20','2023-12-20','p','t'),(226,4,null,'2025-02-18','2024-01-31','o','w'),(227,6,9,'2023-12-17','2024-02-18',null,'m'),(228,0,5,'2025-02-18','2024-02-18','b','g'),(229,4,8,'2023-12-16','2024-01
 [...]
+        
(453,7,8,'2027-01-16','2025-02-18','q','t'),(454,6,3,'2023-12-17','2025-06-18',null,null),(455,5,8,'2023-12-17','2025-06-18','j','i'),(456,4,3,'2023-12-09','2024-02-18',null,'p'),(457,1,8,'2023-12-17','2027-01-16','n','r'),(458,2,1,'2023-12-09','2023-12-10',null,'b'),(459,5,8,'2024-01-19','2023-12-10','r','j'),(460,3,6,'2024-02-18','2025-02-18','g','g'),(461,2,7,'2026-01-18','2023-12-16',null,'e'),(462,2,1,'2024-02-18','2023-12-16','k',null),(463,9,8,'2023-12-12','2024-01-31','j'
 [...]
+    """
+    qt_select """ SELECT count(*)
+                FROM 
table_500_undef_partitions2_keys3_properties4_distributed_by56 AS table1
+                WHERE NOT (  table1 . `col_date_undef_signed` <=> '2024-01-19' 
) ;"""
+}
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to