From 0cc166677ecdca9ad3a91134ccee3d7f9f260190 Mon Sep 17 00:00:00 2001 From: minghong Date: Tue, 2 Jan 2024 19:40:35 +0800 Subject: [PATCH] [fix](nereids) partition prunner evaluates "not x=const" on single node range #29164 (#29359) --- .../rules/OneRangePartitionEvaluator.java | 2 +- .../test_multi_range_partition.groovy | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) 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 e6c2d92c8e2f9a..d63dea78e0e3e7 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 @@ -458,7 +458,7 @@ public EvaluateRangeResult visitOr(Or or, EvaluateRangeInput context) { @Override public EvaluateRangeResult visitNot(Not not, EvaluateRangeInput context) { EvaluateRangeResult result = evaluateChildrenThenThis(not, context); - if (result.isRejectNot()) { + if (result.isRejectNot() && !result.result.equals(BooleanLiteral.TRUE)) { Map newRanges = Maps.newHashMap(); for (Map.Entry entry : result.childrenResult.get(0).columnRanges.entrySet()) { Slot slot = entry.getKey(); diff --git a/regression-test/suites/nereids_rules_p0/partition_prune/test_multi_range_partition.groovy b/regression-test/suites/nereids_rules_p0/partition_prune/test_multi_range_partition.groovy index 1e65e73a376af7..d82eaa19eb6b3c 100644 --- a/regression-test/suites/nereids_rules_p0/partition_prune/test_multi_range_partition.groovy +++ b/regression-test/suites/nereids_rules_p0/partition_prune/test_multi_range_partition.groovy @@ -257,4 +257,40 @@ suite("test_multi_range_partition") { sql "select * from pt where not k3 < 5;" contains "partitions=3/3 (p1,p2,p3)" } + + sql "drop table if exists tt" + sql """ + CREATE TABLE `tt` ( + a bigint(20) NULL, + b bigint(20) null + ) ENGINE=OLAP + duplicate KEY(`a`) + COMMENT 'OLAP' + PARTITION BY RANGE(`a`, `b`) + (PARTITION p0 VALUES [("-2147483648", "-9223372036854775808"), ("5", "5")), + PARTITION p1 VALUES [("5", "5"), ("7", "7")), + PARTITION p2 VALUES [("7", "7"), ("2147483647", "2147483647000"))) + DISTRIBUTED BY HASH(`b`) BUCKETS 10 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "is_being_synced" = "false", + "storage_format" = "V2", + "light_schema_change" = "true", + "disable_auto_compaction" = "false", + "enable_single_replica_compaction" = "false" + ); + """ + sql "SET enable_nereids_planner=true" + sql "SET enable_fallback_to_original_planner=false" + sql "insert into tt values (0, 0), (6, 6), (8, 8)" + explain { + sql """SELECT + * + FROM + tt + WHERE + ( NOT ( a IN ( 5 ) ) + AND b BETWEEN 2 AND 13 )""" + contains "partitions=3/3 (p0,p1,p2)" + } }