This is an automated email from the ASF dual-hosted git repository. dataroaring pushed a commit to branch branch-2.0 in repository https://gitbox.apache.org/repos/asf/doris.git
commit 9357a7f9fa216d919e44ebc343b078f22800ad07 Author: starocean999 <40539150+starocean...@users.noreply.github.com> AuthorDate: Tue Jul 18 14:17:07 2023 +0800 [fix](planner) push conjuncts into SetOperationStmt inline view (#21718) * [fix](planner)push conjuncts into SetOperationStmt inline view --- .../apache/doris/planner/SingleNodePlanner.java | 23 ++++++++ .../test_push_conjuncts_inlineview.groovy | 65 ++++++++++++++++++++++ 2 files changed, 88 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 82495ce243..0d3d65e88c 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 @@ -21,6 +21,7 @@ package org.apache.doris.planner; import org.apache.doris.analysis.AggregateInfo; +import org.apache.doris.analysis.AnalyticExpr; import org.apache.doris.analysis.AnalyticInfo; import org.apache.doris.analysis.Analyzer; import org.apache.doris.analysis.AssertNumRowsElement; @@ -272,6 +273,13 @@ public class SingleNodePlanner { AggregateInfo aggInfo = selectStmt.getAggInfo(); root = analyticPlanner.createSingleNodePlan(root, aggInfo != null ? aggInfo.getGroupingExprs() : null, inputPartitionExprs); + List<Expr> predicates = getBoundPredicates(analyzer, + selectStmt.getAnalyticInfo().getOutputTupleDesc()); + if (!predicates.isEmpty()) { + root = new SelectNode(ctx.getNextNodeId(), root, predicates); + root.init(analyzer); + Preconditions.checkState(root.hasValidStats()); + } if (aggInfo != null && !inputPartitionExprs.isEmpty()) { // analytic computation will benefit from a partition on inputPartitionExprs aggInfo.setPartitionExprs(inputPartitionExprs); @@ -1813,6 +1821,17 @@ public class SingleNodePlanner { e.setIsOnClauseConjunct(false); } inlineViewRef.getAnalyzer().registerConjuncts(viewPredicates, inlineViewRef.getAllTupleIds()); + QueryStmt queryStmt = inlineViewRef.getQueryStmt(); + if (queryStmt instanceof SetOperationStmt) { + // registerConjuncts for every set operand + SetOperationStmt setOperationStmt = (SetOperationStmt) queryStmt; + for (SetOperationStmt.SetOperand setOperand : setOperationStmt.getOperands()) { + setOperand.getAnalyzer().registerConjuncts( + Expr.substituteList(viewPredicates, setOperand.getSmap(), + setOperand.getAnalyzer(), false), + inlineViewRef.getAllTupleIds()); + } + } // mark (fully resolve) slots referenced by remaining unassigned conjuncts as // materialized @@ -2746,6 +2765,10 @@ public class SingleNodePlanner { } sourceExpr = slotDesc.getSourceExprs().get(0); } + if (sourceExpr instanceof AnalyticExpr) { + isAllSlotReferToGroupBys = false; + break; + } // if grouping set is given and column is not in all grouping set list // we cannot push the predicate since the column value can be null if (stmt.getGroupByClause() == null) { diff --git a/regression-test/suites/correctness_p0/test_push_conjuncts_inlineview.groovy b/regression-test/suites/correctness_p0/test_push_conjuncts_inlineview.groovy new file mode 100644 index 0000000000..80a35194f6 --- /dev/null +++ b/regression-test/suites/correctness_p0/test_push_conjuncts_inlineview.groovy @@ -0,0 +1,65 @@ +// 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("test_push_conjuncts_inlineview") { + sql """ set enable_nereids_planner=false""" + sql """ DROP TABLE IF EXISTS `push_conjunct_table` """ + sql """ + CREATE TABLE `push_conjunct_table` ( + `a_key` varchar(255) NULL , + `d_key` varchar(255) NULL , + `c_key` varchar(32) NULL , + `b_key` date NOT NULL + ) ENGINE=OLAP + UNIQUE KEY(`a_key`, `d_key`, `c_key`) + DISTRIBUTED BY HASH(`a_key`, `d_key`, `c_key`) BUCKETS 4 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "in_memory" = "false", + "storage_format" = "V2", + "disable_auto_compaction" = "false" + ); + """ + explain { + sql("""select + 1 + from + ( + select + rank() over( + partition by a_key + , c_key + , d_key + order by + b_key desc + ) as px + from + push_conjunct_table a + + union all + select 2 as px + from + push_conjunct_table a + )a + where + a.px = 1;""") + contains "4:VSELECT" + } + + sql """ DROP TABLE IF EXISTS `push_conjunct_table` """ +} + --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org