This is an automated email from the ASF dual-hosted git repository. yiguolei 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 e7c1d81419 [fix](planner) Pushdown constant predicate to all scan node in the lieteral view. #16217 e7c1d81419 is described below commit e7c1d814193087bc27584e22b2f9d5cdfbbf7f1a Author: AKIRA <33112463+kikyou1...@users.noreply.github.com> AuthorDate: Mon Jan 30 22:18:43 2023 +0800 [fix](planner) Pushdown constant predicate to all scan node in the lieteral view. #16217 Before this PR, planner might push a constant FALSE predicate to the wrong scan nodes in the literal view, and make this predicate useless --- .../apache/doris/planner/SingleNodePlanner.java | 23 ++---- .../data/query_p0/literal_view/lietral_test.out | 3 + .../query_p0/literal_view/lietral_test.groovy | 88 ++++++++++++++++++++++ 3 files changed, 96 insertions(+), 18 deletions(-) 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 c8b9f12d04..199e0c623a 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 @@ -1769,7 +1769,7 @@ public class SingleNodePlanner { return; } - final List<Expr> newConjuncts = cloneExprs(conjuncts); + List<Expr> newConjuncts = cloneExprs(conjuncts); final QueryStmt stmt = inlineViewRef.getViewStmt(); final Analyzer viewAnalyzer = inlineViewRef.getAnalyzer(); viewAnalyzer.markConjunctsAssigned(conjuncts); @@ -1778,23 +1778,10 @@ public class SingleNodePlanner { if (select.getAggInfo() != null) { viewAnalyzer.registerConjuncts(newConjuncts, select.getAggInfo().getOutputTupleId().asList()); } else if (select.getTableRefs().size() > 1) { - // Conjuncts will be assigned to the lowest outer join node or non-outer join's leaf children. - for (int i = select.getTableRefs().size(); i > 1; i--) { - final TableRef joinInnerChild = select.getTableRefs().get(i - 1); - final TableRef joinOuterChild = select.getTableRefs().get(i - 2); - if (!joinInnerChild.getJoinOp().isOuterJoin()) { - // lowest join isn't outer join. - if (i == 2) { - // Register constant for inner. - viewAnalyzer.registerConjuncts(newConjuncts, joinInnerChild.getDesc().getId().asList()); - // Register constant for outer. - final List<Expr> cloneConjuncts = cloneExprs(newConjuncts); - viewAnalyzer.registerConjuncts(cloneConjuncts, joinOuterChild.getDesc().getId().asList()); - } - continue; - } - viewAnalyzer.registerConjuncts(newConjuncts, joinOuterChild.getId()); - break; + for (int i = select.getTableRefs().size() - 1; i >= 0; i--) { + viewAnalyzer.registerConjuncts(newConjuncts, + select.getTableRefs().get(i).getDesc().getId().asList()); + newConjuncts = cloneExprs(newConjuncts); } } else { Preconditions.checkArgument(select.getTableRefs().size() == 1); diff --git a/regression-test/data/query_p0/literal_view/lietral_test.out b/regression-test/data/query_p0/literal_view/lietral_test.out new file mode 100644 index 0000000000..9c9c4c6c8a --- /dev/null +++ b/regression-test/data/query_p0/literal_view/lietral_test.out @@ -0,0 +1,3 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !sql -- + diff --git a/regression-test/suites/query_p0/literal_view/lietral_test.groovy b/regression-test/suites/query_p0/literal_view/lietral_test.groovy new file mode 100644 index 0000000000..1db3f6d720 --- /dev/null +++ b/regression-test/suites/query_p0/literal_view/lietral_test.groovy @@ -0,0 +1,88 @@ +// 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("literal_view_test") { + + sql """DROP TABLE IF EXISTS table1""" + + sql """ + CREATE table table1( + `a` varchar(150) NULL COMMENT "", + `b` varchar(60) NULL COMMENT "" + )ENGINE=OLAP + UNIQUE KEY(`a`, `b`) + DISTRIBUTED BY HASH(`b`) BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "in_memory" = "false", + "storage_format" = "V2" + ); + """ + + sql """ + INSERT into table1 + values('org1','code1'); + """ + + sql """DROP TABLE IF EXISTS table2""" + + sql """ + CREATE table table2( + `c` varchar(40) NOT NULL COMMENT "c" + )ENGINE=OLAP + UNIQUE KEY(`c`) + DISTRIBUTED BY HASH(`c`) BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "in_memory" = "false", + "storage_format" = "V2" + ); + + """ + + sql """DROP TABLE IF EXISTS table3""" + + sql """ + CREATE table table3 ( + `c` varchar(40) NOT NULL COMMENT "c" + )ENGINE=OLAP + UNIQUE KEY(`c`) + DISTRIBUTED BY HASH(`c`) BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "in_memory" = "false", + "storage_format" = "V2" + ); + """ + + sql """DROP VIEW IF EXISTS `test_v`""" + + sql """ + CREATE view `test_v` as + select t1.b + from table1 as t1 + left outer JOIN table2 as org ON t1.a = org.c + left outer join table3 as doi on t1.a = doi.c + ; + """ + + qt_sql """ + SELECT b + FROM test_v + WHERE substring('2022-12',6,2)='01'; + """ +} --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org