[fix](planner)push constant expr in predicate to outer join's other conjuncts by mistake (#11527)

constant expr in predicate should not be pushed to outer join's other conjuncts
This commit is contained in:
morrySnow
2022-08-08 20:56:08 +08:00
committed by GitHub
parent 4f60b37402
commit 1701ffa7c0
3 changed files with 68 additions and 4 deletions

View File

@ -1559,24 +1559,24 @@ public class SingleNodePlanner {
// 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 is't outer join.
// 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 TableRef joinOuterChild = select.getTableRefs().get(0);
final List<Expr> cloneConjuncts = cloneExprs(newConjuncts);
viewAnalyzer.registerConjuncts(cloneConjuncts, joinOuterChild.getDesc().getId().asList());
}
continue;
}
viewAnalyzer.registerOnClauseConjuncts(newConjuncts, joinInnerChild);
viewAnalyzer.registerConjuncts(newConjuncts, joinOuterChild.getId());
break;
}
} else {
Preconditions.checkArgument(select.getTableRefs().size() == 1);
viewAnalyzer.registerConjuncts(newConjuncts, select.getTableRefs().get(0).getDesc().getId().asList());
viewAnalyzer.registerConjuncts(newConjuncts, select.getTableRefs().get(0).getId());
}
} else {
Preconditions.checkArgument(stmt instanceof SetOperationStmt);

View File

@ -0,0 +1,3 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !select --

View File

@ -0,0 +1,61 @@
// 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("constant_push_down_through_outer_join") {
sql """ DROP TABLE IF EXISTS wftest1 """
sql """ DROP TABLE IF EXISTS wftest2 """
sql """
CREATE TABLE `wftest1` (
`aa` varchar(200) NULL COMMENT "",
`bb` int NULL COMMENT ""
) ENGINE=OLAP
UNIQUE KEY (`aa`) COMMENT "aa"
DISTRIBUTED BY HASH(`aa`) BUCKETS 3
PROPERTIES (
"replication_allocation" = "tag.location.default: 1",
"in_memory" = "false",
"storage_format" = "V2"
)
"""
sql """
CREATE TABLE `wftest2` (
`cc` varchar(200) NULL COMMENT "",
`dd` int NULL COMMENT ""
) ENGINE=OLAP
UNIQUE KEY (`cc`)
COMMENT "OLAP"
DISTRIBUTED BY HASH(`cc`) BUCKETS 3
PROPERTIES (
"replication_allocation" = "tag.location.default: 1",
"in_memory" = "false",
"storage_format" = "V2"
)
"""
sql """
INSERT INTO wftest1 VALUES('a', 1), ('b', 1), ('c', 1);
"""
sql """
INSERT INTO wftest2 VALUES('a', 1), ('b', 1), ('d', 1);
"""
order_qt_select """
select t.* from (select * from wftest1 t1 left join wftest2 t2 on t1.aa=t2.cc) t where dayofweek(current_date())=8;
"""
}