This is an automated email from the ASF dual-hosted git repository. morningman pushed a commit to branch branch-1.2-lts in repository https://gitbox.apache.org/repos/asf/doris.git
commit 6b72aa0dbf46021bef61a942a00eba11f6408365 Author: AKIRA <33112463+kikyou1...@users.noreply.github.com> AuthorDate: Sun Jun 25 20:14:20 2023 +0900 [fix](planner) fix push filter through agg #21080 In the previous implementation, the check for groupby exprs was ignored. Add this necessary check to make sure it would work You could reproduce it by runnning belowing sql: CREATE TABLE t_push_filter_through_agg (col1 varchar(11451) not null, col2 int not null, col3 int not null) UNIQUE KEY(col1) DISTRIBUTED BY HASH(col1) BUCKETS 3 PROPERTIES( "replication_num"="1" ); CREATE VIEW `view_i` AS SELECT `b`.`col1` AS `col1`, `b`.`col2` AS `col2` FROM ( SELECT `col1` AS `col1`, sum(`cost`) AS `col2` FROM ( SELECT `col1` AS `col1`, sum(CAST(`col3` AS INT)) AS `cost` FROM `t_push_filter_through_agg` GROUP BY `col1` ) a GROUP BY `col1` ) b; SELECT SUM(`total_cost`) FROM view_a WHERE `dt` BETWEEN '2023-06-12' AND '2023-06-18' LIMIT 1; --- .../apache/doris/planner/SingleNodePlanner.java | 6 +++ .../query_p0/aggregate/push_filter_through_agg.out | 4 ++ .../aggregate/push_filter_through_agg.groovy | 59 ++++++++++++++++++++++ 3 files changed, 69 insertions(+) diff --git a/fe/fe-core/src/main/java/org/apache/doris/planner/SingleNodePlanner.java b/fe/fe-core/src/main/java/org/apache/doris/planner/SingleNodePlanner.java index 1be176bd46..ef080ba6ab 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/planner/SingleNodePlanner.java +++ b/fe/fe-core/src/main/java/org/apache/doris/planner/SingleNodePlanner.java @@ -2716,6 +2716,12 @@ public class SingleNodePlanner { } } } + GroupByClause groupByClause = stmt.getGroupByClause(); + List<Expr> exprs = groupByClause.getGroupingExprs(); + if (!exprs.contains(sourceExpr)) { + isAllSlotReferToGroupBys = false; + break; + } } if (isAllSlotReferToGroupBys) { diff --git a/regression-test/data/query_p0/aggregate/push_filter_through_agg.out b/regression-test/data/query_p0/aggregate/push_filter_through_agg.out new file mode 100644 index 0000000000..e011475a94 --- /dev/null +++ b/regression-test/data/query_p0/aggregate/push_filter_through_agg.out @@ -0,0 +1,4 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !sql -- +\N + diff --git a/regression-test/suites/query_p0/aggregate/push_filter_through_agg.groovy b/regression-test/suites/query_p0/aggregate/push_filter_through_agg.groovy new file mode 100644 index 0000000000..82ee73c4f2 --- /dev/null +++ b/regression-test/suites/query_p0/aggregate/push_filter_through_agg.groovy @@ -0,0 +1,59 @@ +// 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_through_agg") { + sql """ + CREATE TABLE t_push_filter_through_agg (col1 varchar(11451) not null, col2 int not null, col3 int not null) + UNIQUE KEY(col1) + DISTRIBUTED BY HASH(col1) + BUCKETS 3 + PROPERTIES( + "replication_num"="1" + ); + """ + + sql """ + CREATE VIEW `view_i` AS + SELECT + `b`.`col1` AS `col1`, + `b`.`col2` AS `col2` + FROM + ( + SELECT + `col1` AS `col1`, + sum(`cost`) AS `col2` + FROM + ( + SELECT + `col1` AS `col1`, + sum( + CAST(`col3` AS INT) + ) AS `cost` + FROM + `t_push_filter_through_agg` + GROUP BY + `col1` + ) a + GROUP BY + `col1` + ) b; + """ + + qt_sql """ + SELECT SUM(`col2`) FROM view_i WHERE `col1` BETWEEN 10 AND 20 LIMIT 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