This is an automated email from the ASF dual-hosted git repository.
englefly 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 06343e6d686 [opt](nereids)replace scan by empty relation when all
partitions are pruned (#26514)
06343e6d686 is described below
commit 06343e6d68618e0c7e29d76ed8c12fc28a92f417
Author: minghong <[email protected]>
AuthorDate: Wed Nov 8 20:54:35 2023 +0800
[opt](nereids)replace scan by empty relation when all partitions are pruned
(#26514)
* replace scan by empty relation when all partitions are pruned
---
.../rules/rewrite/PruneOlapScanPartition.java | 7 +++++
.../data/empty_relation/eliminate_empty.out | 10 ++++++
.../suites/empty_relation/eliminate_empty.groovy | 36 ++++++++++++++++++++++
3 files changed, 53 insertions(+)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PruneOlapScanPartition.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PruneOlapScanPartition.java
index 1bdff7f6c10..db183d66389 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PruneOlapScanPartition.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PruneOlapScanPartition.java
@@ -24,9 +24,11 @@ import org.apache.doris.nereids.rules.RuleType;
import org.apache.doris.nereids.rules.expression.rules.PartitionPruner;
import
org.apache.doris.nereids.rules.expression.rules.PartitionPruner.PartitionTableType;
import org.apache.doris.nereids.trees.expressions.Slot;
+import org.apache.doris.nereids.trees.plans.logical.LogicalEmptyRelation;
import org.apache.doris.nereids.trees.plans.logical.LogicalFilter;
import org.apache.doris.nereids.trees.plans.logical.LogicalOlapScan;
import org.apache.doris.nereids.util.Utils;
+import org.apache.doris.qe.ConnectContext;
import com.google.common.collect.ImmutableList;
import org.apache.commons.collections.CollectionUtils;
@@ -73,6 +75,11 @@ public class PruneOlapScanPartition extends
OneRewriteRuleFactory {
if (!CollectionUtils.isEmpty(manuallySpecifiedPartitions)) {
prunedPartitions.retainAll(manuallySpecifiedPartitions);
}
+ if (prunedPartitions.isEmpty()) {
+ return new LogicalEmptyRelation(
+
ConnectContext.get().getStatementContext().getNextRelationId(),
+ filter.getOutput());
+ }
LogicalOlapScan rewrittenScan =
scan.withSelectedPartitionIds(ImmutableList.copyOf(prunedPartitions));
return new LogicalFilter<>(filter.getConjuncts(), rewrittenScan);
}).toRule(RuleType.OLAP_SCAN_PARTITION_PRUNE);
diff --git a/regression-test/data/empty_relation/eliminate_empty.out
b/regression-test/data/empty_relation/eliminate_empty.out
index e864cd46e3f..0bcc266b1c2 100644
--- a/regression-test/data/empty_relation/eliminate_empty.out
+++ b/regression-test/data/empty_relation/eliminate_empty.out
@@ -70,3 +70,13 @@ PhysicalResultSink
-- !except_empty_data --
+-- !prune_partition1 --
+PhysicalResultSink
+--PhysicalProject
+----PhysicalEmptyRelation
+
+-- !prune_partition2 --
+PhysicalResultSink
+--PhysicalProject
+----PhysicalEmptyRelation
+
diff --git a/regression-test/suites/empty_relation/eliminate_empty.groovy
b/regression-test/suites/empty_relation/eliminate_empty.groovy
index d9050e9cdc1..326fa69d376 100644
--- a/regression-test/suites/empty_relation/eliminate_empty.groovy
+++ b/regression-test/suites/empty_relation/eliminate_empty.groovy
@@ -127,4 +127,40 @@ suite("eliminate_empty") {
qt_except_empty_data """
select r_regionkey from region where false except select n_nationkey
from nation
"""
+
+ sql """
+ drop table if exists eliminate_partition_prune;
+ """
+ sql """
+ CREATE TABLE `eliminate_partition_prune` (
+ `k1` int(11) NULL COMMENT "",
+ `k2` int(11) NULL COMMENT "",
+ `k3` int(11) NULL COMMENT ""
+ )
+ PARTITION BY RANGE(`k1`, `k2`)
+ (PARTITION p1 VALUES LESS THAN ("3", "1"),
+ PARTITION p2 VALUES [("3", "1"), ("7", "10")),
+ PARTITION p3 VALUES [("7", "10"), ("10", "15")))
+ DISTRIBUTED BY HASH(`k1`) BUCKETS 10
+ PROPERTIES ('replication_num' = '1');
+ """
+
+
+ qt_prune_partition1 """
+ explain shape plan
+ select sum(k2)
+ from
+ (select * from eliminate_partition_prune where k1=100) T
+ group by k3;
+ """
+ sql """
+ insert into eliminate_partition_prune values (7, 0, 0)
+ """
+ qt_prune_partition2 """
+ explain shape plan
+ select sum(k2)
+ from
+ (select * from eliminate_partition_prune where k1=100) T
+ group by k3;
+ """
}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]