This is an automated email from the ASF dual-hosted git repository.
morrysnow 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 7b45bc3d8ba [fix](nereids)fix rangeSet intersect in
PartitionPredicateToRange (#46087)
7b45bc3d8ba is described below
commit 7b45bc3d8ba5d6b35840b046e224d1b965040f63
Author: feiniaofeiafei <[email protected]>
AuthorDate: Fri Jan 3 17:41:44 2025 +0800
[fix](nereids)fix rangeSet intersect in PartitionPredicateToRange (#46087)
---
.../rules/PartitionPredicateToRange.java | 16 +++---
.../test_binary_search_prune.groovy | 64 ++++++++++++++++++++++
2 files changed, 73 insertions(+), 7 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/PartitionPredicateToRange.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/PartitionPredicateToRange.java
index 88ecdab607c..4e4fabed47c 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/PartitionPredicateToRange.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/PartitionPredicateToRange.java
@@ -84,13 +84,7 @@ public class PartitionPredicateToRange extends
DefaultExpressionVisitor<RangeSet
intersects = childRanges;
continue;
}
-
- for (Range<MultiColumnBound> childRange : childRanges.asRanges()) {
- intersects = intersects.subRangeSet(childRange);
- if (intersects.isEmpty()) {
- break;
- }
- }
+ intersects = intersection(childRanges, intersects);
if (intersects.isEmpty()) {
break;
}
@@ -264,4 +258,12 @@ public class PartitionPredicateToRange extends
DefaultExpressionVisitor<RangeSet
Range<MultiColumnBound> range = Range.range(lowerBound,
lowerBoundType, upperBound, upperBoundType);
return ImmutableRangeSet.of(range);
}
+
+ public static <T extends Comparable<?>> RangeSet<T>
intersection(RangeSet<T> rangeSet1, RangeSet<T> rangeSet2) {
+ RangeSet<T> result = TreeRangeSet.create();
+ for (Range<T> range : rangeSet1.asRanges()) {
+ result.addAll(rangeSet2.subRangeSet(range));
+ }
+ return result;
+ }
}
diff --git
a/regression-test/suites/nereids_rules_p0/partition_prune/test_binary_search_prune.groovy
b/regression-test/suites/nereids_rules_p0/partition_prune/test_binary_search_prune.groovy
new file mode 100644
index 00000000000..9f4e11498c7
--- /dev/null
+++
b/regression-test/suites/nereids_rules_p0/partition_prune/test_binary_search_prune.groovy
@@ -0,0 +1,64 @@
+// 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_binary_search_prune") {
+
+ sql """create table
table_200_undef_partitions2_keys3_properties4_distributed_by54 (
+ col_date_undef_signed_not_null date not null ,
+ col_bigint_undef_signed_not_null bigint not null ,
+ col_int_undef_signed int null ,
+ col_int_undef_signed_not_null int not null ,
+ col_bigint_undef_signed bigint null ,
+ col_date_undef_signed date null ,
+ col_varchar_10__undef_signed varchar(10) null ,
+ col_varchar_10__undef_signed_not_null varchar(10) not null ,
+ col_varchar_1024__undef_signed varchar(1024) null ,
+ col_varchar_1024__undef_signed_not_null varchar(1024) not null ,
+ pk int
+ ) engine=olap
+ UNIQUE KEY(col_date_undef_signed_not_null,
col_bigint_undef_signed_not_null)
+ PARTITION BY RANGE(col_date_undef_signed_not_null) (
+ PARTITION p0 VALUES LESS THAN ('2023-12-11'),
+ PARTITION p1 VALUES LESS THAN ('2023-12-15'),
+ PARTITION p2 VALUES LESS THAN ('2023-12-16'),
+ PARTITION p3 VALUES LESS THAN ('2023-12-25'),
+ PARTITION p4 VALUES LESS THAN ('2024-01-18'),
+ PARTITION p5 VALUES LESS THAN ('2026-02-18'),
+ PARTITION p6 VALUES LESS THAN ('5024-02-18'),
+ PARTITION p100 VALUES LESS THAN ('9999-12-31')
+ )
+ distributed by hash(col_bigint_undef_signed_not_null) buckets 30
+ properties("enable_unique_key_merge_on_write" = "true", "replication_num"
= "1");"""
+ sql """insert into
table_200_undef_partitions2_keys3_properties4_distributed_by54(pk,col_int_undef_signed,col_int_undef_signed_not_null,col_bigint_undef_signed,col_bigint_undef_signed_not_null,col_date_undef_signed,col_date_undef_signed_not_null,col_varchar_10__undef_signed,col_varchar_10__undef_signed_not_null,col_varchar_1024__undef_signed,col_varchar_1024__undef_signed_not_null)
values
(0,6,7,-7108875255481177315,-3057140074428691447,'2023-12-09','2024-02-18','o','i','y','r'),(1,-
[...]
+ explain {
+ sql """SELECT
+ table1 . col_bigint_undef_signed AS field1
+ FROM
+ table_200_undef_partitions2_keys3_properties4_distributed_by54 AS
table1
+ WHERE
+ NOT ( ( table1 . `col_int_undef_signed_not_null` IN (NULL) )
+ OR table1 . `col_date_undef_signed_not_null` <> '2012-06-10' )
+ OR table1 . `col_date_undef_signed_not_null` IN ('2027-01-09')
+ GROUP BY
+ field1
+ ORDER BY
+ field1
+ LIMIT 10000;"""
+ contains("partitions=2/8 (p0,p6)")
+ }
+
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]