[fix](Nereids) non-slot filter should not be push through aggregate (#25525)
This commit is contained in:
@ -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);
|
||||
}
|
||||
|
||||
@ -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 --
|
||||
|
||||
@ -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';
|
||||
"""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user