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 9d6b2dceb29 [fix](Nereids) non-slot filter should not be push through 
aggregate (#25525)
9d6b2dceb29 is described below

commit 9d6b2dceb29ce7bc2079b1df0c1861b68445a305
Author: morrySnow <101034200+morrys...@users.noreply.github.com>
AuthorDate: Tue Oct 17 18:02:26 2023 +0800

    [fix](Nereids) non-slot filter should not be push through aggregate (#25525)
---
 .../rewrite/PushdownFilterThroughAggregation.java  |  8 ++--
 .../filter_push_through_aggregate.out              |  3 ++
 .../filter_push_through_aggregate.groovy           | 43 ++++++++++++++++++++++
 3 files changed, 51 insertions(+), 3 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PushdownFilterThroughAggregation.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PushdownFilterThroughAggregation.java
index 217834c4bdc..45fa1c645b2 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PushdownFilterThroughAggregation.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PushdownFilterThroughAggregation.java
@@ -26,6 +26,7 @@ import 
org.apache.doris.nereids.trees.plans.logical.LogicalAggregate;
 import org.apache.doris.nereids.trees.plans.logical.LogicalFilter;
 import org.apache.doris.nereids.util.PlanUtils;
 
+import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Sets;
 
 import java.util.HashSet;
@@ -63,17 +64,18 @@ public class PushdownFilterThroughAggregation extends 
OneRewriteRuleFactory {
             Set<Expression> filterPredicates = Sets.newHashSet();
             filter.getConjuncts().forEach(conjunct -> {
                 Set<Slot> conjunctSlots = conjunct.getInputSlots();
-                if (canPushDownSlots.containsAll(conjunctSlots)) {
+                // NOTICE: filter not contain slot should not be pushed. e.g. 
'a' = 'b'
+                if (!conjunctSlots.isEmpty() && 
canPushDownSlots.containsAll(conjunctSlots)) {
                     pushDownPredicates.add(conjunct);
                 } else {
                     filterPredicates.add(conjunct);
                 }
             });
-            if (pushDownPredicates.size() == 0) {
+            if (pushDownPredicates.isEmpty()) {
                 return null;
             }
             Plan bottomFilter = new LogicalFilter<>(pushDownPredicates, 
aggregate.child(0));
-            aggregate = (LogicalAggregate<Plan>) 
aggregate.withChildren(bottomFilter);
+            aggregate = aggregate.withChildren(ImmutableList.of(bottomFilter));
             return PlanUtils.filterOrSelf(filterPredicates, aggregate);
         }).toRule(RuleType.PUSHDOWN_PREDICATE_THROUGH_AGGREGATION);
     }
diff --git 
a/regression-test/data/nereids_rules_p0/filter_push_down/filter_push_through_aggregate.out
 
b/regression-test/data/nereids_rules_p0/filter_push_down/filter_push_through_aggregate.out
new file mode 100644
index 00000000000..816c5d8a9ca
--- /dev/null
+++ 
b/regression-test/data/nereids_rules_p0/filter_push_down/filter_push_through_aggregate.out
@@ -0,0 +1,3 @@
+-- This file is automatically generated. You should know what you did if you 
want to edit this
+-- !do_not_push_no_slot_filter --
+
diff --git 
a/regression-test/suites/nereids_rules_p0/filter_push_down/filter_push_through_aggregate.groovy
 
b/regression-test/suites/nereids_rules_p0/filter_push_down/filter_push_through_aggregate.groovy
new file mode 100644
index 00000000000..dfb65dd2466
--- /dev/null
+++ 
b/regression-test/suites/nereids_rules_p0/filter_push_down/filter_push_through_aggregate.groovy
@@ -0,0 +1,43 @@
+// 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("filter_push_through_aggregate") {
+    sql "SET enable_nereids_planner=true"
+    sql "SET enable_fallback_to_original_planner=false"
+
+    sql """
+        DROP TABLE IF EXISTS filter_push_through_aggregate
+       """
+    sql """
+    CREATE TABLE IF NOT EXISTS filter_push_through_aggregate(
+      `id` int(11) NULL,
+      `msg` text NULL
+    ) ENGINE = OLAP
+    DISTRIBUTED BY HASH(id) BUCKETS 4
+    PROPERTIES (
+      "replication_allocation" = "tag.location.default: 1"
+    );
+    """
+
+    sql "set disable_nereids_rules='REWRITE_FILTER_EXPRESSION'"
+
+    // 'a' = 'b' should not be push down aggregate.
+    qt_do_not_push_no_slot_filter """
+        select * from (select 'a' a, sum(1) from 
filter_push_through_aggregate) t where a = 'b';
+    """
+}
+


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to