This is an automated email from the ASF dual-hosted git repository. yiguolei pushed a commit to branch branch-2.1 in repository https://gitbox.apache.org/repos/asf/doris.git
commit d2df392994e8dc00dfb5f8e49cca83fca97cb565 Author: minghong <engle...@gmail.com> AuthorDate: Tue May 28 10:48:48 2024 +0800 [fix](nereids) push filter through window, using slot equal-set (#35361) example: filter (y=1) +-- window( ... partition by x) +-- project( A as x, A as y) filter(y=1) is equivalent to filter(x=1), because x and y are in the same equal-set in window#logicalProperties. And hence we could push filter(y=1) through window operator --- .../nereids/properties/FunctionalDependencies.java | 4 ++ .../doris/nereids/trees/plans/algebra/Window.java | 12 ++++++ .../tpch/push_filter_window_eqset.out | 12 ++++++ .../tpch/push_filter_window_eqset.groovy | 46 ++++++++++++++++++++++ 4 files changed, 74 insertions(+) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/properties/FunctionalDependencies.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/properties/FunctionalDependencies.java index a516bf9ae1c..80ea1b025c6 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/properties/FunctionalDependencies.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/properties/FunctionalDependencies.java @@ -106,6 +106,10 @@ public class FunctionalDependencies { return equalSet.calEqualSetList(); } + public Set<Slot> calEqualSet(Slot s) { + return equalSet.calEqualSet(s); + } + public ImmutableSet<FdItem> getFdItems() { return fdItems; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/algebra/Window.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/algebra/Window.java index 00d290940e0..1dacda593dc 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/algebra/Window.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/algebra/Window.java @@ -25,6 +25,7 @@ import org.apache.doris.nereids.glue.translator.PlanTranslatorContext; import org.apache.doris.nereids.trees.expressions.Alias; import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.expressions.NamedExpression; +import org.apache.doris.nereids.trees.expressions.Slot; import org.apache.doris.nereids.trees.expressions.SlotReference; import org.apache.doris.nereids.trees.expressions.WindowExpression; import org.apache.doris.nereids.trees.expressions.WindowFrame; @@ -32,6 +33,7 @@ import org.apache.doris.nereids.trees.expressions.WindowFrame.FrameBoundType; import org.apache.doris.nereids.trees.expressions.WindowFrame.FrameBoundary; import org.apache.doris.nereids.trees.expressions.WindowFrame.FrameUnitsType; import org.apache.doris.nereids.trees.expressions.literal.Literal; +import org.apache.doris.nereids.trees.plans.logical.LogicalWindow; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Maps; @@ -115,6 +117,16 @@ public interface Window { int winExprCount = getWindowExpressions().size(); for (Map.Entry<Expression, Integer> entry : partitionKeyCount.entrySet()) { if (entry.getValue() == winExprCount && entry.getKey() instanceof SlotReference) { + SlotReference slot = (SlotReference) entry.getKey(); + if (this instanceof LogicalWindow) { + LogicalWindow lw = (LogicalWindow) this; + Set<Slot> equalSlots = lw.getLogicalProperties().getTrait().calEqualSet(slot); + for (Slot other : equalSlots) { + if (other instanceof SlotReference) { + commonPartitionKeySet.add((SlotReference) other); + } + } + } commonPartitionKeySet.add((SlotReference) entry.getKey()); } } diff --git a/regression-test/data/nereids_tpch_p0/tpch/push_filter_window_eqset.out b/regression-test/data/nereids_tpch_p0/tpch/push_filter_window_eqset.out new file mode 100644 index 00000000000..0a14dd5f07c --- /dev/null +++ b/regression-test/data/nereids_tpch_p0/tpch/push_filter_window_eqset.out @@ -0,0 +1,12 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !eqset -- +PhysicalResultSink +--PhysicalDistribute[DistributionSpecGather] +----PhysicalProject +------PhysicalWindow +--------PhysicalQuickSort[LOCAL_SORT] +----------PhysicalDistribute[DistributionSpecHash] +------------PhysicalProject +--------------filter((region.r_regionkey = 1)) +----------------PhysicalOlapScan[region] + diff --git a/regression-test/suites/nereids_tpch_p0/tpch/push_filter_window_eqset.groovy b/regression-test/suites/nereids_tpch_p0/tpch/push_filter_window_eqset.groovy new file mode 100644 index 00000000000..e6926b8dd6a --- /dev/null +++ b/regression-test/suites/nereids_tpch_p0/tpch/push_filter_window_eqset.groovy @@ -0,0 +1,46 @@ +/* + * 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("push_filter_window_eqset") { + String db = context.config.getDbNameByFile(new File(context.file.parent)) + sql "use ${db}" + sql 'set enable_nereids_planner=true' + sql 'set enable_fallback_to_original_planner=false'; + + /** + check the filter is pushed through window + PhysicalResultSink + --PhysicalDistribute[DistributionSpecGather] + ----PhysicalProject + ------PhysicalWindow + --------PhysicalQuickSort[LOCAL_SORT] + ----------PhysicalDistribute[DistributionSpecHash] + ------------PhysicalProject + >>>>>--------filter((region.r_regionkey = 1)) + ----------------PhysicalOlapScan[region] + **/ + qt_eqset """ + explain shape plan + select y + from ( + select r_regionkey as x, r_regionkey as y, row_number() over(partition by r_regionkey) as rn from region + ) T + where y = 1; + """ +} \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org