diff --git a/fe/fe-core/src/main/java/org/apache/doris/planner/HashJoinNode.java b/fe/fe-core/src/main/java/org/apache/doris/planner/HashJoinNode.java index 1d0d684bc8..3221b542e8 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/planner/HashJoinNode.java +++ b/fe/fe-core/src/main/java/org/apache/doris/planner/HashJoinNode.java @@ -441,6 +441,11 @@ public class HashJoinNode extends PlanNode { int rightNullableNumber = 0; if (copyLeft) { for (TupleDescriptor leftTupleDesc : analyzer.getDescTbl().getTupleDesc(getChild(0).getOutputTblRefIds())) { + // if the child is cross join node, the only way to get the correct nullable info of its output slots + // is to check if the output tuple ids are outer joined or not. + // then pass this nullable info to hash join node will be correct. + boolean needSetToNullable = + getChild(0) instanceof CrossJoinNode && analyzer.isOuterJoined(leftTupleDesc.getId()); for (SlotDescriptor leftSlotDesc : leftTupleDesc.getSlots()) { if (!isMaterailizedByChild(leftSlotDesc, getChild(0).getOutputSmap())) { continue; @@ -451,6 +456,9 @@ public class HashJoinNode extends PlanNode { outputSlotDesc.setIsNullable(true); leftNullableNumber++; } + if (needSetToNullable) { + outputSlotDesc.setIsNullable(true); + } srcTblRefToOutputTupleSmap.put(new SlotRef(leftSlotDesc), new SlotRef(outputSlotDesc)); } } @@ -458,6 +466,8 @@ public class HashJoinNode extends PlanNode { if (copyRight) { for (TupleDescriptor rightTupleDesc : analyzer.getDescTbl() .getTupleDesc(getChild(1).getOutputTblRefIds())) { + boolean needSetToNullable = + getChild(1) instanceof CrossJoinNode && analyzer.isOuterJoined(rightTupleDesc.getId()); for (SlotDescriptor rightSlotDesc : rightTupleDesc.getSlots()) { if (!isMaterailizedByChild(rightSlotDesc, getChild(1).getOutputSmap())) { continue; @@ -468,6 +478,9 @@ public class HashJoinNode extends PlanNode { outputSlotDesc.setIsNullable(true); rightNullableNumber++; } + if (needSetToNullable) { + outputSlotDesc.setIsNullable(true); + } srcTblRefToOutputTupleSmap.put(new SlotRef(rightSlotDesc), new SlotRef(outputSlotDesc)); } } diff --git a/regression-test/data/correctness_p0/test_outer_join_with_cross_join.out b/regression-test/data/correctness_p0/test_outer_join_with_cross_join.out new file mode 100644 index 0000000000..72d126351a --- /dev/null +++ b/regression-test/data/correctness_p0/test_outer_join_with_cross_join.out @@ -0,0 +1,4 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !select -- +1 + diff --git a/regression-test/suites/correctness_p0/test_outer_join_with_cross_join.groovy b/regression-test/suites/correctness_p0/test_outer_join_with_cross_join.groovy new file mode 100644 index 0000000000..f2162e8174 --- /dev/null +++ b/regression-test/suites/correctness_p0/test_outer_join_with_cross_join.groovy @@ -0,0 +1,115 @@ +// 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_outer_join_with_cross_join") { + sql """ + drop table if exists outerjoin_A; + """ + + sql """ + drop table if exists outerjoin_B; + """ + + sql """ + drop table if exists outerjoin_C; + """ + + sql """ + drop table if exists outerjoin_D; + """ + + sql """ + create table outerjoin_A ( a int not null ) + ENGINE=OLAP + DISTRIBUTED BY HASH(a) BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "in_memory" = "false", + "storage_format" = "V2" + ); + """ + + sql """ + create table outerjoin_B ( a int not null ) + ENGINE=OLAP + DISTRIBUTED BY HASH(a) BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "in_memory" = "false", + "storage_format" = "V2" + ); + """ + + sql """ + create table outerjoin_C ( a int not null ) + ENGINE=OLAP + DISTRIBUTED BY HASH(a) BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "in_memory" = "false", + "storage_format" = "V2" + ); + """ + + sql """ + create table outerjoin_D ( a int not null ) + ENGINE=OLAP + DISTRIBUTED BY HASH(a) BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "in_memory" = "false", + "storage_format" = "V2" + ); + """ + + sql """ + insert into outerjoin_A values( 1 ); + """ + + sql """ + insert into outerjoin_B values( 1 ); + """ + + sql """ + insert into outerjoin_C values( 1 ); + """ + + sql """ + insert into outerjoin_D values( 1 ); + """ + + qt_select """ + select outerjoin_B.a from outerjoin_A left join outerjoin_B on outerjoin_A.a = outerjoin_B.a + inner join outerjoin_C on true left join outerjoin_D on outerjoin_B.a = outerjoin_D.a; + """ + + sql """ + drop table if exists outerjoin_A; + """ + + sql """ + drop table if exists outerjoin_B; + """ + + sql """ + drop table if exists outerjoin_C; + """ + + sql """ + drop table if exists outerjoin_D; + """ +}