You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by st...@apache.org on 2024/03/29 07:24:55 UTC
(doris) branch master updated: [fix](nereids)partition prune should consider <=> operator (#32965)
This is an automated email from the ASF dual-hosted git repository.
starocean999 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new d1095a2d92c [fix](nereids)partition prune should consider <=> operator (#32965)
d1095a2d92c is described below
commit d1095a2d92c0da336be2656813bd530d86473625
Author: starocean999 <40...@users.noreply.github.com>
AuthorDate: Fri Mar 29 15:24:49 2024 +0800
[fix](nereids)partition prune should consider <=> operator (#32965)
---
.../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 deccd6cc1a3..06fea0fb44e 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;
@@ -341,6 +343,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..20b70c86051
--- /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' ) ;"""
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org